2022-03-20 12:35:43 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.admin;
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.config.MainConfig;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
2014-11-29 19:16:00 +00:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2012-11-13 01:42:30 +00:00
|
|
|
import org.bukkit.configuration.ConfigurationSection;
|
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
public class Admin
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
2014-04-09 20:33:03 +00:00
|
|
|
private final UUID uuid;
|
|
|
|
private String lastLoginName;
|
2022-03-22 18:22:16 +00:00
|
|
|
private String loginMessage;
|
2013-08-25 16:32:01 +00:00
|
|
|
private final boolean isSeniorAdmin;
|
2013-09-27 15:01:30 +00:00
|
|
|
private final boolean isTelnetAdmin;
|
2013-08-25 16:32:01 +00:00
|
|
|
private final List<String> consoleAliases;
|
2013-09-27 15:01:30 +00:00
|
|
|
private final List<String> ips;
|
2013-08-25 16:32:01 +00:00
|
|
|
private Date lastLogin;
|
|
|
|
private boolean isActivated;
|
2012-11-13 01:42:30 +00:00
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
public Admin(UUID uuid, String lastLoginName, Date lastLogin, String loginMessage, boolean isTelnetAdmin, boolean isSeniorAdmin, boolean isActivated)
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
2014-04-09 20:33:03 +00:00
|
|
|
this.uuid = uuid;
|
|
|
|
this.lastLoginName = lastLoginName;
|
2014-04-21 15:45:32 +00:00
|
|
|
this.ips = new ArrayList<String>();
|
2013-08-25 16:32:01 +00:00
|
|
|
this.lastLogin = lastLogin;
|
|
|
|
this.loginMessage = loginMessage;
|
2013-09-27 15:01:30 +00:00
|
|
|
this.isTelnetAdmin = isTelnetAdmin;
|
2015-05-13 12:56:38 +00:00
|
|
|
this.isSeniorAdmin = isSeniorAdmin;
|
2014-04-21 15:45:32 +00:00
|
|
|
this.consoleAliases = new ArrayList<String>();
|
2013-08-25 16:32:01 +00:00
|
|
|
this.isActivated = isActivated;
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
public Admin(UUID uuid, ConfigurationSection section)
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
2014-04-09 20:33:03 +00:00
|
|
|
this.uuid = uuid;
|
|
|
|
this.lastLoginName = section.getString("last_login_name");
|
2012-11-13 01:42:30 +00:00
|
|
|
this.ips = section.getStringList("ips");
|
2022-03-20 12:35:43 +00:00
|
|
|
this.lastLogin = Utilities.stringToDate(section.getString("last_login", Utilities.dateToString(new Date(0L))));
|
2013-08-25 16:32:01 +00:00
|
|
|
this.loginMessage = section.getString("custom_login_message", "");
|
|
|
|
this.isSeniorAdmin = section.getBoolean("is_senior_admin", false);
|
2013-09-27 15:01:30 +00:00
|
|
|
this.isTelnetAdmin = section.getBoolean("is_telnet_admin", false);
|
2013-08-25 16:32:01 +00:00
|
|
|
this.consoleAliases = section.getStringList("console_aliases");
|
|
|
|
this.isActivated = section.getBoolean("is_activated", true);
|
2014-10-30 18:44:05 +00:00
|
|
|
|
2022-03-20 12:35:43 +00:00
|
|
|
for (Iterator<?> it = MainConfig.getList(ConfigurationEntry.NOADMIN_IPS).iterator(); it.hasNext();)
|
2014-10-30 18:44:05 +00:00
|
|
|
{
|
|
|
|
ips.remove((String) it.next());
|
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString()
|
|
|
|
{
|
2014-04-09 20:33:03 +00:00
|
|
|
final StringBuilder output = new StringBuilder();
|
2022-03-29 22:01:21 +00:00
|
|
|
final ArrayList<String> fuzziedIps = new ArrayList<>();
|
|
|
|
|
|
|
|
for (String ip : ips)
|
|
|
|
{
|
|
|
|
fuzziedIps.add(Utilities.getFuzzyIp(ip));
|
|
|
|
}
|
2014-04-09 20:33:03 +00:00
|
|
|
|
|
|
|
output.append("UUID: ").append(uuid.toString()).append("\n");
|
|
|
|
output.append("- Last Login Name: ").append(lastLoginName).append("\n");
|
2022-03-29 22:01:21 +00:00
|
|
|
output.append("- IPs: ").append(StringUtils.join(fuzziedIps, ", ")).append("\n");
|
2022-03-20 12:35:43 +00:00
|
|
|
output.append("- Last Login: ").append(Utilities.dateToString(lastLogin)).append("\n");
|
2014-04-09 20:33:03 +00:00
|
|
|
output.append("- Custom Login Message: ").append(loginMessage).append("\n");
|
|
|
|
output.append("- Is Senior Admin: ").append(isSeniorAdmin).append("\n");
|
|
|
|
output.append("- Is Telnet Admin: ").append(isTelnetAdmin).append("\n");
|
|
|
|
output.append("- Console Aliases: ").append(StringUtils.join(consoleAliases, ", ")).append("\n");
|
|
|
|
output.append("- Is Activated: ").append(isActivated);
|
2012-11-13 01:42:30 +00:00
|
|
|
|
|
|
|
return output.toString();
|
|
|
|
}
|
|
|
|
|
2014-04-09 20:33:03 +00:00
|
|
|
public UUID getUniqueId()
|
|
|
|
{
|
|
|
|
return uuid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLastLoginName(String lastLoginName)
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
2014-04-09 20:33:03 +00:00
|
|
|
this.lastLoginName = lastLoginName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getLastLoginName()
|
|
|
|
{
|
|
|
|
return lastLoginName;
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<String> getIps()
|
|
|
|
{
|
2014-04-04 12:03:48 +00:00
|
|
|
return Collections.unmodifiableList(ips);
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
|
|
|
|
2014-04-09 20:33:03 +00:00
|
|
|
public void addIp(String ip)
|
|
|
|
{
|
|
|
|
if (!ips.contains(ip))
|
|
|
|
{
|
|
|
|
ips.add(ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-28 20:23:17 +00:00
|
|
|
public void addIps(List<String> ips)
|
|
|
|
{
|
|
|
|
for (String ip : ips)
|
|
|
|
{
|
|
|
|
addIp(ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-05 12:10:32 +00:00
|
|
|
public void removeIp(String ip)
|
|
|
|
{
|
2022-03-21 17:11:24 +00:00
|
|
|
ips.remove(ip);
|
2014-05-05 12:10:32 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 23:59:29 +00:00
|
|
|
public void clearIPs()
|
|
|
|
{
|
|
|
|
ips.clear();
|
|
|
|
}
|
|
|
|
|
2022-03-22 18:22:16 +00:00
|
|
|
public void setCustomLoginMessage(String newLoginMessage)
|
|
|
|
{
|
|
|
|
this.loginMessage = newLoginMessage;
|
|
|
|
}
|
|
|
|
|
2012-11-13 01:42:30 +00:00
|
|
|
public Date getLastLogin()
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
return lastLogin;
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getCustomLoginMessage()
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
return loginMessage;
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
2022-03-22 18:22:16 +00:00
|
|
|
|
2012-11-19 01:25:47 +00:00
|
|
|
public boolean isSeniorAdmin()
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
return isSeniorAdmin;
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 15:01:30 +00:00
|
|
|
public boolean isTelnetAdmin()
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
2013-09-27 15:01:30 +00:00
|
|
|
return isTelnetAdmin;
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-27 15:01:30 +00:00
|
|
|
public List<String> getConsoleAliases()
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
2014-04-09 20:33:03 +00:00
|
|
|
return Collections.unmodifiableList(consoleAliases);
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
public void setLastLogin(Date lastLogin)
|
2012-11-13 01:42:30 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
this.lastLogin = lastLogin;
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|
2012-11-19 01:25:47 +00:00
|
|
|
|
|
|
|
public boolean isActivated()
|
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
return isActivated;
|
2012-11-19 01:25:47 +00:00
|
|
|
}
|
|
|
|
|
2013-08-25 16:32:01 +00:00
|
|
|
public void setActivated(boolean isActivated)
|
2012-11-19 01:25:47 +00:00
|
|
|
{
|
2013-08-25 16:32:01 +00:00
|
|
|
this.isActivated = isActivated;
|
2012-11-19 01:25:47 +00:00
|
|
|
}
|
2012-11-13 01:42:30 +00:00
|
|
|
}
|