Sweet trick to avoid locking in global tab list, basically reimplement HashSet based on a ConcurrentHashMap.
This commit is contained in:
parent
e5bb5e5168
commit
0721e3cc75
@ -1,8 +1,7 @@
|
|||||||
package net.md_5.bungee.tablist;
|
package net.md_5.bungee.tablist;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
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.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@ -13,7 +12,9 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
|||||||
public class GlobalTabList implements TabListHandler
|
public class GlobalTabList implements TabListHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
private final Set<ProxiedPlayer> sentPings = new HashSet<>();
|
// Sweet trick to avoid locking, basically reimplement HashSet based on a ConcurrentHashMap
|
||||||
|
private static final Object PRESENT = new Object();
|
||||||
|
private final Map<ProxiedPlayer, Object> sentPings = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnect(ProxiedPlayer player)
|
public void onConnect(ProxiedPlayer player)
|
||||||
@ -27,18 +28,16 @@ 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.containsKey(player))
|
||||||
{
|
{
|
||||||
BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, player.getPing()));
|
BungeeCord.getInstance().broadcast(new PacketC9PlayerListItem(player.getDisplayName(), true, player.getPing()));
|
||||||
sentPings.add(player);
|
sentPings.put(player, PRESENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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));
|
||||||
|
Loading…
Reference in New Issue
Block a user