mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Finished TFM_UuidResolver and /uuid. Resolves #214
This commit is contained in:
parent
c4f1d0c06f
commit
8b4b2f97e0
@ -1,3 +1,3 @@
|
|||||||
#Build Number for ANT. Do not edit!
|
#Build Number for ANT. Do not edit!
|
||||||
#Sun Jun 29 10:53:22 CEST 2014
|
#Sun Jun 29 12:03:50 CEST 2014
|
||||||
build.number=893
|
build.number=904
|
||||||
|
@ -6,7 +6,7 @@ import me.StevenLawson.TotalFreedomMod.TFM_ServerInterface;
|
|||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
|
import me.StevenLawson.TotalFreedomMod.TFM_Ban;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
import me.StevenLawson.TotalFreedomMod.TFM_BanManager;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_PlayerEntry;
|
import me.StevenLawson.TotalFreedomMod.TFM_Player;
|
||||||
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 net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
@ -58,7 +58,7 @@ public class Command_glist extends TFM_Command
|
|||||||
|
|
||||||
if (player == null)
|
if (player == null)
|
||||||
{
|
{
|
||||||
final TFM_PlayerEntry entry = TFM_PlayerList.getEntry(args[1]);
|
final TFM_Player entry = TFM_PlayerList.getEntry(args[1]);
|
||||||
|
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
{
|
{
|
||||||
@ -66,7 +66,7 @@ public class Command_glist extends TFM_Command
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
username = entry.getLastJoinName();
|
username = entry.getLastLoginName();
|
||||||
ips.addAll(entry.getIps());
|
ips.addAll(entry.getIps());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -94,7 +94,7 @@ public class Command_rollback extends TFM_Command
|
|||||||
|
|
||||||
if (playerName == null)
|
if (playerName == null)
|
||||||
{
|
{
|
||||||
playerName = TFM_PlayerList.getEntry(playerNameInput).getLastJoinName();
|
playerName = TFM_PlayerList.getEntry(playerNameInput).getLastLoginName();
|
||||||
}
|
}
|
||||||
|
|
||||||
return playerName;
|
return playerName;
|
||||||
|
@ -86,7 +86,7 @@ public class Command_saconfig extends TFM_Command
|
|||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_AdminList.save();
|
TFM_AdminList.saveAll();
|
||||||
|
|
||||||
playerMsg(counter + " IPs removed.");
|
playerMsg(counter + " IPs removed.");
|
||||||
playerMsg(admin.getIps().get(0) + " is now your only IP address");
|
playerMsg(admin.getIps().get(0) + " is now your only IP address");
|
||||||
@ -109,7 +109,7 @@ public class Command_saconfig extends TFM_Command
|
|||||||
TFM_Util.adminAction(sender.getName(), "Removing a supered IP", true);
|
TFM_Util.adminAction(sender.getName(), "Removing a supered IP", true);
|
||||||
|
|
||||||
admin.removeIp(args[1]);
|
admin.removeIp(args[1]);
|
||||||
TFM_AdminList.save();
|
TFM_AdminList.saveAll();
|
||||||
|
|
||||||
playerMsg("Removed IP " + args[1]);
|
playerMsg("Removed IP " + args[1]);
|
||||||
playerMsg("Current IPs: " + StringUtils.join(admin.getIps(), ", "));
|
playerMsg("Current IPs: " + StringUtils.join(admin.getIps(), ", "));
|
||||||
|
@ -1,14 +1,21 @@
|
|||||||
package me.StevenLawson.TotalFreedomMod.Commands;
|
package me.StevenLawson.TotalFreedomMod.Commands;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_Admin;
|
import me.StevenLawson.TotalFreedomMod.TFM_Admin;
|
||||||
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
import me.StevenLawson.TotalFreedomMod.TFM_AdminList;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_Player;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_PlayerList;
|
||||||
|
import me.StevenLawson.TotalFreedomMod.TFM_UuidResolver;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE)
|
@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE)
|
||||||
@CommandParameters(description = "Provides uuid tools", usage = "/<command> recalculate admin")
|
@CommandParameters(description = "Provides uuid tools", usage = "/<command> recalculate <admin | player>")
|
||||||
public class Command_uuid extends TFM_Command
|
public class Command_uuid extends TFM_Command
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -24,18 +31,84 @@ public class Command_uuid extends TFM_Command
|
|||||||
|
|
||||||
if ("admin".equals(args[1]))
|
if ("admin".equals(args[1]))
|
||||||
{
|
{
|
||||||
|
playerMsg("Recalculating admin UUIDs...");
|
||||||
|
|
||||||
|
final Set<TFM_Admin> admins = TFM_AdminList.getAllAdmins();
|
||||||
|
final List<String> names = new ArrayList<String>();
|
||||||
|
|
||||||
for (TFM_Admin admin : TFM_AdminList.getAllAdmins())
|
for (TFM_Admin admin : admins)
|
||||||
{
|
{
|
||||||
final UUID original = admin.getUniqueId();
|
names.add(admin.getLastLoginName());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Map<String, UUID> uuids = new TFM_UuidResolver(names).call();
|
||||||
|
|
||||||
|
int updated = 0;
|
||||||
|
for (String name : uuids.keySet())
|
||||||
|
{
|
||||||
|
for (TFM_Admin admin : admins)
|
||||||
|
{
|
||||||
|
if (!admin.getLastLoginName().equalsIgnoreCase(name))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (admin.getUniqueId().equals(uuids.get(name)))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_AdminList.setUuid(admin, admin.getUniqueId(), uuids.get(name));
|
||||||
|
updated++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
playerMsg("Done, recalculated " + updated + " UUIDs");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ("player".equals(args[1]))
|
||||||
|
{
|
||||||
|
playerMsg("Recalculating player UUIDs...");
|
||||||
|
|
||||||
|
final Set<TFM_Player> players = TFM_PlayerList.getAllPlayers();
|
||||||
|
|
||||||
|
final List<String> names = new ArrayList<String>();
|
||||||
|
|
||||||
|
for (TFM_Player player : players)
|
||||||
|
{
|
||||||
|
names.add(player.getLastLoginName());
|
||||||
|
}
|
||||||
|
|
||||||
|
final Map<String, UUID> uuids = new TFM_UuidResolver(names).call();
|
||||||
|
|
||||||
|
int updated = 0;
|
||||||
|
for (String name : uuids.keySet())
|
||||||
|
{
|
||||||
|
for (TFM_Player player : players)
|
||||||
|
{
|
||||||
|
if (!player.getLastLoginName().equalsIgnoreCase(name))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.getUniqueId().equals(uuids.get(name)))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
TFM_PlayerList.setUuid(player, player.getUniqueId(), uuids.get(name));
|
||||||
|
updated++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
playerMsg("Done, recalculated " + updated + " UUIDs");
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -697,9 +697,9 @@ public class TFM_PlayerListener implements Listener
|
|||||||
|
|
||||||
if (TFM_PlayerList.existsEntry(player))
|
if (TFM_PlayerList.existsEntry(player))
|
||||||
{
|
{
|
||||||
final TFM_PlayerEntry entry = TFM_PlayerList.getEntry(player);
|
final TFM_Player entry = TFM_PlayerList.getEntry(player);
|
||||||
entry.setLastJoinUnix(TFM_Util.getUnixTime());
|
entry.setLastLoginUnix(TFM_Util.getUnixTime());
|
||||||
entry.setLastJoinName(player.getName());
|
entry.setLastLoginName(player.getName());
|
||||||
entry.save();
|
entry.save();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -121,7 +121,13 @@ public class TFM_AdminList
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TFM_Admin newAdmin = new TFM_Admin(
|
if (oldUuid.equals(newUuid))
|
||||||
|
{
|
||||||
|
TFM_Log.warning("could not set new UUID for admin " + admin.getLastLoginName() + ", UUIDs match.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final TFM_Admin newAdmin = new TFM_Admin(
|
||||||
newUuid,
|
newUuid,
|
||||||
admin.getLastLoginName(),
|
admin.getLastLoginName(),
|
||||||
admin.getLastLogin(),
|
admin.getLastLogin(),
|
||||||
@ -130,10 +136,8 @@ public class TFM_AdminList
|
|||||||
admin.isSeniorAdmin(),
|
admin.isSeniorAdmin(),
|
||||||
admin.isActivated());
|
admin.isActivated());
|
||||||
|
|
||||||
for (String ip : admin.getIps())
|
|
||||||
{
|
|
||||||
newAdmin.addIps(admin.getIps());
|
newAdmin.addIps(admin.getIps());
|
||||||
}
|
|
||||||
|
|
||||||
adminList.remove(oldUuid);
|
adminList.remove(oldUuid);
|
||||||
adminList.put(newUuid, newAdmin);
|
adminList.put(newUuid, newAdmin);
|
||||||
@ -143,6 +147,8 @@ public class TFM_AdminList
|
|||||||
config.load();
|
config.load();
|
||||||
config.set("admins." + oldUuid.toString(), null);
|
config.set("admins." + oldUuid.toString(), null);
|
||||||
config.save();
|
config.save();
|
||||||
|
|
||||||
|
save(newAdmin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void load()
|
public static void load()
|
||||||
@ -270,7 +276,7 @@ public class TFM_AdminList
|
|||||||
TFM_Log.info("Done! " + counter + " admins parsed, " + errors + " errors");
|
TFM_Log.info("Done! " + counter + " admins parsed, " + errors + " errors");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save()
|
public static void saveAll()
|
||||||
{
|
{
|
||||||
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILE, true);
|
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILE, true);
|
||||||
config.load();
|
config.load();
|
||||||
@ -298,6 +304,31 @@ public class TFM_AdminList
|
|||||||
config.save();
|
config.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void save(TFM_Admin admin)
|
||||||
|
{
|
||||||
|
if (!adminList.containsValue(admin))
|
||||||
|
{
|
||||||
|
TFM_Log.warning("Could not save admin " + admin.getLastLoginName() + ", admin is not loaded!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final TFM_Config config = new TFM_Config(TotalFreedomMod.plugin, TotalFreedomMod.SUPERADMIN_FILE, true);
|
||||||
|
config.load();
|
||||||
|
|
||||||
|
final UUID uuid = admin.getUniqueId();
|
||||||
|
|
||||||
|
config.set("admins." + uuid + ".last_login_name", admin.getLastLoginName());
|
||||||
|
config.set("admins." + uuid + ".is_activated", admin.isActivated());
|
||||||
|
config.set("admins." + uuid + ".is_telnet_admin", admin.isTelnetAdmin());
|
||||||
|
config.set("admins." + uuid + ".is_senior_admin", admin.isSeniorAdmin());
|
||||||
|
config.set("admins." + uuid + ".last_login", TFM_Util.dateToString(admin.getLastLogin()));
|
||||||
|
config.set("admins." + uuid + ".custom_login_message", admin.getCustomLoginMessage());
|
||||||
|
config.set("admins." + uuid + ".console_aliases", TFM_Util.removeDuplicates(admin.getConsoleAliases()));
|
||||||
|
config.set("admins." + uuid + ".ips", TFM_Util.removeDuplicates(admin.getIps()));
|
||||||
|
|
||||||
|
config.save();
|
||||||
|
}
|
||||||
|
|
||||||
public static TFM_Admin getEntry(Player player)
|
public static TFM_Admin getEntry(Player player)
|
||||||
{
|
{
|
||||||
return getEntry(TFM_Util.getUuid(player));
|
return getEntry(TFM_Util.getUuid(player));
|
||||||
@ -364,7 +395,7 @@ public class TFM_AdminList
|
|||||||
}
|
}
|
||||||
admin.setLastLogin(new Date());
|
admin.setLastLogin(new Date());
|
||||||
admin.setLastLoginName(player.getName());
|
admin.setLastLoginName(player.getName());
|
||||||
save();
|
saveAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSeniorAdmin(CommandSender sender)
|
public static boolean isSeniorAdmin(CommandSender sender)
|
||||||
@ -503,7 +534,7 @@ public class TFM_AdminList
|
|||||||
{
|
{
|
||||||
entry.addIp(ip);
|
entry.addIp(ip);
|
||||||
}
|
}
|
||||||
save();
|
saveAll();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -542,7 +573,7 @@ public class TFM_AdminList
|
|||||||
superadmin.setLastLogin(new Date());
|
superadmin.setLastLogin(new Date());
|
||||||
superadmin.addIp(ip);
|
superadmin.addIp(ip);
|
||||||
}
|
}
|
||||||
save();
|
saveAll();
|
||||||
updateIndexLists();
|
updateIndexLists();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -566,7 +597,7 @@ public class TFM_AdminList
|
|||||||
|
|
||||||
adminList.put(uuid, superadmin);
|
adminList.put(uuid, superadmin);
|
||||||
|
|
||||||
save();
|
saveAll();
|
||||||
updateIndexLists();
|
updateIndexLists();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,7 +616,7 @@ public class TFM_AdminList
|
|||||||
superadmin.setActivated(false);
|
superadmin.setActivated(false);
|
||||||
Command_logs.deactivateSuperadmin(superadmin);
|
Command_logs.deactivateSuperadmin(superadmin);
|
||||||
|
|
||||||
save();
|
saveAll();
|
||||||
updateIndexLists();
|
updateIndexLists();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,7 +649,7 @@ public class TFM_AdminList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
save();
|
saveAll();
|
||||||
updateIndexLists();
|
updateIndexLists();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,29 +8,42 @@ import java.util.UUID;
|
|||||||
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
public class TFM_PlayerEntry
|
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 firstJoinUnix;
|
private long firstLoginUnix;
|
||||||
private long lastJoinUnix;
|
private long lastLoginUnix;
|
||||||
private final List<String> ips;
|
private final List<String> ips;
|
||||||
|
|
||||||
protected TFM_PlayerEntry(UUID uuid, ConfigurationSection section)
|
protected TFM_Player(UUID uuid, ConfigurationSection section)
|
||||||
{
|
{
|
||||||
this(uuid);
|
this(uuid);
|
||||||
|
|
||||||
this.firstJoinName = section.getString("firstjoinname");
|
this.firstJoinName = section.getString("firstjoinname");
|
||||||
this.lastJoinName = section.getString("lastjoinname");
|
this.lastJoinName = section.getString("lastjoinname");
|
||||||
|
|
||||||
this.firstJoinUnix = section.getLong("firstjoinunix");
|
this.firstLoginUnix = section.getLong("firstjoinunix");
|
||||||
this.lastJoinUnix = section.getLong("lastjoinunix");
|
this.lastLoginUnix = section.getLong("lastjoinunix");
|
||||||
|
|
||||||
this.ips.addAll(section.getStringList("ips"));
|
this.ips.addAll(section.getStringList("ips"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TFM_PlayerEntry(UUID uuid)
|
protected TFM_Player(UUID uuid, String firstJoinName, String lastJoinName, long firstJoinUnix, long lastJoinUnix, List<String> ips)
|
||||||
|
{
|
||||||
|
this(uuid);
|
||||||
|
|
||||||
|
this.firstJoinName = firstJoinName;
|
||||||
|
this.lastJoinName = lastJoinName;
|
||||||
|
|
||||||
|
this.firstLoginUnix = firstJoinUnix;
|
||||||
|
this.lastLoginUnix = lastJoinUnix;
|
||||||
|
|
||||||
|
this.ips.addAll(ips);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected TFM_Player(UUID uuid)
|
||||||
{
|
{
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.ips = new ArrayList<String>();
|
this.ips = new ArrayList<String>();
|
||||||
@ -47,44 +60,44 @@ public class TFM_PlayerEntry
|
|||||||
return Collections.unmodifiableList(ips);
|
return Collections.unmodifiableList(ips);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFirstJoinName()
|
public String getFirstLoginName()
|
||||||
{
|
{
|
||||||
return firstJoinName;
|
return firstJoinName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstJoinName(String firstJoinName)
|
public void setFirstLoginName(String firstJoinName)
|
||||||
{
|
{
|
||||||
this.firstJoinName = firstJoinName;
|
this.firstJoinName = firstJoinName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastJoinName()
|
public String getLastLoginName()
|
||||||
{
|
{
|
||||||
return lastJoinName;
|
return lastJoinName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastJoinName(String lastJoinName)
|
public void setLastLoginName(String lastJoinName)
|
||||||
{
|
{
|
||||||
this.lastJoinName = lastJoinName;
|
this.lastJoinName = lastJoinName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getFirstJoinUnix()
|
public long getFirstLoginUnix()
|
||||||
{
|
{
|
||||||
return firstJoinUnix;
|
return firstLoginUnix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstJoinUnix(long firstJoinUnix)
|
public void setFirstLoginUnix(long firstJoinUnix)
|
||||||
{
|
{
|
||||||
this.firstJoinUnix = firstJoinUnix;
|
this.firstLoginUnix = firstJoinUnix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getLastJoinUnix()
|
public long getLastLoginUnix()
|
||||||
{
|
{
|
||||||
return lastJoinUnix;
|
return lastLoginUnix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastJoinUnix(long lastJoinUnix)
|
public void setLastLoginUnix(long lastJoinUnix)
|
||||||
{
|
{
|
||||||
this.lastJoinUnix = lastJoinUnix;
|
this.lastLoginUnix = lastJoinUnix;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addIp(String ip)
|
public boolean addIp(String ip)
|
||||||
@ -101,8 +114,8 @@ public class TFM_PlayerEntry
|
|||||||
{
|
{
|
||||||
return firstJoinName != null
|
return firstJoinName != null
|
||||||
&& lastJoinName != null
|
&& lastJoinName != null
|
||||||
&& firstJoinUnix != 0
|
&& firstLoginUnix != 0
|
||||||
&& lastJoinUnix != 0
|
&& lastLoginUnix != 0
|
||||||
&& !ips.isEmpty();
|
&& !ips.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,8 +140,8 @@ public class TFM_PlayerEntry
|
|||||||
|
|
||||||
section.set("firstjoinname", firstJoinName);
|
section.set("firstjoinname", firstJoinName);
|
||||||
section.set("lastjoinname", lastJoinName);
|
section.set("lastjoinname", lastJoinName);
|
||||||
section.set("firstjoinunix", firstJoinUnix);
|
section.set("firstjoinunix", firstLoginUnix);
|
||||||
section.set("lastjoinunix", lastJoinUnix);
|
section.set("lastjoinunix", lastLoginUnix);
|
||||||
section.set("ips", ips);
|
section.set("ips", ips);
|
||||||
|
|
||||||
config.save();
|
config.save();
|
@ -3,18 +3,21 @@ package me.StevenLawson.TotalFreedomMod;
|
|||||||
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;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import static me.StevenLawson.TotalFreedomMod.TFM_AdminList.save;
|
||||||
|
import net.minecraft.util.com.google.common.collect.Sets;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class TFM_PlayerList
|
public class TFM_PlayerList
|
||||||
{
|
{
|
||||||
private static final Map<UUID, TFM_PlayerEntry> playerList;
|
private static final Map<UUID, TFM_Player> playerList;
|
||||||
private final static TFM_Config config;
|
private final static TFM_Config config;
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
playerList = new HashMap<UUID, TFM_PlayerEntry>();
|
playerList = new HashMap<UUID, TFM_Player>();
|
||||||
config = new TFM_Config(TotalFreedomMod.plugin, "playerlist.yml", false);
|
config = new TFM_Config(TotalFreedomMod.plugin, "playerlist.yml", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,6 +26,11 @@ public class TFM_PlayerList
|
|||||||
throw new AssertionError();
|
throw new AssertionError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Set<TFM_Player> getAllPlayers()
|
||||||
|
{
|
||||||
|
return Sets.newHashSet(playerList.values());
|
||||||
|
}
|
||||||
|
|
||||||
public static TFM_Config getConfig()
|
public static TFM_Config getConfig()
|
||||||
{
|
{
|
||||||
return config;
|
return config;
|
||||||
@ -44,7 +52,7 @@ public class TFM_PlayerList
|
|||||||
|
|
||||||
final UUID uuid = UUID.fromString(uuidString);
|
final UUID uuid = UUID.fromString(uuidString);
|
||||||
|
|
||||||
final TFM_PlayerEntry entry = new TFM_PlayerEntry(uuid, config.getConfigurationSection(uuidString));
|
final TFM_Player entry = new TFM_Player(uuid, config.getConfigurationSection(uuidString));
|
||||||
|
|
||||||
if (!entry.isComplete())
|
if (!entry.isComplete())
|
||||||
{
|
{
|
||||||
@ -70,18 +78,18 @@ public class TFM_PlayerList
|
|||||||
private static void saveAll()
|
private static void saveAll()
|
||||||
{
|
{
|
||||||
// Put entries
|
// Put entries
|
||||||
for (TFM_PlayerEntry entry : playerList.values())
|
for (TFM_Player entry : playerList.values())
|
||||||
{
|
{
|
||||||
entry.save();
|
entry.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_PlayerEntry getEntry(String player)
|
public static TFM_Player getEntry(String player)
|
||||||
{
|
{
|
||||||
|
|
||||||
for (TFM_PlayerEntry entry : playerList.values())
|
for (TFM_Player entry : playerList.values())
|
||||||
{
|
{
|
||||||
if (entry.getLastJoinName().equalsIgnoreCase(player))
|
if (entry.getLastLoginName().equalsIgnoreCase(player))
|
||||||
{
|
{
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
@ -90,7 +98,7 @@ public class TFM_PlayerList
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_PlayerEntry getEntry(UUID uuid)
|
public static TFM_Player getEntry(UUID uuid)
|
||||||
{
|
{
|
||||||
return playerList.get(uuid);
|
return playerList.get(uuid);
|
||||||
}
|
}
|
||||||
@ -100,7 +108,7 @@ public class TFM_PlayerList
|
|||||||
return playerList.containsKey(TFM_Util.getUuid(player));
|
return playerList.containsKey(TFM_Util.getUuid(player));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TFM_PlayerEntry getEntry(Player player)
|
public static TFM_Player getEntry(Player player)
|
||||||
{
|
{
|
||||||
final UUID uuid = TFM_Util.getUuid(player);
|
final UUID uuid = TFM_Util.getUuid(player);
|
||||||
|
|
||||||
@ -109,14 +117,14 @@ public class TFM_PlayerList
|
|||||||
return playerList.get(uuid);
|
return playerList.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
final TFM_PlayerEntry entry = new TFM_PlayerEntry(uuid);
|
final TFM_Player entry = new TFM_Player(uuid);
|
||||||
|
|
||||||
entry.setFirstJoinName(player.getName());
|
entry.setFirstLoginName(player.getName());
|
||||||
entry.setLastJoinName(player.getName());
|
entry.setLastLoginName(player.getName());
|
||||||
|
|
||||||
final long unix = TFM_Util.getUnixTime();
|
final long unix = TFM_Util.getUnixTime();
|
||||||
entry.setFirstJoinUnix(unix);
|
entry.setFirstLoginUnix(unix);
|
||||||
entry.setLastJoinUnix(unix);
|
entry.setLastLoginUnix(unix);
|
||||||
|
|
||||||
entry.addIp(TFM_Util.getIp(player));
|
entry.addIp(TFM_Util.getIp(player));
|
||||||
|
|
||||||
@ -126,6 +134,38 @@ public class TFM_PlayerList
|
|||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setUuid(TFM_Player player, UUID oldUuid, UUID newUuid)
|
||||||
|
{
|
||||||
|
if (!playerList.containsKey(oldUuid))
|
||||||
|
{
|
||||||
|
TFM_Log.warning("Could not set new UUID for player " + player.getLastLoginName() + ", player is not loaded!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oldUuid.equals(newUuid))
|
||||||
|
{
|
||||||
|
TFM_Log.warning("could not set new UUID for player " + player.getLastLoginName() + ", UUIDs match.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final TFM_Player newPlayer = new TFM_Player(
|
||||||
|
newUuid,
|
||||||
|
player.getFirstLoginName(),
|
||||||
|
player.getLastLoginName(),
|
||||||
|
player.getFirstLoginUnix(),
|
||||||
|
player.getLastLoginUnix(),
|
||||||
|
player.getIps());
|
||||||
|
|
||||||
|
playerList.remove(oldUuid);
|
||||||
|
playerList.put(newUuid, newPlayer);
|
||||||
|
|
||||||
|
final TFM_Config config = getConfig();
|
||||||
|
config.set(oldUuid.toString(), null);
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
newPlayer.save();
|
||||||
|
}
|
||||||
|
|
||||||
public static void purgeAll()
|
public static void purgeAll()
|
||||||
{
|
{
|
||||||
// Clear the config entries
|
// Clear the config entries
|
||||||
|
@ -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(player);
|
final UUID uuid = TFM_UuidResolver.getUUIDOf(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)
|
||||||
|
@ -163,7 +163,7 @@ public class TFM_Util
|
|||||||
return ((Player) player).getAddress().getAddress().getHostAddress().trim();
|
return ((Player) player).getAddress().getAddress().getHostAddress().trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
final TFM_PlayerEntry entry = TFM_PlayerList.getEntry(TFM_Util.getUuid(player));
|
final TFM_Player entry = TFM_PlayerList.getEntry(TFM_Util.getUuid(player));
|
||||||
|
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user