mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
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:
parent
b782225dde
commit
06b2a89646
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user