From 6cf08193dfbedb08352fd3a450022afac0ecd331 Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 16 Jan 2016 20:35:21 +1100 Subject: [PATCH] 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. --- .../bungee/playerTracker/PlayerJoinHandler.java | 3 ++- .../bungee/playerTracker/PlayerTracker.java | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerJoinHandler.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerJoinHandler.java index 8e56dab88..36c4f37c8 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerJoinHandler.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerJoinHandler.java @@ -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())); } } } diff --git a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java index 8d0a2cf99..a7b2d004e 100644 --- a/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java +++ b/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerTracker/PlayerTracker.java @@ -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 _repository; - private HashSet _onlineUUIDs = new HashSet(); + private Set _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 onlineUUIDs = new HashSet(); + Set 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.");