diff --git a/proxy/src/main/java/net/md_5/bungee/tablist/Global.java b/proxy/src/main/java/net/md_5/bungee/tablist/Global.java index f83a49d0..08906487 100644 --- a/proxy/src/main/java/net/md_5/bungee/tablist/Global.java +++ b/proxy/src/main/java/net/md_5/bungee/tablist/Global.java @@ -1,8 +1,7 @@ package net.md_5.bungee.tablist; -import java.util.Collections; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; +import java.util.Collection; +import java.util.HashSet; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.ProxyServer; @@ -13,7 +12,7 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem; public class Global implements TabListHandler { - private final Set sentPings = Collections.newSetFromMap( new ConcurrentHashMap() ); + private final Collection sentPings = new HashSet<>(); @Override public void onConnect(ProxiedPlayer player) diff --git a/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPing.java b/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPing.java index 2d414e1b..ceeeed0a 100644 --- a/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPing.java +++ b/proxy/src/main/java/net/md_5/bungee/tablist/GlobalPing.java @@ -1,7 +1,7 @@ package net.md_5.bungee.tablist; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +import gnu.trove.map.TObjectIntMap; +import gnu.trove.map.hash.TObjectIntHashMap; import net.md_5.bungee.BungeeCord; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.packet.PacketC9PlayerListItem; @@ -10,7 +10,7 @@ public class GlobalPing extends Global { private static final int PING_THRESHOLD = 20; - private final Map lastPings = new ConcurrentHashMap<>(); + private final TObjectIntMap lastPings = new TObjectIntHashMap<>(); @Override public void onDisconnect(ProxiedPlayer player) @@ -22,8 +22,8 @@ public class GlobalPing extends Global @Override public void onPingChange(ProxiedPlayer player, int ping) { - Integer lastPing = lastPings.get( player ); - if ( lastPing == null || ( ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing ) ) + int lastPing = lastPings.get( player ); + if ( ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing ) { BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), true, ping ) ); lastPings.put( player, ping ); diff --git a/proxy/src/main/java/net/md_5/bungee/tablist/ServerUnique.java b/proxy/src/main/java/net/md_5/bungee/tablist/ServerUnique.java index acf610b7..73eaee37 100644 --- a/proxy/src/main/java/net/md_5/bungee/tablist/ServerUnique.java +++ b/proxy/src/main/java/net/md_5/bungee/tablist/ServerUnique.java @@ -1,9 +1,9 @@ package net.md_5.bungee.tablist; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; +import com.google.common.collect.HashMultimap; +import com.google.common.collect.Multimap; +import com.google.common.collect.Multimaps; +import java.util.Collection; import net.md_5.bungee.UserConnection; import net.md_5.bungee.api.TabListHandler; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -12,7 +12,7 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem; public class ServerUnique implements TabListHandler { - private final Map> sentUsernames = new ConcurrentHashMap<>(); + private final Multimap sentUsernames = Multimaps.synchronizedMultimap( HashMultimap.create() ); @Override public void onConnect(ProxiedPlayer player) @@ -27,45 +27,32 @@ public class ServerUnique implements TabListHandler @Override public void onDisconnect(ProxiedPlayer player) { - sentUsernames.remove( player ); + sentUsernames.removeAll( player ); } @Override public void onServerChange(ProxiedPlayer player) { - Set usernames = sentUsernames.get( player ); - if ( usernames != null ) + Collection usernames = sentUsernames.get( player ); + synchronized ( sentUsernames ) { - synchronized ( usernames ) + for ( String username : usernames ) { - for ( String username : usernames ) - { - ( (UserConnection) player ).sendPacket( new PacketC9PlayerListItem( username, false, 9999 ) ); - } - usernames.clear(); + ( (UserConnection) player ).sendPacket( new PacketC9PlayerListItem( username, false, 9999 ) ); } + usernames.clear(); } } @Override public boolean onListUpdate(ProxiedPlayer player, String name, boolean online, int ping) { - Set usernames = sentUsernames.get( player ); - if ( usernames == null ) + if ( online ) { - usernames = new HashSet<>(); - sentUsernames.put( player, usernames ); - } - - synchronized ( usernames ) + sentUsernames.put( player, name ); + } else { - if ( online ) - { - usernames.add( name ); - } else - { - usernames.remove( name ); - } + sentUsernames.remove( player, name ); } return true;