Make the tab list implementations pruddy.

This commit is contained in:
md_5 2013-01-18 11:33:44 +11:00
parent df37612494
commit 8e3f750c7c
3 changed files with 27 additions and 16 deletions

View File

@ -1,8 +1,7 @@
package net.md_5.bungee.tablist; package net.md_5.bungee.tablist;
import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.packet.PacketC9PlayerListItem; import net.md_5.bungee.packet.PacketC9PlayerListItem;
@ -10,8 +9,15 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem;
public class GlobalPingTabList extends GlobalTabList public class GlobalPingTabList extends GlobalTabList
{ {
public static final int PING_THRESHOLD = 20; private static final int PING_THRESHOLD = 20;
private Map<ProxiedPlayer, Integer> lastPings = Collections.synchronizedMap(new WeakHashMap<ProxiedPlayer, Integer>()); private final Map<ProxiedPlayer, Integer> lastPings = new ConcurrentHashMap<>();
@Override
public void onDisconnect(ProxiedPlayer player)
{
lastPings.remove(player);
super.onDisconnect(player);
}
@Override @Override
public void onPingChange(ProxiedPlayer player, int ping) public void onPingChange(ProxiedPlayer player, int ping)

View File

@ -1,8 +1,8 @@
package net.md_5.bungee.tablist; package net.md_5.bungee.tablist;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import lombok.Synchronized;
import net.md_5.bungee.BungeeCord; import net.md_5.bungee.BungeeCord;
import net.md_5.bungee.UserConnection; import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.TabListHandler; import net.md_5.bungee.api.TabListHandler;
@ -12,7 +12,7 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem;
public class GlobalTabList implements TabListHandler public class GlobalTabList implements TabListHandler
{ {
private Set<ProxiedPlayer> sentPings = Collections.synchronizedSet(new HashSet<ProxiedPlayer>()); private final Set<ProxiedPlayer> sentPings = new HashSet<>();
@Override @Override
public void onConnect(ProxiedPlayer player) public void onConnect(ProxiedPlayer player)
@ -24,6 +24,7 @@ public class GlobalTabList implements TabListHandler
} }
@Override @Override
@Synchronized(value = "sentPings")
public void onPingChange(ProxiedPlayer player, int ping) public void onPingChange(ProxiedPlayer player, int ping)
{ {
if (!sentPings.contains(player)) if (!sentPings.contains(player))
@ -34,6 +35,7 @@ public class GlobalTabList implements TabListHandler
} }
@Override @Override
@Synchronized(value = "sentPings")
public void onDisconnect(ProxiedPlayer player) public void onDisconnect(ProxiedPlayer player)
{ {
BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), false, 9999)); BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), false, 9999));

View File

@ -1,10 +1,9 @@
package net.md_5.bungee.tablist; package net.md_5.bungee.tablist;
import java.util.Collections; import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap;
import net.md_5.bungee.UserConnection; import net.md_5.bungee.UserConnection;
import net.md_5.bungee.api.TabListHandler; import net.md_5.bungee.api.TabListHandler;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
@ -13,7 +12,7 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem;
public class ServerUniqueTabList implements TabListHandler public class ServerUniqueTabList implements TabListHandler
{ {
private Map<ProxiedPlayer, Set<String>> sentUsernames = Collections.synchronizedMap(new WeakHashMap<ProxiedPlayer, Set<String>>()); private final Map<ProxiedPlayer, Set<String>> sentUsernames = new ConcurrentHashMap<>();
@Override @Override
public void onConnect(ProxiedPlayer player) public void onConnect(ProxiedPlayer player)
@ -28,6 +27,7 @@ public class ServerUniqueTabList implements TabListHandler
@Override @Override
public void onDisconnect(ProxiedPlayer player) public void onDisconnect(ProxiedPlayer player)
{ {
sentUsernames.remove(player);
} }
@Override @Override
@ -53,10 +53,12 @@ public class ServerUniqueTabList implements TabListHandler
Set<String> usernames = sentUsernames.get(player); Set<String> usernames = sentUsernames.get(player);
if (usernames == null) if (usernames == null)
{ {
usernames = new LinkedHashSet<>(); usernames = new HashSet<>();
sentUsernames.put(player, usernames); sentUsernames.put(player, usernames);
} }
synchronized (usernames)
{
if (online) if (online)
{ {
usernames.add(name); usernames.add(name);
@ -64,6 +66,7 @@ public class ServerUniqueTabList implements TabListHandler
{ {
usernames.remove(name); usernames.remove(name);
} }
}
return true; return true;
} }