mirror of
https://github.com/SpigotMC/BungeeCord.git
synced 2024-11-27 20:59:12 +01:00
parent
e506957d38
commit
3a3fb27d9a
@ -25,7 +25,6 @@ import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
@ -265,4 +265,10 @@ public final class UserConnection implements ProxiedPlayer
|
||||
permissions.remove( permission );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package net.md_5.bungee;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Series of utility classes to perform various operations.
|
||||
@ -27,27 +29,6 @@ public class Util
|
||||
return new InetSocketAddress( split[0], port );
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a config path by prefix upper case letters with '_' and
|
||||
* turning them to lowercase.
|
||||
*
|
||||
* @param s the string to normalize
|
||||
* @return the normalized path
|
||||
*/
|
||||
public static String normalize(String s)
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
for ( char c : s.toCharArray() )
|
||||
{
|
||||
if ( Character.isUpperCase( c ) )
|
||||
{
|
||||
result.append( "_" );
|
||||
}
|
||||
result.append( Character.toLowerCase( c ) );
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an integer as a hex value.
|
||||
*
|
||||
@ -73,4 +54,21 @@ public class Util
|
||||
return t.getClass().getSimpleName() + " : " + t.getMessage()
|
||||
+ ( ( trace.length > 0 ) ? " @ " + t.getStackTrace()[0].getClassName() + ":" + t.getStackTrace()[0].getLineNumber() : "" );
|
||||
}
|
||||
|
||||
public static String csv(Collection<?> objects)
|
||||
{
|
||||
return format( objects, ", " );
|
||||
}
|
||||
|
||||
public static String format(Collection<?> objects, String separators)
|
||||
{
|
||||
StringBuilder ret = new StringBuilder();
|
||||
for ( Object o : objects )
|
||||
{
|
||||
ret.append( o );
|
||||
ret.append( separators );
|
||||
}
|
||||
|
||||
return ( ret.length() == 0 ) ? "" : ret.substring( 0, ret.length() - separators.length() );
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import net.md_5.bungee.Util;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@ -47,15 +48,9 @@ public class CommandList extends Command
|
||||
}
|
||||
Collections.sort( players, String.CASE_INSENSITIVE_ORDER );
|
||||
|
||||
if ( !players.isEmpty() )
|
||||
{
|
||||
for ( String player : players )
|
||||
{
|
||||
message.append( player ).append( ChatColor.RESET ).append( ", " );
|
||||
}
|
||||
}
|
||||
message.append( Util.format( players, ChatColor.RESET + ", " ) );
|
||||
|
||||
sender.sendMessage( message.substring( 0, message.length() - 2 ) );
|
||||
sender.sendMessage( message.toString() );
|
||||
}
|
||||
|
||||
sender.sendMessage( "Total players online: " + ProxyServer.getInstance().getPlayers().size() );
|
||||
|
@ -254,32 +254,25 @@ public class DownstreamBridge extends PacketHandler
|
||||
}
|
||||
if ( subChannel.equals( "PlayerList" ) )
|
||||
{
|
||||
ServerInfo server = bungee.getServerInfo( in.readUTF() );
|
||||
if ( server != null )
|
||||
String target = in.readUTF();
|
||||
out.writeUTF( "PlayerList" );
|
||||
if ( target.equals( "ALL" ) )
|
||||
{
|
||||
out.writeUTF( "PlayerList" );
|
||||
out.writeUTF( server.getName() );
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for ( ProxiedPlayer p : server.getPlayers() )
|
||||
out.writeUTF( Util.csv( bungee.getPlayers() ) );
|
||||
} else
|
||||
{
|
||||
ServerInfo server = bungee.getServerInfo( target );
|
||||
if ( server != null )
|
||||
{
|
||||
sb.append( p.getName() );
|
||||
sb.append( "," );
|
||||
out.writeUTF( server.getName() );
|
||||
out.writeUTF( Util.csv( server.getPlayers() ) );
|
||||
}
|
||||
out.writeUTF( sb.substring( 0, sb.length() - 1 ) );
|
||||
}
|
||||
}
|
||||
if ( subChannel.equals( "GetServers" ) )
|
||||
{
|
||||
out.writeUTF( "GetServers" );
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for ( String server : bungee.getServers().keySet() )
|
||||
{
|
||||
sb.append( server );
|
||||
sb.append( "," );
|
||||
}
|
||||
out.writeUTF( sb.substring( 0, sb.length() - 1 ) );
|
||||
out.writeUTF( Util.csv( bungee.getServers().keySet() ) );
|
||||
}
|
||||
if ( subChannel.equals( "Message" ) )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user