Move to external task

Only remove if we have it to remove
Only add if not already in memory
Don't load something we would immediately unload on removeUser
This commit is contained in:
NuclearW 2012-02-23 11:48:48 -05:00
parent b782225dde
commit 06b2a89646
3 changed files with 27 additions and 17 deletions

View File

@ -70,6 +70,7 @@ public class Users {
public static void addUser(Player player)
{
if(!players.containsKey(player))
players.put(player, new PlayerProfile(player));
}
public static void clearUsers()
@ -82,13 +83,10 @@ 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.get(player).save();
players.remove(player);
}
}

View File

@ -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)

View File

@ -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);
}
}