mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
[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:
parent
2c92b0874e
commit
ef9ce2a9a7
@ -1,3 +1,3 @@
|
||||
#Build Number for ANT. Do not edit!
|
||||
#Mon Jun 30 19:03:45 CEST 2014
|
||||
build.number=915
|
||||
#Sat Aug 02 16:25:24 CEST 2014
|
||||
build.number=920
|
||||
|
@ -5,7 +5,6 @@ import me.StevenLawson.TotalFreedomMod.TFM_Ban;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_Util;
|
||||
import me.StevenLawson.TotalFreedomMod.TFM_UuidResolver;
|
||||
import me.StevenLawson.TotalFreedomMod.TotalFreedomMod;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
|
@ -29,7 +29,6 @@ public class Command_gadmin extends TFM_Command
|
||||
CI("ci"),
|
||||
FR("fr"),
|
||||
SMITE("smite");
|
||||
|
||||
private final String modeName;
|
||||
|
||||
private GadminMode(String command)
|
||||
@ -78,12 +77,11 @@ public class Command_gadmin extends TFM_Command
|
||||
while (it.hasNext())
|
||||
{
|
||||
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",
|
||||
player.getName(),
|
||||
ChatColor.stripColor(player.getDisplayName()),
|
||||
hash
|
||||
));
|
||||
hash));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -97,7 +95,7 @@ public class Command_gadmin extends TFM_Command
|
||||
while (it.hasNext() && target == null)
|
||||
{
|
||||
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]))
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ public class Command_glist extends TFM_Command
|
||||
|
||||
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)
|
||||
{
|
||||
@ -79,12 +79,12 @@ public class Command_glist extends TFM_Command
|
||||
Player target = getPlayer(username, true);
|
||||
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");
|
||||
}
|
||||
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)
|
||||
@ -97,7 +97,7 @@ public class Command_glist extends TFM_Command
|
||||
else if (mode.equalsIgnoreCase("unban") || mode.equalsIgnoreCase("pardon"))
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class Command_gtfo extends TFM_Command
|
||||
TFM_BanManager.addIpBan(new TFM_Ban(ip, player.getName(), sender.getName(), null, reason));
|
||||
|
||||
// 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:
|
||||
player.kickPlayer(ChatColor.RED + "GTFO" + (reason != null ? ("\nReason: " + ChatColor.YELLOW + reason) : ""));
|
||||
|
@ -67,7 +67,6 @@ public class Command_landmine extends TFM_Command
|
||||
public static class TFM_LandmineData
|
||||
{
|
||||
public static final List<TFM_LandmineData> landmines = new ArrayList<TFM_LandmineData>();
|
||||
|
||||
public final Location location;
|
||||
public final Player player;
|
||||
public final double radius;
|
||||
|
@ -45,7 +45,7 @@ public class Command_tban extends TFM_Command
|
||||
|
||||
TFM_Util.adminAction(sender.getName(), "Tempbanning: " + player.getName() + " for 5 minutes.", true);
|
||||
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.");
|
||||
|
||||
|
@ -70,7 +70,7 @@ public class Command_tempban extends TFM_Command
|
||||
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.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());
|
||||
|
@ -98,7 +98,7 @@ public class Command_uuid extends TFM_Command
|
||||
continue;
|
||||
}
|
||||
|
||||
TFM_PlayerList.setUuid(player, player.getUniqueId(), uuids.get(name));
|
||||
TFM_PlayerList.setUniqueId(player, uuids.get(name));
|
||||
updated++;
|
||||
break;
|
||||
}
|
||||
|
@ -58,6 +58,16 @@ public class TFM_Config extends YamlConfiguration // BukkitLib @ https://github.
|
||||
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.
|
||||
*
|
||||
|
@ -343,7 +343,6 @@ public class TFM_PlayerListener implements Listener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
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(TFM_Util.getFuzzyIp(ip));
|
||||
TFM_BanManager.unbanUuid(TFM_Util.getUuid(player));
|
||||
TFM_BanManager.unbanUuid(TFM_Util.getUniqueId(player));
|
||||
player.setOp(true);
|
||||
|
||||
if (!TFM_AdminList.isIdentityMatched(player))
|
||||
|
@ -249,7 +249,7 @@ public class TFM_AdminList
|
||||
|
||||
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)
|
||||
{
|
||||
@ -331,7 +331,7 @@ public class TFM_AdminList
|
||||
|
||||
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)
|
||||
@ -438,7 +438,7 @@ public class TFM_AdminList
|
||||
|
||||
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;
|
||||
}
|
||||
@ -494,7 +494,7 @@ public class TFM_AdminList
|
||||
return false;
|
||||
}
|
||||
|
||||
return entry.getUniqueId().equals(TFM_Util.getUuid(player));
|
||||
return entry.getUniqueId().equals(TFM_Util.getUniqueId(player));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@ -550,7 +550,7 @@ public class TFM_AdminList
|
||||
|
||||
public static boolean isAdminImpostor(Player player)
|
||||
{
|
||||
if (superUUIDs.contains(TFM_Util.getUuid(player)))
|
||||
if (superUUIDs.contains(TFM_Util.getUniqueId(player)))
|
||||
{
|
||||
return !isSuperAdmin(player);
|
||||
}
|
||||
@ -560,7 +560,7 @@ public class TFM_AdminList
|
||||
|
||||
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);
|
||||
|
||||
if (adminList.containsKey(uuid))
|
||||
@ -603,7 +603,7 @@ public class TFM_AdminList
|
||||
|
||||
public static void removeSuperadmin(OfflinePlayer player)
|
||||
{
|
||||
final UUID uuid = TFM_Util.getUuid(player);
|
||||
final UUID uuid = TFM_Util.getUniqueId(player);
|
||||
|
||||
if (!adminList.containsKey(uuid))
|
||||
{
|
||||
|
@ -206,7 +206,7 @@ public class TFM_BanManager
|
||||
|
||||
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)
|
||||
|
@ -210,7 +210,7 @@ public class TFM_FrontDoor
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
public class TFM_Player
|
||||
@ -13,8 +12,8 @@ public class TFM_Player
|
||||
private final UUID uuid;
|
||||
private String firstJoinName;
|
||||
private String lastJoinName;
|
||||
private long firstLoginUnix;
|
||||
private long lastLoginUnix;
|
||||
private long firstJoinUnix;
|
||||
private long lastJoinUnix;
|
||||
private final List<String> ips;
|
||||
|
||||
protected TFM_Player(UUID uuid, ConfigurationSection section)
|
||||
@ -24,8 +23,8 @@ public class TFM_Player
|
||||
this.firstJoinName = section.getString("firstjoinname");
|
||||
this.lastJoinName = section.getString("lastjoinname");
|
||||
|
||||
this.firstLoginUnix = section.getLong("firstjoinunix");
|
||||
this.lastLoginUnix = section.getLong("lastjoinunix");
|
||||
this.firstJoinUnix = section.getLong("firstjoinunix");
|
||||
this.lastJoinUnix = section.getLong("lastjoinunix");
|
||||
|
||||
this.ips.addAll(section.getStringList("ips"));
|
||||
}
|
||||
@ -37,8 +36,8 @@ public class TFM_Player
|
||||
this.firstJoinName = firstJoinName;
|
||||
this.lastJoinName = lastJoinName;
|
||||
|
||||
this.firstLoginUnix = firstJoinUnix;
|
||||
this.lastLoginUnix = lastJoinUnix;
|
||||
this.firstJoinUnix = firstJoinUnix;
|
||||
this.lastJoinUnix = lastJoinUnix;
|
||||
|
||||
this.ips.addAll(ips);
|
||||
}
|
||||
@ -87,22 +86,22 @@ public class TFM_Player
|
||||
|
||||
public long getFirstLoginUnix()
|
||||
{
|
||||
return firstLoginUnix;
|
||||
return firstJoinUnix;
|
||||
}
|
||||
|
||||
public void setFirstLoginUnix(long firstJoinUnix)
|
||||
{
|
||||
this.firstLoginUnix = firstJoinUnix;
|
||||
this.firstJoinUnix = firstJoinUnix;
|
||||
}
|
||||
|
||||
public long getLastLoginUnix()
|
||||
{
|
||||
return lastLoginUnix;
|
||||
return lastJoinUnix;
|
||||
}
|
||||
|
||||
public void setLastLoginUnix(long lastJoinUnix)
|
||||
{
|
||||
this.lastLoginUnix = lastJoinUnix;
|
||||
this.lastJoinUnix = lastJoinUnix;
|
||||
}
|
||||
|
||||
public boolean addIp(String ip)
|
||||
@ -115,48 +114,17 @@ public class TFM_Player
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isComplete()
|
||||
public final boolean isComplete()
|
||||
{
|
||||
return firstJoinName != null
|
||||
&& lastJoinName != null
|
||||
&& firstLoginUnix != 0
|
||||
&& lastLoginUnix != 0
|
||||
&& firstJoinUnix != 0
|
||||
&& lastJoinUnix != 0
|
||||
&& !ips.isEmpty();
|
||||
}
|
||||
|
||||
public void save()
|
||||
{
|
||||
save(true);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
TFM_PlayerList.save(this);
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ public class TFM_PlayerData
|
||||
private TFM_PlayerData(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();
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package me.StevenLawson.TotalFreedomMod;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import me.StevenLawson.TotalFreedomMod.Config.TFM_Config;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -12,13 +14,6 @@ import org.bukkit.entity.Player;
|
||||
public class TFM_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()
|
||||
{
|
||||
@ -27,43 +22,15 @@ public class TFM_PlayerList
|
||||
|
||||
public static Set<TFM_Player> getAllPlayers()
|
||||
{
|
||||
return Sets.newHashSet(playerList.values());
|
||||
}
|
||||
|
||||
public static TFM_Config getConfig()
|
||||
{
|
||||
return config;
|
||||
return Collections.unmodifiableSet(Sets.newHashSet(playerList.values()));
|
||||
}
|
||||
|
||||
public static void load()
|
||||
{
|
||||
TFM_Util.TFMethodTimer timer = new TFM_Util.TFMethodTimer();
|
||||
final TFM_Util.MethodTimer timer = new TFM_Util.MethodTimer();
|
||||
timer.start();
|
||||
|
||||
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
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
@ -71,28 +38,22 @@ public class TFM_PlayerList
|
||||
getEntry(player);
|
||||
}
|
||||
|
||||
// Save list
|
||||
saveAll();
|
||||
|
||||
timer.update();
|
||||
|
||||
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())
|
||||
{
|
||||
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())
|
||||
{
|
||||
if (entry.getLastLoginName().equalsIgnoreCase(player))
|
||||
@ -104,85 +65,143 @@ public class TFM_PlayerList
|
||||
return null;
|
||||
}
|
||||
|
||||
// May return null
|
||||
public static TFM_Player getEntry(UUID uuid)
|
||||
{
|
||||
if (playerList.containsKey(uuid))
|
||||
{
|
||||
return playerList.get(uuid);
|
||||
}
|
||||
|
||||
public static boolean existsEntry(Player player)
|
||||
final File configFile = getConfigFile(uuid);
|
||||
|
||||
if (!configFile.exists())
|
||||
{
|
||||
return playerList.containsKey(TFM_Util.getUuid(player));
|
||||
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.getUuid(player);
|
||||
final UUID uuid = TFM_Util.getUniqueId(player);
|
||||
TFM_Player entry = getEntry(uuid);
|
||||
|
||||
if (existsEntry(player))
|
||||
if (entry != null)
|
||||
{
|
||||
return playerList.get(uuid);
|
||||
return entry;
|
||||
}
|
||||
|
||||
final TFM_Player entry = new TFM_Player(uuid);
|
||||
|
||||
final long unix = TFM_Util.getUnixTime();
|
||||
entry = new TFM_Player(uuid);
|
||||
entry.setFirstLoginName(player.getName());
|
||||
entry.setLastLoginName(player.getName());
|
||||
|
||||
final long unix = TFM_Util.getUnixTime();
|
||||
entry.setFirstLoginUnix(unix);
|
||||
entry.setLastLoginUnix(unix);
|
||||
|
||||
entry.addIp(TFM_Util.getIp(player));
|
||||
|
||||
entry.save();
|
||||
save(entry);
|
||||
playerList.put(uuid, entry);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
public static void setUuid(TFM_Player player, UUID oldUuid, UUID newUuid)
|
||||
public static boolean existsEntry(Player player)
|
||||
{
|
||||
if (!playerList.containsKey(oldUuid))
|
||||
{
|
||||
TFM_Log.warning("Could not set new UUID for player " + player.getLastLoginName() + ", player is not loaded!");
|
||||
return;
|
||||
return existsEntry(TFM_Util.getUniqueId(player));
|
||||
}
|
||||
|
||||
if (oldUuid.equals(newUuid))
|
||||
public static boolean existsEntry(UUID uuid)
|
||||
{
|
||||
TFM_Log.warning("could not set new UUID for player " + player.getLastLoginName() + ", UUIDs match.");
|
||||
return;
|
||||
return getConfigFile(uuid).exists();
|
||||
}
|
||||
|
||||
public static void setUniqueId(TFM_Player entry, UUID newUuid)
|
||||
{
|
||||
if (entry.getUniqueId().equals(newUuid))
|
||||
{
|
||||
throw new IllegalArgumentException("Cannot set new UUID: UUIDs match");
|
||||
}
|
||||
|
||||
final boolean reAdd = playerList.containsKey(entry.getUniqueId());
|
||||
playerList.remove(entry.getUniqueId());
|
||||
|
||||
final TFM_Player newPlayer = new TFM_Player(
|
||||
newUuid,
|
||||
player.getFirstLoginName(),
|
||||
player.getLastLoginName(),
|
||||
player.getFirstLoginUnix(),
|
||||
player.getLastLoginUnix(),
|
||||
player.getIps());
|
||||
entry.getFirstLoginName(),
|
||||
entry.getLastLoginName(),
|
||||
entry.getFirstLoginUnix(),
|
||||
entry.getLastLoginUnix(),
|
||||
entry.getIps());
|
||||
|
||||
playerList.remove(oldUuid);
|
||||
if (reAdd)
|
||||
{
|
||||
playerList.put(newUuid, newPlayer);
|
||||
|
||||
final TFM_Config config = getConfig();
|
||||
config.set(oldUuid.toString(), null);
|
||||
config.save();
|
||||
}
|
||||
|
||||
newPlayer.save();
|
||||
|
||||
if (!getConfigFile(entry.getUniqueId()).delete())
|
||||
{
|
||||
TFM_Log.warning("Could not delete config: " + getConfigFile(entry.getUniqueId()).getName());
|
||||
}
|
||||
}
|
||||
|
||||
public static void purgeAll()
|
||||
{
|
||||
// Clear the config entries
|
||||
for (String key : config.getKeys(false))
|
||||
for (File file : getConfigFolder().listFiles())
|
||||
{
|
||||
config.set(key, null);
|
||||
file.delete();
|
||||
}
|
||||
|
||||
config.save();
|
||||
|
||||
// Load online players
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class TFM_ServerInterface
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
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();
|
||||
|
||||
if (username.length() < 3 || username.length() > 20)
|
||||
|
@ -111,17 +111,17 @@ public class TFM_Util
|
||||
return true;
|
||||
}
|
||||
|
||||
public static UUID getUuid(OfflinePlayer offlinePlayer)
|
||||
public static UUID getUniqueId(OfflinePlayer offlinePlayer)
|
||||
{
|
||||
if (offlinePlayer instanceof Player)
|
||||
{
|
||||
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);
|
||||
|
||||
@ -198,10 +198,12 @@ public class TFM_Util
|
||||
{
|
||||
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)
|
||||
{
|
||||
@ -222,7 +224,7 @@ public class TFM_Util
|
||||
|
||||
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_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);
|
||||
|
||||
break;
|
||||
@ -542,7 +544,7 @@ public class TFM_Util
|
||||
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.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);
|
||||
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(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.");
|
||||
|
||||
@ -1094,12 +1096,12 @@ public class TFM_Util
|
||||
STRIKE_ONE, STRIKE_TWO, STRIKE_THREE;
|
||||
}
|
||||
|
||||
public static class TFMethodTimer
|
||||
public static class MethodTimer
|
||||
{
|
||||
private long lastStart;
|
||||
private long total = 0;
|
||||
|
||||
public TFMethodTimer()
|
||||
public MethodTimer()
|
||||
{
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user