Use faster collections for the various tab lists.
This commit is contained in:
parent
d1124ca70b
commit
6b504d9160
@ -1,8 +1,7 @@
|
|||||||
package net.md_5.bungee.tablist;
|
package net.md_5.bungee.tablist;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collection;
|
||||||
import java.util.Set;
|
import java.util.HashSet;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
|
||||||
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,7 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
|||||||
public class Global implements TabListHandler
|
public class Global implements TabListHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
private final Set<ProxiedPlayer> sentPings = Collections.newSetFromMap( new ConcurrentHashMap<ProxiedPlayer, Boolean>() );
|
private final Collection<ProxiedPlayer> sentPings = new HashSet<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnect(ProxiedPlayer player)
|
public void onConnect(ProxiedPlayer player)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package net.md_5.bungee.tablist;
|
package net.md_5.bungee.tablist;
|
||||||
|
|
||||||
import java.util.Map;
|
import gnu.trove.map.TObjectIntMap;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import gnu.trove.map.hash.TObjectIntHashMap;
|
||||||
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,7 +10,7 @@ public class GlobalPing extends Global
|
|||||||
{
|
{
|
||||||
|
|
||||||
private static final int PING_THRESHOLD = 20;
|
private static final int PING_THRESHOLD = 20;
|
||||||
private final Map<ProxiedPlayer, Integer> lastPings = new ConcurrentHashMap<>();
|
private final TObjectIntMap<ProxiedPlayer> lastPings = new TObjectIntHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisconnect(ProxiedPlayer player)
|
public void onDisconnect(ProxiedPlayer player)
|
||||||
@ -22,8 +22,8 @@ public class GlobalPing extends Global
|
|||||||
@Override
|
@Override
|
||||||
public void onPingChange(ProxiedPlayer player, int ping)
|
public void onPingChange(ProxiedPlayer player, int ping)
|
||||||
{
|
{
|
||||||
Integer lastPing = lastPings.get( player );
|
int lastPing = lastPings.get( player );
|
||||||
if ( lastPing == null || ( ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing ) )
|
if ( ping - PING_THRESHOLD > lastPing && ping + PING_THRESHOLD < lastPing )
|
||||||
{
|
{
|
||||||
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), true, ping ) );
|
BungeeCord.getInstance().broadcast( new PacketC9PlayerListItem( player.getDisplayName(), true, ping ) );
|
||||||
lastPings.put( player, ping );
|
lastPings.put( player, ping );
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package net.md_5.bungee.tablist;
|
package net.md_5.bungee.tablist;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import com.google.common.collect.HashMultimap;
|
||||||
import java.util.Map;
|
import com.google.common.collect.Multimap;
|
||||||
import java.util.Set;
|
import com.google.common.collect.Multimaps;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.Collection;
|
||||||
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;
|
||||||
@ -12,7 +12,7 @@ import net.md_5.bungee.packet.PacketC9PlayerListItem;
|
|||||||
public class ServerUnique implements TabListHandler
|
public class ServerUnique implements TabListHandler
|
||||||
{
|
{
|
||||||
|
|
||||||
private final Map<ProxiedPlayer, Set<String>> sentUsernames = new ConcurrentHashMap<>();
|
private final Multimap<ProxiedPlayer, String> sentUsernames = Multimaps.synchronizedMultimap( HashMultimap.<ProxiedPlayer, String>create() );
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnect(ProxiedPlayer player)
|
public void onConnect(ProxiedPlayer player)
|
||||||
@ -27,45 +27,32 @@ public class ServerUnique implements TabListHandler
|
|||||||
@Override
|
@Override
|
||||||
public void onDisconnect(ProxiedPlayer player)
|
public void onDisconnect(ProxiedPlayer player)
|
||||||
{
|
{
|
||||||
sentUsernames.remove( player );
|
sentUsernames.removeAll( player );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServerChange(ProxiedPlayer player)
|
public void onServerChange(ProxiedPlayer player)
|
||||||
{
|
{
|
||||||
Set<String> usernames = sentUsernames.get( player );
|
Collection<String> usernames = sentUsernames.get( player );
|
||||||
if ( usernames != null )
|
synchronized ( sentUsernames )
|
||||||
{
|
{
|
||||||
synchronized ( usernames )
|
for ( String username : usernames )
|
||||||
{
|
{
|
||||||
for ( String username : usernames )
|
( (UserConnection) player ).sendPacket( new PacketC9PlayerListItem( username, false, 9999 ) );
|
||||||
{
|
|
||||||
( (UserConnection) player ).sendPacket( new PacketC9PlayerListItem( username, false, 9999 ) );
|
|
||||||
}
|
|
||||||
usernames.clear();
|
|
||||||
}
|
}
|
||||||
|
usernames.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onListUpdate(ProxiedPlayer player, String name, boolean online, int ping)
|
public boolean onListUpdate(ProxiedPlayer player, String name, boolean online, int ping)
|
||||||
{
|
{
|
||||||
Set<String> usernames = sentUsernames.get( player );
|
if ( online )
|
||||||
if ( usernames == null )
|
|
||||||
{
|
{
|
||||||
usernames = new HashSet<>();
|
sentUsernames.put( player, name );
|
||||||
sentUsernames.put( player, usernames );
|
} else
|
||||||
}
|
|
||||||
|
|
||||||
synchronized ( usernames )
|
|
||||||
{
|
{
|
||||||
if ( online )
|
sentUsernames.remove( player, name );
|
||||||
{
|
|
||||||
usernames.add( name );
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
usernames.remove( name );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user