Reformat API + Protocol
This commit is contained in:
parent
8840dade68
commit
ce6656afc0
@ -11,91 +11,91 @@ public enum ChatColor
|
|||||||
/**
|
/**
|
||||||
* Represents black.
|
* Represents black.
|
||||||
*/
|
*/
|
||||||
BLACK('0'),
|
BLACK( '0' ),
|
||||||
/**
|
/**
|
||||||
* Represents dark blue.
|
* Represents dark blue.
|
||||||
*/
|
*/
|
||||||
DARK_BLUE('1'),
|
DARK_BLUE( '1' ),
|
||||||
/**
|
/**
|
||||||
* Represents dark green.
|
* Represents dark green.
|
||||||
*/
|
*/
|
||||||
DARK_GREEN('2'),
|
DARK_GREEN( '2' ),
|
||||||
/**
|
/**
|
||||||
* Represents dark blue (aqua).
|
* Represents dark blue (aqua).
|
||||||
*/
|
*/
|
||||||
DARK_AQUA('3'),
|
DARK_AQUA( '3' ),
|
||||||
/**
|
/**
|
||||||
* Represents dark red.
|
* Represents dark red.
|
||||||
*/
|
*/
|
||||||
DARK_RED('4'),
|
DARK_RED( '4' ),
|
||||||
/**
|
/**
|
||||||
* Represents dark purple.
|
* Represents dark purple.
|
||||||
*/
|
*/
|
||||||
DARK_PURPLE('5'),
|
DARK_PURPLE( '5' ),
|
||||||
/**
|
/**
|
||||||
* Represents gold.
|
* Represents gold.
|
||||||
*/
|
*/
|
||||||
GOLD('6'),
|
GOLD( '6' ),
|
||||||
/**
|
/**
|
||||||
* Represents gray.
|
* Represents gray.
|
||||||
*/
|
*/
|
||||||
GRAY('7'),
|
GRAY( '7' ),
|
||||||
/**
|
/**
|
||||||
* Represents dark gray.
|
* Represents dark gray.
|
||||||
*/
|
*/
|
||||||
DARK_GRAY('8'),
|
DARK_GRAY( '8' ),
|
||||||
/**
|
/**
|
||||||
* Represents blue.
|
* Represents blue.
|
||||||
*/
|
*/
|
||||||
BLUE('9'),
|
BLUE( '9' ),
|
||||||
/**
|
/**
|
||||||
* Represents green.
|
* Represents green.
|
||||||
*/
|
*/
|
||||||
GREEN('a'),
|
GREEN( 'a' ),
|
||||||
/**
|
/**
|
||||||
* Represents aqua.
|
* Represents aqua.
|
||||||
*/
|
*/
|
||||||
AQUA('b'),
|
AQUA( 'b' ),
|
||||||
/**
|
/**
|
||||||
* Represents red.
|
* Represents red.
|
||||||
*/
|
*/
|
||||||
RED('c'),
|
RED( 'c' ),
|
||||||
/**
|
/**
|
||||||
* Represents light purple.
|
* Represents light purple.
|
||||||
*/
|
*/
|
||||||
LIGHT_PURPLE('d'),
|
LIGHT_PURPLE( 'd' ),
|
||||||
/**
|
/**
|
||||||
* Represents yellow.
|
* Represents yellow.
|
||||||
*/
|
*/
|
||||||
YELLOW('e'),
|
YELLOW( 'e' ),
|
||||||
/**
|
/**
|
||||||
* Represents white.
|
* Represents white.
|
||||||
*/
|
*/
|
||||||
WHITE('f'),
|
WHITE( 'f' ),
|
||||||
/**
|
/**
|
||||||
* Represents magical characters that change around randomly.
|
* Represents magical characters that change around randomly.
|
||||||
*/
|
*/
|
||||||
MAGIC('k'),
|
MAGIC( 'k' ),
|
||||||
/**
|
/**
|
||||||
* Makes the text bold.
|
* Makes the text bold.
|
||||||
*/
|
*/
|
||||||
BOLD('l'),
|
BOLD( 'l' ),
|
||||||
/**
|
/**
|
||||||
* Makes a line appear through the text.
|
* Makes a line appear through the text.
|
||||||
*/
|
*/
|
||||||
STRIKETHROUGH('m'),
|
STRIKETHROUGH( 'm' ),
|
||||||
/**
|
/**
|
||||||
* Makes the text appear underlined.
|
* Makes the text appear underlined.
|
||||||
*/
|
*/
|
||||||
UNDERLINE('n'),
|
UNDERLINE( 'n' ),
|
||||||
/**
|
/**
|
||||||
* Makes the text italic.
|
* Makes the text italic.
|
||||||
*/
|
*/
|
||||||
ITALIC('o'),
|
ITALIC( 'o' ),
|
||||||
/**
|
/**
|
||||||
* Resets all previous chat colors or formats.
|
* Resets all previous chat colors or formats.
|
||||||
*/
|
*/
|
||||||
RESET('r');
|
RESET( 'r' );
|
||||||
/**
|
/**
|
||||||
* The special character which prefixes all chat colour codes. Use this if
|
* The special character which prefixes all chat colour codes. Use this if
|
||||||
* you need to dynamically convert colour codes from your custom format.
|
* you need to dynamically convert colour codes from your custom format.
|
||||||
@ -104,7 +104,7 @@ public enum ChatColor
|
|||||||
/**
|
/**
|
||||||
* Pattern to remove all colour codes.
|
* 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}.
|
* This colour's colour char prefixed by the {@link #COLOR_CHAR}.
|
||||||
*/
|
*/
|
||||||
@ -112,10 +112,10 @@ public enum ChatColor
|
|||||||
|
|
||||||
private ChatColor(char code)
|
private ChatColor(char code)
|
||||||
{
|
{
|
||||||
this.toString = new String(new char[]
|
this.toString = new String( new char[]
|
||||||
{
|
{
|
||||||
COLOR_CHAR, code
|
COLOR_CHAR, code
|
||||||
});
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -132,25 +132,25 @@ public enum ChatColor
|
|||||||
*/
|
*/
|
||||||
public static String stripColor(final String input)
|
public static String stripColor(final String input)
|
||||||
{
|
{
|
||||||
if (input == null)
|
if ( input == null )
|
||||||
{
|
{
|
||||||
return 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)
|
public static String translateAlternateColorCodes(char altColorChar, String textToTranslate)
|
||||||
{
|
{
|
||||||
char[] b = textToTranslate.toCharArray();
|
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] = 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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,8 +27,8 @@ public abstract class ProxyServer
|
|||||||
*/
|
*/
|
||||||
public static void setInstance(ProxyServer instance)
|
public static void setInstance(ProxyServer instance)
|
||||||
{
|
{
|
||||||
Preconditions.checkNotNull(instance, "instance");
|
Preconditions.checkNotNull( instance, "instance" );
|
||||||
Preconditions.checkArgument(ProxyServer.instance == null, "Instance already set");
|
Preconditions.checkArgument( ProxyServer.instance == null, "Instance already set" );
|
||||||
ProxyServer.instance = instance;
|
ProxyServer.instance = instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public abstract class ServerInfo
|
|||||||
@Synchronized("players")
|
@Synchronized("players")
|
||||||
public void addPlayer(ProxiedPlayer player)
|
public void addPlayer(ProxiedPlayer player)
|
||||||
{
|
{
|
||||||
players.add(player);
|
players.add( player );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,7 +51,7 @@ public abstract class ServerInfo
|
|||||||
@Synchronized("players")
|
@Synchronized("players")
|
||||||
public void removePlayer(ProxiedPlayer player)
|
public void removePlayer(ProxiedPlayer player)
|
||||||
{
|
{
|
||||||
players.remove(player);
|
players.remove( player );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,7 +62,7 @@ public abstract class ServerInfo
|
|||||||
@Synchronized("players")
|
@Synchronized("players")
|
||||||
public Collection<ProxiedPlayer> getPlayers()
|
public Collection<ProxiedPlayer> getPlayers()
|
||||||
{
|
{
|
||||||
return Collections.unmodifiableCollection(players);
|
return Collections.unmodifiableCollection( players );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,7 +27,7 @@ public class ChatEvent extends TargetedEvent implements Cancellable
|
|||||||
|
|
||||||
public ChatEvent(Connection sender, Connection receiver, String message)
|
public ChatEvent(Connection sender, Connection receiver, String message)
|
||||||
{
|
{
|
||||||
super(sender, receiver);
|
super( sender, receiver );
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class PluginMessageEvent extends TargetedEvent implements Cancellable
|
|||||||
|
|
||||||
public PluginMessageEvent(Connection sender, Connection receiver, String tag, byte[] data)
|
public PluginMessageEvent(Connection sender, Connection receiver, String tag, byte[] data)
|
||||||
{
|
{
|
||||||
super(sender, receiver);
|
super( sender, receiver );
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ public abstract class Command
|
|||||||
*/
|
*/
|
||||||
public Command(String name)
|
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)
|
public Command(String name, String permission, String... aliases)
|
||||||
{
|
{
|
||||||
Preconditions.checkArgument(name != null, "name");
|
Preconditions.checkArgument( name != null, "name" );
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
this.aliases = aliases;
|
this.aliases = aliases;
|
||||||
|
@ -12,34 +12,34 @@ public class PluginClassloader extends URLClassLoader
|
|||||||
|
|
||||||
public PluginClassloader(URL[] urls)
|
public PluginClassloader(URL[] urls)
|
||||||
{
|
{
|
||||||
super(urls);
|
super( urls );
|
||||||
allLoaders.add(this);
|
allLoaders.add( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
|
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
|
private Class<?> loadClass0(String name, boolean resolve, boolean checkOther) throws ClassNotFoundException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return super.loadClass(name, resolve);
|
return super.loadClass( name, resolve );
|
||||||
} catch (ClassNotFoundException ex)
|
} catch ( ClassNotFoundException ex )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
if (checkOther)
|
if ( checkOther )
|
||||||
{
|
{
|
||||||
for (PluginClassloader loader : allLoaders)
|
for ( PluginClassloader loader : allLoaders )
|
||||||
{
|
{
|
||||||
if (loader != this)
|
if ( loader != this )
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return loader.loadClass0(name, resolve, false);
|
return loader.loadClass0( name, resolve, false );
|
||||||
} catch (ClassNotFoundException ex)
|
} catch ( ClassNotFoundException ex )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ import org.yaml.snakeyaml.Yaml;
|
|||||||
public class PluginManager
|
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 Yaml yaml = new Yaml();
|
||||||
private final EventBus eventBus = new EventBus();
|
private final EventBus eventBus = new EventBus();
|
||||||
@ -41,10 +41,10 @@ public class PluginManager
|
|||||||
*/
|
*/
|
||||||
public void registerCommand(Command command)
|
public void registerCommand(Command command)
|
||||||
{
|
{
|
||||||
commandMap.put(command.getName().toLowerCase(), command);
|
commandMap.put( command.getName().toLowerCase(), command );
|
||||||
for (String alias : command.getAliases())
|
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)
|
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)
|
public boolean dispatchCommand(CommandSender sender, String commandLine)
|
||||||
{
|
{
|
||||||
String[] split = argsSplit.split(commandLine);
|
String[] split = argsSplit.split( commandLine );
|
||||||
Command command = commandMap.get(split[0].toLowerCase());
|
Command command = commandMap.get( split[0].toLowerCase() );
|
||||||
if (command == null)
|
if ( command == null )
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String permission = command.getPermission();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] args = Arrays.copyOfRange(split, 1, split.length);
|
String[] args = Arrays.copyOfRange( split, 1, split.length );
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command.execute(sender, args);
|
command.execute( sender, args );
|
||||||
} catch (Exception ex)
|
} catch ( Exception ex )
|
||||||
{
|
{
|
||||||
sender.sendMessage(ChatColor.RED + "An internal error occurred whilst executing this command, please check the console log for details.");
|
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);
|
ProxyServer.getInstance().getLogger().log( Level.WARNING, "Error in dispatching command", ex );
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ public class PluginManager
|
|||||||
*/
|
*/
|
||||||
public Plugin getPlugin(String name)
|
public Plugin getPlugin(String name)
|
||||||
{
|
{
|
||||||
return plugins.get(name);
|
return plugins.get( name );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -120,19 +120,19 @@ public class PluginManager
|
|||||||
*/
|
*/
|
||||||
public void enablePlugins()
|
public void enablePlugins()
|
||||||
{
|
{
|
||||||
for (Map.Entry<String, Plugin> entry : plugins.entrySet())
|
for ( Map.Entry<String, Plugin> entry : plugins.entrySet() )
|
||||||
{
|
{
|
||||||
Plugin plugin = entry.getValue();
|
Plugin plugin = entry.getValue();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plugin.onEnable();
|
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()
|
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
|
public void loadPlugin(File file) throws Exception
|
||||||
{
|
{
|
||||||
Preconditions.checkNotNull(file, "file");
|
Preconditions.checkNotNull( file, "file" );
|
||||||
Preconditions.checkArgument(file.isFile(), "Must load from 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");
|
JarEntry pdf = jar.getJarEntry( "plugin.yml" );
|
||||||
Preconditions.checkNotNull(pdf, "Plugin must have a 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);
|
PluginDescription desc = yaml.loadAs( in, PluginDescription.class );
|
||||||
URLClassLoader loader = new PluginClassloader(new URL[]
|
URLClassLoader loader = new PluginClassloader( new URL[]
|
||||||
{
|
{
|
||||||
file.toURI().toURL()
|
file.toURI().toURL()
|
||||||
});
|
} );
|
||||||
Class<?> main = loader.loadClass(desc.getMain());
|
Class<?> main = loader.loadClass( desc.getMain() );
|
||||||
Plugin plugin = (Plugin) main.getDeclaredConstructor().newInstance();
|
Plugin plugin = (Plugin) main.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
plugin.init(desc);
|
plugin.init( desc );
|
||||||
plugins.put(desc.getName(), plugin);
|
plugins.put( desc.getName(), plugin );
|
||||||
plugin.onLoad();
|
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()
|
desc.getName(), desc.getVersion(), desc.getAuthor()
|
||||||
});
|
} );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -183,19 +183,19 @@ public class PluginManager
|
|||||||
*/
|
*/
|
||||||
public void loadPlugins(File folder)
|
public void loadPlugins(File folder)
|
||||||
{
|
{
|
||||||
Preconditions.checkNotNull(folder, "folder");
|
Preconditions.checkNotNull( folder, "folder" );
|
||||||
Preconditions.checkArgument(folder.isDirectory(), "Must load from a directory");
|
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
|
try
|
||||||
{
|
{
|
||||||
loadPlugin(file);
|
loadPlugin( file );
|
||||||
} catch (Exception ex)
|
} 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)
|
public <T extends Event> T callEvent(T event)
|
||||||
{
|
{
|
||||||
eventBus.post(event);
|
eventBus.post( event );
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,6 +224,6 @@ public class PluginManager
|
|||||||
*/
|
*/
|
||||||
public void registerListener(Listener listener)
|
public void registerListener(Listener listener)
|
||||||
{
|
{
|
||||||
eventBus.register(listener);
|
eventBus.register( listener );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,126 +2,350 @@ package net.md_5.mendax;
|
|||||||
|
|
||||||
import static net.md_5.mendax.PacketDefinitions.OpCode.*;
|
import static net.md_5.mendax.PacketDefinitions.OpCode.*;
|
||||||
|
|
||||||
public class PacketDefinitions {
|
public class PacketDefinitions
|
||||||
|
{
|
||||||
|
|
||||||
public static final OpCode[][] opCodes = new OpCode[256][];
|
public static final OpCode[][] opCodes = new OpCode[ 256 ][];
|
||||||
|
|
||||||
public enum OpCode {
|
public enum OpCode
|
||||||
|
{
|
||||||
|
|
||||||
BOOLEAN, BULK_CHUNK, BYTE, BYTE_INT, DOUBLE, FLOAT, INT, INT_3, INT_BYTE, ITEM, LONG, METADATA, OPTIONAL_MOTION, SHORT, SHORT_BYTE, SHORT_ITEM, STRING, USHORT_BYTE
|
BOOLEAN, BULK_CHUNK, BYTE, BYTE_INT, DOUBLE, FLOAT, INT, INT_3, INT_BYTE, ITEM, LONG, METADATA, OPTIONAL_MOTION, SHORT, SHORT_BYTE, SHORT_ITEM, STRING, USHORT_BYTE
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static
|
||||||
opCodes[0x00] = new OpCode[]{INT};
|
{
|
||||||
opCodes[0x01] = new OpCode[]{INT, STRING, BYTE, BYTE, BYTE, BYTE, BYTE};
|
opCodes[0x00] = new OpCode[]
|
||||||
opCodes[0x02] = new OpCode[]{BYTE, STRING, STRING, INT};
|
{
|
||||||
opCodes[0x03] = new OpCode[]{STRING};
|
INT
|
||||||
opCodes[0x04] = new OpCode[]{LONG, LONG};
|
};
|
||||||
opCodes[0x05] = new OpCode[]{INT, SHORT, ITEM};
|
opCodes[0x01] = new OpCode[]
|
||||||
opCodes[0x06] = new OpCode[]{INT, INT, INT};
|
{
|
||||||
opCodes[0x07] = new OpCode[]{INT, INT, BOOLEAN};
|
INT, STRING, BYTE, BYTE, BYTE, BYTE, BYTE
|
||||||
opCodes[0x08] = new OpCode[]{SHORT, SHORT, FLOAT};
|
};
|
||||||
opCodes[0x09] = new OpCode[]{INT, BYTE, BYTE, SHORT, STRING};
|
opCodes[0x02] = new OpCode[]
|
||||||
opCodes[0x0A] = new OpCode[]{BOOLEAN};
|
{
|
||||||
opCodes[0x0B] = new OpCode[]{DOUBLE, DOUBLE, DOUBLE, DOUBLE, BOOLEAN};
|
BYTE, STRING, STRING, INT
|
||||||
opCodes[0x0C] = new OpCode[]{FLOAT, FLOAT, BOOLEAN};
|
};
|
||||||
opCodes[0x0D] = new OpCode[]{DOUBLE, DOUBLE, DOUBLE, DOUBLE, FLOAT, FLOAT, BOOLEAN};
|
opCodes[0x03] = new OpCode[]
|
||||||
opCodes[0x0E] = new OpCode[]{BYTE, INT, BYTE, INT, BYTE};
|
{
|
||||||
opCodes[0x0F] = new OpCode[]{INT, BYTE, INT, BYTE, ITEM, BYTE, BYTE, BYTE};
|
STRING
|
||||||
opCodes[0x10] = new OpCode[]{SHORT};
|
};
|
||||||
opCodes[0x11] = new OpCode[]{INT, BYTE, INT, BYTE, INT};
|
opCodes[0x04] = new OpCode[]
|
||||||
opCodes[0x12] = new OpCode[]{INT, BYTE};
|
{
|
||||||
opCodes[0x13] = new OpCode[]{INT, BYTE};
|
LONG, LONG
|
||||||
opCodes[0x14] = new OpCode[]{INT, STRING, INT, INT, INT, BYTE, BYTE, SHORT, METADATA};
|
};
|
||||||
opCodes[0x16] = new OpCode[]{INT, INT};
|
opCodes[0x05] = new OpCode[]
|
||||||
opCodes[0x17] = new OpCode[]{INT, BYTE, INT, INT, INT, BYTE, BYTE, OPTIONAL_MOTION};
|
{
|
||||||
opCodes[0x18] = new OpCode[]{INT, BYTE, INT, INT, INT, BYTE, BYTE, BYTE, SHORT, SHORT, SHORT, METADATA};
|
INT, SHORT, ITEM
|
||||||
opCodes[0x19] = new OpCode[]{INT, STRING, INT, INT, INT, INT};
|
};
|
||||||
opCodes[0x1A] = new OpCode[]{INT, INT, INT, INT, SHORT};
|
opCodes[0x06] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, INT, INT
|
||||||
|
};
|
||||||
|
opCodes[0x07] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, INT, BOOLEAN
|
||||||
|
};
|
||||||
|
opCodes[0x08] = new OpCode[]
|
||||||
|
{
|
||||||
|
SHORT, SHORT, FLOAT
|
||||||
|
};
|
||||||
|
opCodes[0x09] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE, BYTE, SHORT, STRING
|
||||||
|
};
|
||||||
|
opCodes[0x0A] = new OpCode[]
|
||||||
|
{
|
||||||
|
BOOLEAN
|
||||||
|
};
|
||||||
|
opCodes[0x0B] = new OpCode[]
|
||||||
|
{
|
||||||
|
DOUBLE, DOUBLE, DOUBLE, DOUBLE, BOOLEAN
|
||||||
|
};
|
||||||
|
opCodes[0x0C] = new OpCode[]
|
||||||
|
{
|
||||||
|
FLOAT, FLOAT, BOOLEAN
|
||||||
|
};
|
||||||
|
opCodes[0x0D] = new OpCode[]
|
||||||
|
{
|
||||||
|
DOUBLE, DOUBLE, DOUBLE, DOUBLE, FLOAT, FLOAT, BOOLEAN
|
||||||
|
};
|
||||||
|
opCodes[0x0E] = new OpCode[]
|
||||||
|
{
|
||||||
|
BYTE, INT, BYTE, INT, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x0F] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE, INT, BYTE, ITEM, BYTE, BYTE, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x10] = new OpCode[]
|
||||||
|
{
|
||||||
|
SHORT
|
||||||
|
};
|
||||||
|
opCodes[0x11] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE, INT, BYTE, INT
|
||||||
|
};
|
||||||
|
opCodes[0x12] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x13] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x14] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, STRING, INT, INT, INT, BYTE, BYTE, SHORT, METADATA
|
||||||
|
};
|
||||||
|
opCodes[0x16] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, INT
|
||||||
|
};
|
||||||
|
opCodes[0x17] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE, INT, INT, INT, BYTE, BYTE, OPTIONAL_MOTION
|
||||||
|
};
|
||||||
|
opCodes[0x18] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE, INT, INT, INT, BYTE, BYTE, BYTE, SHORT, SHORT, SHORT, METADATA
|
||||||
|
};
|
||||||
|
opCodes[0x19] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, STRING, INT, INT, INT, INT
|
||||||
|
};
|
||||||
|
opCodes[0x1A] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, INT, INT, INT, SHORT
|
||||||
|
};
|
||||||
opCodes[0x1B] = null; // Does not exist
|
opCodes[0x1B] = null; // Does not exist
|
||||||
opCodes[0x1C] = new OpCode[]{INT, SHORT, SHORT, SHORT};
|
opCodes[0x1C] = new OpCode[]
|
||||||
opCodes[0x1D] = new OpCode[]{BYTE_INT};
|
{
|
||||||
opCodes[0x1E] = new OpCode[]{INT};
|
INT, SHORT, SHORT, SHORT
|
||||||
opCodes[0x1F] = new OpCode[]{INT, BYTE, BYTE, BYTE};
|
};
|
||||||
opCodes[0x20] = new OpCode[]{INT, BYTE, BYTE};
|
opCodes[0x1D] = new OpCode[]
|
||||||
opCodes[0x21] = new OpCode[]{INT, BYTE, BYTE, BYTE, BYTE, BYTE};
|
{
|
||||||
opCodes[0x22] = new OpCode[]{INT, INT, INT, INT, BYTE, BYTE};
|
BYTE_INT
|
||||||
opCodes[0x23] = new OpCode[]{INT, BYTE};
|
};
|
||||||
|
opCodes[0x1E] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT
|
||||||
|
};
|
||||||
|
opCodes[0x1F] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE, BYTE, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x20] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x21] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE, BYTE, BYTE, BYTE, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x22] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, INT, INT, INT, BYTE, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x23] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE
|
||||||
|
};
|
||||||
opCodes[0x24] = null; // Does not exist
|
opCodes[0x24] = null; // Does not exist
|
||||||
opCodes[0x25] = null; // Does not exist
|
opCodes[0x25] = null; // Does not exist
|
||||||
opCodes[0x26] = new OpCode[]{INT, BYTE};
|
opCodes[0x26] = new OpCode[]
|
||||||
opCodes[0x27] = new OpCode[]{INT, INT};
|
{
|
||||||
opCodes[0x28] = new OpCode[]{INT, METADATA};
|
INT, BYTE
|
||||||
opCodes[0x29] = new OpCode[]{INT, BYTE, BYTE, SHORT};
|
};
|
||||||
opCodes[0x2A] = new OpCode[]{INT, BYTE};
|
opCodes[0x27] = new OpCode[]
|
||||||
opCodes[0x2B] = new OpCode[]{FLOAT, SHORT, SHORT};
|
{
|
||||||
|
INT, INT
|
||||||
|
};
|
||||||
|
opCodes[0x28] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, METADATA
|
||||||
|
};
|
||||||
|
opCodes[0x29] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE, BYTE, SHORT
|
||||||
|
};
|
||||||
|
opCodes[0x2A] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x2B] = new OpCode[]
|
||||||
|
{
|
||||||
|
FLOAT, SHORT, SHORT
|
||||||
|
};
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// 0x2C -> 0x32 Do not exist
|
// 0x2C -> 0x32 Do not exist
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
opCodes[0x33] = new OpCode[]{INT, INT, BOOLEAN, SHORT, SHORT, INT_BYTE};
|
opCodes[0x33] = new OpCode[]
|
||||||
opCodes[0x34] = new OpCode[]{INT, INT, SHORT, INT_BYTE};
|
{
|
||||||
opCodes[0x35] = new OpCode[]{INT, BYTE, INT, SHORT, BYTE};
|
INT, INT, BOOLEAN, SHORT, SHORT, INT_BYTE
|
||||||
opCodes[0x36] = new OpCode[]{INT, SHORT, INT, BYTE, BYTE, SHORT};
|
};
|
||||||
opCodes[0x37] = new OpCode[]{INT, INT, INT, INT, BYTE};
|
opCodes[0x34] = new OpCode[]
|
||||||
opCodes[0x38] = new OpCode[]{BULK_CHUNK};
|
{
|
||||||
|
INT, INT, SHORT, INT_BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x35] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE, INT, SHORT, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x36] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, SHORT, INT, BYTE, BYTE, SHORT
|
||||||
|
};
|
||||||
|
opCodes[0x37] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, INT, INT, INT, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x38] = new OpCode[]
|
||||||
|
{
|
||||||
|
BULK_CHUNK
|
||||||
|
};
|
||||||
opCodes[0x39] = null; // Does not exist
|
opCodes[0x39] = null; // Does not exist
|
||||||
opCodes[0x3A] = null; // Does not exist
|
opCodes[0x3A] = null; // Does not exist
|
||||||
opCodes[0x3B] = null; // Does not exist
|
opCodes[0x3B] = null; // Does not exist
|
||||||
opCodes[0x3C] = new OpCode[]{DOUBLE, DOUBLE, DOUBLE, FLOAT, INT_3, FLOAT, FLOAT, FLOAT};
|
opCodes[0x3C] = new OpCode[]
|
||||||
opCodes[0x3D] = new OpCode[]{INT, INT, BYTE, INT, INT, BOOLEAN};
|
{
|
||||||
opCodes[0x3E] = new OpCode[]{STRING, INT, INT, INT, FLOAT, BYTE};
|
DOUBLE, DOUBLE, DOUBLE, FLOAT, INT_3, FLOAT, FLOAT, FLOAT
|
||||||
|
};
|
||||||
|
opCodes[0x3D] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, INT, BYTE, INT, INT, BOOLEAN
|
||||||
|
};
|
||||||
|
opCodes[0x3E] = new OpCode[]
|
||||||
|
{
|
||||||
|
STRING, INT, INT, INT, FLOAT, BYTE
|
||||||
|
};
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// 0x3F -> 0x45 Do not exist
|
// 0x3F -> 0x45 Do not exist
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
opCodes[0x46] = new OpCode[]{BYTE, BYTE};
|
opCodes[0x46] = new OpCode[]
|
||||||
opCodes[0x47] = new OpCode[]{INT, BYTE, INT, INT, INT};
|
{
|
||||||
|
BYTE, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x47] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, BYTE, INT, INT, INT
|
||||||
|
};
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// 0x4A -> 0x63 Do not exist
|
// 0x4A -> 0x63 Do not exist
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
opCodes[0x64] = new OpCode[]{BYTE, BYTE, STRING, BYTE};
|
opCodes[0x64] = new OpCode[]
|
||||||
opCodes[0x65] = new OpCode[]{BYTE};
|
{
|
||||||
opCodes[0x66] = new OpCode[]{BYTE, SHORT, BYTE, SHORT, BOOLEAN, ITEM};
|
BYTE, BYTE, STRING, BYTE
|
||||||
opCodes[0x67] = new OpCode[]{BYTE, SHORT, ITEM};
|
};
|
||||||
opCodes[0x68] = new OpCode[]{BYTE, SHORT_ITEM};
|
opCodes[0x65] = new OpCode[]
|
||||||
opCodes[0x69] = new OpCode[]{BYTE, SHORT, SHORT};
|
{
|
||||||
opCodes[0x6A] = new OpCode[]{BYTE, SHORT, BOOLEAN};
|
BYTE
|
||||||
opCodes[0x6B] = new OpCode[]{SHORT, ITEM};
|
};
|
||||||
opCodes[0x6C] = new OpCode[]{BYTE, BYTE};
|
opCodes[0x66] = new OpCode[]
|
||||||
|
{
|
||||||
|
BYTE, SHORT, BYTE, SHORT, BOOLEAN, ITEM
|
||||||
|
};
|
||||||
|
opCodes[0x67] = new OpCode[]
|
||||||
|
{
|
||||||
|
BYTE, SHORT, ITEM
|
||||||
|
};
|
||||||
|
opCodes[0x68] = new OpCode[]
|
||||||
|
{
|
||||||
|
BYTE, SHORT_ITEM
|
||||||
|
};
|
||||||
|
opCodes[0x69] = new OpCode[]
|
||||||
|
{
|
||||||
|
BYTE, SHORT, SHORT
|
||||||
|
};
|
||||||
|
opCodes[0x6A] = new OpCode[]
|
||||||
|
{
|
||||||
|
BYTE, SHORT, BOOLEAN
|
||||||
|
};
|
||||||
|
opCodes[0x6B] = new OpCode[]
|
||||||
|
{
|
||||||
|
SHORT, ITEM
|
||||||
|
};
|
||||||
|
opCodes[0x6C] = new OpCode[]
|
||||||
|
{
|
||||||
|
BYTE, BYTE
|
||||||
|
};
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// 0x6D -> 0x81 Do not exist
|
// 0x6D -> 0x81 Do not exist
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
opCodes[0x82] = new OpCode[]{INT, SHORT, INT, STRING, STRING, STRING, STRING};
|
opCodes[0x82] = new OpCode[]
|
||||||
opCodes[0x83] = new OpCode[]{SHORT, SHORT, USHORT_BYTE};
|
{
|
||||||
opCodes[0x84] = new OpCode[]{INT, SHORT, INT, BYTE, SHORT_BYTE};
|
INT, SHORT, INT, STRING, STRING, STRING, STRING
|
||||||
|
};
|
||||||
|
opCodes[0x83] = new OpCode[]
|
||||||
|
{
|
||||||
|
SHORT, SHORT, USHORT_BYTE
|
||||||
|
};
|
||||||
|
opCodes[0x84] = new OpCode[]
|
||||||
|
{
|
||||||
|
INT, SHORT, INT, BYTE, SHORT_BYTE
|
||||||
|
};
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// 0x85 -> 0xC7 Do not exist
|
// 0x85 -> 0xC7 Do not exist
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
opCodes[0xC8] = new OpCode[]{INT, BYTE};
|
opCodes[0xC8] = new OpCode[]
|
||||||
opCodes[0xC9] = new OpCode[]{STRING, BOOLEAN, SHORT};
|
{
|
||||||
opCodes[0xCA] = new OpCode[]{BYTE, BYTE, BYTE};
|
INT, BYTE
|
||||||
opCodes[0xCB] = new OpCode[]{STRING};
|
};
|
||||||
opCodes[0xCC] = new OpCode[]{STRING, BYTE, BYTE, BYTE, BOOLEAN};
|
opCodes[0xC9] = new OpCode[]
|
||||||
opCodes[0xCD] = new OpCode[]{BYTE};
|
{
|
||||||
|
STRING, BOOLEAN, SHORT
|
||||||
|
};
|
||||||
|
opCodes[0xCA] = new OpCode[]
|
||||||
|
{
|
||||||
|
BYTE, BYTE, BYTE
|
||||||
|
};
|
||||||
|
opCodes[0xCB] = new OpCode[]
|
||||||
|
{
|
||||||
|
STRING
|
||||||
|
};
|
||||||
|
opCodes[0xCC] = new OpCode[]
|
||||||
|
{
|
||||||
|
STRING, BYTE, BYTE, BYTE, BOOLEAN
|
||||||
|
};
|
||||||
|
opCodes[0xCD] = new OpCode[]
|
||||||
|
{
|
||||||
|
BYTE
|
||||||
|
};
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// 0xCE -> 0xF9 Do not exist
|
// 0xCE -> 0xF9 Do not exist
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
opCodes[0xFA] = new OpCode[]{STRING, SHORT_BYTE};
|
opCodes[0xFA] = new OpCode[]
|
||||||
|
{
|
||||||
|
STRING, SHORT_BYTE
|
||||||
|
};
|
||||||
opCodes[0xFB] = null; // Does not exist
|
opCodes[0xFB] = null; // Does not exist
|
||||||
opCodes[0xFC] = new OpCode[]{SHORT_BYTE, SHORT_BYTE};
|
opCodes[0xFC] = new OpCode[]
|
||||||
opCodes[0xFD] = new OpCode[]{STRING, SHORT_BYTE, SHORT_BYTE};
|
{
|
||||||
opCodes[0xFE] = new OpCode[]{}; // Should be byte, screw you too bitchy server admins!
|
SHORT_BYTE, SHORT_BYTE
|
||||||
opCodes[0xFF] = new OpCode[]{STRING};
|
};
|
||||||
|
opCodes[0xFD] = new OpCode[]
|
||||||
|
{
|
||||||
|
STRING, SHORT_BYTE, SHORT_BYTE
|
||||||
|
};
|
||||||
|
opCodes[0xFE] = new OpCode[]
|
||||||
|
{
|
||||||
|
}; // Should be byte, screw you too bitchy server admins!
|
||||||
|
opCodes[0xFF] = new OpCode[]
|
||||||
|
{
|
||||||
|
STRING
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,15 @@ package net.md_5.mendax.datainput;
|
|||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class BulkChunk extends Instruction {
|
public class BulkChunk extends Instruction
|
||||||
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(DataInput in, byte[] buffer) throws IOException {
|
void read(DataInput in, byte[] buffer) throws IOException
|
||||||
|
{
|
||||||
short count = in.readShort();
|
short count = in.readShort();
|
||||||
int size = in.readInt();
|
int size = in.readInt();
|
||||||
in.readBoolean();
|
in.readBoolean();
|
||||||
skip(in, buffer, size + count * 12);
|
skip( in, buffer, size + count * 12 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,23 @@ package net.md_5.mendax.datainput;
|
|||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
class ByteHeader extends Instruction {
|
class ByteHeader extends Instruction
|
||||||
|
{
|
||||||
|
|
||||||
private final Instruction child;
|
private final Instruction child;
|
||||||
|
|
||||||
ByteHeader(Instruction child) {
|
ByteHeader(Instruction child)
|
||||||
|
{
|
||||||
this.child = child;
|
this.child = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(DataInput in, byte[] buffer) throws IOException {
|
void read(DataInput in, byte[] buffer) throws IOException
|
||||||
|
{
|
||||||
byte size = in.readByte();
|
byte size = in.readByte();
|
||||||
for (byte b = 0; b < size; b++) {
|
for ( byte b = 0; b < size; b++ )
|
||||||
child.read(in, buffer);
|
{
|
||||||
|
child.read( in, buffer );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,56 +7,71 @@ import java.util.List;
|
|||||||
import net.md_5.mendax.PacketDefinitions;
|
import net.md_5.mendax.PacketDefinitions;
|
||||||
import net.md_5.mendax.PacketDefinitions.OpCode;
|
import net.md_5.mendax.PacketDefinitions.OpCode;
|
||||||
|
|
||||||
public class DataInputPacketReader {
|
public class DataInputPacketReader
|
||||||
|
{
|
||||||
|
|
||||||
private static final Instruction[][] instructions = new Instruction[256][];
|
private static final Instruction[][] instructions = new Instruction[ 256 ][];
|
||||||
|
|
||||||
static {
|
static
|
||||||
for (int i = 0; i < instructions.length; i++) {
|
{
|
||||||
|
for ( int i = 0; i < instructions.length; i++ )
|
||||||
|
{
|
||||||
List<Instruction> output = new ArrayList<Instruction>();
|
List<Instruction> output = new ArrayList<Instruction>();
|
||||||
|
|
||||||
OpCode[] enums = PacketDefinitions.opCodes[i];
|
OpCode[] enums = PacketDefinitions.opCodes[i];
|
||||||
if (enums != null) {
|
if ( enums != null )
|
||||||
for (OpCode struct : enums) {
|
{
|
||||||
try {
|
for ( OpCode struct : enums )
|
||||||
output.add((Instruction) Instruction.class.getDeclaredField(struct.name()).get(null));
|
{
|
||||||
} catch (Exception ex) {
|
try
|
||||||
throw new UnsupportedOperationException("No definition for " + struct.name());
|
{
|
||||||
|
output.add( (Instruction) Instruction.class.getDeclaredField( struct.name() ).get( null ) );
|
||||||
|
} catch ( Exception ex )
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( "No definition for " + struct.name() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Instruction> crushed = new ArrayList<Instruction>();
|
List<Instruction> crushed = new ArrayList<Instruction>();
|
||||||
int nextJumpSize = 0;
|
int nextJumpSize = 0;
|
||||||
for (Instruction child : output) {
|
for ( Instruction child : output )
|
||||||
if (child instanceof Jump) {
|
{
|
||||||
nextJumpSize += ((Jump) child).len;
|
if ( child instanceof Jump )
|
||||||
} else {
|
{
|
||||||
if (nextJumpSize != 0) {
|
nextJumpSize += ( (Jump) child ).len;
|
||||||
crushed.add(new Jump(nextJumpSize));
|
} else
|
||||||
|
{
|
||||||
|
if ( nextJumpSize != 0 )
|
||||||
|
{
|
||||||
|
crushed.add( new Jump( nextJumpSize ) );
|
||||||
}
|
}
|
||||||
crushed.add(child);
|
crushed.add( child );
|
||||||
nextJumpSize = 0;
|
nextJumpSize = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nextJumpSize != 0) {
|
if ( nextJumpSize != 0 )
|
||||||
crushed.add(new Jump(nextJumpSize));
|
{
|
||||||
|
crushed.add( new Jump( nextJumpSize ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
instructions[i] = crushed.toArray(new Instruction[crushed.size()]);
|
instructions[i] = crushed.toArray( new Instruction[ crushed.size() ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void readPacket(DataInput in, byte[] buffer) throws IOException {
|
public static void readPacket(DataInput in, byte[] buffer) throws IOException
|
||||||
|
{
|
||||||
int packetId = in.readUnsignedByte();
|
int packetId = in.readUnsignedByte();
|
||||||
Instruction[] packetDef = instructions[packetId];
|
Instruction[] packetDef = instructions[packetId];
|
||||||
|
|
||||||
if (packetDef == null) {
|
if ( packetDef == null )
|
||||||
throw new IOException("Unknown packet id " + packetId);
|
{
|
||||||
|
throw new IOException( "Unknown packet id " + packetId );
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Instruction instruction : packetDef) {
|
for ( Instruction instruction : packetDef )
|
||||||
instruction.read(in, buffer);
|
{
|
||||||
|
instruction.read( in, buffer );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,32 +3,34 @@ package net.md_5.mendax.datainput;
|
|||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
abstract class Instruction {
|
abstract class Instruction
|
||||||
|
{
|
||||||
|
|
||||||
static final Instruction BOOLEAN = new Jump(1);
|
static final Instruction BOOLEAN = new Jump( 1 );
|
||||||
static final Instruction BULK_CHUNK = new BulkChunk();
|
static final Instruction BULK_CHUNK = new BulkChunk();
|
||||||
static final Instruction BYTE = new Jump(1);
|
static final Instruction BYTE = new Jump( 1 );
|
||||||
// BYTE_INT moved down
|
// BYTE_INT moved down
|
||||||
static final Instruction DOUBLE = new Jump(8);
|
static final Instruction DOUBLE = new Jump( 8 );
|
||||||
static final Instruction FLOAT = new Jump(4);
|
static final Instruction FLOAT = new Jump( 4 );
|
||||||
static final Instruction INT = new Jump(4);
|
static final Instruction INT = new Jump( 4 );
|
||||||
static final Instruction INT_3 = new IntHeader(new Jump(3));
|
static final Instruction INT_3 = new IntHeader( new Jump( 3 ) );
|
||||||
static final Instruction INT_BYTE = new IntHeader(BYTE);
|
static final Instruction INT_BYTE = new IntHeader( BYTE );
|
||||||
static final Instruction ITEM = new Item();
|
static final Instruction ITEM = new Item();
|
||||||
static final Instruction LONG = new Jump(8);
|
static final Instruction LONG = new Jump( 8 );
|
||||||
static final Instruction METADATA = new MetaData();
|
static final Instruction METADATA = new MetaData();
|
||||||
static final Instruction OPTIONAL_MOTION = new OptionalMotion();
|
static final Instruction OPTIONAL_MOTION = new OptionalMotion();
|
||||||
static final Instruction SHORT = new Jump(2);
|
static final Instruction SHORT = new Jump( 2 );
|
||||||
static final Instruction SHORT_BYTE = new ShortHeader(BYTE);
|
static final Instruction SHORT_BYTE = new ShortHeader( BYTE );
|
||||||
static final Instruction SHORT_ITEM = new ShortHeader(ITEM);
|
static final Instruction SHORT_ITEM = new ShortHeader( ITEM );
|
||||||
static final Instruction STRING = new ShortHeader(new Jump(2));
|
static final Instruction STRING = new ShortHeader( new Jump( 2 ) );
|
||||||
static final Instruction USHORT_BYTE = new UnsignedShortByte();
|
static final Instruction USHORT_BYTE = new UnsignedShortByte();
|
||||||
// Illegal forward references below this line
|
// Illegal forward references below this line
|
||||||
static final Instruction BYTE_INT = new ByteHeader(INT);
|
static final Instruction BYTE_INT = new ByteHeader( INT );
|
||||||
|
|
||||||
abstract void read(DataInput in, byte[] buffer) throws IOException;
|
abstract void read(DataInput in, byte[] buffer) throws IOException;
|
||||||
|
|
||||||
final void skip(DataInput in, byte[] buffer, int len) throws IOException {
|
final void skip(DataInput in, byte[] buffer, int len) throws IOException
|
||||||
in.readFully(buffer, 0, len);
|
{
|
||||||
|
in.readFully( buffer, 0, len );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,23 @@ package net.md_5.mendax.datainput;
|
|||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
class IntHeader extends Instruction {
|
class IntHeader extends Instruction
|
||||||
|
{
|
||||||
|
|
||||||
private final Instruction child;
|
private final Instruction child;
|
||||||
|
|
||||||
IntHeader(Instruction child) {
|
IntHeader(Instruction child)
|
||||||
|
{
|
||||||
this.child = child;
|
this.child = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(DataInput in, byte[] buffer) throws IOException {
|
void read(DataInput in, byte[] buffer) throws IOException
|
||||||
|
{
|
||||||
int size = in.readInt();
|
int size = in.readInt();
|
||||||
for (int i = 0; i < size; i++) {
|
for ( int i = 0; i < size; i++ )
|
||||||
child.read(in, buffer);
|
{
|
||||||
|
child.read( in, buffer );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,17 @@ package net.md_5.mendax.datainput;
|
|||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
class Item extends Instruction {
|
class Item extends Instruction
|
||||||
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(DataInput in, byte[] buffer) throws IOException {
|
void read(DataInput in, byte[] buffer) throws IOException
|
||||||
|
{
|
||||||
short type = in.readShort();
|
short type = in.readShort();
|
||||||
if (type >= 0) {
|
if ( type >= 0 )
|
||||||
skip(in, buffer, 3);
|
{
|
||||||
SHORT_BYTE.read(in, buffer);
|
skip( in, buffer, 3 );
|
||||||
|
SHORT_BYTE.read( in, buffer );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,23 @@ package net.md_5.mendax.datainput;
|
|||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
class Jump extends Instruction {
|
class Jump extends Instruction
|
||||||
|
{
|
||||||
|
|
||||||
final int len;
|
final int len;
|
||||||
|
|
||||||
Jump(int len) {
|
Jump(int len)
|
||||||
if (len < 0) {
|
{
|
||||||
|
if ( len < 0 )
|
||||||
|
{
|
||||||
throw new IndexOutOfBoundsException();
|
throw new IndexOutOfBoundsException();
|
||||||
}
|
}
|
||||||
this.len = len;
|
this.len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(DataInput in, byte[] buffer) throws IOException {
|
void read(DataInput in, byte[] buffer) throws IOException
|
||||||
skip(in, buffer, len);
|
{
|
||||||
|
skip( in, buffer, len );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,37 +3,41 @@ package net.md_5.mendax.datainput;
|
|||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
class MetaData extends Instruction {
|
class MetaData extends Instruction
|
||||||
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(DataInput in, byte[] buffer) throws IOException {
|
void read(DataInput in, byte[] buffer) throws IOException
|
||||||
|
{
|
||||||
int x = in.readUnsignedByte();
|
int x = in.readUnsignedByte();
|
||||||
while (x != 127) {
|
while ( x != 127 )
|
||||||
|
{
|
||||||
int type = x >> 5;
|
int type = x >> 5;
|
||||||
switch (type) {
|
switch ( type )
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
BYTE.read(in, buffer);
|
BYTE.read( in, buffer );
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
SHORT.read(in, buffer);
|
SHORT.read( in, buffer );
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
INT.read(in, buffer);
|
INT.read( in, buffer );
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
FLOAT.read(in, buffer);
|
FLOAT.read( in, buffer );
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
STRING.read(in, buffer);
|
STRING.read( in, buffer );
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
ITEM.read(in, buffer);
|
ITEM.read( in, buffer );
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
skip(in, buffer, 12); // int, int, int
|
skip( in, buffer, 12 ); // int, int, int
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown metadata type " + type);
|
throw new IllegalArgumentException( "Unknown metadata type " + type );
|
||||||
}
|
}
|
||||||
x = in.readUnsignedByte();
|
x = in.readUnsignedByte();
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,16 @@ package net.md_5.mendax.datainput;
|
|||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class OptionalMotion extends Instruction {
|
public class OptionalMotion extends Instruction
|
||||||
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(DataInput in, byte[] buffer) throws IOException {
|
void read(DataInput in, byte[] buffer) throws IOException
|
||||||
|
{
|
||||||
int data = in.readInt();
|
int data = in.readInt();
|
||||||
if (data > 0) {
|
if ( data > 0 )
|
||||||
skip(in, buffer, 6);
|
{
|
||||||
|
skip( in, buffer, 6 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,23 @@ package net.md_5.mendax.datainput;
|
|||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
class ShortHeader extends Instruction {
|
class ShortHeader extends Instruction
|
||||||
|
{
|
||||||
|
|
||||||
private final Instruction child;
|
private final Instruction child;
|
||||||
|
|
||||||
ShortHeader(Instruction child) {
|
ShortHeader(Instruction child)
|
||||||
|
{
|
||||||
this.child = child;
|
this.child = child;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(DataInput in, byte[] buffer) throws IOException {
|
void read(DataInput in, byte[] buffer) throws IOException
|
||||||
|
{
|
||||||
short size = in.readShort();
|
short size = in.readShort();
|
||||||
for (short s = 0; s < size; s++) {
|
for ( short s = 0; s < size; s++ )
|
||||||
child.read(in, buffer);
|
{
|
||||||
|
child.read( in, buffer );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,13 @@ package net.md_5.mendax.datainput;
|
|||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class UnsignedShortByte extends Instruction {
|
public class UnsignedShortByte extends Instruction
|
||||||
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void read(DataInput in, byte[] buffer) throws IOException {
|
void read(DataInput in, byte[] buffer) throws IOException
|
||||||
|
{
|
||||||
int size = in.readUnsignedShort();
|
int size = in.readUnsignedShort();
|
||||||
skip(in, buffer, size);
|
skip( in, buffer, size );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user