2020-08-15 06:44:57 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.staff;
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2020-06-30 07:25:38 +00:00
|
|
|
import java.sql.ResultSet;
|
|
|
|
import java.sql.SQLException;
|
2020-08-08 05:51:09 +00:00
|
|
|
import java.util.ArrayList;
|
2015-10-19 17:43:46 +00:00
|
|
|
import java.util.Date;
|
2020-05-29 10:14:21 +00:00
|
|
|
import java.util.HashMap;
|
2015-10-19 17:43:46 +00:00
|
|
|
import java.util.List;
|
2020-05-29 10:14:21 +00:00
|
|
|
import java.util.Map;
|
2015-10-19 17:43:46 +00:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2017-08-01 19:59:24 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode;
|
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2020-06-30 07:25:38 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2019-07-28 06:04:16 +00:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2015-10-19 17:43:46 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2020-08-15 06:44:57 +00:00
|
|
|
public class StaffMember
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private String name;
|
|
|
|
@Getter
|
2016-03-06 15:56:15 +00:00
|
|
|
private boolean active = true;
|
2015-10-19 17:43:46 +00:00
|
|
|
@Getter
|
|
|
|
@Setter
|
2020-09-28 03:17:01 +00:00
|
|
|
private Rank rank = Rank.ADMIN;
|
2015-10-19 17:43:46 +00:00
|
|
|
@Getter
|
2020-08-08 05:51:09 +00:00
|
|
|
private final List<String> ips = new ArrayList<>();
|
2015-10-19 17:43:46 +00:00
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private Date lastLogin = new Date();
|
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
private String loginMessage = null;
|
2017-12-29 18:12:47 +00:00
|
|
|
@Getter
|
|
|
|
@Setter
|
2018-04-19 14:29:19 +00:00
|
|
|
private Boolean commandSpy = false;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
2018-05-22 23:01:24 +00:00
|
|
|
private Boolean potionSpy = false;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
2018-06-01 22:39:52 +00:00
|
|
|
private String acFormat = null;
|
|
|
|
@Getter
|
|
|
|
@Setter
|
2020-09-14 09:36:25 +00:00
|
|
|
private String pteroID = null;
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2020-08-15 06:44:57 +00:00
|
|
|
public StaffMember(Player player)
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
|
|
|
this.name = player.getName();
|
2020-07-01 01:51:06 +00:00
|
|
|
this.ips.add(FUtil.getIp(player));
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 06:44:57 +00:00
|
|
|
public StaffMember(ResultSet resultSet)
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2020-06-30 07:25:38 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
this.name = resultSet.getString("username");
|
|
|
|
this.active = resultSet.getBoolean("active");
|
|
|
|
this.rank = Rank.findRank(resultSet.getString("rank"));
|
|
|
|
this.ips.clear();
|
|
|
|
this.ips.addAll(FUtil.stringToList(resultSet.getString("ips")));
|
|
|
|
this.lastLogin = new Date(resultSet.getLong("last_login"));
|
|
|
|
this.loginMessage = resultSet.getString("login_message");
|
|
|
|
this.commandSpy = resultSet.getBoolean("command_spy");
|
|
|
|
this.potionSpy = resultSet.getBoolean("potion_spy");
|
|
|
|
this.acFormat = resultSet.getString("ac_format");
|
2020-09-14 09:36:25 +00:00
|
|
|
this.pteroID = resultSet.getString("ptero_id");
|
2020-06-30 07:25:38 +00:00
|
|
|
}
|
|
|
|
catch (SQLException e)
|
|
|
|
{
|
2020-08-15 16:35:48 +00:00
|
|
|
FLog.severe("Failed to load staff: " + e.getMessage());
|
2020-06-30 07:25:38 +00:00
|
|
|
}
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString()
|
|
|
|
{
|
|
|
|
final StringBuilder output = new StringBuilder();
|
|
|
|
|
2020-08-15 16:35:48 +00:00
|
|
|
output.append("Staff: ").append(name).append("\n")
|
2015-10-19 17:43:46 +00:00
|
|
|
.append("- IPs: ").append(StringUtils.join(ips, ", ")).append("\n")
|
|
|
|
.append("- Last Login: ").append(FUtil.dateToString(lastLogin)).append("\n")
|
|
|
|
.append("- Custom Login Message: ").append(loginMessage).append("\n")
|
|
|
|
.append("- Rank: ").append(rank.getName()).append("\n")
|
2017-12-29 18:12:47 +00:00
|
|
|
.append("- Is Active: ").append(active).append("\n")
|
2018-07-24 06:58:17 +00:00
|
|
|
.append("- Potion Spy: ").append(potionSpy).append("\n")
|
|
|
|
.append("- Admin Chat Format: ").append(acFormat).append("\n")
|
2020-09-14 09:36:25 +00:00
|
|
|
.append("- Pterodactyl ID: ").append(pteroID).append("\n");
|
2015-10-19 17:43:46 +00:00
|
|
|
|
|
|
|
return output.toString();
|
|
|
|
}
|
|
|
|
|
2020-05-29 10:14:21 +00:00
|
|
|
public Map<String, Object> toSQLStorable()
|
|
|
|
{
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>()
|
|
|
|
{{
|
|
|
|
put("username", name);
|
|
|
|
put("active", active);
|
|
|
|
put("rank", rank.toString());
|
|
|
|
put("ips", FUtil.listToString(ips));
|
|
|
|
put("last_login", lastLogin.getTime());
|
|
|
|
put("login_message", loginMessage);
|
|
|
|
put("command_spy", commandSpy);
|
|
|
|
put("potion_spy", potionSpy);
|
|
|
|
put("ac_format", acFormat);
|
2020-09-14 09:36:25 +00:00
|
|
|
put("ptero_id", pteroID);
|
2020-05-29 10:14:21 +00:00
|
|
|
}};
|
|
|
|
return map;
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
public boolean hasLoginMessage()
|
|
|
|
{
|
|
|
|
return loginMessage != null && !loginMessage.isEmpty();
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
// Util IP methods
|
|
|
|
public void addIp(String ip)
|
|
|
|
{
|
|
|
|
if (!ips.contains(ip))
|
|
|
|
{
|
|
|
|
ips.add(ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addIps(List<String> ips)
|
|
|
|
{
|
|
|
|
for (String ip : ips)
|
|
|
|
{
|
|
|
|
addIp(ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeIp(String ip)
|
|
|
|
{
|
|
|
|
if (ips.contains(ip))
|
|
|
|
{
|
|
|
|
ips.remove(ip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void clearIPs()
|
|
|
|
{
|
|
|
|
ips.clear();
|
|
|
|
}
|
|
|
|
|
2017-08-01 19:59:24 +00:00
|
|
|
public void setActive(boolean active)
|
|
|
|
{
|
|
|
|
this.active = active;
|
|
|
|
|
|
|
|
final TotalFreedomMod plugin = TotalFreedomMod.plugin();
|
|
|
|
|
|
|
|
if (!active)
|
|
|
|
{
|
2020-09-28 03:17:01 +00:00
|
|
|
if (getRank().isAtLeast(Rank.ADMIN))
|
2017-08-01 19:59:24 +00:00
|
|
|
{
|
|
|
|
if (plugin.btb != null)
|
|
|
|
{
|
|
|
|
plugin.btb.killTelnetSessions(getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin.lv.updateLogsRegistration(null, getName(), LogsRegistrationMode.DELETE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
public boolean isValid()
|
|
|
|
{
|
2020-05-29 10:14:21 +00:00
|
|
|
return name != null
|
2015-10-19 17:43:46 +00:00
|
|
|
&& rank != null
|
|
|
|
&& !ips.isEmpty()
|
|
|
|
&& lastLogin != null;
|
|
|
|
}
|
2020-08-15 16:35:48 +00:00
|
|
|
}
|