Fixx issue #228 and #188 - CSV classes and ALL target for player list

This commit is contained in:
md_5 2013-03-26 17:53:22 +11:00
parent e506957d38
commit 3a3fb27d9a
5 changed files with 39 additions and 48 deletions

View File

@ -25,7 +25,6 @@ import java.util.Map;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;

View File

@ -265,4 +265,10 @@ public final class UserConnection implements ProxiedPlayer
permissions.remove( permission ); permissions.remove( permission );
} }
} }
@Override
public String toString()
{
return name;
}
} }

View File

@ -1,6 +1,8 @@
package net.md_5.bungee; package net.md_5.bungee;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.List;
/** /**
* Series of utility classes to perform various operations. * Series of utility classes to perform various operations.
@ -27,27 +29,6 @@ public class Util
return new InetSocketAddress( split[0], port ); 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. * Formats an integer as a hex value.
* *
@ -73,4 +54,21 @@ public class Util
return t.getClass().getSimpleName() + " : " + t.getMessage() return t.getClass().getSimpleName() + " : " + t.getMessage()
+ ( ( trace.length > 0 ) ? " @ " + t.getStackTrace()[0].getClassName() + ":" + t.getStackTrace()[0].getLineNumber() : "" ); + ( ( 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() );
}
} }

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import net.md_5.bungee.Util;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
@ -47,15 +48,9 @@ public class CommandList extends Command
} }
Collections.sort( players, String.CASE_INSENSITIVE_ORDER ); Collections.sort( players, String.CASE_INSENSITIVE_ORDER );
if ( !players.isEmpty() ) message.append( Util.format( players, ChatColor.RESET + ", " ) );
{
for ( String player : players )
{
message.append( player ).append( ChatColor.RESET ).append( ", " );
}
}
sender.sendMessage( message.substring( 0, message.length() - 2 ) ); sender.sendMessage( message.toString() );
} }
sender.sendMessage( "Total players online: " + ProxyServer.getInstance().getPlayers().size() ); sender.sendMessage( "Total players online: " + ProxyServer.getInstance().getPlayers().size() );

View File

@ -254,32 +254,25 @@ public class DownstreamBridge extends PacketHandler
} }
if ( subChannel.equals( "PlayerList" ) ) if ( subChannel.equals( "PlayerList" ) )
{ {
ServerInfo server = bungee.getServerInfo( in.readUTF() ); String target = in.readUTF();
out.writeUTF( "PlayerList" );
if ( target.equals( "ALL" ) )
{
out.writeUTF( Util.csv( bungee.getPlayers() ) );
} else
{
ServerInfo server = bungee.getServerInfo( target );
if ( server != null ) if ( server != null )
{ {
out.writeUTF( "PlayerList" );
out.writeUTF( server.getName() ); out.writeUTF( server.getName() );
out.writeUTF( Util.csv( server.getPlayers() ) );
StringBuilder sb = new StringBuilder();
for ( ProxiedPlayer p : server.getPlayers() )
{
sb.append( p.getName() );
sb.append( "," );
} }
out.writeUTF( sb.substring( 0, sb.length() - 1 ) );
} }
} }
if ( subChannel.equals( "GetServers" ) ) if ( subChannel.equals( "GetServers" ) )
{ {
out.writeUTF( "GetServers" ); out.writeUTF( "GetServers" );
out.writeUTF( Util.csv( bungee.getServers().keySet() ) );
StringBuilder sb = new StringBuilder();
for ( String server : bungee.getServers().keySet() )
{
sb.append( server );
sb.append( "," );
}
out.writeUTF( sb.substring( 0, sb.length() - 1 ) );
} }
if ( subChannel.equals( "Message" ) ) if ( subChannel.equals( "Message" ) )
{ {