Make the tab list implementations pruddy.
This commit is contained in:
parent
df37612494
commit
8e3f750c7c
@ -1,8 +1,7 @@
|
||||
package net.md_5.bungee.tablist;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
||||
@ -10,8 +9,15 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
||||
public class GlobalPingTabList extends GlobalTabList
|
||||
{
|
||||
|
||||
public static final int PING_THRESHOLD = 20;
|
||||
private Map<ProxiedPlayer, Integer> lastPings = Collections.synchronizedMap(new WeakHashMap<ProxiedPlayer, Integer>());
|
||||
private static final int PING_THRESHOLD = 20;
|
||||
private final Map<ProxiedPlayer, Integer> lastPings = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public void onDisconnect(ProxiedPlayer player)
|
||||
{
|
||||
lastPings.remove(player);
|
||||
super.onDisconnect(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPingChange(ProxiedPlayer player, int ping)
|
||||
|
@ -1,8 +1,8 @@
|
||||
package net.md_5.bungee.tablist;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import lombok.Synchronized;
|
||||
import net.md_5.bungee.BungeeCord;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.TabListHandler;
|
||||
@ -12,7 +12,7 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
||||
public class GlobalTabList implements TabListHandler
|
||||
{
|
||||
|
||||
private Set<ProxiedPlayer> sentPings = Collections.synchronizedSet(new HashSet<ProxiedPlayer>());
|
||||
private final Set<ProxiedPlayer> sentPings = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public void onConnect(ProxiedPlayer player)
|
||||
@ -24,6 +24,7 @@ public class GlobalTabList implements TabListHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
@Synchronized(value = "sentPings")
|
||||
public void onPingChange(ProxiedPlayer player, int ping)
|
||||
{
|
||||
if (!sentPings.contains(player))
|
||||
@ -34,6 +35,7 @@ public class GlobalTabList implements TabListHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
@Synchronized(value = "sentPings")
|
||||
public void onDisconnect(ProxiedPlayer player)
|
||||
{
|
||||
BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), false, 9999));
|
||||
|
@ -1,10 +1,9 @@
|
||||
package net.md_5.bungee.tablist;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import net.md_5.bungee.UserConnection;
|
||||
import net.md_5.bungee.api.TabListHandler;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@ -13,7 +12,7 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
||||
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
|
||||
public void onConnect(ProxiedPlayer player)
|
||||
@ -28,6 +27,7 @@ public class ServerUniqueTabList implements TabListHandler
|
||||
@Override
|
||||
public void onDisconnect(ProxiedPlayer player)
|
||||
{
|
||||
sentUsernames.remove(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,10 +53,12 @@ public class ServerUniqueTabList implements TabListHandler
|
||||
Set<String> usernames = sentUsernames.get(player);
|
||||
if (usernames == null)
|
||||
{
|
||||
usernames = new LinkedHashSet<>();
|
||||
usernames = new HashSet<>();
|
||||
sentUsernames.put(player, usernames);
|
||||
}
|
||||
|
||||
synchronized (usernames)
|
||||
{
|
||||
if (online)
|
||||
{
|
||||
usernames.add(name);
|
||||
@ -64,6 +66,7 @@ public class ServerUniqueTabList implements TabListHandler
|
||||
{
|
||||
usernames.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user