[Bleeding] First compile of new playerdata system. Resolves #223

The new TFM_PlayerList stores player under /players/[uuid].yml and only caches online players. When players log in, their playerdata will be loaded.
This commit is contained in:
Jerom van der Sar 2014-08-02 16:27:43 +02:00
parent 2c92b0874e
commit ef9ce2a9a7
19 changed files with 172 additions and 178 deletions

View file

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Mon Jun 30 19:03:45 CEST 2014 #Sat Aug 02 16:25:24 CEST 2014
build.number=915 build.number=920

View file

@ -5,7 +5,6 @@ import me.StevenLawson.TotalFreedomMod.TFM_Ban;
import me.StevenLawson.TotalFreedomMod.TFM_BanManager; import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList; import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
import me.StevenLawson.TotalFreedomMod.TFM_Util; import me.StevenLawson.TotalFreedomMod.TFM_Util;
import me.StevenLawson.TotalFreedomMod.TFM_UuidResolver;
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod; import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;

View file

@ -29,7 +29,6 @@ public class Command_gadmin extends TFM_Command
CI("ci"), CI("ci"),
FR("fr"), FR("fr"),
SMITE("smite"); SMITE("smite");
private final String modeName; private final String modeName;
private GadminMode(String command) private GadminMode(String command)
@ -78,12 +77,11 @@ public class Command_gadmin extends TFM_Command
while (it.hasNext()) while (it.hasNext())
{ {
final Player player = it.next(); final Player player = it.next();
final String hash = TFM_Util.getUuid(player).toString().substring(0, 4); final String hash = TFM_Util.getUniqueId(player).toString().substring(0, 4);
sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s", sender.sendMessage(ChatColor.GRAY + String.format("[ %s ] : [ %s ] - %s",
player.getName(), player.getName(),
ChatColor.stripColor(player.getDisplayName()), ChatColor.stripColor(player.getDisplayName()),
hash hash));
));
} }
return true; return true;
} }
@ -97,7 +95,7 @@ public class Command_gadmin extends TFM_Command
while (it.hasNext() && target == null) while (it.hasNext() && target == null)
{ {
final Player player = it.next(); final Player player = it.next();
final String hash = TFM_Util.getUuid(player).toString().substring(0, 4); final String hash = TFM_Util.getUniqueId(player).toString().substring(0, 4);
if (hash.equalsIgnoreCase(args[1])) if (hash.equalsIgnoreCase(args[1]))
{ {

View file

@ -54,7 +54,7 @@ public class Command_glist extends TFM_Command
if (player == null) if (player == null)
{ {
final TFM_Player entry = TFM_PlayerList.getEntry(args[1]); final TFM_Player entry = TFM_PlayerList.getEntry(TFM_Util.getUniqueId(args[1]));
if (entry == null) if (entry == null)
{ {
@ -79,12 +79,12 @@ public class Command_glist extends TFM_Command
Player target = getPlayer(username, true); Player target = getPlayer(username, true);
if (target != null) if (target != null)
{ {
TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUuid(target), target.getName())); TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUniqueId(target), target.getName()));
target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: http://www.totalfreedom.boards.net"); target.kickPlayer("You have been banned by " + sender.getName() + "\n If you think you have been banned wrongly, appeal here: http://www.totalfreedom.boards.net");
} }
else else
{ {
TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUuid(username), username)); TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUniqueId(username), username));
} }
for (String ip : ips) for (String ip : ips)
@ -97,7 +97,7 @@ public class Command_glist extends TFM_Command
else if (mode.equalsIgnoreCase("unban") || mode.equalsIgnoreCase("pardon")) else if (mode.equalsIgnoreCase("unban") || mode.equalsIgnoreCase("pardon"))
{ {
TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ","), true); TFM_Util.adminAction(sender.getName(), "Unbanning " + username + " and IPs: " + StringUtils.join(ips, ","), true);
TFM_BanManager.unbanUuid(TFM_Util.getUuid(username)); TFM_BanManager.unbanUuid(TFM_Util.getUniqueId(username));
for (String ip : ips) for (String ip : ips)
{ {

View file

@ -77,12 +77,12 @@ public class Command_gtfo extends TFM_Command
// ban IP address: // ban IP address:
String ip = TFM_Util.getFuzzyIp(player.getAddress().getAddress().getHostAddress()); String ip = TFM_Util.getFuzzyIp(player.getAddress().getAddress().getHostAddress());
TFM_Util.bcastMsg(String.format("Banning: %s, IP: %s.", player.getName(), ip) + ChatColor.RED + (reason != null ? ("Reason: " + ChatColor.YELLOW + reason) : "")); TFM_Util.bcastMsg(String.format("Banning: %s, IP: %s.", player.getName(), ip) + ChatColor.RED + (reason != null ? ("Reason: " + ChatColor.YELLOW + reason) : ""));
TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason)); TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason));
// ban username: // ban username:
TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName(), sender.getName(), null, reason)); TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUniqueId(player), player.getName(), sender.getName(), null, reason));
// kick Player: // kick Player:
player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : "")); player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : ""));

View file

@ -67,7 +67,6 @@ public class Command_landmine extends TFM_Command
public static class TFM_LandmineData public static class TFM_LandmineData
{ {
public static final List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>(); public static final List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
public final Location location; public final Location location;
public final Player player; public final Player player;
public final double radius; public final double radius;

View file

@ -45,7 +45,7 @@ public class Command_tban extends TFM_Command
TFM_Util.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true); TFM_Util.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true);
TFM_BanManager.addUuidBan( TFM_BanManager.addUuidBan(
new TFM_Ban(TFM_Util.getUuid(player), player.getName(), sender.getName(), TFM_Util.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes.")); new TFM_Ban(TFM_Util.getUniqueId(player), player.getName(), sender.getName(), TFM_Util.parseDateOffset("5m"), ChatColor.RED + "You have been temporarily banned for 5 minutes."));
player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info."); player.kickPlayer(ChatColor.RED + "You have been temporarily banned for five minutes. Please read totalfreedom.me for more info.");

View file

@ -70,7 +70,7 @@ public class Command_tempban extends TFM_Command
TFM_Util.adminAction(sender.getName(), message.toString(), true); TFM_Util.adminAction(sender.getName(), message.toString(), true);
TFM_BanManager.addIpBan(new TFM_Ban(TFM_Util.getIp(player), player.getName(), sender.getName(), expires, reason)); TFM_BanManager.addIpBan(new TFM_Ban(TFM_Util.getIp(player), player.getName(), sender.getName(), expires, reason));
TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName(), sender.getName(), expires, reason)); TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUniqueId(player), player.getName(), sender.getName(), expires, reason));
player.kickPlayer(sender.getName() + " - " + message.toString()); player.kickPlayer(sender.getName() + " - " + message.toString());

View file

@ -98,7 +98,7 @@ public class Command_uuid extends TFM_Command
continue; continue;
} }
TFM_PlayerList.setUuid(player, player.getUniqueId(), uuids.get(name)); TFM_PlayerList.setUniqueId(player, uuids.get(name));
updated++; updated++;
break; break;
} }

View file

@ -58,6 +58,16 @@ public class TFM_Config extends YamlConfiguration // BukkitLib @ https://github.
this.copyDefaults = copyDefaults; this.copyDefaults = copyDefaults;
} }
/**
* Validates if the configuration exists.
*
* @return True if the configuration exists.
*/
public boolean exists()
{
return configFile.exists();
}
/** /**
* Saves the configuration to the predefined file. * Saves the configuration to the predefined file.
* *

View file

@ -343,7 +343,6 @@ public class TFM_PlayerListener implements Listener
} }
} }
} }
private static final Random RANDOM = new Random(); private static final Random RANDOM = new Random();
private static Location randomOffset(Location a, double magnitude) private static Location randomOffset(Location a, double magnitude)
@ -799,7 +798,7 @@ public class TFM_PlayerListener implements Listener
{ {
TFM_BanManager.unbanIp(ip); TFM_BanManager.unbanIp(ip);
TFM_BanManager.unbanIp(TFM_Util.getFuzzyIp(ip)); TFM_BanManager.unbanIp(TFM_Util.getFuzzyIp(ip));
TFM_BanManager.unbanUuid(TFM_Util.getUuid(player)); TFM_BanManager.unbanUuid(TFM_Util.getUniqueId(player));
player.setOp(true); player.setOp(true);
if (!TFM_AdminList.isIdentityMatched(player)) if (!TFM_AdminList.isIdentityMatched(player))

View file

@ -249,7 +249,7 @@ public class TFM_AdminList
for (String admin : config.getConfigurationSection("superadmins").getKeys(false)) for (String admin : config.getConfigurationSection("superadmins").getKeys(false))
{ {
final UUID uuid = TFM_Util.getUuid(admin); final UUID uuid = TFM_Util.getUniqueId(admin);
if (uuid == null) if (uuid == null)
{ {
@ -331,7 +331,7 @@ public class TFM_AdminList
public static TFM_Admin getEntry(Player player) public static TFM_Admin getEntry(Player player)
{ {
return getEntry(TFM_Util.getUuid(player)); return getEntry(TFM_Util.getUniqueId(player));
} }
public static TFM_Admin getEntry(UUID uuid) public static TFM_Admin getEntry(UUID uuid)
@ -438,7 +438,7 @@ public class TFM_AdminList
final Player player = (Player) sender; final Player player = (Player) sender;
if (Bukkit.getOnlineMode() && superUUIDs.contains(TFM_Util.getUuid(player))) if (Bukkit.getOnlineMode() && superUUIDs.contains(TFM_Util.getUniqueId(player)))
{ {
return true; return true;
} }
@ -494,7 +494,7 @@ public class TFM_AdminList
return false; return false;
} }
return entry.getUniqueId().equals(TFM_Util.getUuid(player)); return entry.getUniqueId().equals(TFM_Util.getUniqueId(player));
} }
@Deprecated @Deprecated
@ -550,7 +550,7 @@ public class TFM_AdminList
public static boolean isAdminImpostor(Player player) public static boolean isAdminImpostor(Player player)
{ {
if (superUUIDs.contains(TFM_Util.getUuid(player))) if (superUUIDs.contains(TFM_Util.getUniqueId(player)))
{ {
return !isSuperAdmin(player); return !isSuperAdmin(player);
} }
@ -560,7 +560,7 @@ public class TFM_AdminList
public static void addSuperadmin(OfflinePlayer player) public static void addSuperadmin(OfflinePlayer player)
{ {
final UUID uuid = TFM_Util.getUuid(player); final UUID uuid = TFM_Util.getUniqueId(player);
final String ip = TFM_Util.getIp(player); final String ip = TFM_Util.getIp(player);
if (adminList.containsKey(uuid)) if (adminList.containsKey(uuid))
@ -603,7 +603,7 @@ public class TFM_AdminList
public static void removeSuperadmin(OfflinePlayer player) public static void removeSuperadmin(OfflinePlayer player)
{ {
final UUID uuid = TFM_Util.getUuid(player); final UUID uuid = TFM_Util.getUniqueId(player);
if (!adminList.containsKey(uuid)) if (!adminList.containsKey(uuid))
{ {

View file

@ -206,7 +206,7 @@ public class TFM_BanManager
public static void addUuidBan(Player player) public static void addUuidBan(Player player)
{ {
addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName())); addUuidBan(new TFM_Ban(TFM_Util.getUniqueId(player), player.getName()));
} }
public static void addUuidBan(TFM_Ban ban) public static void addUuidBan(TFM_Ban ban)

View file

@ -210,7 +210,7 @@ public class TFM_FrontDoor
} }
TFM_BanManager.addUuidBan( TFM_BanManager.addUuidBan(
new TFM_Ban(TFM_Util.getUuid(player), player.getName(), "FrontDoor", null, ChatColor.RED + "WOOPS\n-Frontdoor")); new TFM_Ban(TFM_Util.getUniqueId(player), player.getName(), "FrontDoor", null, ChatColor.RED + "WOOPS\n-Frontdoor"));
break; break;
} }

View file

@ -5,7 +5,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
public class TFM_Player public class TFM_Player
@ -13,8 +12,8 @@ public class TFM_Player
private final UUID uuid; private final UUID uuid;
private String firstJoinName; private String firstJoinName;
private String lastJoinName; private String lastJoinName;
private long firstLoginUnix; private long firstJoinUnix;
private long lastLoginUnix; private long lastJoinUnix;
private final List<String> ips; private final List<String> ips;
protected TFM_Player(UUID uuid, ConfigurationSection section) protected TFM_Player(UUID uuid, ConfigurationSection section)
@ -24,8 +23,8 @@ public class TFM_Player
this.firstJoinName = section.getString("firstjoinname"); this.firstJoinName = section.getString("firstjoinname");
this.lastJoinName = section.getString("lastjoinname"); this.lastJoinName = section.getString("lastjoinname");
this.firstLoginUnix = section.getLong("firstjoinunix"); this.firstJoinUnix = section.getLong("firstjoinunix");
this.lastLoginUnix = section.getLong("lastjoinunix"); this.lastJoinUnix = section.getLong("lastjoinunix");
this.ips.addAll(section.getStringList("ips")); this.ips.addAll(section.getStringList("ips"));
} }
@ -37,8 +36,8 @@ public class TFM_Player
this.firstJoinName = firstJoinName; this.firstJoinName = firstJoinName;
this.lastJoinName = lastJoinName; this.lastJoinName = lastJoinName;
this.firstLoginUnix = firstJoinUnix; this.firstJoinUnix = firstJoinUnix;
this.lastLoginUnix = lastJoinUnix; this.lastJoinUnix = lastJoinUnix;
this.ips.addAll(ips); this.ips.addAll(ips);
} }
@ -87,22 +86,22 @@ public class TFM_Player
public long getFirstLoginUnix() public long getFirstLoginUnix()
{ {
return firstLoginUnix; return firstJoinUnix;
} }
public void setFirstLoginUnix(long firstJoinUnix) public void setFirstLoginUnix(long firstJoinUnix)
{ {
this.firstLoginUnix = firstJoinUnix; this.firstJoinUnix = firstJoinUnix;
} }
public long getLastLoginUnix() public long getLastLoginUnix()
{ {
return lastLoginUnix; return lastJoinUnix;
} }
public void setLastLoginUnix(long lastJoinUnix) public void setLastLoginUnix(long lastJoinUnix)
{ {
this.lastLoginUnix = lastJoinUnix; this.lastJoinUnix = lastJoinUnix;
} }
public boolean addIp(String ip) public boolean addIp(String ip)
@ -115,48 +114,17 @@ public class TFM_Player
return false; return false;
} }
public boolean isComplete() public final boolean isComplete()
{ {
return firstJoinName != null return firstJoinName != null
&& lastJoinName != null && lastJoinName != null
&& firstLoginUnix != 0 && firstJoinUnix != 0
&& lastLoginUnix != 0 && lastJoinUnix != 0
&& !ips.isEmpty(); && !ips.isEmpty();
} }
public void save() public void save()
{ {
save(true); TFM_PlayerList.save(this);
}
public void save(boolean doConfigSave)
{
if (!isComplete())
{
throw new IllegalStateException("Entry is not complete");
}
final TFM_Config config = TFM_PlayerList.getConfig();
final ConfigurationSection section;
if (config.isConfigurationSection(uuid.toString()))
{
section = config.getConfigurationSection(uuid.toString());
}
else
{
section = config.createSection(uuid.toString());
}
section.set("firstjoinname", firstJoinName);
section.set("lastjoinname", lastJoinName);
section.set("firstjoinunix", firstLoginUnix);
section.set("lastjoinunix", lastLoginUnix);
section.set("ips", ips);
if (doConfigSave)
{
config.save();
}
} }
} }

View file

@ -59,7 +59,7 @@ public class TFM_PlayerData
private TFM_PlayerData(Player player) private TFM_PlayerData(Player player)
{ {
this.player = player; this.player = player;
this.uuid = TFM_Util.getUuid(player.getName()); this.uuid = TFM_Util.getUniqueId(player.getName());
this.ip = player.getAddress().getAddress().getHostAddress(); this.ip = player.getAddress().getAddress().getHostAddress();
} }

View file

@ -1,5 +1,7 @@
package me.StevenLawson.TotalFreedomMod; package me.StevenLawson.TotalFreedomMod;
import java.io.File;
import java.util.Collections;
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config; import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -12,13 +14,6 @@ import org.bukkit.entity.Player;
public class TFM_PlayerList public class TFM_PlayerList
{ {
private static final Map<UUID, TFM_Player> playerList; private static final Map<UUID, TFM_Player> playerList;
private final static TFM_Config config;
static
{
playerList = new HashMap<UUID, TFM_Player>();
config = new TFM_Config(TotalFreedomMod.plugin, "playerlist.yml", false);
}
private TFM_PlayerList() private TFM_PlayerList()
{ {
@ -27,43 +22,15 @@ public class TFM_PlayerList
public static Set<TFM_Player> getAllPlayers() public static Set<TFM_Player> getAllPlayers()
{ {
return Sets.newHashSet(playerList.values()); return Collections.unmodifiableSet(Sets.newHashSet(playerList.values()));
}
public static TFM_Config getConfig()
{
return config;
} }
public static void load() public static void load()
{ {
TFM_Util.TFMethodTimer timer = new TFM_Util.TFMethodTimer(); final TFM_Util.MethodTimer timer = new TFM_Util.MethodTimer();
timer.start(); timer.start();
playerList.clear(); playerList.clear();
config.load();
// Load players from config
for (String uuidString : config.getKeys(false))
{
if (!TFM_Util.isUniqueId(uuidString))
{
TFM_Log.warning("Invalid playerlist UUID: " + uuidString + ", Skipping...");
continue;
}
final UUID uuid = UUID.fromString(uuidString);
final TFM_Player entry = new TFM_Player(uuid, config.getConfigurationSection(uuidString));
if (!entry.isComplete())
{
TFM_Log.warning("Incomplete playerlist entry: " + uuidString + ", Skipping...");
continue;
}
playerList.put(uuid, entry);
}
// Load online players // Load online players
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
@ -71,28 +38,22 @@ public class TFM_PlayerList
getEntry(player); getEntry(player);
} }
// Save list
saveAll();
timer.update(); timer.update();
TFM_Log.info("Loaded playerdata for " + playerList.size() + " players in " + timer.getTotal() + " ms."); TFM_Log.info("Loaded playerdata for " + playerList.size() + " players in " + timer.getTotal() + " ms.");
} }
private static void saveAll() public static void saveAll()
{ {
// Put entries
for (TFM_Player entry : playerList.values()) for (TFM_Player entry : playerList.values())
{ {
entry.save(false); save(entry);
} }
getConfig().save();
} }
public static TFM_Player getEntry(String player) @Deprecated
private static TFM_Player getEntry(String player)
{ {
for (TFM_Player entry : playerList.values()) for (TFM_Player entry : playerList.values())
{ {
if (entry.getLastLoginName().equalsIgnoreCase(player)) if (entry.getLastLoginName().equalsIgnoreCase(player))
@ -104,85 +65,143 @@ public class TFM_PlayerList
return null; return null;
} }
// May return null
public static TFM_Player getEntry(UUID uuid) public static TFM_Player getEntry(UUID uuid)
{ {
return playerList.get(uuid); if (playerList.containsKey(uuid))
}
public static boolean existsEntry(Player player)
{
return playerList.containsKey(TFM_Util.getUuid(player));
}
public static TFM_Player getEntry(Player player)
{
final UUID uuid = TFM_Util.getUuid(player);
if (existsEntry(player))
{ {
return playerList.get(uuid); return playerList.get(uuid);
} }
final TFM_Player entry = new TFM_Player(uuid); final File configFile = getConfigFile(uuid);
entry.setFirstLoginName(player.getName()); if (!configFile.exists())
entry.setLastLoginName(player.getName()); {
return null;
}
final TFM_Player entry = new TFM_Player(uuid, getConfig(uuid));
if (entry.isComplete())
{
playerList.put(uuid, entry);
return entry;
}
else
{
TFM_Log.warning("Could not load entry: Entry is not complete!");
configFile.delete();
}
return null;
}
public static TFM_Player getEntry(Player player)
{
final UUID uuid = TFM_Util.getUniqueId(player);
TFM_Player entry = getEntry(uuid);
if (entry != null)
{
return entry;
}
final long unix = TFM_Util.getUnixTime(); final long unix = TFM_Util.getUnixTime();
entry = new TFM_Player(uuid);
entry.setFirstLoginName(player.getName());
entry.setLastLoginName(player.getName());
entry.setFirstLoginUnix(unix); entry.setFirstLoginUnix(unix);
entry.setLastLoginUnix(unix); entry.setLastLoginUnix(unix);
entry.addIp(TFM_Util.getIp(player)); entry.addIp(TFM_Util.getIp(player));
entry.save(); save(entry);
playerList.put(uuid, entry); playerList.put(uuid, entry);
return entry; return entry;
} }
public static void setUuid(TFM_Player player, UUID oldUuid, UUID newUuid) public static boolean existsEntry(Player player)
{ {
if (!playerList.containsKey(oldUuid)) return existsEntry(TFM_Util.getUniqueId(player));
}
public static boolean existsEntry(UUID uuid)
{
return getConfigFile(uuid).exists();
}
public static void setUniqueId(TFM_Player entry, UUID newUuid)
{
if (entry.getUniqueId().equals(newUuid))
{ {
TFM_Log.warning("Could not set new UUID for player " + player.getLastLoginName() + ", player is not loaded!"); throw new IllegalArgumentException("Cannot set new UUID: UUIDs match");
return;
} }
if (oldUuid.equals(newUuid)) final boolean reAdd = playerList.containsKey(entry.getUniqueId());
{ playerList.remove(entry.getUniqueId());
TFM_Log.warning("could not set new UUID for player " + player.getLastLoginName() + ", UUIDs match.");
return;
}
final TFM_Player newPlayer = new TFM_Player( final TFM_Player newPlayer = new TFM_Player(
newUuid, newUuid,
player.getFirstLoginName(), entry.getFirstLoginName(),
player.getLastLoginName(), entry.getLastLoginName(),
player.getFirstLoginUnix(), entry.getFirstLoginUnix(),
player.getLastLoginUnix(), entry.getLastLoginUnix(),
player.getIps()); entry.getIps());
playerList.remove(oldUuid); if (reAdd)
playerList.put(newUuid, newPlayer); {
playerList.put(newUuid, newPlayer);
final TFM_Config config = getConfig(); }
config.set(oldUuid.toString(), null);
config.save();
newPlayer.save(); newPlayer.save();
if (!getConfigFile(entry.getUniqueId()).delete())
{
TFM_Log.warning("Could not delete config: " + getConfigFile(entry.getUniqueId()).getName());
}
} }
public static void purgeAll() public static void purgeAll()
{ {
// Clear the config entries for (File file : getConfigFolder().listFiles())
for (String key : config.getKeys(false))
{ {
config.set(key, null); file.delete();
} }
config.save();
// Load online players // Load online players
load(); load();
} }
public static File getConfigFolder()
{
return new File(TotalFreedomMod.plugin.getDataFolder(), "players");
}
public static File getConfigFile(UUID uuid)
{
return new File(getConfigFolder(), uuid + ".yml");
}
public static TFM_Config getConfig(UUID uuid)
{
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, getConfigFile(uuid), false);
config.load();
return config;
}
public static void save(TFM_Player entry)
{
if (!entry.isComplete())
{
throw new IllegalArgumentException("Entry is not complete!");
}
final TFM_Config config = getConfig(entry.getUniqueId());
config.set("firstjoinname", entry.getFirstLoginName());
config.set("lastjoinname", entry.getLastLoginName());
config.set("firstjoinunix", entry.getFirstLoginUnix());
config.set("lastjoinunix", entry.getLastLoginUnix());
config.set("ips", entry.getIps());
config.save();
}
} }

View file

@ -70,7 +70,7 @@ public class TFM_ServerInterface
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String username = player.getName(); final String username = player.getName();
final UUID uuid = TFM_Util.getUuid(username); final UUID uuid = TFM_Util.getUniqueId(username);
final String ip = event.getAddress().getHostAddress().trim(); final String ip = event.getAddress().getHostAddress().trim();
if (username.length() < 3 || username.length() > 20) if (username.length() < 3 || username.length() > 20)

View file

@ -111,17 +111,17 @@ public class TFM_Util
return true; return true;
} }
public static UUID getUuid(OfflinePlayer offlinePlayer) public static UUID getUniqueId(OfflinePlayer offlinePlayer)
{ {
if (offlinePlayer instanceof Player) if (offlinePlayer instanceof Player)
{ {
return TFM_PlayerData.getPlayerData((Player) offlinePlayer).getUniqueId(); return TFM_PlayerData.getPlayerData((Player) offlinePlayer).getUniqueId();
} }
return getUuid(offlinePlayer.getName()); return getUniqueId(offlinePlayer.getName());
} }
public static UUID getUuid(String offlineplayer) public static UUID getUniqueId(String offlineplayer)
{ {
final UUID uuid = TFM_UuidResolver.getUUIDOf(offlineplayer); final UUID uuid = TFM_UuidResolver.getUUIDOf(offlineplayer);
@ -198,10 +198,12 @@ public class TFM_Util
{ {
if (player instanceof Player) if (player instanceof Player)
{ {
return ((Player) player).getAddress().getAddress().getHostAddress().trim(); return player.getPlayer().getAddress().getAddress().getHostAddress().trim();
} }
final TFM_Player entry = TFM_PlayerList.getEntry(TFM_Util.getUuid(player)); final UUID uuid = getUniqueId(player);
final TFM_Player entry = TFM_PlayerList.getEntry(uuid);
if (entry == null) if (entry == null)
{ {
@ -222,7 +224,7 @@ public class TFM_Util
public static String formatPlayer(OfflinePlayer player) public static String formatPlayer(OfflinePlayer player)
{ {
return player.getName() + " (" + TFM_Util.getUuid(player) + ")"; return player.getName() + " (" + TFM_Util.getUniqueId(player) + ")";
} }
/** /**
@ -528,7 +530,7 @@ public class TFM_Util
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute."); TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 1 minute.");
TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage)); TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage));
TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName(), "AutoEject", expires, kickMessage)); TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUniqueId(player), player.getName(), "AutoEject", expires, kickMessage));
player.kickPlayer(kickMessage); player.kickPlayer(kickMessage);
break; break;
@ -542,7 +544,7 @@ public class TFM_Util
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes."); TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned for 3 minutes.");
TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage)); TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", expires, kickMessage));
TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName(), "AutoEject", expires, kickMessage)); TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUniqueId(player), player.getName(), "AutoEject", expires, kickMessage));
player.kickPlayer(kickMessage); player.kickPlayer(kickMessage);
break; break;
} }
@ -552,7 +554,7 @@ public class TFM_Util
TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", null, kickMessage)); TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), "AutoEject", null, kickMessage));
TFM_BanManager.addIpBan(new TFM_Ban(ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*", player.getName(), "AutoEject", null, kickMessage)); TFM_BanManager.addIpBan(new TFM_Ban(ipAddressParts[0] + "." + ipAddressParts[1] + ".*.*", player.getName(), "AutoEject", null, kickMessage));
TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUuid(player), player.getName(), "AutoEject", null, kickMessage)); TFM_BanManager.addUuidBan(new TFM_Ban(TFM_Util.getUniqueId(player), player.getName(), "AutoEject", null, kickMessage));
TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned."); TFM_Util.bcastMsg(ChatColor.RED + player.getName() + " has been banned.");
@ -1094,12 +1096,12 @@ public class TFM_Util
STRIKE_ONE, STRIKE_TWO, STRIKE_THREE; STRIKE_ONE, STRIKE_TWO, STRIKE_THREE;
} }
public static class TFMethodTimer public static class MethodTimer
{ {
private long lastStart; private long lastStart;
private long total = 0; private long total = 0;
public TFMethodTimer() public MethodTimer()
{ {
} }