Save and remove player entries on leave

Removed timer for player loading, applied to plugin instead
This commit is contained in:
unknown 2014-08-27 00:28:44 +02:00
parent b6d3e5baca
commit 0240b65fad
4 changed files with 44 additions and 39 deletions

View File

@ -1,4 +1,3 @@
#Build Number for ANT. Do not edit!
#Tue Aug 26 18:22:59 CEST 2014
build.number=935
#Wed Aug 27 00:27:30 CEST 2014
build.number=939

View File

@ -733,41 +733,33 @@ public class TFM_PlayerListener implements Listener
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent event)
{
final Player player = event.getPlayer();
if (TotalFreedomMod.fuckoffEnabledFor.containsKey(player))
{
TotalFreedomMod.fuckoffEnabledFor.remove(player);
}
TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
playerdata.disarmMP44();
if (playerdata.isCaged())
{
playerdata.regenerateHistory();
playerdata.clearHistory();
}
TFM_Log.info("[EXIT] " + player.getName() + " left the game.", true);
playerLeave(event.getPlayer());
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent event)
{
final Player player = event.getPlayer();
playerLeave(event.getPlayer());
}
private void playerLeave(Player player)
{
if (TotalFreedomMod.fuckoffEnabledFor.containsKey(player))
{
TotalFreedomMod.fuckoffEnabledFor.remove(player);
}
final TFM_PlayerData playerdata = TFM_PlayerData.getPlayerData(player);
playerdata.disarmMP44();
if (playerdata.isCaged())
{
playerdata.regenerateHistory();
playerdata.clearHistory();
}
TFM_PlayerList.removeEntry(player);
TFM_Log.info("[EXIT] " + player.getName() + " left the game.", true);
}

View File

@ -13,7 +13,7 @@ import org.bukkit.entity.Player;
public class TFM_PlayerList
{
private static final Map<UUID, TFM_Player> playerList = new HashMap<UUID, TFM_Player>();
private static final Map<UUID, TFM_Player> PLAYER_LIST = new HashMap<UUID, TFM_Player>();
private TFM_PlayerList()
{
@ -22,15 +22,12 @@ public class TFM_PlayerList
public static Set<TFM_Player> getAllPlayers()
{
return Collections.unmodifiableSet(Sets.newHashSet(playerList.values()));
return Collections.unmodifiableSet(Sets.newHashSet(PLAYER_LIST.values()));
}
public static void load()
{
final TFM_Util.MethodTimer timer = new TFM_Util.MethodTimer();
timer.start();
playerList.clear();
PLAYER_LIST.clear();
// Load online players
for (Player player : Bukkit.getOnlinePlayers())
@ -38,14 +35,12 @@ public class TFM_PlayerList
getEntry(player);
}
timer.update();
TFM_Log.info("Loaded playerdata for " + playerList.size() + " players in " + timer.getTotal() + " ms");
TFM_Log.info("Loaded playerdata for " + PLAYER_LIST.size() + " players");
}
public static void saveAll()
{
for (TFM_Player entry : playerList.values())
for (TFM_Player entry : PLAYER_LIST.values())
{
save(entry);
}
@ -54,9 +49,9 @@ public class TFM_PlayerList
// May return null
public static TFM_Player getEntry(UUID uuid)
{
if (playerList.containsKey(uuid))
if (PLAYER_LIST.containsKey(uuid))
{
return playerList.get(uuid);
return PLAYER_LIST.get(uuid);
}
final File configFile = getConfigFile(uuid);
@ -70,7 +65,7 @@ public class TFM_PlayerList
if (entry.isComplete())
{
playerList.put(uuid, entry);
PLAYER_LIST.put(uuid, entry);
return entry;
}
else
@ -101,11 +96,25 @@ public class TFM_PlayerList
entry.addIp(TFM_Util.getIp(player));
save(entry);
playerList.put(uuid, entry);
PLAYER_LIST.put(uuid, entry);
return entry;
}
public static void removeEntry(Player player)
{
final UUID uuid = TFM_Util.getUniqueId(player);
if (!PLAYER_LIST.containsKey(uuid))
{
return;
}
save(PLAYER_LIST.get(uuid));
PLAYER_LIST.remove(uuid);
}
public static boolean existsEntry(Player player)
{
return existsEntry(TFM_Util.getUniqueId(player));
@ -123,10 +132,10 @@ public class TFM_PlayerList
throw new IllegalArgumentException("Cannot set new UUID: UUIDs match");
}
final boolean reAdd = playerList.containsKey(entry.getUniqueId());
playerList.remove(entry.getUniqueId());
final boolean reAdd = PLAYER_LIST.containsKey(entry.getUniqueId());
PLAYER_LIST.remove(entry.getUniqueId());
final TFM_Player newPlayer = new TFM_Player(
final TFM_Player newEntry = new TFM_Player(
newUuid,
entry.getFirstLoginName(),
entry.getLastLoginName(),
@ -136,10 +145,10 @@ public class TFM_PlayerList
if (reAdd)
{
playerList.put(newUuid, newPlayer);
PLAYER_LIST.put(newUuid, newEntry);
}
newPlayer.save();
newEntry.save();
if (!getConfigFile(entry.getUniqueId()).delete())
{

View File

@ -70,6 +70,9 @@ public class TotalFreedomMod extends JavaPlugin
TFM_Log.info("Made by Madgeek1450 and DarthSalamon");
TFM_Log.info("Compiled " + buildDate + " by " + buildCreator);
final TFM_Util.MethodTimer timer = new TFM_Util.MethodTimer();
timer.start();
if (!TFM_ServerInterface.COMPILE_NMS_VERSION.equals(TFM_Util.getNmsVersion()))
{
TFM_Log.warning(pluginName + " is compiled for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " but the server is running "
@ -155,7 +158,9 @@ public class TotalFreedomMod extends JavaPlugin
TFM_HTTPD_Manager.start();
TFM_FrontDoor.start();
TFM_Log.info("Version " + pluginVersion + " for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " enabled");
timer.update();
TFM_Log.info("Version " + pluginVersion + " for " + TFM_ServerInterface.COMPILE_NMS_VERSION + " enabled in " + timer.getTotal() + "ms");
// Metrics @ http://mcstats.org/plugin/TotalFreedomMod
try