diff --git a/src/main/java/com/gmail/nossr50/Users.java b/src/main/java/com/gmail/nossr50/Users.java index b5b8403df..2d36024f7 100644 --- a/src/main/java/com/gmail/nossr50/Users.java +++ b/src/main/java/com/gmail/nossr50/Users.java @@ -70,7 +70,8 @@ public class Users { public static void addUser(Player player) { - players.put(player, new PlayerProfile(player)); + if(!players.containsKey(player)) + players.put(player, new PlayerProfile(player)); } public static void clearUsers() { @@ -82,14 +83,11 @@ public class Users { public static void removeUser(Player player) { - PlayerProfile PP = Users.getProfile(player); - - //Only remove PlayerProfile if user is offline - if(!player.isOnline()) + //Only remove PlayerProfile if user is offline and we have it in memory + if(!player.isOnline() && players.containsKey(player)) { - PP.save(); - if(players.containsKey(player)) - players.remove(player); + players.get(player).save(); + players.remove(player); } } diff --git a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java index 32a81fe48..eee9d3478 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java @@ -57,6 +57,7 @@ import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcPermissions; import com.gmail.nossr50.commands.general.XprateCommand; import com.gmail.nossr50.config.LoadProperties; +import com.gmail.nossr50.runnables.RemoveProfileFromMemoryTask; import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.spout.mmoHelper; import com.gmail.nossr50.datatypes.PlayerProfile; @@ -169,9 +170,8 @@ public class mcPlayerListener implements Listener } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void onPlayerQuit(final PlayerQuitEvent event) + public void onPlayerQuit(PlayerQuitEvent event) { - /* * GARBAGE COLLECTION */ @@ -193,13 +193,7 @@ public class mcPlayerListener implements Listener Users.getProfile(player).save(); //Schedule PlayerProfile removal 2 minutes after quitting - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, - new Runnable() { - public void run() { - //Remove PlayerProfile - Users.removeUser(event.getPlayer()); - } - }, 2400); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveProfileFromMemoryTask(player), 2400); } @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) diff --git a/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java b/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java new file mode 100644 index 000000000..71a013543 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/runnables/RemoveProfileFromMemoryTask.java @@ -0,0 +1,18 @@ +package com.gmail.nossr50.runnables; + +import org.bukkit.entity.Player; + +import com.gmail.nossr50.Users; + +public class RemoveProfileFromMemoryTask implements Runnable { + private Player player; + + public RemoveProfileFromMemoryTask(Player player) { + this.player = player; + } + + @Override + public void run() { + Users.removeUser(player); + } +}