mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-24 03:05:49 +01:00
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;
|
||||
|
||||
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<ProxiedPlayer> sentPings = Collections.newSetFromMap( new ConcurrentHashMap<ProxiedPlayer, Boolean>() );
|
||||
private final Collection<ProxiedPlayer> sentPings = new HashSet<>();
|
||||
|
||||
@Override
|
||||
public void onConnect(ProxiedPlayer player)
|
||||
|
@ -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<ProxiedPlayer, Integer> lastPings = new ConcurrentHashMap<>();
|
||||
private final TObjectIntMap<ProxiedPlayer> 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 );
|
||||
|
@ -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<ProxiedPlayer, Set<String>> sentUsernames = new ConcurrentHashMap<>();
|
||||
private final Multimap<ProxiedPlayer, String> sentUsernames = Multimaps.synchronizedMultimap( HashMultimap.<ProxiedPlayer, String>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<String> usernames = sentUsernames.get( player );
|
||||
if ( usernames != null )
|
||||
Collection<String> 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<String> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user