mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-06-29 03:36:42 +00:00
1.16, overhaul of player data
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
package me.totalfreedom.totalfreedommod.admin;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Arrays;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@ -12,6 +13,7 @@ import lombok.Setter;
|
||||
import me.totalfreedom.totalfreedommod.LogViewer.LogsRegistrationMode;
|
||||
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@ -31,7 +33,6 @@ public class Admin
|
||||
private Rank rank = Rank.SUPER_ADMIN;
|
||||
@Getter
|
||||
private final List<String> ips = Lists.newArrayList();
|
||||
private final List<String> backupCodes = Lists.newArrayList();
|
||||
@Getter
|
||||
@Setter
|
||||
private Date lastLogin = new Date();
|
||||
@ -40,12 +41,6 @@ public class Admin
|
||||
private String loginMessage = null;
|
||||
@Getter
|
||||
@Setter
|
||||
private String discordID = null;
|
||||
@Getter
|
||||
@Setter
|
||||
private String tag = null;
|
||||
@Getter
|
||||
@Setter
|
||||
private Boolean commandSpy = false;
|
||||
@Getter
|
||||
@Setter
|
||||
@ -60,32 +55,33 @@ public class Admin
|
||||
@Setter
|
||||
private Boolean logStick = false;
|
||||
|
||||
public static final String CONFIG_FILENAME = "admins.yml";
|
||||
|
||||
public Admin(Player player)
|
||||
{
|
||||
this.name = player.getName();
|
||||
this.ips.add(Ips.getIp(player));
|
||||
}
|
||||
|
||||
public Admin(String username, List<String> ips, Rank rank, Boolean active, Date lastLogin, String loginMessage, String tag, String discordID, List<String> backupCodes, Boolean commandSpy, Boolean potionSpy, String acFormat, Boolean oldTags, Boolean logStick)
|
||||
public Admin(ResultSet resultSet)
|
||||
{
|
||||
this.name = username;
|
||||
this.active = active;
|
||||
this.rank = rank;
|
||||
this.ips.clear();
|
||||
this.ips.addAll(ips);
|
||||
this.lastLogin = lastLogin;
|
||||
this.loginMessage = loginMessage;
|
||||
this.tag = tag;
|
||||
this.discordID = discordID;
|
||||
this.backupCodes.clear();
|
||||
this.backupCodes.addAll(backupCodes);
|
||||
this.commandSpy = commandSpy;
|
||||
this.potionSpy = potionSpy;
|
||||
this.acFormat = acFormat;
|
||||
this.oldTags = oldTags;
|
||||
this.logStick = logStick;
|
||||
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");
|
||||
this.oldTags = resultSet.getBoolean("old_tags");
|
||||
this.logStick = resultSet.getBoolean("log_stick");
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
FLog.severe("Failed to load admin: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -99,13 +95,10 @@ public class Admin
|
||||
.append("- Custom Login Message: ").append(loginMessage).append("\n")
|
||||
.append("- Rank: ").append(rank.getName()).append("\n")
|
||||
.append("- Is Active: ").append(active).append("\n")
|
||||
.append("- Discord ID: ").append(discordID).append("\n")
|
||||
.append("- Tag: ").append(tag).append("\n").append(ChatColor.GRAY)
|
||||
.append("- Potion Spy: ").append(potionSpy).append("\n")
|
||||
.append("- Admin Chat Format: ").append(acFormat).append("\n")
|
||||
.append("- Old Tags: ").append(oldTags).append("\n")
|
||||
.append("- Log Stick: ").append(logStick).append("\n")
|
||||
.append("- Backup Codes: ").append(backupCodes.size()).append("/10");
|
||||
.append("- Log Stick: ").append(logStick).append("\n");
|
||||
|
||||
return output.toString();
|
||||
}
|
||||
@ -125,11 +118,8 @@ public class Admin
|
||||
put("active", active);
|
||||
put("rank", rank.toString());
|
||||
put("ips", FUtil.listToString(ips));
|
||||
put("backup_codes", FUtil.listToString(backupCodes));
|
||||
put("last_login", lastLogin.getTime());
|
||||
put("login_message", loginMessage);
|
||||
put("discord_id", discordID);
|
||||
put("tag", tag);
|
||||
put("command_spy", commandSpy);
|
||||
put("potion_spy", potionSpy);
|
||||
put("ac_format", acFormat);
|
||||
@ -179,22 +169,6 @@ public class Admin
|
||||
ips.clear();
|
||||
}
|
||||
|
||||
public List<String> getBackupCodes()
|
||||
{
|
||||
return Collections.unmodifiableList(backupCodes);
|
||||
}
|
||||
|
||||
public void setBackupCodes(List<String> codes)
|
||||
{
|
||||
backupCodes.clear();
|
||||
backupCodes.addAll(codes);
|
||||
}
|
||||
|
||||
public void removeBackupCode(String code)
|
||||
{
|
||||
backupCodes.remove(code);
|
||||
}
|
||||
|
||||
public void setActive(boolean active)
|
||||
{
|
||||
this.active = active;
|
||||
|
@ -18,7 +18,6 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import net.pravian.aero.config.YamlConfig;
|
||||
import net.pravian.aero.util.Ips;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -27,9 +26,6 @@ import org.bukkit.plugin.ServicePriority;
|
||||
|
||||
public class AdminList extends FreedomService
|
||||
{
|
||||
|
||||
public static final String CONFIG_FILENAME = "admins.yml";
|
||||
|
||||
@Getter
|
||||
private final Set<Admin> allAdmins = Sets.newHashSet(); // Includes disabled admins
|
||||
// Only active admins below
|
||||
@ -40,30 +36,16 @@ public class AdminList extends FreedomService
|
||||
public final List<String> verifiedNoAdmins = new ArrayList<>();
|
||||
public final Map<String, List<String>> verifiedNoAdminIps = Maps.newHashMap();
|
||||
public static ArrayList<Player> vanished = new ArrayList<>();
|
||||
//
|
||||
private final YamlConfig config;
|
||||
|
||||
public AdminList(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
|
||||
this.config = new YamlConfig(plugin, CONFIG_FILENAME, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
load();
|
||||
|
||||
server.getServicesManager().register(Function.class, new Function<Player, Boolean>()
|
||||
{
|
||||
@Override
|
||||
public Boolean apply(Player player)
|
||||
{
|
||||
return isAdmin(player);
|
||||
}
|
||||
}, plugin, ServicePriority.Normal);
|
||||
|
||||
deactivateOldEntries(false);
|
||||
}
|
||||
|
||||
@ -74,8 +56,6 @@ public class AdminList extends FreedomService
|
||||
|
||||
public void load()
|
||||
{
|
||||
config.load();
|
||||
|
||||
allAdmins.clear();
|
||||
try
|
||||
{
|
||||
@ -83,28 +63,14 @@ public class AdminList extends FreedomService
|
||||
{
|
||||
while (adminSet.next())
|
||||
{
|
||||
String name = adminSet.getString("username");
|
||||
List<String> ips = FUtil.stringToList(adminSet.getString("ips"));
|
||||
Rank rank = Rank.findRank(adminSet.getString("rank"));
|
||||
Boolean active = adminSet.getBoolean("active");;
|
||||
Date lastLogin = new Date(adminSet.getLong("last_login"));
|
||||
String loginMessage = adminSet.getString("login_message");
|
||||
String tag = adminSet.getString("tag");
|
||||
String discordID = adminSet.getString("discord_id");
|
||||
List<String> backupCodes = FUtil.stringToList(adminSet.getString("backup_codes"));
|
||||
Boolean commandSpy = adminSet.getBoolean("command_spy");
|
||||
Boolean potionSpy = adminSet.getBoolean("potion_spy");
|
||||
String acFormat = adminSet.getString("ac_format");
|
||||
Boolean oldTags = adminSet.getBoolean("old_tags");
|
||||
Boolean logStick = adminSet.getBoolean("log_stick");
|
||||
Admin admin = new Admin(name, ips, rank, active, lastLogin, loginMessage, tag, discordID, backupCodes, commandSpy, potionSpy, acFormat, oldTags, logStick);
|
||||
Admin admin = new Admin(adminSet);
|
||||
allAdmins.add(admin);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
FLog.severe("Failed to get adminlist: " + e.getMessage());
|
||||
FLog.severe("Failed to load adminlist: " + e.getMessage());
|
||||
}
|
||||
|
||||
updateTables();
|
||||
|
Reference in New Issue
Block a user