Fix small memory leak in Mineplexer.

* Leak was on line 74 (toString omitted when removing from String collection).
* Impact was actually pretty much nil - collection is rebuilt every minute.
* Side effect of optimization by using UUID itself which has a good hashCode and fast equals implementation.
This commit is contained in:
md_5 2016-01-16 20:35:21 +11:00
parent 46695f8449
commit 6cf08193df
2 changed files with 10 additions and 8 deletions

View File

@ -1,5 +1,6 @@
package mineplex.bungee.playerTracker;
import java.util.UUID;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.PlayerJoinCommand;
import mineplex.serverdata.commands.ServerCommand;
@ -21,7 +22,7 @@ public class PlayerJoinHandler implements CommandCallback
{
PlayerJoinCommand joinCommand = (PlayerJoinCommand)command;
_playerTracker.kickPlayerIfOnline(joinCommand.getUuid());
_playerTracker.kickPlayerIfOnline(UUID.fromString(joinCommand.getUuid()));
}
}
}

View File

@ -2,6 +2,7 @@ package mineplex.bungee.playerTracker;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@ -27,7 +28,7 @@ public class PlayerTracker implements Listener, Runnable
// Repository storing player status' across network.
private DataRepository<PlayerStatus> _repository;
private HashSet<String> _onlineUUIDs = new HashSet<String>();
private Set<UUID> _onlineUUIDs = new HashSet<>();
private Plugin _plugin;
@ -76,32 +77,32 @@ public class PlayerTracker implements Listener, Runnable
@EventHandler
public void playerConnect(final PostLoginEvent event)
{
_onlineUUIDs.add(event.getPlayer().getUniqueId().toString());
_onlineUUIDs.add(event.getPlayer().getUniqueId());
}
@Override
public void run()
{
HashSet<String> onlineUUIDs = new HashSet<String>();
Set<UUID> onlineUUIDs = new HashSet<>();
for (ProxiedPlayer player : _plugin.getProxy().getPlayers())
{
onlineUUIDs.add(player.getUniqueId().toString());
onlineUUIDs.add(player.getUniqueId());
}
_onlineUUIDs = onlineUUIDs;
}
public boolean isPlayerOnline(String uuid)
public boolean isPlayerOnline(UUID uuid)
{
return _onlineUUIDs.contains(uuid);
}
public void kickPlayerIfOnline(String uuid)
public void kickPlayerIfOnline(UUID uuid)
{
if (_onlineUUIDs.contains(uuid))
{
ProxiedPlayer player = _plugin.getProxy().getPlayer(UUID.fromString(uuid));
ProxiedPlayer player = _plugin.getProxy().getPlayer(uuid);
if (player != null)
player.disconnect("You have logged in from another location.");