Reformat API + Protocol

This commit is contained in:
md_5
2013-02-09 19:13:40 +11:00
parent 8840dade68
commit ce6656afc0
20 changed files with 531 additions and 260 deletions

View File

@@ -11,91 +11,91 @@ public enum ChatColor
/**
* Represents black.
*/
BLACK('0'),
BLACK( '0' ),
/**
* Represents dark blue.
*/
DARK_BLUE('1'),
DARK_BLUE( '1' ),
/**
* Represents dark green.
*/
DARK_GREEN('2'),
DARK_GREEN( '2' ),
/**
* Represents dark blue (aqua).
*/
DARK_AQUA('3'),
DARK_AQUA( '3' ),
/**
* Represents dark red.
*/
DARK_RED('4'),
DARK_RED( '4' ),
/**
* Represents dark purple.
*/
DARK_PURPLE('5'),
DARK_PURPLE( '5' ),
/**
* Represents gold.
*/
GOLD('6'),
GOLD( '6' ),
/**
* Represents gray.
*/
GRAY('7'),
GRAY( '7' ),
/**
* Represents dark gray.
*/
DARK_GRAY('8'),
DARK_GRAY( '8' ),
/**
* Represents blue.
*/
BLUE('9'),
BLUE( '9' ),
/**
* Represents green.
*/
GREEN('a'),
GREEN( 'a' ),
/**
* Represents aqua.
*/
AQUA('b'),
AQUA( 'b' ),
/**
* Represents red.
*/
RED('c'),
RED( 'c' ),
/**
* Represents light purple.
*/
LIGHT_PURPLE('d'),
LIGHT_PURPLE( 'd' ),
/**
* Represents yellow.
*/
YELLOW('e'),
YELLOW( 'e' ),
/**
* Represents white.
*/
WHITE('f'),
WHITE( 'f' ),
/**
* Represents magical characters that change around randomly.
*/
MAGIC('k'),
MAGIC( 'k' ),
/**
* Makes the text bold.
*/
BOLD('l'),
BOLD( 'l' ),
/**
* Makes a line appear through the text.
*/
STRIKETHROUGH('m'),
STRIKETHROUGH( 'm' ),
/**
* Makes the text appear underlined.
*/
UNDERLINE('n'),
UNDERLINE( 'n' ),
/**
* Makes the text italic.
*/
ITALIC('o'),
ITALIC( 'o' ),
/**
* Resets all previous chat colors or formats.
*/
RESET('r');
RESET( 'r' );
/**
* The special character which prefixes all chat colour codes. Use this if
* you need to dynamically convert colour codes from your custom format.
@@ -104,7 +104,7 @@ public enum ChatColor
/**
* Pattern to remove all colour codes.
*/
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf(COLOR_CHAR) + "[0-9A-FK-OR]");
private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile( "(?i)" + String.valueOf( COLOR_CHAR ) + "[0-9A-FK-OR]" );
/**
* This colour's colour char prefixed by the {@link #COLOR_CHAR}.
*/
@@ -112,10 +112,10 @@ public enum ChatColor
private ChatColor(char code)
{
this.toString = new String(new char[]
this.toString = new String( new char[]
{
COLOR_CHAR, code
});
} );
}
@Override
@@ -132,25 +132,25 @@ public enum ChatColor
*/
public static String stripColor(final String input)
{
if (input == null)
if ( input == null )
{
return null;
}
return STRIP_COLOR_PATTERN.matcher(input).replaceAll("");
return STRIP_COLOR_PATTERN.matcher( input ).replaceAll( "" );
}
public static String translateAlternateColorCodes(char altColorChar, String textToTranslate)
{
char[] b = textToTranslate.toCharArray();
for (int i = 0; i < b.length - 1; i++)
for ( int i = 0; i < b.length - 1; i++ )
{
if (b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i + 1]) > -1)
if ( b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf( b[i + 1] ) > -1 )
{
b[i] = ChatColor.COLOR_CHAR;
b[i + 1] = Character.toLowerCase(b[i + 1]);
b[i + 1] = Character.toLowerCase( b[i + 1] );
}
}
return new String(b);
return new String( b );
}
}

View File

@@ -27,8 +27,8 @@ public abstract class ProxyServer
*/
public static void setInstance(ProxyServer instance)
{
Preconditions.checkNotNull(instance, "instance");
Preconditions.checkArgument(ProxyServer.instance == null, "Instance already set");
Preconditions.checkNotNull( instance, "instance" );
Preconditions.checkArgument( ProxyServer.instance == null, "Instance already set" );
ProxyServer.instance = instance;
}

View File

@@ -40,7 +40,7 @@ public abstract class ServerInfo
@Synchronized("players")
public void addPlayer(ProxiedPlayer player)
{
players.add(player);
players.add( player );
}
/**
@@ -51,7 +51,7 @@ public abstract class ServerInfo
@Synchronized("players")
public void removePlayer(ProxiedPlayer player)
{
players.remove(player);
players.remove( player );
}
/**
@@ -62,7 +62,7 @@ public abstract class ServerInfo
@Synchronized("players")
public Collection<ProxiedPlayer> getPlayers()
{
return Collections.unmodifiableCollection(players);
return Collections.unmodifiableCollection( players );
}
/**

View File

@@ -27,7 +27,7 @@ public class ChatEvent extends TargetedEvent implements Cancellable
public ChatEvent(Connection sender, Connection receiver, String message)
{
super(sender, receiver);
super( sender, receiver );
this.message = message;
}
}

View File

@@ -30,7 +30,7 @@ public class PluginMessageEvent extends TargetedEvent implements Cancellable
public PluginMessageEvent(Connection sender, Connection receiver, String tag, byte[] data)
{
super(sender, receiver);
super( sender, receiver );
this.tag = tag;
this.data = data;
}

View File

@@ -25,7 +25,7 @@ public abstract class Command
*/
public Command(String name)
{
this(name, null);
this( name, null );
}
/**
@@ -38,7 +38,7 @@ public abstract class Command
*/
public Command(String name, String permission, String... aliases)
{
Preconditions.checkArgument(name != null, "name");
Preconditions.checkArgument( name != null, "name" );
this.name = name;
this.permission = permission;
this.aliases = aliases;

View File

@@ -12,34 +12,34 @@ public class PluginClassloader extends URLClassLoader
public PluginClassloader(URL[] urls)
{
super(urls);
allLoaders.add(this);
super( urls );
allLoaders.add( this );
}
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
{
return loadClass0(name, resolve, true);
return loadClass0( name, resolve, true );
}
private Class<?> loadClass0(String name, boolean resolve, boolean checkOther) throws ClassNotFoundException
{
try
{
return super.loadClass(name, resolve);
} catch (ClassNotFoundException ex)
return super.loadClass( name, resolve );
} catch ( ClassNotFoundException ex )
{
}
if (checkOther)
if ( checkOther )
{
for (PluginClassloader loader : allLoaders)
for ( PluginClassloader loader : allLoaders )
{
if (loader != this)
if ( loader != this )
{
try
{
return loader.loadClass0(name, resolve, false);
} catch (ClassNotFoundException ex)
return loader.loadClass0( name, resolve, false );
} catch ( ClassNotFoundException ex )
{
}
}

View File

@@ -27,7 +27,7 @@ import org.yaml.snakeyaml.Yaml;
public class PluginManager
{
private static final Pattern argsSplit = Pattern.compile(" ");
private static final Pattern argsSplit = Pattern.compile( " " );
/*========================================================================*/
private final Yaml yaml = new Yaml();
private final EventBus eventBus = new EventBus();
@@ -41,10 +41,10 @@ public class PluginManager
*/
public void registerCommand(Command command)
{
commandMap.put(command.getName().toLowerCase(), command);
for (String alias : command.getAliases())
commandMap.put( command.getName().toLowerCase(), command );
for ( String alias : command.getAliases() )
{
commandMap.put(alias.toLowerCase(), command);
commandMap.put( alias.toLowerCase(), command );
}
}
@@ -55,7 +55,7 @@ public class PluginManager
*/
public void unregisterCommand(Command command)
{
commandMap.values().remove(command);
commandMap.values().remove( command );
}
/**
@@ -68,28 +68,28 @@ public class PluginManager
*/
public boolean dispatchCommand(CommandSender sender, String commandLine)
{
String[] split = argsSplit.split(commandLine);
Command command = commandMap.get(split[0].toLowerCase());
if (command == null)
String[] split = argsSplit.split( commandLine );
Command command = commandMap.get( split[0].toLowerCase() );
if ( command == null )
{
return false;
}
String permission = command.getPermission();
if (permission != null && !permission.isEmpty() && !sender.hasPermission(permission))
if ( permission != null && !permission.isEmpty() && !sender.hasPermission( permission ) )
{
sender.sendMessage(ChatColor.RED + "You do not have permission to execute this command!");
sender.sendMessage( ChatColor.RED + "You do not have permission to execute this command!" );
return true;
}
String[] args = Arrays.copyOfRange(split, 1, split.length);
String[] args = Arrays.copyOfRange( split, 1, split.length );
try
{
command.execute(sender, args);
} catch (Exception ex)
command.execute( sender, args );
} catch ( Exception ex )
{
sender.sendMessage(ChatColor.RED + "An internal error occurred whilst executing this command, please check the console log for details.");
ProxyServer.getInstance().getLogger().log(Level.WARNING, "Error in dispatching command", ex);
sender.sendMessage( ChatColor.RED + "An internal error occurred whilst executing this command, please check the console log for details." );
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Error in dispatching command", ex );
}
return true;
}
@@ -112,7 +112,7 @@ public class PluginManager
*/
public Plugin getPlugin(String name)
{
return plugins.get(name);
return plugins.get( name );
}
/**
@@ -120,19 +120,19 @@ public class PluginManager
*/
public void enablePlugins()
{
for (Map.Entry<String, Plugin> entry : plugins.entrySet())
for ( Map.Entry<String, Plugin> entry : plugins.entrySet() )
{
Plugin plugin = entry.getValue();
try
{
plugin.onEnable();
ProxyServer.getInstance().getLogger().log(Level.INFO, "Enabled plugin {0} version {1} by {2}", new Object[]
ProxyServer.getInstance().getLogger().log( Level.INFO, "Enabled plugin {0} version {1} by {2}", new Object[]
{
entry.getKey(), plugin.getDescription().getVersion(), plugin.getDescription().getAuthor()
});
} catch (Exception ex)
} );
} catch ( Exception ex )
{
ProxyServer.getInstance().getLogger().log(Level.WARNING, "Exception encountered when loading plugin: " + entry.getKey(), ex);
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Exception encountered when loading plugin: " + entry.getKey(), ex );
}
}
}
@@ -147,31 +147,31 @@ public class PluginManager
*/
public void loadPlugin(File file) throws Exception
{
Preconditions.checkNotNull(file, "file");
Preconditions.checkArgument(file.isFile(), "Must load from file");
Preconditions.checkNotNull( file, "file" );
Preconditions.checkArgument( file.isFile(), "Must load from file" );
try (JarFile jar = new JarFile(file))
try ( JarFile jar = new JarFile( file ) )
{
JarEntry pdf = jar.getJarEntry("plugin.yml");
Preconditions.checkNotNull(pdf, "Plugin must have a plugin.yml");
JarEntry pdf = jar.getJarEntry( "plugin.yml" );
Preconditions.checkNotNull( pdf, "Plugin must have a plugin.yml" );
try (InputStream in = jar.getInputStream(pdf))
try ( InputStream in = jar.getInputStream( pdf ) )
{
PluginDescription desc = yaml.loadAs(in, PluginDescription.class);
URLClassLoader loader = new PluginClassloader(new URL[]
PluginDescription desc = yaml.loadAs( in, PluginDescription.class );
URLClassLoader loader = new PluginClassloader( new URL[]
{
file.toURI().toURL()
});
Class<?> main = loader.loadClass(desc.getMain());
} );
Class<?> main = loader.loadClass( desc.getMain() );
Plugin plugin = (Plugin) main.getDeclaredConstructor().newInstance();
plugin.init(desc);
plugins.put(desc.getName(), plugin);
plugin.init( desc );
plugins.put( desc.getName(), plugin );
plugin.onLoad();
ProxyServer.getInstance().getLogger().log(Level.INFO, "Loaded plugin {0} version {1} by {2}", new Object[]
ProxyServer.getInstance().getLogger().log( Level.INFO, "Loaded plugin {0} version {1} by {2}", new Object[]
{
desc.getName(), desc.getVersion(), desc.getAuthor()
});
} );
}
}
}
@@ -183,19 +183,19 @@ public class PluginManager
*/
public void loadPlugins(File folder)
{
Preconditions.checkNotNull(folder, "folder");
Preconditions.checkArgument(folder.isDirectory(), "Must load from a directory");
Preconditions.checkNotNull( folder, "folder" );
Preconditions.checkArgument( folder.isDirectory(), "Must load from a directory" );
for (File file : folder.listFiles())
for ( File file : folder.listFiles() )
{
if (file.isFile() && file.getName().endsWith(".jar"))
if ( file.isFile() && file.getName().endsWith( ".jar" ) )
{
try
{
loadPlugin(file);
} catch (Exception ex)
loadPlugin( file );
} catch ( Exception ex )
{
ProxyServer.getInstance().getLogger().log(Level.WARNING, "Could not load plugin from file " + file, ex);
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Could not load plugin from file " + file, ex );
}
}
}
@@ -211,7 +211,7 @@ public class PluginManager
*/
public <T extends Event> T callEvent(T event)
{
eventBus.post(event);
eventBus.post( event );
return event;
}
@@ -224,6 +224,6 @@ public class PluginManager
*/
public void registerListener(Listener listener)
{
eventBus.register(listener);
eventBus.register( listener );
}
}