Clean-up and format; use diamond operator.

This commit is contained in:
Major-
2014-07-09 23:29:46 +01:00
parent 27b228a836
commit 31ba87262a
491 changed files with 22126 additions and 22125 deletions
+252 -252
View File
@@ -25,281 +25,281 @@ package net.burtleburtle.bob.rand;
*/ */
public final class IsaacRandom { public final class IsaacRandom {
/** /**
* The golden ratio. * The golden ratio.
*/ */
private static final int GOLDEN_RATIO = 0x9e3779b9; private static final int GOLDEN_RATIO = 0x9e3779b9;
/** /**
* The log of the size of the result and memory arrays. * The log of the size of the result and memory arrays.
*/ */
private static final int LOG_SIZE = 8; private static final int LOG_SIZE = 8;
/** /**
* The size of the result and memory arrays. * The size of the result and memory arrays.
*/ */
private static final int SIZE = 1 << LOG_SIZE; private static final int SIZE = 1 << LOG_SIZE;
/** /**
* A mask for pseudorandom lookup. * A mask for pseudorandom lookup.
*/ */
private static int MASK = SIZE - 1 << 2; private static int MASK = SIZE - 1 << 2;
/** /**
* The accumulator. * The accumulator.
*/ */
private int a; private int a;
/** /**
* The last result. * The last result.
*/ */
private int b; private int b;
/** /**
* The counter. * The counter.
*/ */
private int c; private int c;
/** /**
* The count through the results in the results array. * The count through the results in the results array.
*/ */
private int count; private int count;
/** /**
* The internal state. * The internal state.
*/ */
private int[] mem; private int[] mem;
/** /**
* The results given to the user. * The results given to the user.
*/ */
private int[] rsl; private int[] rsl;
/** /**
* Creates the random number generator without an initial seed. * Creates the random number generator without an initial seed.
*/ */
public IsaacRandom() { public IsaacRandom() {
mem = new int[SIZE]; mem = new int[SIZE];
rsl = new int[SIZE]; rsl = new int[SIZE];
init(false); init(false);
}
/**
* Creates the random number generator with the specified seed.
*
* @param seed The seed.
*/
public IsaacRandom(int[] seed) {
mem = new int[SIZE];
rsl = new int[SIZE];
for (int i = 0; i < seed.length; ++i) {
rsl[i] = seed[i];
}
init(true);
}
/**
* Initialises this random number generator.
*
* @param hasSeed Set to {@code true} if a seed was passed to the constructor.
*/
private void init(boolean hasSeed) {
int i;
int a, b, c, d, e, f, g, h;
a = b = c = d = e = f = g = h = GOLDEN_RATIO;
for (i = 0; i < 4; ++i) {
a ^= b << 11;
d += a;
b += c;
b ^= c >>> 2;
e += b;
c += d;
c ^= d << 8;
f += c;
d += e;
d ^= e >>> 16;
g += d;
e += f;
e ^= f << 10;
h += e;
f += g;
f ^= g >>> 4;
a += f;
g += h;
g ^= h << 8;
b += g;
h += a;
h ^= a >>> 9;
c += h;
a += b;
} }
/** for (i = 0; i < SIZE; i += 8) { /* fill in mem[] with messy stuff */
* Creates the random number generator with the specified seed. if (hasSeed) {
* a += rsl[i];
* @param seed The seed. b += rsl[i + 1];
*/ c += rsl[i + 2];
public IsaacRandom(int[] seed) { d += rsl[i + 3];
mem = new int[SIZE]; e += rsl[i + 4];
rsl = new int[SIZE]; f += rsl[i + 5];
for (int i = 0; i < seed.length; ++i) { g += rsl[i + 6];
rsl[i] = seed[i]; h += rsl[i + 7];
} }
init(true); a ^= b << 11;
d += a;
b += c;
b ^= c >>> 2;
e += b;
c += d;
c ^= d << 8;
f += c;
d += e;
d ^= e >>> 16;
g += d;
e += f;
e ^= f << 10;
h += e;
f += g;
f ^= g >>> 4;
a += f;
g += h;
g ^= h << 8;
b += g;
h += a;
h ^= a >>> 9;
c += h;
a += b;
mem[i] = a;
mem[i + 1] = b;
mem[i + 2] = c;
mem[i + 3] = d;
mem[i + 4] = e;
mem[i + 5] = f;
mem[i + 6] = g;
mem[i + 7] = h;
} }
/** if (hasSeed) { /* second pass makes all of seed affect all of mem */
* Initialises this random number generator. for (i = 0; i < SIZE; i += 8) {
* a += mem[i];
* @param hasSeed Set to {@code true} if a seed was passed to the constructor. b += mem[i + 1];
*/ c += mem[i + 2];
private void init(boolean hasSeed) { d += mem[i + 3];
int i; e += mem[i + 4];
int a, b, c, d, e, f, g, h; f += mem[i + 5];
a = b = c = d = e = f = g = h = GOLDEN_RATIO; g += mem[i + 6];
h += mem[i + 7];
for (i = 0; i < 4; ++i) { a ^= b << 11;
a ^= b << 11; d += a;
d += a; b += c;
b += c; b ^= c >>> 2;
b ^= c >>> 2; e += b;
e += b; c += d;
c += d; c ^= d << 8;
c ^= d << 8; f += c;
f += c; d += e;
d += e; d ^= e >>> 16;
d ^= e >>> 16; g += d;
g += d; e += f;
e += f; e ^= f << 10;
e ^= f << 10; h += e;
h += e; f += g;
f += g; f ^= g >>> 4;
f ^= g >>> 4; a += f;
a += f; g += h;
g += h; g ^= h << 8;
g ^= h << 8; b += g;
b += g; h += a;
h += a; h ^= a >>> 9;
h ^= a >>> 9; c += h;
c += h; a += b;
a += b; mem[i] = a;
} mem[i + 1] = b;
mem[i + 2] = c;
for (i = 0; i < SIZE; i += 8) { /* fill in mem[] with messy stuff */ mem[i + 3] = d;
if (hasSeed) { mem[i + 4] = e;
a += rsl[i]; mem[i + 5] = f;
b += rsl[i + 1]; mem[i + 6] = g;
c += rsl[i + 2]; mem[i + 7] = h;
d += rsl[i + 3]; }
e += rsl[i + 4];
f += rsl[i + 5];
g += rsl[i + 6];
h += rsl[i + 7];
}
a ^= b << 11;
d += a;
b += c;
b ^= c >>> 2;
e += b;
c += d;
c ^= d << 8;
f += c;
d += e;
d ^= e >>> 16;
g += d;
e += f;
e ^= f << 10;
h += e;
f += g;
f ^= g >>> 4;
a += f;
g += h;
g ^= h << 8;
b += g;
h += a;
h ^= a >>> 9;
c += h;
a += b;
mem[i] = a;
mem[i + 1] = b;
mem[i + 2] = c;
mem[i + 3] = d;
mem[i + 4] = e;
mem[i + 5] = f;
mem[i + 6] = g;
mem[i + 7] = h;
}
if (hasSeed) { /* second pass makes all of seed affect all of mem */
for (i = 0; i < SIZE; i += 8) {
a += mem[i];
b += mem[i + 1];
c += mem[i + 2];
d += mem[i + 3];
e += mem[i + 4];
f += mem[i + 5];
g += mem[i + 6];
h += mem[i + 7];
a ^= b << 11;
d += a;
b += c;
b ^= c >>> 2;
e += b;
c += d;
c ^= d << 8;
f += c;
d += e;
d ^= e >>> 16;
g += d;
e += f;
e ^= f << 10;
h += e;
f += g;
f ^= g >>> 4;
a += f;
g += h;
g ^= h << 8;
b += g;
h += a;
h ^= a >>> 9;
c += h;
a += b;
mem[i] = a;
mem[i + 1] = b;
mem[i + 2] = c;
mem[i + 3] = d;
mem[i + 4] = e;
mem[i + 5] = f;
mem[i + 6] = g;
mem[i + 7] = h;
}
}
isaac();
count = SIZE;
} }
/** isaac();
* Generates 256 results. count = SIZE;
*/ }
private void isaac() {
int i, j, x, y;
b += ++c; /**
for (i = 0, j = SIZE / 2; i < SIZE / 2;) { * Generates 256 results.
x = mem[i]; */
a ^= a << 13; private void isaac() {
a += mem[j++]; int i, j, x, y;
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
x = mem[i]; b += ++c;
a ^= a >>> 6; for (i = 0, j = SIZE / 2; i < SIZE / 2;) {
a += mem[j++]; x = mem[i];
mem[i] = y = mem[(x & MASK) >> 2] + a + b; a ^= a << 13;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x; a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
x = mem[i]; x = mem[i];
a ^= a << 2; a ^= a >>> 6;
a += mem[j++]; a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b; mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x; rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
x = mem[i]; x = mem[i];
a ^= a >>> 16; a ^= a << 2;
a += mem[j++]; a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b; mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x; rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
}
for (j = 0; j < SIZE / 2;) { x = mem[i];
x = mem[i]; a ^= a >>> 16;
a ^= a << 13; a += mem[j++];
a += mem[j++]; mem[i] = y = mem[(x & MASK) >> 2] + a + b;
mem[i] = y = mem[(x & MASK) >> 2] + a + b; rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
x = mem[i];
a ^= a >>> 6;
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
x = mem[i];
a ^= a << 2;
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
x = mem[i];
a ^= a >>> 16;
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
}
} }
/** for (j = 0; j < SIZE / 2;) {
* Gets the next random value. x = mem[i];
* a ^= a << 13;
* @return The next random value. a += mem[j++];
*/ mem[i] = y = mem[(x & MASK) >> 2] + a + b;
public int nextInt() { rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
if (0 == count--) {
isaac(); x = mem[i];
count = SIZE - 1; a ^= a >>> 6;
} a += mem[j++];
return rsl[count]; mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
x = mem[i];
a ^= a << 2;
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
x = mem[i];
a ^= a >>> 16;
a += mem[j++];
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
} }
}
/**
* Gets the next random value.
*
* @return The next random value.
*/
public int nextInt() {
if (0 == count--) {
isaac();
count = SIZE - 1;
}
return rsl[count];
}
} }
+124 -124
View File
@@ -32,144 +32,144 @@ import org.apollo.util.plugin.PluginManager;
*/ */
public final class Server { public final class Server {
/** /**
* The logger for this class. * The logger for this class.
*/ */
private static final Logger logger = Logger.getLogger(Server.class.getName()); private static final Logger logger = Logger.getLogger(Server.class.getName());
/** /**
* The entry point of the Apollo server application. * The entry point of the Apollo server application.
* *
* @param args The command-line arguments passed to the application. * @param args The command-line arguments passed to the application.
*/ */
public static void main(String[] args) { public static void main(String[] args) {
try { try {
Server server = new Server(); Server server = new Server();
server.init(args.length == 1 ? args[0] : Release317.class.getName()); server.init(args.length == 1 ? args[0] : Release317.class.getName());
SocketAddress service = new InetSocketAddress(NetworkConstants.SERVICE_PORT); SocketAddress service = new InetSocketAddress(NetworkConstants.SERVICE_PORT);
SocketAddress http = new InetSocketAddress(NetworkConstants.HTTP_PORT); SocketAddress http = new InetSocketAddress(NetworkConstants.HTTP_PORT);
SocketAddress jaggrab = new InetSocketAddress(NetworkConstants.JAGGRAB_PORT); SocketAddress jaggrab = new InetSocketAddress(NetworkConstants.JAGGRAB_PORT);
server.start(); server.start();
server.bind(service, http, jaggrab); server.bind(service, http, jaggrab);
} catch (Throwable t) { } catch (Throwable t) {
logger.log(Level.SEVERE, "Error whilst starting server.", t); logger.log(Level.SEVERE, "Error whilst starting server.", t);
} }
}
/**
* The server's context.
*/
private ServerContext context;
/**
* The {@link ServerBootstrap} for the HTTP listener.
*/
private final ServerBootstrap httpBootstrap = new ServerBootstrap();
/**
* The {@link ServerBootstrap} for the JAGGRAB listener.
*/
private final ServerBootstrap jagGrabBootstrap = new ServerBootstrap();
/**
* The {@link ServerBootstrap} for the service listener.
*/
private final ServerBootstrap serviceBootstrap = new ServerBootstrap();
/**
* The event loop group.
*/
private final EventLoopGroup loopGroup = new NioEventLoopGroup();
/**
* The service manager.
*/
private final ServiceManager serviceManager;
/**
* Creates the Apollo server.
*
* @throws Exception If an error occurs whilst creating services.
*/
public Server() throws Exception {
logger.info("Starting Apollo...");
serviceManager = new ServiceManager();
}
/**
* Binds the server to the specified address.
*
* @param serviceAddress The service address to bind to.
* @param httpAddress The HTTP address to bind to.
* @param jagGrabAddress The JAGGRAB address to bind to.
*/
public void bind(SocketAddress serviceAddress, SocketAddress httpAddress, SocketAddress jagGrabAddress) {
logger.info("Binding service listener to address: " + serviceAddress + "...");
serviceBootstrap.bind(serviceAddress);
logger.info("Binding HTTP listener to address: " + httpAddress + "...");
try {
httpBootstrap.bind(httpAddress);
} catch (Throwable t) {
logger.log(Level.WARNING,
"Binding to HTTP failed: client will use JAGGRAB as a fallback (not recommended)!", t);
} }
/** logger.info("Binding JAGGRAB listener to address: " + jagGrabAddress + "...");
* The server's context. jagGrabBootstrap.bind(jagGrabAddress);
*/
private ServerContext context;
/** logger.info("Ready for connections.");
* The {@link ServerBootstrap} for the HTTP listener. }
*/
private final ServerBootstrap httpBootstrap = new ServerBootstrap();
/** /**
* The {@link ServerBootstrap} for the JAGGRAB listener. * Initialises the server.
*/ *
private final ServerBootstrap jagGrabBootstrap = new ServerBootstrap(); * @param releaseClassName The class name of the current active {@link Release}.
* @throws ClassNotFoundException If the release class could not be found.
* @throws IllegalAccessException If the release class could not be accessed.
* @throws InstantiationException If the release class could not be instantiated.
*/
public void init(String releaseClassName) throws ClassNotFoundException, InstantiationException,
IllegalAccessException {
Class<?> clazz = Class.forName(releaseClassName);
Release release = (Release) clazz.newInstance();
/** logger.info("Initialized release #" + release.getReleaseNumber() + ".");
* The {@link ServerBootstrap} for the service listener.
*/
private final ServerBootstrap serviceBootstrap = new ServerBootstrap();
/** serviceBootstrap.group(loopGroup);
* The event loop group. httpBootstrap.group(loopGroup);
*/ jagGrabBootstrap.group(loopGroup);
private final EventLoopGroup loopGroup = new NioEventLoopGroup();
/** context = new ServerContext(release, serviceManager);
* The service manager. ApolloHandler handler = new ApolloHandler(context);
*/
private final ServiceManager serviceManager;
/** ChannelInitializer<SocketChannel> serviceInitializer = new ServiceChannelInitializer(handler);
* Creates the Apollo server. serviceBootstrap.channel(NioServerSocketChannel.class);
* serviceBootstrap.childHandler(serviceInitializer);
* @throws Exception If an error occurs whilst creating services.
*/
public Server() throws Exception {
logger.info("Starting Apollo...");
serviceManager = new ServiceManager();
}
/** ChannelInitializer<SocketChannel> httpInitializer = new HttpChannelInitializer(handler);
* Binds the server to the specified address. httpBootstrap.channel(NioServerSocketChannel.class);
* httpBootstrap.childHandler(httpInitializer);
* @param serviceAddress The service address to bind to.
* @param httpAddress The HTTP address to bind to.
* @param jagGrabAddress The JAGGRAB address to bind to.
*/
public void bind(SocketAddress serviceAddress, SocketAddress httpAddress, SocketAddress jagGrabAddress) {
logger.info("Binding service listener to address: " + serviceAddress + "...");
serviceBootstrap.bind(serviceAddress);
logger.info("Binding HTTP listener to address: " + httpAddress + "..."); ChannelInitializer<SocketChannel> jagGrabInitializer = new JagGrabChannelInitializer(handler);
try { jagGrabBootstrap.channel(NioServerSocketChannel.class);
httpBootstrap.bind(httpAddress); jagGrabBootstrap.childHandler(jagGrabInitializer);
} catch (Throwable t) { }
logger.log(Level.WARNING,
"Binding to HTTP failed: client will use JAGGRAB as a fallback (not recommended)!", t);
}
logger.info("Binding JAGGRAB listener to address: " + jagGrabAddress + "..."); /**
jagGrabBootstrap.bind(jagGrabAddress); * Starts the server.
*
* @throws Exception If an error occurs.
*/
public void start() throws Exception {
PluginManager manager = new PluginManager(new PluginContext(context));
serviceManager.startAll();
logger.info("Ready for connections."); int releaseNo = context.getRelease().getReleaseNumber();
} IndexedFileSystem fs = new IndexedFileSystem(new File("data/fs/" + releaseNo), true);
World.getWorld().init(releaseNo, fs, manager);
/** }
* Initialises the server.
*
* @param releaseClassName The class name of the current active {@link Release}.
* @throws ClassNotFoundException If the release class could not be found.
* @throws IllegalAccessException If the release class could not be accessed.
* @throws InstantiationException If the release class could not be instantiated.
*/
public void init(String releaseClassName) throws ClassNotFoundException, InstantiationException,
IllegalAccessException {
Class<?> clazz = Class.forName(releaseClassName);
Release release = (Release) clazz.newInstance();
logger.info("Initialized release #" + release.getReleaseNumber() + ".");
serviceBootstrap.group(loopGroup);
httpBootstrap.group(loopGroup);
jagGrabBootstrap.group(loopGroup);
context = new ServerContext(release, serviceManager);
ApolloHandler handler = new ApolloHandler(context);
ChannelInitializer<SocketChannel> serviceInitializer = new ServiceChannelInitializer(handler);
serviceBootstrap.channel(NioServerSocketChannel.class);
serviceBootstrap.childHandler(serviceInitializer);
ChannelInitializer<SocketChannel> httpInitializer = new HttpChannelInitializer(handler);
httpBootstrap.channel(NioServerSocketChannel.class);
httpBootstrap.childHandler(httpInitializer);
ChannelInitializer<SocketChannel> jagGrabInitializer = new JagGrabChannelInitializer(handler);
jagGrabBootstrap.channel(NioServerSocketChannel.class);
jagGrabBootstrap.childHandler(jagGrabInitializer);
}
/**
* Starts the server.
*
* @throws Exception If an error occurs.
*/
public void start() throws Exception {
PluginManager manager = new PluginManager(new PluginContext(context));
serviceManager.startAll();
int releaseNo = context.getRelease().getReleaseNumber();
IndexedFileSystem fs = new IndexedFileSystem(new File("data/fs/" + releaseNo), true);
World.getWorld().init(releaseNo, fs, manager);
}
} }
+45 -45
View File
@@ -11,55 +11,55 @@ import org.apollo.net.release.Release;
*/ */
public final class ServerContext { public final class ServerContext {
/** /**
* The current release. * The current release.
*/ */
private final Release release; private final Release release;
/** /**
* The service manager. * The service manager.
*/ */
private final ServiceManager serviceManager; private final ServiceManager serviceManager;
/** /**
* Creates a new server context. * Creates a new server context.
* *
* @param release The current release. * @param release The current release.
* @param serviceManager The service manager. * @param serviceManager The service manager.
*/ */
ServerContext(Release release, ServiceManager serviceManager) { ServerContext(Release release, ServiceManager serviceManager) {
this.release = release; this.release = release;
this.serviceManager = serviceManager; this.serviceManager = serviceManager;
this.serviceManager.setContext(this); this.serviceManager.setContext(this);
} }
/** /**
* Gets the current release. * Gets the current release.
* *
* @return The current release. * @return The current release.
*/ */
public Release getRelease() { public Release getRelease() {
return release; return release;
} }
/** /**
* Gets a service. This method is shorthand for {@code getServiceManager().getService(...)}. * Gets a service. This method is shorthand for {@code getServiceManager().getService(...)}.
* *
* @param <S> The type of service. * @param <S> The type of service.
* @param clazz The service class. * @param clazz The service class.
* @return The service, or {@code null} if it could not be found. * @return The service, or {@code null} if it could not be found.
*/ */
public <S extends Service> S getService(Class<S> clazz) { public <S extends Service> S getService(Class<S> clazz) {
return serviceManager.getService(clazz); return serviceManager.getService(clazz);
} }
/** /**
* Gets the service manager. * Gets the service manager.
* *
* @return The service manager. * @return The service manager.
*/ */
public ServiceManager getServiceManager() { public ServiceManager getServiceManager() {
return serviceManager; return serviceManager;
} }
} }
+24 -24
View File
@@ -7,32 +7,32 @@ package org.apollo;
*/ */
public abstract class Service { public abstract class Service {
/** /**
* The server context. * The server context.
*/ */
private ServerContext context; private ServerContext context;
/** /**
* Gets the {@link ServerContext}. * Gets the {@link ServerContext}.
* *
* @return The context. * @return The context.
*/ */
public final ServerContext getContext() { public final ServerContext getContext() {
return context; return context;
} }
/** /**
* Sets the {@link ServerContext}. * Sets the {@link ServerContext}.
* *
* @param context The context. * @param context The context.
*/ */
public final void setContext(ServerContext context) { public final void setContext(ServerContext context) {
this.context = context; this.context = context;
} }
/** /**
* Starts the service. * Starts the service.
*/ */
public abstract void start(); public abstract void start();
} }
+89 -89
View File
@@ -18,108 +18,108 @@ import org.xml.sax.SAXException;
*/ */
public final class ServiceManager { public final class ServiceManager {
/** /**
* The logger for this class. * The logger for this class.
*/ */
private static final Logger logger = Logger.getLogger(ServiceManager.class.getName()); private static final Logger logger = Logger.getLogger(ServiceManager.class.getName());
/** /**
* The service map. * The service map.
*/ */
private Map<Class<? extends Service>, Service> services = new HashMap<Class<? extends Service>, Service>(); private Map<Class<? extends Service>, Service> services = new HashMap<Class<? extends Service>, Service>();
/** /**
* Creates and initializes the {@link ServiceManager}. * Creates and initializes the {@link ServiceManager}.
* *
* @throws Exception If an error occurs. * @throws Exception If an error occurs.
*/ */
public ServiceManager() throws Exception { public ServiceManager() throws Exception {
init(); init();
}
/**
* Gets a service.
*
* @param <S> The type of service.
* @param clazz The service class.
* @return The service.
*/
@SuppressWarnings("unchecked")
public <S extends Service> S getService(Class<S> clazz) {
return (S) services.get(clazz);
}
/**
* Initializes this service manager.
*
* @throws SAXException If the service XML file could not be parsed.
* @throws IOException If the file could not be accessed.
* @throws IllegalAccessException If the service could not be accessed.
* @throws InstantiationException If the service could not be instantiated.
* @throws ClassNotFoundException If the service could not be found.
*/
@SuppressWarnings("unchecked")
private void init() throws SAXException, IOException, InstantiationException, IllegalAccessException,
ClassNotFoundException {
logger.info("Registering services...");
XmlParser parser = new XmlParser();
XmlNode rootNode;
try (InputStream is = new FileInputStream("data/services.xml")) {
rootNode = parser.parse(is);
} }
/** if (!rootNode.getName().equals("services")) {
* Gets a service. throw new IOException("Unexpected name of root node.");
*
* @param <S> The type of service.
* @param clazz The service class.
* @return The service.
*/
@SuppressWarnings("unchecked")
public <S extends Service> S getService(Class<S> clazz) {
return (S) services.get(clazz);
} }
/** for (XmlNode childNode : rootNode) {
* Initializes this service manager. if (!childNode.getName().equals("service")) {
* throw new IOException("Unexpected name of child node.");
* @throws SAXException If the service XML file could not be parsed. }
* @throws IOException If the file could not be accessed.
* @throws IllegalAccessException If the service could not be accessed.
* @throws InstantiationException If the service could not be instantiated.
* @throws ClassNotFoundException If the service could not be found.
*/
@SuppressWarnings("unchecked")
private void init() throws SAXException, IOException, InstantiationException, IllegalAccessException,
ClassNotFoundException {
logger.info("Registering services...");
XmlParser parser = new XmlParser(); if (!childNode.hasValue()) {
XmlNode rootNode; throw new IOException("Child node must have a value.");
}
try (InputStream is = new FileInputStream("data/services.xml")) { Class<? extends Service> clazz = (Class<? extends Service>) Class.forName(childNode.getValue());
rootNode = parser.parse(is); register((Class<Service>) clazz, clazz.newInstance());
}
if (!rootNode.getName().equals("services")) {
throw new IOException("Unexpected name of root node.");
}
for (XmlNode childNode : rootNode) {
if (!childNode.getName().equals("service")) {
throw new IOException("Unexpected name of child node.");
}
if (!childNode.hasValue()) {
throw new IOException("Child node must have a value.");
}
Class<? extends Service> clazz = (Class<? extends Service>) Class.forName(childNode.getValue());
register((Class<Service>) clazz, clazz.newInstance());
}
} }
}
/** /**
* Registers a service. * Registers a service.
* *
* @param <S> The type of service. * @param <S> The type of service.
* @param clazz The service's class. * @param clazz The service's class.
* @param service The service. * @param service The service.
*/ */
private <S extends Service> void register(Class<S> clazz, S service) { private <S extends Service> void register(Class<S> clazz, S service) {
logger.fine("Registering service: " + clazz + "..."); logger.fine("Registering service: " + clazz + "...");
services.put(clazz, service); services.put(clazz, service);
} }
/** /**
* Sets the context of all services. * Sets the context of all services.
* *
* @param ctx The server context. * @param ctx The server context.
*/ */
public void setContext(ServerContext ctx) { public void setContext(ServerContext ctx) {
for (Service service : services.values()) { for (Service service : services.values()) {
service.setContext(ctx); service.setContext(ctx);
}
} }
}
/** /**
* Starts all the services. * Starts all the services.
*/ */
public void startAll() { public void startAll() {
logger.info("Starting services..."); logger.info("Starting services...");
for (Service service : services.values()) { for (Service service : services.values()) {
logger.fine("Starting service: " + service.getClass().getName() + "..."); logger.fine("Starting service: " + service.getClass().getName() + "...");
service.start(); service.start();
}
} }
}
} }
+34 -34
View File
@@ -7,43 +7,43 @@ package org.apollo.fs;
*/ */
public final class FileDescriptor { public final class FileDescriptor {
/** /**
* The file id. * The file id.
*/ */
private final int file; private final int file;
/** /**
* The file type. * The file type.
*/ */
private final int type; private final int type;
/** /**
* Creates the file descriptor. * Creates the file descriptor.
* *
* @param type The file type. * @param type The file type.
* @param file The file id. * @param file The file id.
*/ */
public FileDescriptor(int type, int file) { public FileDescriptor(int type, int file) {
this.type = type; this.type = type;
this.file = file; this.file = file;
} }
/** /**
* Gets the file id. * Gets the file id.
* *
* @return The file id. * @return The file id.
*/ */
public int getFile() { public int getFile() {
return file; return file;
} }
/** /**
* Gets the file type. * Gets the file type.
* *
* @return The file type. * @return The file type.
*/ */
public int getType() { public int getType() {
return type; return type;
} }
} }
+30 -30
View File
@@ -7,41 +7,41 @@ package org.apollo.fs;
*/ */
public final class FileSystemConstants { public final class FileSystemConstants {
/** /**
* The number of archives in cache 0. * The number of archives in cache 0.
*/ */
public static final int ARCHIVE_COUNT = 9; public static final int ARCHIVE_COUNT = 9;
/** /**
* The size of a chunk. * The size of a chunk.
*/ */
public static final int CHUNK_SIZE = 512; public static final int CHUNK_SIZE = 512;
/** /**
* The size of a header. * The size of a header.
*/ */
public static final int HEADER_SIZE = 8; public static final int HEADER_SIZE = 8;
/** /**
* The size of a block. * The size of a block.
*/ */
public static final int BLOCK_SIZE = HEADER_SIZE + CHUNK_SIZE; public static final int BLOCK_SIZE = HEADER_SIZE + CHUNK_SIZE;
/** /**
* The number of caches. * The number of caches.
*/ */
public static final int CACHE_COUNT = 5; public static final int CACHE_COUNT = 5;
/** /**
* The size of an index. * The size of an index.
*/ */
public static final int INDEX_SIZE = 6; public static final int INDEX_SIZE = 6;
/** /**
* Default private constructor to prevent instantiation. * Default private constructor to prevent instantiation.
*/ */
private FileSystemConstants() { private FileSystemConstants() {
} }
} }
+50 -50
View File
@@ -7,61 +7,61 @@ package org.apollo.fs;
*/ */
public final class Index { public final class Index {
/** /**
* Decodes a buffer into an index. * Decodes a buffer into an index.
* *
* @param buffer The buffer. * @param buffer The buffer.
* @return The decoded {@link Index}. * @return The decoded {@link Index}.
* @throws IllegalArgumentException If the buffer length is invalid. * @throws IllegalArgumentException If the buffer length is invalid.
*/ */
public static Index decode(byte[] buffer) { public static Index decode(byte[] buffer) {
if (buffer.length != FileSystemConstants.INDEX_SIZE) { if (buffer.length != FileSystemConstants.INDEX_SIZE) {
throw new IllegalArgumentException("Incorrect buffer length."); throw new IllegalArgumentException("Incorrect buffer length.");
}
int size = (buffer[0] & 0xFF) << 16 | (buffer[1] & 0xFF) << 8 | buffer[2] & 0xFF;
int block = (buffer[3] & 0xFF) << 16 | (buffer[4] & 0xFF) << 8 | buffer[5] & 0xFF;
return new Index(size, block);
} }
/** int size = (buffer[0] & 0xFF) << 16 | (buffer[1] & 0xFF) << 8 | buffer[2] & 0xFF;
* The first block of the file. int block = (buffer[3] & 0xFF) << 16 | (buffer[4] & 0xFF) << 8 | buffer[5] & 0xFF;
*/
private final int block;
/** return new Index(size, block);
* The size of the file. }
*/
private final int size;
/** /**
* Creates the index. * The first block of the file.
* */
* @param size The size of the file. private final int block;
* @param block The first block of the file.
*/
public Index(int size, int block) {
this.size = size;
this.block = block;
}
/** /**
* Gets the first block of the file. * The size of the file.
* */
* @return The first block of the file. private final int size;
*/
public int getBlock() {
return block;
}
/** /**
* Gets the size of the file. * Creates the index.
* *
* @return The size of the file. * @param size The size of the file.
*/ * @param block The first block of the file.
public int getSize() { */
return size; public Index(int size, int block) {
} this.size = size;
this.block = block;
}
/**
* Gets the first block of the file.
*
* @return The first block of the file.
*/
public int getBlock() {
return block;
}
/**
* Gets the size of the file.
*
* @return The size of the file.
*/
public int getSize() {
return size;
}
} }
+237 -237
View File
@@ -16,275 +16,275 @@ import java.util.zip.CRC32;
*/ */
public final class IndexedFileSystem implements Closeable { public final class IndexedFileSystem implements Closeable {
/** /**
* The cached CRC table. * The cached CRC table.
*/ */
private ByteBuffer crcTable; private ByteBuffer crcTable;
/** /**
* The data file. * The data file.
*/ */
private RandomAccessFile data; private RandomAccessFile data;
/** /**
* The index files. * The index files.
*/ */
private RandomAccessFile[] indices = new RandomAccessFile[256]; private RandomAccessFile[] indices = new RandomAccessFile[256];
/** /**
* Read only flag. * Read only flag.
*/ */
private final boolean readOnly; private final boolean readOnly;
/** /**
* Creates the file system with the specified base directory. * Creates the file system with the specified base directory.
* *
* @param base The base directory. * @param base The base directory.
* @param readOnly Indicates whether the file system will be read only or not. * @param readOnly Indicates whether the file system will be read only or not.
* @throws FileNotFoundException If the data files could not be found. * @throws FileNotFoundException If the data files could not be found.
*/ */
public IndexedFileSystem(File base, boolean readOnly) throws FileNotFoundException { public IndexedFileSystem(File base, boolean readOnly) throws FileNotFoundException {
this.readOnly = readOnly; this.readOnly = readOnly;
detectLayout(base); detectLayout(base);
}
@Override
public void close() throws IOException {
if (data != null) {
synchronized (data) {
data.close();
}
} }
@Override for (RandomAccessFile index : indices) {
public void close() throws IOException { if (index != null) {
if (data != null) { synchronized (index) {
synchronized (data) { index.close();
data.close();
}
} }
}
}
}
for (RandomAccessFile index : indices) { /**
if (index != null) { * Automatically detect the layout of the specified directory.
synchronized (index) { *
index.close(); * @param base The base directory.
} * @throws FileNotFoundException If the data files could not be found.
} */
} private void detectLayout(File base) throws FileNotFoundException {
int indexCount = 0;
for (int index = 0; index < indices.length; index++) {
File f = new File(base.getAbsolutePath() + "/main_file_cache.idx" + index);
if (f.exists() && !f.isDirectory()) {
indexCount++;
indices[index] = new RandomAccessFile(f, readOnly ? "r" : "rw");
}
}
if (indexCount <= 0) {
throw new FileNotFoundException("No index file(s) present.");
} }
/** File oldEngineData = new File(base.getAbsolutePath() + "/main_file_cache.dat");
* Automatically detect the layout of the specified directory. File newEngineData = new File(base.getAbsolutePath() + "/main_file_cache.dat2");
* if (oldEngineData.exists() && !oldEngineData.isDirectory()) {
* @param base The base directory. data = new RandomAccessFile(oldEngineData, readOnly ? "r" : "rw");
* @throws FileNotFoundException If the data files could not be found. } else if (newEngineData.exists() && !oldEngineData.isDirectory()) {
*/ data = new RandomAccessFile(newEngineData, readOnly ? "r" : "rw");
private void detectLayout(File base) throws FileNotFoundException { } else {
int indexCount = 0; throw new FileNotFoundException("No data file present.");
for (int index = 0; index < indices.length; index++) { }
File f = new File(base.getAbsolutePath() + "/main_file_cache.idx" + index); }
if (f.exists() && !f.isDirectory()) {
indexCount++;
indices[index] = new RandomAccessFile(f, readOnly ? "r" : "rw");
}
}
if (indexCount <= 0) {
throw new FileNotFoundException("No index file(s) present.");
}
File oldEngineData = new File(base.getAbsolutePath() + "/main_file_cache.dat"); /**
File newEngineData = new File(base.getAbsolutePath() + "/main_file_cache.dat2"); * Gets the CRC table.
if (oldEngineData.exists() && !oldEngineData.isDirectory()) { *
data = new RandomAccessFile(oldEngineData, readOnly ? "r" : "rw"); * @return The CRC table.
} else if (newEngineData.exists() && !oldEngineData.isDirectory()) { * @throws IOException If an I/O error occurs.
data = new RandomAccessFile(newEngineData, readOnly ? "r" : "rw"); */
} else { public ByteBuffer getCrcTable() throws IOException {
throw new FileNotFoundException("No data file present."); if (readOnly) {
synchronized (this) {
if (crcTable != null) {
return crcTable.duplicate();
} }
}
int archives = getFileCount(0);
int hash = 1234;
int[] crcs = new int[archives];
// calculate the CRCs
CRC32 crc32 = new CRC32();
for (int i = 1; i < crcs.length; i++) {
crc32.reset();
ByteBuffer buffer = getFile(0, i);
byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes, 0, bytes.length);
crc32.update(bytes, 0, bytes.length);
crcs[i] = (int) crc32.getValue();
}
// hash the CRCs and place them in the buffer
ByteBuffer buffer = ByteBuffer.allocate(crcs.length * 4 + 4);
for (int crc : crcs) {
hash = (hash << 1) + crc;
buffer.putInt(crc);
}
buffer.putInt(hash);
buffer.flip();
synchronized (this) {
crcTable = buffer.asReadOnlyBuffer();
return crcTable.duplicate();
}
}
throw new IOException("Cannot get CRC table from a writable file system.");
}
/**
* Gets a file.
*
* @param descriptor The {@link FileDescriptor} which points to the file.
* @return A {@link ByteBuffer} which contains the contents of the file.
* @throws IOException If an I/O error occurs.
*/
public ByteBuffer getFile(FileDescriptor descriptor) throws IOException {
Index index = getIndex(descriptor);
ByteBuffer buffer = ByteBuffer.allocate(index.getSize());
// calculate some initial values
long ptr = index.getBlock() * FileSystemConstants.BLOCK_SIZE;
int read = 0;
int size = index.getSize();
int blocks = size / FileSystemConstants.CHUNK_SIZE;
if (size % FileSystemConstants.CHUNK_SIZE != 0) {
blocks++;
} }
/** for (int i = 0; i < blocks; i++) {
* Gets the CRC table. // read header
* byte[] header = new byte[FileSystemConstants.HEADER_SIZE];
* @return The CRC table. synchronized (data) {
* @throws IOException If an I/O error occurs. data.seek(ptr);
*/ data.readFully(header);
public ByteBuffer getCrcTable() throws IOException { }
if (readOnly) {
synchronized (this) {
if (crcTable != null) {
return crcTable.duplicate();
}
}
int archives = getFileCount(0); // increment pointers
int hash = 1234; ptr += FileSystemConstants.HEADER_SIZE;
int[] crcs = new int[archives];
// calculate the CRCs // parse header
CRC32 crc32 = new CRC32(); int nextFile = (header[0] & 0xFF) << 8 | header[1] & 0xFF;
for (int i = 1; i < crcs.length; i++) { int curChunk = (header[2] & 0xFF) << 8 | header[3] & 0xFF;
crc32.reset(); int nextBlock = (header[4] & 0xFF) << 16 | (header[5] & 0xFF) << 8 | header[6] & 0xFF;
int nextType = header[7] & 0xFF;
ByteBuffer buffer = getFile(0, i); // check expected chunk id is correct
byte[] bytes = new byte[buffer.remaining()]; if (i != curChunk) {
buffer.get(bytes, 0, bytes.length); throw new IOException("Chunk id mismatch.");
crc32.update(bytes, 0, bytes.length); }
crcs[i] = (int) crc32.getValue(); // calculate how much we can read
} int chunkSize = size - read;
if (chunkSize > FileSystemConstants.CHUNK_SIZE) {
chunkSize = FileSystemConstants.CHUNK_SIZE;
}
// hash the CRCs and place them in the buffer // read the next chunk and put it in the buffer
ByteBuffer buffer = ByteBuffer.allocate(crcs.length * 4 + 4); byte[] chunk = new byte[chunkSize];
for (int crc : crcs) { synchronized (data) {
hash = (hash << 1) + crc; data.seek(ptr);
buffer.putInt(crc); data.readFully(chunk);
} }
buffer.put(chunk);
buffer.putInt(hash); // increment pointers
buffer.flip(); read += chunkSize;
ptr = (long) nextBlock * (long) FileSystemConstants.BLOCK_SIZE;
synchronized (this) { // if we still have more data to read, check the validity of the header
crcTable = buffer.asReadOnlyBuffer(); if (size > read) {
return crcTable.duplicate(); if (nextType != descriptor.getType() + 1) {
} throw new IOException("File type mismatch.");
} }
throw new IOException("Cannot get CRC table from a writable file system.");
if (nextFile != descriptor.getFile()) {
throw new IOException("File id mismatch.");
}
}
} }
/** buffer.flip();
* Gets a file. return buffer;
* }
* @param descriptor The {@link FileDescriptor} which points to the file.
* @return A {@link ByteBuffer} which contains the contents of the file.
* @throws IOException If an I/O error occurs.
*/
public ByteBuffer getFile(FileDescriptor descriptor) throws IOException {
Index index = getIndex(descriptor);
ByteBuffer buffer = ByteBuffer.allocate(index.getSize());
// calculate some initial values /**
long ptr = index.getBlock() * FileSystemConstants.BLOCK_SIZE; * Gets a file.
int read = 0; *
int size = index.getSize(); * @param type The file type.
int blocks = size / FileSystemConstants.CHUNK_SIZE; * @param file The file id.
if (size % FileSystemConstants.CHUNK_SIZE != 0) { * @return A {@link ByteBuffer} which contains the contents of the file.
blocks++; * @throws IOException If an I/O error occurs.
} */
public ByteBuffer getFile(int type, int file) throws IOException {
return getFile(new FileDescriptor(type, file));
}
for (int i = 0; i < blocks; i++) { /**
// read header * Gets the number of files with the specified type.
byte[] header = new byte[FileSystemConstants.HEADER_SIZE]; *
synchronized (data) { * @param type The type.
data.seek(ptr); * @return The number of files.
data.readFully(header); * @throws IOException If an I/O error occurs.
} */
private int getFileCount(int type) throws IOException {
// increment pointers if (type < 0 || type >= indices.length) {
ptr += FileSystemConstants.HEADER_SIZE; throw new IndexOutOfBoundsException("File type out of bounds.");
// parse header
int nextFile = (header[0] & 0xFF) << 8 | header[1] & 0xFF;
int curChunk = (header[2] & 0xFF) << 8 | header[3] & 0xFF;
int nextBlock = (header[4] & 0xFF) << 16 | (header[5] & 0xFF) << 8 | header[6] & 0xFF;
int nextType = header[7] & 0xFF;
// check expected chunk id is correct
if (i != curChunk) {
throw new IOException("Chunk id mismatch.");
}
// calculate how much we can read
int chunkSize = size - read;
if (chunkSize > FileSystemConstants.CHUNK_SIZE) {
chunkSize = FileSystemConstants.CHUNK_SIZE;
}
// read the next chunk and put it in the buffer
byte[] chunk = new byte[chunkSize];
synchronized (data) {
data.seek(ptr);
data.readFully(chunk);
}
buffer.put(chunk);
// increment pointers
read += chunkSize;
ptr = (long) nextBlock * (long) FileSystemConstants.BLOCK_SIZE;
// if we still have more data to read, check the validity of the header
if (size > read) {
if (nextType != descriptor.getType() + 1) {
throw new IOException("File type mismatch.");
}
if (nextFile != descriptor.getFile()) {
throw new IOException("File id mismatch.");
}
}
}
buffer.flip();
return buffer;
} }
/** RandomAccessFile indexFile = indices[type];
* Gets a file. synchronized (indexFile) {
* return (int) (indexFile.length() / FileSystemConstants.INDEX_SIZE);
* @param type The file type. }
* @param file The file id. }
* @return A {@link ByteBuffer} which contains the contents of the file.
* @throws IOException If an I/O error occurs. /**
*/ * Gets the index of a file.
public ByteBuffer getFile(int type, int file) throws IOException { *
return getFile(new FileDescriptor(type, file)); * @param descriptor The {@link FileDescriptor} which points to the file.
* @return The {@link Index}.
* @throws IOException If an I/O error occurs.
*/
private Index getIndex(FileDescriptor descriptor) throws IOException {
int index = descriptor.getType();
if (index < 0 || index >= indices.length) {
throw new IndexOutOfBoundsException("File descriptor type out of bounds.");
} }
/** byte[] buffer = new byte[FileSystemConstants.INDEX_SIZE];
* Gets the number of files with the specified type. RandomAccessFile indexFile = indices[index];
* synchronized (indexFile) {
* @param type The type. long ptr = descriptor.getFile() * FileSystemConstants.INDEX_SIZE;
* @return The number of files. if (ptr >= 0 && indexFile.length() >= ptr + FileSystemConstants.INDEX_SIZE) {
* @throws IOException If an I/O error occurs. indexFile.seek(ptr);
*/ indexFile.readFully(buffer);
private int getFileCount(int type) throws IOException { } else {
if (type < 0 || type >= indices.length) { throw new FileNotFoundException("Could not find find index.");
throw new IndexOutOfBoundsException("File type out of bounds."); }
}
RandomAccessFile indexFile = indices[type];
synchronized (indexFile) {
return (int) (indexFile.length() / FileSystemConstants.INDEX_SIZE);
}
} }
/** return Index.decode(buffer);
* Gets the index of a file. }
*
* @param descriptor The {@link FileDescriptor} which points to the file.
* @return The {@link Index}.
* @throws IOException If an I/O error occurs.
*/
private Index getIndex(FileDescriptor descriptor) throws IOException {
int index = descriptor.getType();
if (index < 0 || index >= indices.length) {
throw new IndexOutOfBoundsException("File descriptor type out of bounds.");
}
byte[] buffer = new byte[FileSystemConstants.INDEX_SIZE]; /**
RandomAccessFile indexFile = indices[index]; * Checks if this {@link IndexedFileSystem} is read only.
synchronized (indexFile) { *
long ptr = descriptor.getFile() * FileSystemConstants.INDEX_SIZE; * @return {@code true} if so, {@code false} if not.
if (ptr >= 0 && indexFile.length() >= ptr + FileSystemConstants.INDEX_SIZE) { */
indexFile.seek(ptr); public boolean isReadOnly() {
indexFile.readFully(buffer); return readOnly;
} else { }
throw new FileNotFoundException("Could not find find index.");
}
}
return Index.decode(buffer);
}
/**
* Checks if this {@link IndexedFileSystem} is read only.
*
* @return {@code true} if so, {@code false} if not.
*/
public boolean isReadOnly() {
return readOnly;
}
} }
+80 -80
View File
@@ -14,92 +14,92 @@ import org.apollo.util.CompressionUtil;
*/ */
public final class Archive { public final class Archive {
/** /**
* Decodes the archive in the specified buffer. * Decodes the archive in the specified buffer.
* *
* @param buffer The buffer. * @param buffer The buffer.
* @return The archive. * @return The archive.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
public static Archive decode(ByteBuffer buffer) throws IOException { public static Archive decode(ByteBuffer buffer) throws IOException {
int extractedSize = BufferUtil.readUnsignedTriByte(buffer); int extractedSize = BufferUtil.readUnsignedTriByte(buffer);
int size = BufferUtil.readUnsignedTriByte(buffer); int size = BufferUtil.readUnsignedTriByte(buffer);
boolean extracted = false; boolean extracted = false;
if (size != extractedSize) { if (size != extractedSize) {
byte[] compressed = new byte[size]; byte[] compressed = new byte[size];
byte[] uncompressed = new byte[extractedSize]; byte[] uncompressed = new byte[extractedSize];
buffer.get(compressed); buffer.get(compressed);
CompressionUtil.unbzip2(compressed, uncompressed); CompressionUtil.unbzip2(compressed, uncompressed);
buffer = ByteBuffer.wrap(uncompressed); buffer = ByteBuffer.wrap(uncompressed);
extracted = true; extracted = true;
}
int entries = buffer.getShort() & 0xFFFF;
int[] identifiers = new int[entries];
int[] extractedSizes = new int[entries];
int[] sizes = new int[entries];
for (int i = 0; i < entries; i++) {
identifiers[i] = buffer.getInt();
extractedSizes[i] = BufferUtil.readUnsignedTriByte(buffer);
sizes[i] = BufferUtil.readUnsignedTriByte(buffer);
}
ArchiveEntry[] entry = new ArchiveEntry[entries];
for (int i = 0; i < entries; i++) {
ByteBuffer entryBuffer;
if (!extracted) {
byte[] compressed = new byte[sizes[i]];
byte[] uncompressed = new byte[extractedSizes[i]];
buffer.get(compressed);
CompressionUtil.unbzip2(compressed, uncompressed);
entryBuffer = ByteBuffer.wrap(uncompressed);
} else {
byte[] buf = new byte[extractedSizes[i]];
buffer.get(buf);
entryBuffer = ByteBuffer.wrap(buf);
}
entry[i] = new ArchiveEntry(identifiers[i], entryBuffer);
}
return new Archive(entry);
} }
/** int entries = buffer.getShort() & 0xFFFF;
* The entries in this archive. int[] identifiers = new int[entries];
*/ int[] extractedSizes = new int[entries];
private final ArchiveEntry[] entries; int[] sizes = new int[entries];
/** for (int i = 0; i < entries; i++) {
* Creates a new archive. identifiers[i] = buffer.getInt();
* extractedSizes[i] = BufferUtil.readUnsignedTriByte(buffer);
* @param entries The entries in this archive. sizes[i] = BufferUtil.readUnsignedTriByte(buffer);
*/
public Archive(ArchiveEntry[] entries) {
this.entries = entries;
} }
/** ArchiveEntry[] entry = new ArchiveEntry[entries];
* Gets an entry by its name. for (int i = 0; i < entries; i++) {
* ByteBuffer entryBuffer;
* @param name The name. if (!extracted) {
* @return The entry. byte[] compressed = new byte[sizes[i]];
* @throws FileNotFoundException If the file could not be found. byte[] uncompressed = new byte[extractedSizes[i]];
*/ buffer.get(compressed);
public ArchiveEntry getEntry(String name) throws FileNotFoundException { CompressionUtil.unbzip2(compressed, uncompressed);
int hash = 0; entryBuffer = ByteBuffer.wrap(uncompressed);
name = name.toUpperCase(); } else {
byte[] buf = new byte[extractedSizes[i]];
for (int i = 0; i < name.length(); i++) { buffer.get(buf);
hash = hash * 61 + name.charAt(i) - 32; entryBuffer = ByteBuffer.wrap(buf);
} }
entry[i] = new ArchiveEntry(identifiers[i], entryBuffer);
for (ArchiveEntry entry : entries) {
if (entry.getIdentifier() == hash) {
return entry;
}
}
throw new FileNotFoundException("Could not find entry: " + name + ".");
} }
return new Archive(entry);
}
/**
* The entries in this archive.
*/
private final ArchiveEntry[] entries;
/**
* Creates a new archive.
*
* @param entries The entries in this archive.
*/
public Archive(ArchiveEntry[] entries) {
this.entries = entries;
}
/**
* Gets an entry by its name.
*
* @param name The name.
* @return The entry.
* @throws FileNotFoundException If the file could not be found.
*/
public ArchiveEntry getEntry(String name) throws FileNotFoundException {
int hash = 0;
name = name.toUpperCase();
for (int i = 0; i < name.length(); i++) {
hash = hash * 61 + name.charAt(i) - 32;
}
for (ArchiveEntry entry : entries) {
if (entry.getIdentifier() == hash) {
return entry;
}
}
throw new FileNotFoundException("Could not find entry: " + name + ".");
}
} }
+34 -34
View File
@@ -9,43 +9,43 @@ import java.nio.ByteBuffer;
*/ */
public final class ArchiveEntry { public final class ArchiveEntry {
/** /**
* The buffer of this entry. * The buffer of this entry.
*/ */
private final ByteBuffer buffer; private final ByteBuffer buffer;
/** /**
* The identifier of this entry. * The identifier of this entry.
*/ */
private final int identifier; private final int identifier;
/** /**
* Creates a new archive entry. * Creates a new archive entry.
* *
* @param identifier The identifier. * @param identifier The identifier.
* @param buffer The buffer. * @param buffer The buffer.
*/ */
public ArchiveEntry(int identifier, ByteBuffer buffer) { public ArchiveEntry(int identifier, ByteBuffer buffer) {
this.identifier = identifier; this.identifier = identifier;
this.buffer = buffer.asReadOnlyBuffer(); this.buffer = buffer.asReadOnlyBuffer();
} }
/** /**
* Gets the buffer of this entry. * Gets the buffer of this entry.
* *
* @return This buffer of this entry. * @return This buffer of this entry.
*/ */
public ByteBuffer getBuffer() { public ByteBuffer getBuffer() {
return buffer.duplicate(); return buffer.duplicate();
} }
/** /**
* Gets the identifier of this entry. * Gets the identifier of this entry.
* *
* @return The identifier of this entry. * @return The identifier of this entry.
*/ */
public int getIdentifier() { public int getIdentifier() {
return identifier; return identifier;
} }
} }
@@ -15,144 +15,144 @@ import org.apollo.util.BufferUtil;
*/ */
public final class ItemDefinitionDecoder { public final class ItemDefinitionDecoder {
/** /**
* The {@link IndexedFileSystem}. * The {@link IndexedFileSystem}.
*/ */
private final IndexedFileSystem fs; private final IndexedFileSystem fs;
/** /**
* Creates the item definition decoder. * Creates the item definition decoder.
* *
* @param fs The indexed file system. * @param fs The indexed file system.
*/ */
public ItemDefinitionDecoder(IndexedFileSystem fs) { public ItemDefinitionDecoder(IndexedFileSystem fs) {
this.fs = fs; this.fs = fs;
}
/**
* Decodes the item definitions.
*
* @return The item definitions.
* @throws IOException If an I/O error occurs.
*/
public ItemDefinition[] decode() throws IOException {
Archive config = Archive.decode(fs.getFile(0, 2));
ByteBuffer data = config.getEntry("obj.dat").getBuffer();
ByteBuffer idx = config.getEntry("obj.idx").getBuffer();
int count = idx.getShort(), index = 2;
int[] indices = new int[count];
for (int i = 0; i < count; i++) {
indices[i] = index;
index += idx.getShort();
} }
/** ItemDefinition[] defs = new ItemDefinition[count];
* Decodes the item definitions. for (int i = 0; i < count; i++) {
* data.position(indices[i]);
* @return The item definitions. defs[i] = decode(i, data);
* @throws IOException If an I/O error occurs.
*/
public ItemDefinition[] decode() throws IOException {
Archive config = Archive.decode(fs.getFile(0, 2));
ByteBuffer data = config.getEntry("obj.dat").getBuffer();
ByteBuffer idx = config.getEntry("obj.idx").getBuffer();
int count = idx.getShort(), index = 2;
int[] indices = new int[count];
for (int i = 0; i < count; i++) {
indices[i] = index;
index += idx.getShort();
}
ItemDefinition[] defs = new ItemDefinition[count];
for (int i = 0; i < count; i++) {
data.position(indices[i]);
defs[i] = decode(i, data);
}
return defs;
} }
/** return defs;
* Decodes a single definition. }
*
* @param id The item's id.
* @param buffer The buffer.
* @return The {@link ItemDefinition}.
*/
private ItemDefinition decode(int id, ByteBuffer buffer) {
ItemDefinition definition = new ItemDefinition(id);
while (true) {
int opcode = buffer.get() & 0xFF;
if (opcode == 0) { /**
return definition; * Decodes a single definition.
} else if (opcode == 1) { *
buffer.getShort(); * @param id The item's id.
} else if (opcode == 2) { * @param buffer The buffer.
definition.setName(BufferUtil.readString(buffer)); * @return The {@link ItemDefinition}.
} else if (opcode == 3) { */
definition.setDescription(BufferUtil.readString(buffer)); private ItemDefinition decode(int id, ByteBuffer buffer) {
} else if (opcode == 4) { ItemDefinition definition = new ItemDefinition(id);
buffer.getShort(); while (true) {
} else if (opcode == 5) { int opcode = buffer.get() & 0xFF;
buffer.getShort();
} else if (opcode == 6) { if (opcode == 0) {
buffer.getShort(); return definition;
} else if (opcode == 7) { } else if (opcode == 1) {
buffer.getShort(); buffer.getShort();
} else if (opcode == 8) { } else if (opcode == 2) {
buffer.getShort(); definition.setName(BufferUtil.readString(buffer));
} else if (opcode == 10) { } else if (opcode == 3) {
buffer.getShort(); definition.setDescription(BufferUtil.readString(buffer));
} else if (opcode == 11) { } else if (opcode == 4) {
definition.setStackable(true); buffer.getShort();
} else if (opcode == 12) { } else if (opcode == 5) {
definition.setValue(buffer.getInt()); buffer.getShort();
} else if (opcode == 16) { } else if (opcode == 6) {
definition.setMembersOnly(true); buffer.getShort();
} else if (opcode == 23) { } else if (opcode == 7) {
buffer.getShort(); buffer.getShort();
buffer.get(); } else if (opcode == 8) {
} else if (opcode == 24) { buffer.getShort();
buffer.getShort(); } else if (opcode == 10) {
} else if (opcode == 25) { buffer.getShort();
buffer.getShort(); } else if (opcode == 11) {
buffer.get(); definition.setStackable(true);
} else if (opcode == 26) { } else if (opcode == 12) {
buffer.getShort(); definition.setValue(buffer.getInt());
} else if (opcode >= 30 && opcode < 35) { } else if (opcode == 16) {
String str = BufferUtil.readString(buffer); definition.setMembersOnly(true);
if (str.equalsIgnoreCase("hidden")) { } else if (opcode == 23) {
str = null; buffer.getShort();
} buffer.get();
definition.setGroundAction(opcode - 30, str); } else if (opcode == 24) {
} else if (opcode >= 35 && opcode < 40) { buffer.getShort();
definition.setInventoryAction(opcode - 35, BufferUtil.readString(buffer)); } else if (opcode == 25) {
} else if (opcode == 40) { buffer.getShort();
int colourCount = buffer.get() & 0xFF; buffer.get();
for (int i = 0; i < colourCount; i++) { } else if (opcode == 26) {
buffer.getShort(); buffer.getShort();
buffer.getShort(); } else if (opcode >= 30 && opcode < 35) {
} String str = BufferUtil.readString(buffer);
} else if (opcode == 78) { if (str.equalsIgnoreCase("hidden")) {
buffer.getShort(); str = null;
} else if (opcode == 79) {
buffer.getShort();
} else if (opcode == 90) {
buffer.getShort();
} else if (opcode == 91) {
buffer.getShort();
} else if (opcode == 92) {
buffer.getShort();
} else if (opcode == 93) {
buffer.getShort();
} else if (opcode == 95) {
buffer.getShort();
} else if (opcode == 97) {
definition.setNoteInfoId(buffer.getShort() & 0xFFFF);
} else if (opcode == 98) {
definition.setNoteGraphicId(buffer.getShort() & 0xFFFF);
} else if (opcode >= 100 && opcode < 110) {
buffer.getShort();
buffer.getShort();
} else if (opcode == 110) {
buffer.getShort();
} else if (opcode == 111) {
buffer.getShort();
} else if (opcode == 112) {
buffer.getShort();
} else if (opcode == 113) {
buffer.get();
} else if (opcode == 114) {
buffer.getShort();
} else if (opcode == 115) {
definition.setTeam(buffer.get() & 0xFF);
}
} }
definition.setGroundAction(opcode - 30, str);
} else if (opcode >= 35 && opcode < 40) {
definition.setInventoryAction(opcode - 35, BufferUtil.readString(buffer));
} else if (opcode == 40) {
int colourCount = buffer.get() & 0xFF;
for (int i = 0; i < colourCount; i++) {
buffer.getShort();
buffer.getShort();
}
} else if (opcode == 78) {
buffer.getShort();
} else if (opcode == 79) {
buffer.getShort();
} else if (opcode == 90) {
buffer.getShort();
} else if (opcode == 91) {
buffer.getShort();
} else if (opcode == 92) {
buffer.getShort();
} else if (opcode == 93) {
buffer.getShort();
} else if (opcode == 95) {
buffer.getShort();
} else if (opcode == 97) {
definition.setNoteInfoId(buffer.getShort() & 0xFFFF);
} else if (opcode == 98) {
definition.setNoteGraphicId(buffer.getShort() & 0xFFFF);
} else if (opcode >= 100 && opcode < 110) {
buffer.getShort();
buffer.getShort();
} else if (opcode == 110) {
buffer.getShort();
} else if (opcode == 111) {
buffer.getShort();
} else if (opcode == 112) {
buffer.getShort();
} else if (opcode == 113) {
buffer.get();
} else if (opcode == 114) {
buffer.getShort();
} else if (opcode == 115) {
definition.setTeam(buffer.get() & 0xFF);
}
} }
}
} }
@@ -15,144 +15,144 @@ import org.apollo.util.BufferUtil;
*/ */
public final class NpcDefinitionDecoder { public final class NpcDefinitionDecoder {
/** /**
* The {@link IndexedFileSystem}. * The {@link IndexedFileSystem}.
*/ */
private final IndexedFileSystem fs; private final IndexedFileSystem fs;
/** /**
* Creates the npc definition decoder. * Creates the npc definition decoder.
* *
* @param fs The indexed file system. * @param fs The indexed file system.
*/ */
public NpcDefinitionDecoder(IndexedFileSystem fs) { public NpcDefinitionDecoder(IndexedFileSystem fs) {
this.fs = fs; this.fs = fs;
}
/**
* Decodes the npc definitions.
*
* @return An array of all parsed npc definitions.
* @throws IOException If an I/O error occurs.
*/
public NpcDefinition[] decode() throws IOException {
Archive config = Archive.decode(fs.getFile(0, 2));
ByteBuffer data = config.getEntry("npc.dat").getBuffer();
ByteBuffer idx = config.getEntry("npc.idx").getBuffer();
int count = idx.getShort(), index = 2;
int[] indices = new int[count];
for (int i = 0; i < count; i++) {
indices[i] = index;
index += idx.getShort();
} }
/** NpcDefinition[] defs = new NpcDefinition[count];
* Decodes the npc definitions. for (int i = 0; i < count; i++) {
* data.position(indices[i]);
* @return An array of all parsed npc definitions. defs[i] = decode(i, data);
* @throws IOException If an I/O error occurs.
*/
public NpcDefinition[] decode() throws IOException {
Archive config = Archive.decode(fs.getFile(0, 2));
ByteBuffer data = config.getEntry("npc.dat").getBuffer();
ByteBuffer idx = config.getEntry("npc.idx").getBuffer();
int count = idx.getShort(), index = 2;
int[] indices = new int[count];
for (int i = 0; i < count; i++) {
indices[i] = index;
index += idx.getShort();
}
NpcDefinition[] defs = new NpcDefinition[count];
for (int i = 0; i < count; i++) {
data.position(indices[i]);
defs[i] = decode(i, data);
}
return defs;
} }
/** return defs;
* Decodes a single definition. }
*
* @param id The npc's id.
* @param buffer The buffer.
* @return The {@link NpcDefinition}.
*/
private NpcDefinition decode(int id, ByteBuffer buffer) {
NpcDefinition definition = new NpcDefinition(id);
while (true) {
int opcode = buffer.get() & 0xFF;
if (opcode == 0) { /**
return definition; * Decodes a single definition.
} else if (opcode == 1) { *
int length = buffer.get() & 0xFF; * @param id The npc's id.
int[] models = new int[length]; * @param buffer The buffer.
for (int i = 0; i < length; i++) { * @return The {@link NpcDefinition}.
models[i] = buffer.getShort(); */
} private NpcDefinition decode(int id, ByteBuffer buffer) {
} else if (opcode == 2) { NpcDefinition definition = new NpcDefinition(id);
definition.setName(BufferUtil.readString(buffer)); while (true) {
} else if (opcode == 3) { int opcode = buffer.get() & 0xFF;
definition.setDescription(BufferUtil.readString(buffer));
} else if (opcode == 12) {
definition.setSize(buffer.get());
} else if (opcode == 13) {
definition.setStandAnimation(buffer.getShort());
} else if (opcode == 14) {
definition.setWalkAnimation(buffer.getShort());
} else if (opcode == 17) {
definition
.setWalkAnimations(buffer.getShort(), buffer.getShort(), buffer.getShort(), buffer.getShort());
} else if (opcode >= 30 && opcode < 40) {
String str = BufferUtil.readString(buffer);
if (str.equals("hidden")) {
str = null;
}
definition.setInteraction(opcode - 30, str);
} else if (opcode == 40) {
int length = buffer.get() & 0xFF;
int[] originalColours = new int[length];
int[] replacementColours = new int[length];
for (int i = 0; i < length; i++) {
originalColours[i] = buffer.getShort();
replacementColours[i] = buffer.getShort();
}
} else if (opcode == 60) {
int length = buffer.get() & 0xFF;
int[] additionalModels = new int[length];
for (int i = 0; i < length; i++) {
additionalModels[i] = buffer.getShort();
}
} else if (opcode == 90) {
buffer.getShort(); // Dummy
} else if (opcode == 91) {
buffer.getShort(); // Dummy
} else if (opcode == 92) {
buffer.getShort(); // Dummy
} else if (opcode == 95) {
definition.setCombatLevel(buffer.getShort());
} else if (opcode == 97) {
buffer.getShort();
} else if (opcode == 98) {
buffer.getShort();
} else if (opcode == 100) {
buffer.get();
} else if (opcode == 101) {
buffer.get();
} else if (opcode == 102) {
buffer.getShort();
} else if (opcode == 103) {
buffer.getShort();
} else if (opcode == 106) {
int morphVariableBitsIndex = buffer.getShort();
if (morphVariableBitsIndex == 65535) {
morphVariableBitsIndex = -1;
}
int morphismCount = buffer.getShort();
if (morphismCount == 65535) {
morphismCount = -1;
}
int count = buffer.get() & 0xFF; if (opcode == 0) {
int[] morphisms = new int[count + 1]; return definition;
for (int i = 0; i <= count; i++) { } else if (opcode == 1) {
int morphism = buffer.getShort(); int length = buffer.get() & 0xFF;
if (morphism == 65535) { int[] models = new int[length];
morphism = -1; for (int i = 0; i < length; i++) {
} models[i] = buffer.getShort();
morphisms[i] = morphism;
}
} else if (opcode == 107) {
@SuppressWarnings("unused")
boolean clickable = false;
}
} }
} else if (opcode == 2) {
definition.setName(BufferUtil.readString(buffer));
} else if (opcode == 3) {
definition.setDescription(BufferUtil.readString(buffer));
} else if (opcode == 12) {
definition.setSize(buffer.get());
} else if (opcode == 13) {
definition.setStandAnimation(buffer.getShort());
} else if (opcode == 14) {
definition.setWalkAnimation(buffer.getShort());
} else if (opcode == 17) {
definition
.setWalkAnimations(buffer.getShort(), buffer.getShort(), buffer.getShort(), buffer.getShort());
} else if (opcode >= 30 && opcode < 40) {
String str = BufferUtil.readString(buffer);
if (str.equals("hidden")) {
str = null;
}
definition.setInteraction(opcode - 30, str);
} else if (opcode == 40) {
int length = buffer.get() & 0xFF;
int[] originalColours = new int[length];
int[] replacementColours = new int[length];
for (int i = 0; i < length; i++) {
originalColours[i] = buffer.getShort();
replacementColours[i] = buffer.getShort();
}
} else if (opcode == 60) {
int length = buffer.get() & 0xFF;
int[] additionalModels = new int[length];
for (int i = 0; i < length; i++) {
additionalModels[i] = buffer.getShort();
}
} else if (opcode == 90) {
buffer.getShort(); // Dummy
} else if (opcode == 91) {
buffer.getShort(); // Dummy
} else if (opcode == 92) {
buffer.getShort(); // Dummy
} else if (opcode == 95) {
definition.setCombatLevel(buffer.getShort());
} else if (opcode == 97) {
buffer.getShort();
} else if (opcode == 98) {
buffer.getShort();
} else if (opcode == 100) {
buffer.get();
} else if (opcode == 101) {
buffer.get();
} else if (opcode == 102) {
buffer.getShort();
} else if (opcode == 103) {
buffer.getShort();
} else if (opcode == 106) {
int morphVariableBitsIndex = buffer.getShort();
if (morphVariableBitsIndex == 65535) {
morphVariableBitsIndex = -1;
}
int morphismCount = buffer.getShort();
if (morphismCount == 65535) {
morphismCount = -1;
}
int count = buffer.get() & 0xFF;
int[] morphisms = new int[count + 1];
for (int i = 0; i <= count; i++) {
int morphism = buffer.getShort();
if (morphism == 65535) {
morphism = -1;
}
morphisms[i] = morphism;
}
} else if (opcode == 107) {
@SuppressWarnings("unused")
boolean clickable = false;
}
} }
}
} }
@@ -15,131 +15,131 @@ import org.apollo.util.BufferUtil;
*/ */
public final class ObjectDefinitionDecoder { public final class ObjectDefinitionDecoder {
/** /**
* The {@link IndexedFileSystem}. * The {@link IndexedFileSystem}.
*/ */
private final IndexedFileSystem fs; private final IndexedFileSystem fs;
/** /**
* Creates the decoder. * Creates the decoder.
* *
* @param fs The {@link IndexedFileSystem}. * @param fs The {@link IndexedFileSystem}.
*/ */
public ObjectDefinitionDecoder(IndexedFileSystem fs) { public ObjectDefinitionDecoder(IndexedFileSystem fs) {
this.fs = fs; this.fs = fs;
}
/**
* Decodes all of the data into {@link ObjectDefinition}s.
*
* @return The definitions.
* @throws IOException If an error occurs when decoding the archive or finding an entry.
*/
public ObjectDefinition[] decode() throws IOException {
Archive config = Archive.decode(fs.getFile(0, 2));
ByteBuffer data = config.getEntry("loc.dat").getBuffer();
ByteBuffer idx = config.getEntry("loc.idx").getBuffer();
int count = idx.getShort(), index = 2;
int[] indices = new int[count];
for (int i = 0; i < count; i++) {
indices[i] = index;
index += idx.getShort();
} }
/** ObjectDefinition[] defs = new ObjectDefinition[count];
* Decodes all of the data into {@link ObjectDefinition}s. for (int i = 0; i < count; i++) {
* data.position(indices[i]);
* @return The definitions. defs[i] = decode(i, data);
* @throws IOException If an error occurs when decoding the archive or finding an entry.
*/
public ObjectDefinition[] decode() throws IOException {
Archive config = Archive.decode(fs.getFile(0, 2));
ByteBuffer data = config.getEntry("loc.dat").getBuffer();
ByteBuffer idx = config.getEntry("loc.idx").getBuffer();
int count = idx.getShort(), index = 2;
int[] indices = new int[count];
for (int i = 0; i < count; i++) {
indices[i] = index;
index += idx.getShort();
}
ObjectDefinition[] defs = new ObjectDefinition[count];
for (int i = 0; i < count; i++) {
data.position(indices[i]);
defs[i] = decode(i, data);
}
return defs;
} }
return defs;
}
/** /**
* Decodes data from the cache into an {@link ObjectDefinition}. * Decodes data from the cache into an {@link ObjectDefinition}.
* *
* @param id The id of the object. * @param id The id of the object.
* @param data The {@link ByteBuffer} containing the data. * @param data The {@link ByteBuffer} containing the data.
* @return The object definition. * @return The object definition.
*/ */
public ObjectDefinition decode(int id, ByteBuffer data) { public ObjectDefinition decode(int id, ByteBuffer data) {
ObjectDefinition definition = new ObjectDefinition(id); ObjectDefinition definition = new ObjectDefinition(id);
while (true) { while (true) {
int opcode = data.get() & 0xFF; int opcode = data.get() & 0xFF;
if (opcode == 0) { if (opcode == 0) {
return definition; return definition;
} else if (opcode == 1) { } else if (opcode == 1) {
int amount = data.get() & 0xFF; int amount = data.get() & 0xFF;
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
data.getShort(); data.getShort();
data.get(); data.get();
}
} else if (opcode == 2) {
definition.setName(BufferUtil.readString(data));
} else if (opcode == 3) {
definition.setDescription(BufferUtil.readString(data));
} else if (opcode == 5) {
int amount = data.get() & 0xFF;
for (int i = 0; i < amount; i++) {
data.getShort();
}
} else if (opcode == 14) {
definition.setWidth(data.get() & 0xFF);
} else if (opcode == 15) {
definition.setHeight(data.get() & 0xFF);
} else if (opcode == 17) {
definition.setSolid(false);
} else if (opcode == 18) {
definition.setImpenetrable(false);
} else if (opcode == 19) {
definition.setInteractive((data.get() & 0xFF) == 1);
} else if (opcode == 24) {
data.getShort();
} else if (opcode == 28) {
data.get();
} else if (opcode == 29) {
data.get();
} else if (opcode >= 30 && opcode < 39) {
String[] actions = definition.getMenuActions();
if (actions == null) {
actions = new String[10];
}
String action = BufferUtil.readString(data);
actions[opcode - 30] = action;
definition.setMenuActions(actions);
} else if (opcode == 39) {
data.get();
} else if (opcode == 40) {
int amount = data.get() & 0xFF;
for (int i = 0; i < amount; i++) {
data.getShort();
data.getShort();
}
} else if (opcode == 60) {
data.getShort();
} else if (opcode == 65) {
data.getShort();
} else if (opcode == 66) {
data.getShort();
} else if (opcode == 67) {
data.getShort();
} else if (opcode == 68) {
data.getShort();
} else if (opcode == 69) {
data.get();
} else if (opcode == 70) {
data.getShort();
} else if (opcode == 71) {
data.getShort();
} else if (opcode == 72) {
data.getShort();
} else if (opcode == 75) {
data.get();
} else {
continue;
}
} }
} else if (opcode == 2) {
definition.setName(BufferUtil.readString(data));
} else if (opcode == 3) {
definition.setDescription(BufferUtil.readString(data));
} else if (opcode == 5) {
int amount = data.get() & 0xFF;
for (int i = 0; i < amount; i++) {
data.getShort();
}
} else if (opcode == 14) {
definition.setWidth(data.get() & 0xFF);
} else if (opcode == 15) {
definition.setHeight(data.get() & 0xFF);
} else if (opcode == 17) {
definition.setSolid(false);
} else if (opcode == 18) {
definition.setImpenetrable(false);
} else if (opcode == 19) {
definition.setInteractive((data.get() & 0xFF) == 1);
} else if (opcode == 24) {
data.getShort();
} else if (opcode == 28) {
data.get();
} else if (opcode == 29) {
data.get();
} else if (opcode >= 30 && opcode < 39) {
String[] actions = definition.getMenuActions();
if (actions == null) {
actions = new String[10];
}
String action = BufferUtil.readString(data);
actions[opcode - 30] = action;
definition.setMenuActions(actions);
} else if (opcode == 39) {
data.get();
} else if (opcode == 40) {
int amount = data.get() & 0xFF;
for (int i = 0; i < amount; i++) {
data.getShort();
data.getShort();
}
} else if (opcode == 60) {
data.getShort();
} else if (opcode == 65) {
data.getShort();
} else if (opcode == 66) {
data.getShort();
} else if (opcode == 67) {
data.getShort();
} else if (opcode == 68) {
data.getShort();
} else if (opcode == 69) {
data.get();
} else if (opcode == 70) {
data.getShort();
} else if (opcode == 71) {
data.getShort();
} else if (opcode == 72) {
data.getShort();
} else if (opcode == 75) {
data.get();
} else {
continue;
}
} }
}
} }
@@ -20,100 +20,100 @@ import org.apollo.util.CompressionUtil;
*/ */
public final class StaticObjectDecoder { public final class StaticObjectDecoder {
/** /**
* The {@link IndexedFileSystem}. * The {@link IndexedFileSystem}.
*/ */
private final IndexedFileSystem fs; private final IndexedFileSystem fs;
/** /**
* Creates the decoder. * Creates the decoder.
* *
* @param fs The indexed file system. * @param fs The indexed file system.
*/ */
public StaticObjectDecoder(IndexedFileSystem fs) { public StaticObjectDecoder(IndexedFileSystem fs) {
this.fs = fs; this.fs = fs;
}
/**
* Decodes all static objects and places them in the returned array.
*
* @return The decoded objects.
* @throws IOException If an I/O error occurs.
*/
public GameObject[] decode() throws IOException {
Archive versionList = Archive.decode(fs.getFile(0, 5));
ByteBuffer buffer = versionList.getEntry("map_index").getBuffer();
int indices = buffer.remaining() / 7;
int[] areas = new int[indices];
int[] landscapes = new int[indices];
for (int i = 0; i < indices; i++) {
areas[i] = buffer.getShort() & 0xFFFF;
@SuppressWarnings("unused")
int mapFile = buffer.getShort() & 0xFFFF;
landscapes[i] = buffer.getShort() & 0xFFFF;
@SuppressWarnings("unused")
boolean members = (buffer.get() & 0xFF) == 1;
} }
/** List<GameObject> objects = new ArrayList<>();
* Decodes all static objects and places them in the returned array.
*
* @return The decoded objects.
* @throws IOException If an I/O error occurs.
*/
public GameObject[] decode() throws IOException {
Archive versionList = Archive.decode(fs.getFile(0, 5));
ByteBuffer buffer = versionList.getEntry("map_index").getBuffer();
int indices = buffer.remaining() / 7; for (int i = 0; i < indices; i++) {
int[] areas = new int[indices]; ByteBuffer compressed = fs.getFile(4, landscapes[i]);
int[] landscapes = new int[indices]; ByteBuffer uncompressed = ByteBuffer.wrap(CompressionUtil.ungzip(compressed));
for (int i = 0; i < indices; i++) { Collection<GameObject> areaObjects = parseArea(areas[i], uncompressed);
areas[i] = buffer.getShort() & 0xFFFF; objects.addAll(areaObjects);
@SuppressWarnings("unused")
int mapFile = buffer.getShort() & 0xFFFF;
landscapes[i] = buffer.getShort() & 0xFFFF;
@SuppressWarnings("unused")
boolean members = (buffer.get() & 0xFF) == 1;
}
List<GameObject> objects = new ArrayList<GameObject>();
for (int i = 0; i < indices; i++) {
ByteBuffer compressed = fs.getFile(4, landscapes[i]);
ByteBuffer uncompressed = ByteBuffer.wrap(CompressionUtil.ungzip(compressed));
Collection<GameObject> areaObjects = parseArea(areas[i], uncompressed);
objects.addAll(areaObjects);
}
return objects.toArray(new GameObject[objects.size()]);
} }
/** return objects.toArray(new GameObject[objects.size()]);
* Parses a single area from the specified buffer. }
*
* @param area The identifier of that area.
* @param buffer The buffer which holds the area's data.
* @return A collection of all parsed objects.
*/
private Collection<GameObject> parseArea(int area, ByteBuffer buffer) {
List<GameObject> objects = new ArrayList<GameObject>();
int x = (area >> 8 & 0xFF) * 64; /**
int y = (area & 0xFF) * 64; * Parses a single area from the specified buffer.
*
* @param area The identifier of that area.
* @param buffer The buffer which holds the area's data.
* @return A collection of all parsed objects.
*/
private Collection<GameObject> parseArea(int area, ByteBuffer buffer) {
List<GameObject> objects = new ArrayList<>();
int id = -1; int x = (area >> 8 & 0xFF) * 64;
int idOffset; int y = (area & 0xFF) * 64;
while ((idOffset = BufferUtil.readSmart(buffer)) != 0) { int id = -1;
id += idOffset; int idOffset;
int position = 0; while ((idOffset = BufferUtil.readSmart(buffer)) != 0) {
int positionOffset; id += idOffset;
while ((positionOffset = BufferUtil.readSmart(buffer)) != 0) { int position = 0;
position += positionOffset - 1; int positionOffset;
int localX = position >> 6 & 0x3F; while ((positionOffset = BufferUtil.readSmart(buffer)) != 0) {
int localY = position & 0x3F; position += positionOffset - 1;
int height = position >> 12;
int info = buffer.get() & 0xFF; int localX = position >> 6 & 0x3F;
int type = info >> 2; int localY = position & 0x3F;
int rotation = info & 3; int height = position >> 12;
Position pos = new Position(x + localX, y + localY, height); int info = buffer.get() & 0xFF;
int type = info >> 2;
int rotation = info & 3;
GameObject object = new GameObject(id, pos, type, rotation); Position pos = new Position(x + localX, y + localY, height);
objects.add(object);
}
}
return objects; GameObject object = new GameObject(id, pos, type, rotation);
objects.add(object);
}
} }
return objects;
}
} }
+13 -13
View File
@@ -7,21 +7,21 @@ package org.apollo.game;
*/ */
public final class GameConstants { public final class GameConstants {
/** /**
* The maximum events per pulse per session. * The maximum events per pulse per session.
*/ */
public static final int EVENTS_PER_PULSE = 10; public static final int EVENTS_PER_PULSE = 10;
/** /**
* The delay between consecutive pulses, in milliseconds. * The delay between consecutive pulses, in milliseconds.
*/ */
public static final int PULSE_DELAY = 600; public static final int PULSE_DELAY = 600;
/** /**
* Default private constructor to prevent instantiation by other classes. * Default private constructor to prevent instantiation by other classes.
*/ */
private GameConstants() { private GameConstants() {
} }
} }
+24 -24
View File
@@ -10,32 +10,32 @@ import java.util.logging.Logger;
*/ */
public final class GamePulseHandler implements Runnable { public final class GamePulseHandler implements Runnable {
/** /**
* The logger for this class. * The logger for this class.
*/ */
private static final Logger logger = Logger.getLogger(GamePulseHandler.class.getName()); private static final Logger logger = Logger.getLogger(GamePulseHandler.class.getName());
/** /**
* The {@link GameService}. * The {@link GameService}.
*/ */
private final GameService service; private final GameService service;
/** /**
* Creates the game pulse handler object. * Creates the game pulse handler object.
* *
* @param service The {@link GameService}. * @param service The {@link GameService}.
*/ */
GamePulseHandler(GameService service) { GamePulseHandler(GameService service) {
this.service = service; this.service = service;
} }
@Override @Override
public void run() { public void run() {
try { try {
service.pulse(); service.pulse();
} catch (Throwable t) { } catch (Throwable t) {
logger.log(Level.SEVERE, "Exception during pulse.", t); logger.log(Level.SEVERE, "Exception during pulse.", t);
}
} }
}
} }
+139 -139
View File
@@ -31,157 +31,157 @@ import org.xml.sax.SAXException;
*/ */
public final class GameService extends Service { public final class GameService extends Service {
/** /**
* The number of times to unregister players per cycle. This is to ensure the saving threads don't get swamped with * The number of times to unregister players per cycle. This is to ensure the saving threads don't get swamped with
* requests and slow everything down. * requests and slow everything down.
*/ */
private static final int UNREGISTERS_PER_CYCLE = 50; private static final int UNREGISTERS_PER_CYCLE = 50;
/** /**
* The {@link EventHandlerChainGroup}. * The {@link EventHandlerChainGroup}.
*/ */
private EventHandlerChainGroup chainGroup; private EventHandlerChainGroup chainGroup;
/** /**
* A queue of players to remove. * A queue of players to remove.
*/ */
private final Queue<Player> oldPlayers = new ConcurrentLinkedQueue<Player>(); private final Queue<Player> oldPlayers = new ConcurrentLinkedQueue<>();
/** /**
* The scheduled executor service. * The scheduled executor service.
*/ */
private final ScheduledExecutorService scheduledExecutor = Executors private final ScheduledExecutorService scheduledExecutor = Executors
.newSingleThreadScheduledExecutor(new NamedThreadFactory("GameService")); .newSingleThreadScheduledExecutor(new NamedThreadFactory("GameService"));
/** /**
* The {@link ClientSynchronizer}. * The {@link ClientSynchronizer}.
*/ */
private ClientSynchronizer synchronizer; private ClientSynchronizer synchronizer;
/** /**
* Creates the game service. * Creates the game service.
* *
* @throws Exception If an error occurs during initialization. * @throws Exception If an error occurs during initialization.
*/ */
public GameService() throws Exception { public GameService() throws Exception {
init(); init();
}
/**
* Finalizes the unregistration of a player.
*
* @param player The player.
*/
public void finalizePlayerUnregistration(Player player) {
synchronized (this) {
World.getWorld().unregister(player);
}
}
/**
* Gets the event handler chains.
*
* @return The event handler chains.
*/
public EventHandlerChainGroup getEventHandlerChains() {
return chainGroup;
}
/**
* Initializes the game service.
*
* @throws IOException If there is an error with the file (e.g. does not exist, cannot be read, does not contain
* valid nodes).
* @throws SAXException If there is an error parsing the file.
* @throws ClassNotFoundException If an event handler could not be found.
* @throws InstantiationException If an event handler could not be instantiated.
* @throws IllegalAccessException If an event handler could not be accessed.
*/
private void init() throws IOException, SAXException, ClassNotFoundException, InstantiationException,
IllegalAccessException {
try (InputStream is = new FileInputStream("data/events.xml")) {
EventHandlerChainParser chainGroupParser = new EventHandlerChainParser(is);
chainGroup = chainGroupParser.parse();
} }
/** try (InputStream is = new FileInputStream("data/synchronizer.xml")) {
* Finalizes the unregistration of a player. XmlParser parser = new XmlParser();
* XmlNode rootNode = parser.parse(is);
* @param player The player.
*/ if (!rootNode.getName().equals("synchronizer")) {
public void finalizePlayerUnregistration(Player player) { throw new IOException("Invalid root node name.");
synchronized (this) { }
World.getWorld().unregister(player);
XmlNode activeNode = rootNode.getChild("active");
if (activeNode == null || !activeNode.hasValue()) {
throw new IOException("No active node/value.");
}
Class<?> clazz = Class.forName(activeNode.getValue());
synchronizer = (ClientSynchronizer) clazz.newInstance();
}
try (InputStream is = new FileInputStream("data/rsa.xml")) {
RsaKeyParser parser = new RsaKeyParser(is);
parser.parse();
}
}
/**
* Called every pulse.
*/
public void pulse() {
synchronized (this) {
LoginService loginService = getContext().getService(LoginService.class);
World world = World.getWorld();
int unregistered = 0;
Player old;
while (unregistered < UNREGISTERS_PER_CYCLE && (old = oldPlayers.poll()) != null) {
loginService.submitSaveRequest(old.getSession(), old);
unregistered++;
}
for (Player p : world.getPlayerRepository()) {
GameSession session = p.getSession();
if (session != null) {
session.handlePendingEvents(chainGroup);
} }
}
world.pulse();
synchronizer.synchronize();
} }
}
/** /**
* Gets the event handler chains. * Registers a player (may block!).
* *
* @return The event handler chains. * @param player The player.
*/ * @return A {@link RegistrationStatus}.
public EventHandlerChainGroup getEventHandlerChains() { */
return chainGroup; public RegistrationStatus registerPlayer(Player player) {
synchronized (this) {
return World.getWorld().register(player);
} }
}
/** /**
* Initializes the game service. * Starts the game service.
* */
* @throws IOException If there is an error with the file (e.g. does not exist, cannot be read, does not contain @Override
* valid nodes). public void start() {
* @throws SAXException If there is an error parsing the file. scheduledExecutor.scheduleAtFixedRate(new GamePulseHandler(this), GameConstants.PULSE_DELAY,
* @throws ClassNotFoundException If an event handler could not be found. GameConstants.PULSE_DELAY, TimeUnit.MILLISECONDS);
* @throws InstantiationException If an event handler could not be instantiated. }
* @throws IllegalAccessException If an event handler could not be accessed.
*/
private void init() throws IOException, SAXException, ClassNotFoundException, InstantiationException,
IllegalAccessException {
try (InputStream is = new FileInputStream("data/events.xml")) {
EventHandlerChainParser chainGroupParser = new EventHandlerChainParser(is);
chainGroup = chainGroupParser.parse();
}
try (InputStream is = new FileInputStream("data/synchronizer.xml")) { /**
XmlParser parser = new XmlParser(); * Unregisters a player. Returns immediately. The player is unregistered at the start of the next cycle.
XmlNode rootNode = parser.parse(is); *
* @param player The player.
if (!rootNode.getName().equals("synchronizer")) { */
throw new IOException("Invalid root node name."); public void unregisterPlayer(Player player) {
} oldPlayers.add(player);
}
XmlNode activeNode = rootNode.getChild("active");
if (activeNode == null || !activeNode.hasValue()) {
throw new IOException("No active node/value.");
}
Class<?> clazz = Class.forName(activeNode.getValue());
synchronizer = (ClientSynchronizer) clazz.newInstance();
}
try (InputStream is = new FileInputStream("data/rsa.xml")) {
RsaKeyParser parser = new RsaKeyParser(is);
parser.parse();
}
}
/**
* Called every pulse.
*/
public void pulse() {
synchronized (this) {
LoginService loginService = getContext().getService(LoginService.class);
World world = World.getWorld();
int unregistered = 0;
Player old;
while (unregistered < UNREGISTERS_PER_CYCLE && (old = oldPlayers.poll()) != null) {
loginService.submitSaveRequest(old.getSession(), old);
unregistered++;
}
for (Player p : world.getPlayerRepository()) {
GameSession session = p.getSession();
if (session != null) {
session.handlePendingEvents(chainGroup);
}
}
world.pulse();
synchronizer.synchronize();
}
}
/**
* Registers a player (may block!).
*
* @param player The player.
* @return A {@link RegistrationStatus}.
*/
public RegistrationStatus registerPlayer(Player player) {
synchronized (this) {
return World.getWorld().register(player);
}
}
/**
* Starts the game service.
*/
@Override
public void start() {
scheduledExecutor.scheduleAtFixedRate(new GamePulseHandler(this), GameConstants.PULSE_DELAY,
GameConstants.PULSE_DELAY, TimeUnit.MILLISECONDS);
}
/**
* Unregisters a player. Returns immediately. The player is unregistered at the start of the next cycle.
*
* @param player The player.
*/
public void unregisterPlayer(Player player) {
oldPlayers.add(player);
}
} }
+36 -36
View File
@@ -14,44 +14,44 @@ import org.apollo.game.scheduling.ScheduledTask;
*/ */
public abstract class Action<T extends Mob> extends ScheduledTask { public abstract class Action<T extends Mob> extends ScheduledTask {
/** /**
* The mob performing the action. * The mob performing the action.
*/ */
protected final T mob; protected final T mob;
/** /**
* A flag indicating if this action is stopping. * A flag indicating if this action is stopping.
*/ */
private boolean stopping = false; private boolean stopping = false;
/** /**
* Creates a new action. * Creates a new action.
* *
* @param delay The delay in pulses. * @param delay The delay in pulses.
* @param immediate A flag indicating if the action should happen immediately. * @param immediate A flag indicating if the action should happen immediately.
* @param mob The mob performing the action. * @param mob The mob performing the action.
*/ */
public Action(int delay, boolean immediate, T mob) { public Action(int delay, boolean immediate, T mob) {
super(delay, immediate); super(delay, immediate);
this.mob = mob; this.mob = mob;
} }
/** /**
* Gets the mob which performed the action. * Gets the mob which performed the action.
* *
* @return The mob. * @return The mob.
*/ */
public T getMob() { public T getMob() {
return mob; return mob;
} }
@Override @Override
public void stop() { public void stop() {
super.stop(); super.stop();
if (!stopping) { if (!stopping) {
stopping = true; stopping = true;
mob.stopAction(); mob.stopAction();
}
} }
}
} }
+54 -54
View File
@@ -11,66 +11,66 @@ import org.apollo.game.model.entity.Mob;
*/ */
public abstract class DistancedAction<T extends Mob> extends Action<T> { public abstract class DistancedAction<T extends Mob> extends Action<T> {
/** /**
* The delay once the threshold is reached. * The delay once the threshold is reached.
*/ */
private final int delay; private final int delay;
/** /**
* The minimum distance before the action fires. * The minimum distance before the action fires.
*/ */
private final int distance; private final int distance;
/** /**
* A flag indicating if this action fires immediately after the threshold is reached. * A flag indicating if this action fires immediately after the threshold is reached.
*/ */
private final boolean immediate; private final boolean immediate;
/** /**
* The position to distance check with. * The position to distance check with.
*/ */
private final Position position; private final Position position;
/** /**
* A flag indicating if the distance has been reached yet. * A flag indicating if the distance has been reached yet.
*/ */
private boolean reached = false; private boolean reached = false;
/** /**
* Creates a new DistancedAction. * Creates a new DistancedAction.
* *
* @param delay The delay between executions once the distance threshold is reached. * @param delay The delay between executions once the distance threshold is reached.
* @param immediate Whether or not this action fires immediately after the distance threshold is reached. * @param immediate Whether or not this action fires immediately after the distance threshold is reached.
* @param mob The mob. * @param mob The mob.
* @param position The position. * @param position The position.
* @param distance The distance. * @param distance The distance.
*/ */
public DistancedAction(int delay, boolean immediate, T mob, Position position, int distance) { public DistancedAction(int delay, boolean immediate, T mob, Position position, int distance) {
super(0, true, mob); super(0, true, mob);
this.position = position; this.position = position;
this.distance = distance; this.distance = distance;
this.delay = delay; this.delay = delay;
this.immediate = immediate; this.immediate = immediate;
}
@Override
public void execute() {
if (reached) {
// some actions (e.g. agility) will cause the player to move away again
// so we don't check once the player got close enough once
executeAction();
} else if (mob.getPosition().getDistance(position) <= distance) {
reached = true;
setDelay(delay);
if (immediate) {
executeAction();
}
} }
}
@Override /**
public void execute() { * Executes the actual action. Called when the distance requirement is met.
if (reached) { */
// some actions (e.g. agility) will cause the player to move away again public abstract void executeAction();
// so we don't check once the player got close enough once
executeAction();
} else if (mob.getPosition().getDistance(position) <= distance) {
reached = true;
setDelay(delay);
if (immediate) {
executeAction();
}
}
}
/**
* Executes the actual action. Called when the distance requirement is met.
*/
public abstract void executeAction();
} }
+34 -34
View File
@@ -7,43 +7,43 @@ package org.apollo.game.command;
*/ */
public final class Command { public final class Command {
/** /**
* The command's arguments. * The command's arguments.
*/ */
private final String[] arguments; private final String[] arguments;
/** /**
* The name of the command. * The name of the command.
*/ */
private final String name; private final String name;
/** /**
* Creates the command. * Creates the command.
* *
* @param name The name of the command. * @param name The name of the command.
* @param arguments The command's arguments. * @param arguments The command's arguments.
*/ */
public Command(String name, String[] arguments) { public Command(String name, String[] arguments) {
this.name = name; this.name = name;
this.arguments = arguments; this.arguments = arguments;
} }
/** /**
* Gets the command's arguments. * Gets the command's arguments.
* *
* @return The command's arguments. * @return The command's arguments.
*/ */
public String[] getArguments() { public String[] getArguments() {
return arguments; return arguments;
} }
/** /**
* Gets the name of the command. * Gets the name of the command.
* *
* @return The name of the command. * @return The name of the command.
*/ */
public String getName() { public String getName() {
return name; return name;
} }
} }
@@ -12,39 +12,39 @@ import org.apollo.game.model.entity.Player;
*/ */
public final class CommandDispatcher { public final class CommandDispatcher {
/** /**
* A map of event listeners. * A map of event listeners.
*/ */
private final Map<String, CommandListener> listeners = new HashMap<String, CommandListener>(); private final Map<String, CommandListener> listeners = new HashMap<String, CommandListener>();
/** /**
* Creates the command dispatcher and registers a listener for the credits command. * Creates the command dispatcher and registers a listener for the credits command.
*/ */
public CommandDispatcher() { public CommandDispatcher() {
listeners.put("credits", new CreditsCommandListener()); listeners.put("credits", new CreditsCommandListener());
} }
/** /**
* Dispatches a command to the appropriate listener. * Dispatches a command to the appropriate listener.
* *
* @param player The player. * @param player The player.
* @param command The command. * @param command The command.
*/ */
public void dispatch(Player player, Command command) { public void dispatch(Player player, Command command) {
CommandListener listener = listeners.get(command.getName().toLowerCase()); CommandListener listener = listeners.get(command.getName().toLowerCase());
if (listener != null) { if (listener != null) {
listener.executePrivileged(player, command); listener.executePrivileged(player, command);
}
} }
}
/** /**
* Registers a listener with the dispatcher. * Registers a listener with the dispatcher.
* *
* @param command The command's name. * @param command The command's name.
* @param listener The listener. * @param listener The listener.
*/ */
public void register(String command, CommandListener listener) { public void register(String command, CommandListener listener) {
listeners.put(command.toLowerCase(), listener); listeners.put(command.toLowerCase(), listener);
} }
} }
@@ -11,45 +11,45 @@ import org.apollo.game.model.settings.PrivilegeLevel;
*/ */
public abstract class CommandListener { public abstract class CommandListener {
/** /**
* The minimum privilege level. * The minimum privilege level.
*/ */
private final PrivilegeLevel level; private final PrivilegeLevel level;
/** /**
* Creates a new command listener with a {@link PrivilegeLevel#STANDARD} requirement. * Creates a new command listener with a {@link PrivilegeLevel#STANDARD} requirement.
*/ */
public CommandListener() { public CommandListener() {
this(PrivilegeLevel.STANDARD); this(PrivilegeLevel.STANDARD);
} }
/** /**
* Creates a new command listener. * Creates a new command listener.
* *
* @param level The required {@link PrivilegeLevel}. * @param level The required {@link PrivilegeLevel}.
*/ */
public CommandListener(PrivilegeLevel level) { public CommandListener(PrivilegeLevel level) {
this.level = level; this.level = level;
} }
/** /**
* Executes the action for this command. * Executes the action for this command.
* *
* @param player The player. * @param player The player.
* @param command The command. * @param command The command.
*/ */
public abstract void execute(Player player, Command command); public abstract void execute(Player player, Command command);
/** /**
* Executes a privileged command. * Executes a privileged command.
* *
* @param player The player. * @param player The player.
* @param command The command. * @param command The command.
*/ */
public final void executePrivileged(Player player, Command command) { public final void executePrivileged(Player player, Command command) {
if (player.getPrivilegeLevel().toInteger() >= level.toInteger()) { if (player.getPrivilegeLevel().toInteger() >= level.toInteger()) {
execute(player, command); execute(player, command);
}
} }
}
} }
@@ -15,36 +15,36 @@ import org.apollo.util.plugin.PluginManager;
*/ */
public final class CreditsCommandListener extends CommandListener { public final class CreditsCommandListener extends CommandListener {
/* /*
* If you are considering removing this command, please bear in mind that Apollo took several people thousands of * If you are considering removing this command, please bear in mind that Apollo took several people thousands of
* hours to create. We released it to the world for free and it isn't much to ask to leave this command in. It isn't * hours to create. We released it to the world for free and it isn't much to ask to leave this command in. It isn't
* very obtrusive and gives us some well-deserved recognition for the work we have done. Thank you! * very obtrusive and gives us some well-deserved recognition for the work we have done. Thank you!
* *
* The list of authors is generated from the plugin manager. If you create a custom plugin, make sure you add your * The list of authors is generated from the plugin manager. If you create a custom plugin, make sure you add your
* name to the plugin.xml file and it'll appear here automatically! * name to the plugin.xml file and it'll appear here automatically!
*/ */
@Override @Override
public void execute(Player player, Command command) { public void execute(Player player, Command command) {
PluginManager mgr = World.getWorld().getPluginManager(); PluginManager mgr = World.getWorld().getPluginManager();
final Set<String> authors = mgr.getAuthors(); final Set<String> authors = mgr.getAuthors();
List<String> text = new ArrayList<String>(12 + authors.size()); List<String> text = new ArrayList<>(12 + authors.size());
text.add("@dre@Apollo"); text.add("@dre@Apollo");
text.add("@dre@Introduction"); text.add("@dre@Introduction");
text.add(""); text.add("");
text.add("This server is based on Apollo, a lightweight, fast, secure"); text.add("This server is based on Apollo, a lightweight, fast, secure");
text.add("and open-source RuneScape emulator. For more"); text.add("and open-source RuneScape emulator. For more");
text.add("information about Apollo, visit the website at:"); text.add("information about Apollo, visit the website at:");
text.add("@dbl@https://github.com/apollo-rsps/apollo"); text.add("@dbl@https://github.com/apollo-rsps/apollo");
text.add(""); text.add("");
text.add("Apollo is released under the terms of the ISC license."); text.add("Apollo is released under the terms of the ISC license.");
text.add(""); text.add("");
text.add("@dre@Credits"); text.add("@dre@Credits");
text.add(""); text.add("");
text.addAll(authors); text.addAll(authors);
player.sendQuestInterface(text); player.sendQuestInterface(text);
} }
} }
@@ -11,13 +11,13 @@ import org.apollo.game.model.entity.Player;
*/ */
public abstract class EventHandler<E extends Event> { public abstract class EventHandler<E extends Event> {
/** /**
* Handles an event. * Handles an event.
* *
* @param ctx The context. * @param ctx The context.
* @param player The player. * @param player The player.
* @param event The event. * @param event The event.
*/ */
public abstract void handle(EventHandlerContext ctx, Player player, E event); public abstract void handle(EventHandlerContext ctx, Player player, E event);
} }
@@ -9,9 +9,9 @@ import org.apollo.game.event.handler.chain.EventHandlerChain;
*/ */
public abstract class EventHandlerContext { public abstract class EventHandlerContext {
/** /**
* Breaks the handler chain. * Breaks the handler chain.
*/ */
public abstract void breakHandlerChain(); public abstract void breakHandlerChain();
} }
@@ -13,58 +13,58 @@ import org.apollo.game.model.entity.Player;
*/ */
public final class EventHandlerChain<E extends Event> { public final class EventHandlerChain<E extends Event> {
/** /**
* The handlers. * The handlers.
*/ */
private EventHandler<E>[] handlers; private EventHandler<E>[] handlers;
/** /**
* Creates the event handler chain. * Creates the event handler chain.
* *
* @param handlers The handlers. * @param handlers The handlers.
*/ */
@SafeVarargs @SafeVarargs
public EventHandlerChain(EventHandler<E>... handlers) { public EventHandlerChain(EventHandler<E>... handlers) {
this.handlers = handlers; this.handlers = handlers;
} }
/** /**
* Dynamically adds an event handler to the end of the chain. * Dynamically adds an event handler to the end of the chain.
* *
* @param handler The handler. * @param handler The handler.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void addLast(EventHandler<E> handler) { public void addLast(EventHandler<E> handler) {
EventHandler<E>[] old = handlers; EventHandler<E>[] old = handlers;
handlers = new EventHandler[old.length + 1]; handlers = new EventHandler[old.length + 1];
System.arraycopy(old, 0, handlers, 0, old.length); System.arraycopy(old, 0, handlers, 0, old.length);
handlers[old.length] = handler; handlers[old.length] = handler;
} }
/** /**
* Handles the event, passing it down the chain until the chain is broken or the event reaches the end of the chain. * Handles the event, passing it down the chain until the chain is broken or the event reaches the end of the chain.
* *
* @param player The player. * @param player The player.
* @param event The event. * @param event The event.
*/ */
public void handle(Player player, E event) { public void handle(Player player, E event) {
final boolean[] running = new boolean[1]; final boolean[] running = new boolean[1];
running[0] = true; running[0] = true;
EventHandlerContext ctx = new EventHandlerContext() { EventHandlerContext ctx = new EventHandlerContext() {
@Override @Override
public void breakHandlerChain() { public void breakHandlerChain() {
running[0] = false; running[0] = false;
} }
}; };
for (EventHandler<E> handler : handlers) { for (EventHandler<E> handler : handlers) {
handler.handle(ctx, player, event); handler.handle(ctx, player, event);
if (!running[0]) { if (!running[0]) {
break; break;
} }
}
} }
}
} }
@@ -11,40 +11,40 @@ import org.apollo.game.event.Event;
*/ */
public final class EventHandlerChainGroup { public final class EventHandlerChainGroup {
/** /**
* The map of event classes to event handler chains. * The map of event classes to event handler chains.
*/ */
private final Map<Class<? extends Event>, EventHandlerChain<?>> chains; private final Map<Class<? extends Event>, EventHandlerChain<?>> chains;
/** /**
* Creates the event handler chain group. * Creates the event handler chain group.
* *
* @param chains The chains map. * @param chains The chains map.
*/ */
public EventHandlerChainGroup(Map<Class<? extends Event>, EventHandlerChain<?>> chains) { public EventHandlerChainGroup(Map<Class<? extends Event>, EventHandlerChain<?>> chains) {
this.chains = chains; this.chains = chains;
} }
/** /**
* Gets an {@link EventHandlerChain} from this group. * Gets an {@link EventHandlerChain} from this group.
* *
* @param <E> The type of event. * @param <E> The type of event.
* @param clazz The event class. * @param clazz The event class.
* @return The {@link EventHandlerChain} if one was found, {@code null} otherwise. * @return The {@link EventHandlerChain} if one was found, {@code null} otherwise.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <E extends Event> EventHandlerChain<E> getChain(Class<E> clazz) { public <E extends Event> EventHandlerChain<E> getChain(Class<E> clazz) {
return (EventHandlerChain<E>) chains.get(clazz); return (EventHandlerChain<E>) chains.get(clazz);
} }
/** /**
* Registers an {@link EventHandlerChain} associated with the specified {@link Class} to this group. * Registers an {@link EventHandlerChain} associated with the specified {@link Class} to this group.
* *
* @param clazz The event class. * @param clazz The event class.
* @param chain The event handler chain. * @param chain The event handler chain.
*/ */
public <E extends Event> void register(Class<E> clazz, EventHandlerChain<E> chain) { public <E extends Event> void register(Class<E> clazz, EventHandlerChain<E> chain) {
chains.put(clazz, chain); chains.put(clazz, chain);
} }
} }
@@ -12,23 +12,23 @@ import org.apollo.game.model.entity.Player;
*/ */
public final class BankButtonEventHandler extends EventHandler<ButtonEvent> { public final class BankButtonEventHandler extends EventHandler<ButtonEvent> {
/** /**
* The withdraw as item button id. * The withdraw as item button id.
*/ */
private static final int WITHDRAW_AS_ITEM = 5387; private static final int WITHDRAW_AS_ITEM = 5387;
/** /**
* The withdraw as note button id. * The withdraw as note button id.
*/ */
private static final int WITHDRAW_AS_NOTE = 5386; private static final int WITHDRAW_AS_NOTE = 5386;
@Override @Override
public void handle(EventHandlerContext ctx, Player player, ButtonEvent event) { public void handle(EventHandlerContext ctx, Player player, ButtonEvent event) {
if (event.getWidgetId() == WITHDRAW_AS_ITEM) { if (event.getWidgetId() == WITHDRAW_AS_ITEM) {
player.setWithdrawingNotes(false); player.setWithdrawingNotes(false);
} else if (event.getWidgetId() == WITHDRAW_AS_NOTE) { } else if (event.getWidgetId() == WITHDRAW_AS_NOTE) {
player.setWithdrawingNotes(true); player.setWithdrawingNotes(true);
}
} }
}
} }
@@ -16,72 +16,72 @@ import org.apollo.game.model.inter.bank.BankWithdrawEnterAmountListener;
*/ */
public final class BankEventHandler extends EventHandler<ItemActionEvent> { public final class BankEventHandler extends EventHandler<ItemActionEvent> {
/** /**
* Converts an option to an amount. * Converts an option to an amount.
* *
* @param option The option. * @param option The option.
* @return The amount. * @return The amount.
* @throws IllegalArgumentException If the option is invalid. * @throws IllegalArgumentException If the option is invalid.
*/ */
private static final int optionToAmount(int option) { private static final int optionToAmount(int option) {
switch (option) { switch (option) {
case 1: case 1:
return 1; return 1;
case 2: case 2:
return 5; return 5;
case 3: case 3:
return 10; return 10;
case 4: case 4:
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
case 5: case 5:
return -1; return -1;
}
throw new IllegalArgumentException("Invalid option supplied.");
} }
throw new IllegalArgumentException("Invalid option supplied.");
}
/** /**
* Handles a deposit action. * Handles a deposit action.
* *
* @param ctx The event handler context. * @param ctx The event handler context.
* @param player The player. * @param player The player.
* @param event The event. * @param event The event.
*/ */
private void deposit(EventHandlerContext ctx, Player player, ItemActionEvent event) { private void deposit(EventHandlerContext ctx, Player player, ItemActionEvent event) {
int amount = optionToAmount(event.getOption()); int amount = optionToAmount(event.getOption());
if (amount == -1) { if (amount == -1) {
player.getInterfaceSet().openEnterAmountDialogue( player.getInterfaceSet().openEnterAmountDialogue(
new BankDepositEnterAmountListener(player, event.getSlot(), event.getId())); new BankDepositEnterAmountListener(player, event.getSlot(), event.getId()));
} else if (!BankUtils.deposit(player, event.getSlot(), event.getId(), amount)) { } else if (!BankUtils.deposit(player, event.getSlot(), event.getId(), amount)) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
}
} }
}
@Override @Override
public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) { public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) {
if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) { if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) {
if (event.getInterfaceId() == BankConstants.SIDEBAR_INVENTORY_ID) { if (event.getInterfaceId() == BankConstants.SIDEBAR_INVENTORY_ID) {
deposit(ctx, player, event); deposit(ctx, player, event);
} else if (event.getInterfaceId() == BankConstants.BANK_INVENTORY_ID) { } else if (event.getInterfaceId() == BankConstants.BANK_INVENTORY_ID) {
withdraw(ctx, player, event); withdraw(ctx, player, event);
} }
}
} }
}
/** /**
* Handles a withdraw action. * Handles a withdraw action.
* *
* @param ctx The event handler context. * @param ctx The event handler context.
* @param player The player. * @param player The player.
* @param event The event. * @param event The event.
*/ */
private void withdraw(EventHandlerContext ctx, Player player, ItemActionEvent event) { private void withdraw(EventHandlerContext ctx, Player player, ItemActionEvent event) {
int amount = optionToAmount(event.getOption()); int amount = optionToAmount(event.getOption());
if (amount == -1) { if (amount == -1) {
player.getInterfaceSet().openEnterAmountDialogue( player.getInterfaceSet().openEnterAmountDialogue(
new BankWithdrawEnterAmountListener(player, event.getSlot(), event.getId())); new BankWithdrawEnterAmountListener(player, event.getSlot(), event.getId()));
} else if (!BankUtils.withdraw(player, event.getSlot(), event.getId(), amount)) { } else if (!BankUtils.withdraw(player, event.getSlot(), event.getId(), amount)) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
}
} }
}
} }
@@ -13,9 +13,9 @@ import org.apollo.game.sync.block.SynchronizationBlock;
*/ */
public final class ChatEventHandler extends EventHandler<ChatEvent> { public final class ChatEventHandler extends EventHandler<ChatEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, ChatEvent event) { public void handle(EventHandlerContext ctx, Player player, ChatEvent event) {
player.getBlockSet().add(SynchronizationBlock.createChatBlock(player, event)); player.getBlockSet().add(SynchronizationBlock.createChatBlock(player, event));
} }
} }
@@ -12,13 +12,13 @@ import org.apollo.game.model.entity.Player;
*/ */
public final class ChatVerificationHandler extends EventHandler<ChatEvent> { public final class ChatVerificationHandler extends EventHandler<ChatEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, ChatEvent event) { public void handle(EventHandlerContext ctx, Player player, ChatEvent event) {
int color = event.getTextColor(); int color = event.getTextColor();
int effects = event.getTextEffects(); int effects = event.getTextEffects();
if (color < 0 || color > 11 || effects < 0 || effects > 5) { if (color < 0 || color > 11 || effects < 0 || effects > 5) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
}
} }
}
} }
@@ -12,10 +12,10 @@ import org.apollo.game.model.entity.Player;
*/ */
public final class ClosedInterfaceEventHandler extends EventHandler<ClosedInterfaceEvent> { public final class ClosedInterfaceEventHandler extends EventHandler<ClosedInterfaceEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, ClosedInterfaceEvent event) { public void handle(EventHandlerContext ctx, Player player, ClosedInterfaceEvent event) {
System.out.println("closing interface"); System.out.println("closing interface");
player.getInterfaceSet().interfaceClosed(); player.getInterfaceSet().interfaceClosed();
} }
} }
@@ -14,16 +14,16 @@ import org.apollo.game.model.entity.Player;
*/ */
public final class CommandEventHandler extends EventHandler<CommandEvent> { public final class CommandEventHandler extends EventHandler<CommandEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, CommandEvent event) { public void handle(EventHandlerContext ctx, Player player, CommandEvent event) {
String[] components = event.getCommand().split(" "); String[] components = event.getCommand().split(" ");
String name = components[0]; String name = components[0];
String[] arguments = new String[components.length - 1]; String[] arguments = new String[components.length - 1];
System.arraycopy(components, 1, arguments, 0, arguments.length); System.arraycopy(components, 1, arguments, 0, arguments.length);
Command command = new Command(name, arguments); Command command = new Command(name, arguments);
World.getWorld().getCommandDispatcher().dispatch(player, command); World.getWorld().getCommandDispatcher().dispatch(player, command);
} }
} }
@@ -13,15 +13,15 @@ import org.apollo.game.model.inter.InterfaceType;
*/ */
public final class DialogueButtonHandler extends EventHandler<ButtonEvent> { public final class DialogueButtonHandler extends EventHandler<ButtonEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, ButtonEvent event) { public void handle(EventHandlerContext ctx, Player player, ButtonEvent event) {
if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) { if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) {
boolean breakChain = player.getInterfaceSet().buttonClicked(event.getWidgetId()); boolean breakChain = player.getInterfaceSet().buttonClicked(event.getWidgetId());
if (breakChain) { if (breakChain) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
} }
}
} }
}
} }
@@ -13,11 +13,11 @@ import org.apollo.game.model.inter.InterfaceType;
*/ */
public final class DialogueContinueEventHandler extends EventHandler<DialogueContinueEvent> { public final class DialogueContinueEventHandler extends EventHandler<DialogueContinueEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, DialogueContinueEvent event) { public void handle(EventHandlerContext ctx, Player player, DialogueContinueEvent event) {
if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) { if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) {
player.getInterfaceSet().continueRequested(); player.getInterfaceSet().continueRequested();
}
} }
}
} }
@@ -12,9 +12,9 @@ import org.apollo.game.model.entity.Player;
*/ */
public final class EnteredAmountEventHandler extends EventHandler<EnteredAmountEvent> { public final class EnteredAmountEventHandler extends EventHandler<EnteredAmountEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, EnteredAmountEvent event) { public void handle(EventHandlerContext ctx, Player player, EnteredAmountEvent event) {
player.getInterfaceSet().enteredAmount(event.getAmount()); player.getInterfaceSet().enteredAmount(event.getAmount());
} }
} }
@@ -20,81 +20,81 @@ import org.apollo.util.LanguageUtil;
*/ */
public final class EquipEventHandler extends EventHandler<ItemOptionEvent> { public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, ItemOptionEvent event) { public void handle(EventHandlerContext ctx, Player player, ItemOptionEvent event) {
if (event.getOption() != 2 || event.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID) { if (event.getOption() != 2 || event.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID) {
return; return;
}
int inventorySlot = event.getSlot();
Item equipping = player.getInventory().get(inventorySlot);
int equippingId = equipping.getId();
EquipmentDefinition definition = EquipmentDefinition.lookup(equippingId);
if (definition == null) {
// We don't break the chain here or any item option events won't work!
return;
}
for (int id = 0; id < 5; id++) {
int requirement = definition.getLevel(id);
if (player.getSkillSet().getSkill(id).getMaximumLevel() < requirement) {
String skillName = Skill.getName(id);
String article = LanguageUtil.getIndefiniteArticle(skillName);
player.sendMessage("You need " + article + " " + skillName + " level of " + requirement
+ " to equip this item.");
ctx.breakHandlerChain();
return;
}
}
Inventory inventory = player.getInventory();
Inventory equipment = player.getEquipment();
int equipmentSlot = definition.getSlot();
Item currentlyEquipped = equipment.get(equipmentSlot);
if (equipping.getDefinition().isStackable()
&& (currentlyEquipped == null || currentlyEquipped.getId() == equippingId)) {
equipment.set(definition.getSlot(), equipping);
inventory.reset(inventorySlot);
return;
}
Item weapon = equipment.get(EquipmentConstants.WEAPON);
Item shield = equipment.get(EquipmentConstants.SHIELD);
if (definition.isTwoHanded()) {
int slotsRequired = weapon != null ? shield != null ? 1 : 0 : 0;
if (inventory.freeSlots() < slotsRequired) {
ctx.breakHandlerChain();
return;
}
equipment.reset(EquipmentConstants.WEAPON);
equipment.reset(EquipmentConstants.SHIELD);
equipment.set(EquipmentConstants.WEAPON, inventory.reset(inventorySlot));
if (shield != null) {
inventory.add(shield);
}
if (weapon != null) {
inventory.add(weapon);
}
} else if (definition.getSlot() == EquipmentConstants.SHIELD && weapon != null
&& EquipmentDefinition.lookup(weapon.getId()).isTwoHanded()) {
equipment.set(EquipmentConstants.SHIELD, inventory.reset(inventorySlot));
inventory.add(equipment.reset(EquipmentConstants.WEAPON));
} else {
Item previous = equipment.reset(equipmentSlot);
inventory.remove(equipping); // no need for fancy stuff here as we know the item isn't stackable.
equipment.set(equipmentSlot, equipping);
if (previous != null) {
inventory.add(previous);
}
}
} }
int inventorySlot = event.getSlot();
Item equipping = player.getInventory().get(inventorySlot);
int equippingId = equipping.getId();
EquipmentDefinition definition = EquipmentDefinition.lookup(equippingId);
if (definition == null) {
// We don't break the chain here or any item option events won't work!
return;
}
for (int id = 0; id < 5; id++) {
int requirement = definition.getLevel(id);
if (player.getSkillSet().getSkill(id).getMaximumLevel() < requirement) {
String skillName = Skill.getName(id);
String article = LanguageUtil.getIndefiniteArticle(skillName);
player.sendMessage("You need " + article + " " + skillName + " level of " + requirement
+ " to equip this item.");
ctx.breakHandlerChain();
return;
}
}
Inventory inventory = player.getInventory();
Inventory equipment = player.getEquipment();
int equipmentSlot = definition.getSlot();
Item currentlyEquipped = equipment.get(equipmentSlot);
if (equipping.getDefinition().isStackable()
&& (currentlyEquipped == null || currentlyEquipped.getId() == equippingId)) {
equipment.set(definition.getSlot(), equipping);
inventory.reset(inventorySlot);
return;
}
Item weapon = equipment.get(EquipmentConstants.WEAPON);
Item shield = equipment.get(EquipmentConstants.SHIELD);
if (definition.isTwoHanded()) {
int slotsRequired = weapon != null ? shield != null ? 1 : 0 : 0;
if (inventory.freeSlots() < slotsRequired) {
ctx.breakHandlerChain();
return;
}
equipment.reset(EquipmentConstants.WEAPON);
equipment.reset(EquipmentConstants.SHIELD);
equipment.set(EquipmentConstants.WEAPON, inventory.reset(inventorySlot));
if (shield != null) {
inventory.add(shield);
}
if (weapon != null) {
inventory.add(weapon);
}
} else if (definition.getSlot() == EquipmentConstants.SHIELD && weapon != null
&& EquipmentDefinition.lookup(weapon.getId()).isTwoHanded()) {
equipment.set(EquipmentConstants.SHIELD, inventory.reset(inventorySlot));
inventory.add(equipment.reset(EquipmentConstants.WEAPON));
} else {
Item previous = equipment.reset(equipmentSlot);
inventory.remove(equipping); // no need for fancy stuff here as we know the item isn't stackable.
equipment.set(equipmentSlot, equipping);
if (previous != null) {
inventory.add(previous);
}
}
}
} }
@@ -16,36 +16,36 @@ import org.apollo.game.model.inv.SynchronizationInventoryListener;
*/ */
public final class ItemOnItemVerificationHandler extends EventHandler<ItemOnItemEvent> { public final class ItemOnItemVerificationHandler extends EventHandler<ItemOnItemEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, ItemOnItemEvent event) { public void handle(EventHandlerContext ctx, Player player, ItemOnItemEvent event) {
Inventory inventory; Inventory inventory;
switch (event.getInterfaceId()) { switch (event.getInterfaceId()) {
case SynchronizationInventoryListener.INVENTORY_ID: case SynchronizationInventoryListener.INVENTORY_ID:
case BankConstants.SIDEBAR_INVENTORY_ID: case BankConstants.SIDEBAR_INVENTORY_ID:
inventory = player.getInventory(); inventory = player.getInventory();
break; break;
case SynchronizationInventoryListener.EQUIPMENT_ID: case SynchronizationInventoryListener.EQUIPMENT_ID:
inventory = player.getEquipment(); inventory = player.getEquipment();
break; break;
case BankConstants.BANK_INVENTORY_ID: case BankConstants.BANK_INVENTORY_ID:
inventory = player.getBank(); inventory = player.getBank();
break; break;
default: default:
ctx.breakHandlerChain(); ctx.breakHandlerChain();
return; return;
}
int slot = event.getTargetSlot();
if (slot < 0 || slot >= inventory.capacity()) {
ctx.breakHandlerChain();
return;
}
Item item = inventory.get(slot);
if (item == null || item.getId() != event.getTargetId()) {
ctx.breakHandlerChain();
}
} }
int slot = event.getTargetSlot();
if (slot < 0 || slot >= inventory.capacity()) {
ctx.breakHandlerChain();
return;
}
Item item = inventory.get(slot);
if (item == null || item.getId() != event.getTargetId()) {
ctx.breakHandlerChain();
}
}
} }
@@ -16,27 +16,27 @@ import org.apollo.game.model.inv.SynchronizationInventoryListener;
*/ */
public final class ItemOnObjectVerificationHandler extends EventHandler<ItemOnObjectEvent> { public final class ItemOnObjectVerificationHandler extends EventHandler<ItemOnObjectEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, ItemOnObjectEvent event) { public void handle(EventHandlerContext ctx, Player player, ItemOnObjectEvent event) {
if (event.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID if (event.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID
&& event.getInterfaceId() != BankConstants.SIDEBAR_INVENTORY_ID) { && event.getInterfaceId() != BankConstants.SIDEBAR_INVENTORY_ID) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
return; return;
}
Inventory inventory = player.getInventory();
int slot = event.getSlot();
if (slot < 0 || slot >= inventory.capacity()) {
ctx.breakHandlerChain();
return;
}
Item item = inventory.get(slot);
if (item == null || item.getId() != event.getId()) {
ctx.breakHandlerChain();
return;
}
} }
Inventory inventory = player.getInventory();
int slot = event.getSlot();
if (slot < 0 || slot >= inventory.capacity()) {
ctx.breakHandlerChain();
return;
}
Item item = inventory.get(slot);
if (item == null || item.getId() != event.getId()) {
ctx.breakHandlerChain();
return;
}
}
} }
@@ -16,36 +16,36 @@ import org.apollo.game.model.inv.SynchronizationInventoryListener;
*/ */
public final class ItemVerificationHandler extends EventHandler<InventoryItemEvent> { public final class ItemVerificationHandler extends EventHandler<InventoryItemEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, InventoryItemEvent event) { public void handle(EventHandlerContext ctx, Player player, InventoryItemEvent event) {
Inventory inventory; Inventory inventory;
switch (event.getInterfaceId()) { switch (event.getInterfaceId()) {
case SynchronizationInventoryListener.INVENTORY_ID: case SynchronizationInventoryListener.INVENTORY_ID:
case BankConstants.SIDEBAR_INVENTORY_ID: case BankConstants.SIDEBAR_INVENTORY_ID:
inventory = player.getInventory(); inventory = player.getInventory();
break; break;
case SynchronizationInventoryListener.EQUIPMENT_ID: case SynchronizationInventoryListener.EQUIPMENT_ID:
inventory = player.getEquipment(); inventory = player.getEquipment();
break; break;
case BankConstants.BANK_INVENTORY_ID: case BankConstants.BANK_INVENTORY_ID:
inventory = player.getBank(); inventory = player.getBank();
break; break;
default: default:
ctx.breakHandlerChain(); ctx.breakHandlerChain();
return; return;
}
int slot = event.getSlot();
if (slot < 0 || slot >= inventory.capacity()) {
ctx.breakHandlerChain();
return;
}
Item item = inventory.get(slot);
if (item == null || item.getId() != event.getId()) {
ctx.breakHandlerChain();
}
} }
int slot = event.getSlot();
if (slot < 0 || slot >= inventory.capacity()) {
ctx.breakHandlerChain();
return;
}
Item item = inventory.get(slot);
if (item == null || item.getId() != event.getId()) {
ctx.breakHandlerChain();
}
}
} }
@@ -15,18 +15,18 @@ import org.apollo.game.model.entity.Player;
*/ */
public final class NpcActionVerificationHandler extends EventHandler<NpcActionEvent> { public final class NpcActionVerificationHandler extends EventHandler<NpcActionEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, NpcActionEvent event) { public void handle(EventHandlerContext ctx, Player player, NpcActionEvent event) {
if (event.getIndex() < 0 || event.getIndex() >= WorldConstants.MAXIMUM_NPCS) { if (event.getIndex() < 0 || event.getIndex() >= WorldConstants.MAXIMUM_NPCS) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
return; return;
}
Npc npc = World.getWorld().getNpcRepository().get(event.getIndex());
if (npc == null || !player.getPosition().isWithinDistance(npc.getPosition(), 15)) {
ctx.breakHandlerChain();
}
} }
Npc npc = World.getWorld().getNpcRepository().get(event.getIndex());
if (npc == null || !player.getPosition().isWithinDistance(npc.getPosition(), 15)) {
ctx.breakHandlerChain();
}
}
} }
@@ -13,11 +13,11 @@ import org.apollo.game.model.entity.Player;
*/ */
public final class PlayerDesignEventHandler extends EventHandler<PlayerDesignEvent> { public final class PlayerDesignEventHandler extends EventHandler<PlayerDesignEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) { public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) {
player.setAppearance(event.getAppearance()); player.setAppearance(event.getAppearance());
player.setNew(true); player.setNew(true);
player.send(new CloseInterfaceEvent()); player.send(new CloseInterfaceEvent());
} }
} }
@@ -14,71 +14,71 @@ import org.apollo.game.model.settings.Gender;
*/ */
public final class PlayerDesignVerificationHandler extends EventHandler<PlayerDesignEvent> { public final class PlayerDesignVerificationHandler extends EventHandler<PlayerDesignEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) { public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) {
if (!valid(event.getAppearance())) { if (!valid(event.getAppearance())) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
} }
}
/**
* Checks if an appearance combination is valid.
*
* @param appearance The appearance combination.
* @return {@code true} if so, {@code false} if not.
*/
private boolean valid(Appearance appearance) {
int[] colors = appearance.getColors();
int[] maxColors = new int[] { 11, 15, 15, 5, 7 };
for (int i = 0; i < colors.length; i++) {
if (colors[i] < 0 || colors[i] > maxColors[i]) {
return false;
}
} }
/** Gender gender = appearance.getGender();
* Checks if an appearance combination is valid. if (gender == Gender.MALE) {
* return validMaleStyle(appearance);
* @param appearance The appearance combination. } else if (gender == Gender.FEMALE) {
* @return {@code true} if so, {@code false} if not. return validFemaleStyle(appearance);
*/
private boolean valid(Appearance appearance) {
int[] colors = appearance.getColors();
int[] maxColors = new int[] { 11, 15, 15, 5, 7 };
for (int i = 0; i < colors.length; i++) {
if (colors[i] < 0 || colors[i] > maxColors[i]) {
return false;
}
}
Gender gender = appearance.getGender();
if (gender == Gender.MALE) {
return validMaleStyle(appearance);
} else if (gender == Gender.FEMALE) {
return validFemaleStyle(appearance);
}
throw new IllegalArgumentException("Player can only be either male or female.");
} }
throw new IllegalArgumentException("Player can only be either male or female.");
}
/** /**
* Checks if a {@link Gender#FEMALE} style combination is valid. * Checks if a {@link Gender#FEMALE} style combination is valid.
* *
* @param appearance The appearance combination. * @param appearance The appearance combination.
* @return {@code true} if so, {@code false} if not. * @return {@code true} if so, {@code false} if not.
*/ */
private boolean validFemaleStyle(Appearance appearance) { private boolean validFemaleStyle(Appearance appearance) {
int[] styles = appearance.getStyle(); int[] styles = appearance.getStyle();
int[] minStyles = new int[] { 45, 255, 56, 61, 67, 70, 79 }; int[] minStyles = new int[] { 45, 255, 56, 61, 67, 70, 79 };
int[] maxStyles = new int[] { 54, 255, 60, 65, 68, 77, 80 }; int[] maxStyles = new int[] { 54, 255, 60, 65, 68, 77, 80 };
for (int i = 0; i < styles.length; i++) { for (int i = 0; i < styles.length; i++) {
if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) { if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) {
return false; return false;
} }
}
return true;
} }
return true;
}
/** /**
* Checks if a {@link Gender#MALE} style combination is valid. * Checks if a {@link Gender#MALE} style combination is valid.
* *
* @param appearance The appearance combination. * @param appearance The appearance combination.
* @return {@code true} if so, {@code false} if not. * @return {@code true} if so, {@code false} if not.
*/ */
private boolean validMaleStyle(Appearance appearance) { private boolean validMaleStyle(Appearance appearance) {
int[] styles = appearance.getStyle(); int[] styles = appearance.getStyle();
int[] minStyles = new int[] { 0, 10, 18, 26, 33, 36, 42 }; int[] minStyles = new int[] { 0, 10, 18, 26, 33, 36, 42 };
int[] maxStyles = new int[] { 8, 17, 25, 31, 34, 40, 43 }; int[] maxStyles = new int[] { 8, 17, 25, 31, 34, 40, 43 };
for (int i = 0; i < styles.length; i++) { for (int i = 0; i < styles.length; i++) {
if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) { if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) {
return false; return false;
} }
}
return true;
} }
return true;
}
} }
@@ -16,43 +16,43 @@ import org.apollo.game.model.inv.SynchronizationInventoryListener;
*/ */
public final class RemoveEventHandler extends EventHandler<ItemActionEvent> { public final class RemoveEventHandler extends EventHandler<ItemActionEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) { public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) {
if (event.getOption() == 1 && event.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) { if (event.getOption() == 1 && event.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) {
Inventory inventory = player.getInventory(); Inventory inventory = player.getInventory();
Inventory equipment = player.getEquipment(); Inventory equipment = player.getEquipment();
int slot = event.getSlot(); int slot = event.getSlot();
Item item = equipment.get(slot); Item item = equipment.get(slot);
int id = item.getId(); int id = item.getId();
if (inventory.freeSlots() == 0 && !item.getDefinition().isStackable()) { if (inventory.freeSlots() == 0 && !item.getDefinition().isStackable()) {
inventory.forceCapacityExceeded(); inventory.forceCapacityExceeded();
ctx.breakHandlerChain(); ctx.breakHandlerChain();
return; return;
} }
boolean removed = true; boolean removed = true;
inventory.stopFiringEvents(); inventory.stopFiringEvents();
equipment.stopFiringEvents(); equipment.stopFiringEvents();
try { try {
int remaining = inventory.add(id, item.getAmount()); int remaining = inventory.add(id, item.getAmount());
removed = remaining == 0; removed = remaining == 0;
equipment.set(slot, removed ? null : new Item(id, remaining)); equipment.set(slot, removed ? null : new Item(id, remaining));
} finally { } finally {
inventory.startFiringEvents(); inventory.startFiringEvents();
equipment.startFiringEvents(); equipment.startFiringEvents();
} }
if (removed) { if (removed) {
inventory.forceRefresh(); inventory.forceRefresh();
equipment.forceRefresh(slot); equipment.forceRefresh(slot);
} else { } else {
inventory.forceCapacityExceeded(); inventory.forceCapacityExceeded();
} }
}
} }
}
} }
@@ -16,32 +16,32 @@ import org.apollo.game.model.inv.SynchronizationInventoryListener;
*/ */
public final class SwitchItemEventHandler extends EventHandler<SwitchItemEvent> { public final class SwitchItemEventHandler extends EventHandler<SwitchItemEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, SwitchItemEvent event) { public void handle(EventHandlerContext ctx, Player player, SwitchItemEvent event) {
Inventory inventory; Inventory inventory;
boolean insertPermitted = false; boolean insertPermitted = false;
switch (event.getInterfaceId()) { switch (event.getInterfaceId()) {
case SynchronizationInventoryListener.INVENTORY_ID: case SynchronizationInventoryListener.INVENTORY_ID:
case BankConstants.SIDEBAR_INVENTORY_ID: case BankConstants.SIDEBAR_INVENTORY_ID:
inventory = player.getInventory(); inventory = player.getInventory();
break; break;
case SynchronizationInventoryListener.EQUIPMENT_ID: case SynchronizationInventoryListener.EQUIPMENT_ID:
inventory = player.getEquipment(); inventory = player.getEquipment();
break; break;
case BankConstants.BANK_INVENTORY_ID: case BankConstants.BANK_INVENTORY_ID:
inventory = player.getBank(); inventory = player.getBank();
insertPermitted = true; insertPermitted = true;
break; break;
default: default:
return; // not a known inventory, ignore return; // not a known inventory, ignore
}
if (event.getOldSlot() >= 0 && event.getNewSlot() >= 0 && event.getOldSlot() < inventory.capacity()
&& event.getNewSlot() < inventory.capacity()) {
// events must be fired for it to work if a sidebar inventory overlay is used
inventory.swap(insertPermitted ? event.isInserting() : false, event.getOldSlot(), event.getNewSlot());
}
} }
if (event.getOldSlot() >= 0 && event.getNewSlot() >= 0 && event.getOldSlot() < inventory.capacity()
&& event.getNewSlot() < inventory.capacity()) {
// events must be fired for it to work if a sidebar inventory overlay is used
inventory.swap(insertPermitted ? event.isInserting() : false, event.getOldSlot(), event.getNewSlot());
}
}
} }
@@ -14,28 +14,28 @@ import org.apollo.game.model.entity.WalkingQueue;
*/ */
public final class WalkEventHandler extends EventHandler<WalkEvent> { public final class WalkEventHandler extends EventHandler<WalkEvent> {
@Override @Override
public void handle(EventHandlerContext ctx, Player player, WalkEvent event) { public void handle(EventHandlerContext ctx, Player player, WalkEvent event) {
WalkingQueue queue = player.getWalkingQueue(); WalkingQueue queue = player.getWalkingQueue();
Position[] steps = event.getSteps(); Position[] steps = event.getSteps();
for (int i = 0; i < steps.length; i++) { for (int i = 0; i < steps.length; i++) {
Position step = steps[i]; Position step = steps[i];
if (i == 0) { if (i == 0) {
if (!queue.addFirstStep(step)) { if (!queue.addFirstStep(step)) {
return; // ignore packet return; // ignore packet
}
} else {
queue.addStep(step);
}
} }
} else {
queue.setRunningQueue(event.isRunning() || player.isRunning()); queue.addStep(step);
}
if (queue.size() > 0) {
player.stopAction();
}
player.getInterfaceSet().close();
} }
queue.setRunningQueue(event.isRunning() || player.isRunning());
if (queue.size() > 0) {
player.stopAction();
}
player.getInterfaceSet().close();
}
} }
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class AddFriendEvent extends Event { public final class AddFriendEvent extends Event {
/** /**
* The username of the befriended player. * The username of the befriended player.
*/ */
private final String username; private final String username;
/** /**
* Creates a new befriend user event. * Creates a new befriend user event.
* *
* @param username The befriended player's username. * @param username The befriended player's username.
*/ */
public AddFriendEvent(String username) { public AddFriendEvent(String username) {
this.username = username; this.username = username;
} }
/** /**
* Gets the username of the befriended player. * Gets the username of the befriended player.
* *
* @return The username. * @return The username.
*/ */
public String getUsername() { public String getUsername() {
return username; return username;
} }
} }
@@ -5,78 +5,78 @@ import org.apollo.game.model.Item;
public final class AddGlobalTileItemEvent extends Event { public final class AddGlobalTileItemEvent extends Event {
/** /**
* The item to add to the tile. * The item to add to the tile.
*/ */
private final Item item; private final Item item;
/** /**
* The position offset * The position offset
*/ */
private final int positionOffset; private final int positionOffset;
/** /**
* The index of the player who dropped the item. * The index of the player who dropped the item.
*/ */
private final int index; private final int index;
/** /**
* Creates the add global tile item event. * Creates the add global tile item event.
* *
* @param item The item to add to the tile. * @param item The item to add to the tile.
* @param index The index of the player who dropped the item. * @param index The index of the player who dropped the item.
*/ */
public AddGlobalTileItemEvent(Item item, int index) { public AddGlobalTileItemEvent(Item item, int index) {
this(item, index, 0); this(item, index, 0);
} }
/** /**
* Creates the add global tile item event. * Creates the add global tile item event.
* *
* @param item The item to add to the tile. * @param item The item to add to the tile.
* @param index The index of the player who dropped the item. * @param index The index of the player who dropped the item.
* @param positionOffset The offset from the 'base' position. * @param positionOffset The offset from the 'base' position.
*/ */
public AddGlobalTileItemEvent(Item item, int index, int positionOffset) { public AddGlobalTileItemEvent(Item item, int index, int positionOffset) {
this.item = item; this.item = item;
this.index = index; this.index = index;
this.positionOffset = positionOffset; this.positionOffset = positionOffset;
} }
/** /**
* Gets the id of the item. * Gets the id of the item.
* *
* @return The id. * @return The id.
*/ */
public int getId() { public int getId() {
return item.getId(); return item.getId();
} }
/** /**
* Gets the amount of the item. * Gets the amount of the item.
* *
* @return The amount. * @return The amount.
*/ */
public int getAmount() { public int getAmount() {
return item.getAmount(); return item.getAmount();
} }
/** /**
* Gets the index of the player who dropped the item. * Gets the index of the player who dropped the item.
* *
* @return The index. * @return The index.
*/ */
public int getIndex() { public int getIndex() {
return index; return index;
} }
/** /**
* Gets the offset from the 'base' position. * Gets the offset from the 'base' position.
* *
* @return The offset. * @return The offset.
*/ */
public int getPositionOffset() { public int getPositionOffset() {
return positionOffset; return positionOffset;
} }
} }
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class AddIgnoreEvent extends Event { public final class AddIgnoreEvent extends Event {
/** /**
* The username of the ignored player. * The username of the ignored player.
*/ */
private final String username; private final String username;
/** /**
* Creates a new ignore player event. * Creates a new ignore player event.
* *
* @param username The ignored player's username. * @param username The ignored player's username.
*/ */
public AddIgnoreEvent(String username) { public AddIgnoreEvent(String username) {
this.username = username; this.username = username;
} }
/** /**
* Gets the username of the ignored player. * Gets the username of the ignored player.
* *
* @return The username. * @return The username.
*/ */
public String getUsername() { public String getUsername() {
return username; return username;
} }
} }
@@ -10,61 +10,61 @@ import org.apollo.game.model.Item;
*/ */
public final class AddTileItemEvent extends Event { public final class AddTileItemEvent extends Event {
/** /**
* The item to add to the tile. * The item to add to the tile.
*/ */
private final Item item; private final Item item;
/** /**
* The position offset * The position offset
*/ */
private final int positionOffset; private final int positionOffset;
/** /**
* Creates an add tile item event. * Creates an add tile item event.
* *
* @param item The item to add to the tile. * @param item The item to add to the tile.
*/ */
public AddTileItemEvent(Item item) { public AddTileItemEvent(Item item) {
this(item, 0); this(item, 0);
} }
/** /**
* Creates an add tile item event. * Creates an add tile item event.
* *
* @param item The item to add to the tile. * @param item The item to add to the tile.
* @param positionOffset The offset from the 'base' position. * @param positionOffset The offset from the 'base' position.
*/ */
public AddTileItemEvent(Item item, int positionOffset) { public AddTileItemEvent(Item item, int positionOffset) {
this.item = item; this.item = item;
this.positionOffset = positionOffset; this.positionOffset = positionOffset;
} }
/** /**
* Gets the id of the item. * Gets the id of the item.
* *
* @return The id. * @return The id.
*/ */
public int getId() { public int getId() {
return item.getId(); return item.getId();
} }
/** /**
* Gets the amount of the item. * Gets the amount of the item.
* *
* @return The amount. * @return The amount.
*/ */
public int getAmount() { public int getAmount() {
return item.getAmount(); return item.getAmount();
} }
/** /**
* Gets the offset from the 'base' position. * Gets the offset from the 'base' position.
* *
* @return The offset. * @return The offset.
*/ */
public int getPositionOffset() { public int getPositionOffset() {
return positionOffset; return positionOffset;
} }
} }
@@ -9,40 +9,40 @@ import org.apollo.game.event.Event;
*/ */
public final class ArrowKeyEvent extends Event { public final class ArrowKeyEvent extends Event {
/** /**
* The camera roll. * The camera roll.
*/ */
private final int roll; private final int roll;
/** /**
* The camera yaw. * The camera yaw.
*/ */
private final int yaw; private final int yaw;
/** /**
* Creates a new arrow key event. * Creates a new arrow key event.
*/ */
public ArrowKeyEvent(int roll, int yaw) { public ArrowKeyEvent(int roll, int yaw) {
this.roll = roll; this.roll = roll;
this.yaw = yaw; this.yaw = yaw;
} }
/** /**
* Gets the roll of the camera. * Gets the roll of the camera.
* *
* @return The roll. * @return The roll.
*/ */
public int getRoll() { public int getRoll() {
return roll; return roll;
} }
/** /**
* Gets the yaw of the camera. * Gets the yaw of the camera.
* *
* @return The yaw. * @return The yaw.
*/ */
public int getYaw() { public int getYaw() {
return yaw; return yaw;
} }
} }
+20 -20
View File
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class ButtonEvent extends Event { public final class ButtonEvent extends Event {
/** /**
* The widget id. * The widget id.
*/ */
private final int widgetId; private final int widgetId;
/** /**
* Creates the button event. * Creates the button event.
* *
* @param widgetId The widget id. * @param widgetId The widget id.
*/ */
public ButtonEvent(int widgetId) { public ButtonEvent(int widgetId) {
this.widgetId = widgetId; this.widgetId = widgetId;
} }
/** /**
* Gets the widget id. * Gets the widget id.
* *
* @return The widget id. * @return The widget id.
*/ */
public int getWidgetId() { public int getWidgetId() {
return widgetId; return widgetId;
} }
} }
+62 -62
View File
@@ -9,75 +9,75 @@ import org.apollo.game.event.Event;
*/ */
public final class ChatEvent extends Event { public final class ChatEvent extends Event {
/** /**
* The text color. * The text color.
*/ */
private final int color; private final int color;
/** /**
* The compressed message. * The compressed message.
*/ */
private final byte[] compressedMessage; private final byte[] compressedMessage;
/** /**
* The text effects. * The text effects.
*/ */
private final int effects; private final int effects;
/** /**
* The message. * The message.
*/ */
private final String message; private final String message;
/** /**
* Creates a new chat event. * Creates a new chat event.
* *
* @param message The message. * @param message The message.
* @param compressedMessage The compressed message. * @param compressedMessage The compressed message.
* @param color The text color. * @param color The text color.
* @param effects The text effects. * @param effects The text effects.
*/ */
public ChatEvent(String message, byte[] compressedMessage, int color, int effects) { public ChatEvent(String message, byte[] compressedMessage, int color, int effects) {
this.message = message; this.message = message;
this.compressedMessage = compressedMessage; this.compressedMessage = compressedMessage;
this.color = color; this.color = color;
this.effects = effects; this.effects = effects;
} }
/** /**
* Gets the compressed message. * Gets the compressed message.
* *
* @return The compressed message. * @return The compressed message.
*/ */
public byte[] getCompressedMessage() { public byte[] getCompressedMessage() {
return compressedMessage; return compressedMessage;
} }
/** /**
* Gets the message. * Gets the message.
* *
* @return The message. * @return The message.
*/ */
public String getMessage() { public String getMessage() {
return message; return message;
} }
/** /**
* Gets the text color. * Gets the text color.
* *
* @return The text color. * @return The text color.
*/ */
public int getTextColor() { public int getTextColor() {
return color; return color;
} }
/** /**
* Gets the text effects. * Gets the text effects.
* *
* @return The text effects. * @return The text effects.
*/ */
public int getTextEffects() { public int getTextEffects() {
return effects; return effects;
} }
} }
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class CommandEvent extends Event { public final class CommandEvent extends Event {
/** /**
* The command. * The command.
*/ */
private final String command; private final String command;
/** /**
* Creates the command event. * Creates the command event.
* *
* @param command The command. * @param command The command.
*/ */
public CommandEvent(String command) { public CommandEvent(String command) {
this.command = command; this.command = command;
} }
/** /**
* Gets the command. * Gets the command.
* *
* @return The command. * @return The command.
*/ */
public String getCommand() { public String getCommand() {
return command; return command;
} }
} }
+34 -34
View File
@@ -9,43 +9,43 @@ import org.apollo.game.event.Event;
*/ */
public final class ConfigEvent extends Event { public final class ConfigEvent extends Event {
/** /**
* The identifier. * The identifier.
*/ */
private final int id; private final int id;
/** /**
* The value. * The value.
*/ */
private final int value; private final int value;
/** /**
* Creates a new config event. * Creates a new config event.
* *
* @param id The config's identifier. * @param id The config's identifier.
* @param value The value. * @param value The value.
*/ */
public ConfigEvent(int id, int value) { public ConfigEvent(int id, int value) {
this.id = id; this.id = id;
this.value = value; this.value = value;
} }
/** /**
* Gets the config's identifier. * Gets the config's identifier.
* *
* @return The config id. * @return The config id.
*/ */
public int getId() { public int getId() {
return id; return id;
} }
/** /**
* Gets the config's value. * Gets the config's value.
* *
* @return The config value. * @return The config value.
*/ */
public int getValue() { public int getValue() {
return value; return value;
} }
} }
@@ -10,27 +10,27 @@ import org.apollo.game.event.Event;
*/ */
public final class DialogueContinueEvent extends Event { public final class DialogueContinueEvent extends Event {
/** /**
* The interface id. * The interface id.
*/ */
private final int interfaceId; private final int interfaceId;
/** /**
* Creates a new dialogue continue event. * Creates a new dialogue continue event.
* *
* @param interfaceId The interface id. * @param interfaceId The interface id.
*/ */
public DialogueContinueEvent(int interfaceId) { public DialogueContinueEvent(int interfaceId) {
this.interfaceId = interfaceId; this.interfaceId = interfaceId;
} }
/** /**
* Gets the interface id of the button. * Gets the interface id of the button.
* *
* @return The interface id. * @return The interface id.
*/ */
public int getInterfaceId() { public int getInterfaceId() {
return interfaceId; return interfaceId;
} }
} }
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class DisplayCrossbonesEvent extends Event { public final class DisplayCrossbonesEvent extends Event {
/** /**
* Whether or not the crossbones should be displayed. * Whether or not the crossbones should be displayed.
*/ */
private final boolean display; private final boolean display;
/** /**
* Creates a display crossbones event. * Creates a display crossbones event.
* *
* @param display Whether or not the crossbones should be displayed. * @param display Whether or not the crossbones should be displayed.
*/ */
public DisplayCrossbonesEvent(boolean display) { public DisplayCrossbonesEvent(boolean display) {
this.display = display; this.display = display;
} }
/** /**
* Indicates whether the crossbones will be displayed. * Indicates whether the crossbones will be displayed.
* *
* @return {@code true} if the crossbones will be displayed, otherwise {@code false}. * @return {@code true} if the crossbones will be displayed, otherwise {@code false}.
*/ */
public boolean isDisplayed() { public boolean isDisplayed() {
return display; return display;
} }
} }
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class DisplayTabInterfaceEvent extends Event { public final class DisplayTabInterfaceEvent extends Event {
/** /**
* The tab index. * The tab index.
*/ */
private final int tab; private final int tab;
/** /**
* Creates a new display tab interface event. * Creates a new display tab interface event.
* *
* @param tab The index of the tab to display. * @param tab The index of the tab to display.
*/ */
public DisplayTabInterfaceEvent(int tab) { public DisplayTabInterfaceEvent(int tab) {
this.tab = tab; this.tab = tab;
} }
/** /**
* Gets the index of the tab to display. * Gets the index of the tab to display.
* *
* @return The tab index. * @return The tab index.
*/ */
public int getTab() { public int getTab() {
return tab; return tab;
} }
} }
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class EnteredAmountEvent extends Event { public final class EnteredAmountEvent extends Event {
/** /**
* The amount. * The amount.
*/ */
private final int amount; private final int amount;
/** /**
* Creates the entered amount event. * Creates the entered amount event.
* *
* @param amount The amount. * @param amount The amount.
*/ */
public EnteredAmountEvent(int amount) { public EnteredAmountEvent(int amount) {
this.amount = amount; this.amount = amount;
} }
/** /**
* Gets the amount. * Gets the amount.
* *
* @return The amount. * @return The amount.
*/ */
public int getAmount() { public int getAmount() {
return amount; return amount;
} }
} }
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
*/ */
public final class FifthItemActionEvent extends ItemActionEvent { public final class FifthItemActionEvent extends ItemActionEvent {
/** /**
* Creates the fifth item action event. * Creates the fifth item action event.
* *
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param id The item id. * @param id The item id.
* @param slot The item slot. * @param slot The item slot.
*/ */
public FifthItemActionEvent(int interfaceId, int id, int slot) { public FifthItemActionEvent(int interfaceId, int id, int slot) {
super(5, interfaceId, id, slot); super(5, interfaceId, id, slot);
} }
} }
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
*/ */
public final class FifthItemOptionEvent extends ItemOptionEvent { public final class FifthItemOptionEvent extends ItemOptionEvent {
/** /**
* Creates the fifth item option event. * Creates the fifth item option event.
* *
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param id The id. * @param id The id.
* @param slot The slot. * @param slot The slot.
*/ */
public FifthItemOptionEvent(int interfaceId, int id, int slot) { public FifthItemOptionEvent(int interfaceId, int id, int slot) {
super(5, interfaceId, id, slot); super(5, interfaceId, id, slot);
} }
} }
@@ -7,13 +7,13 @@ package org.apollo.game.event.impl;
*/ */
public final class FifthPlayerActionEvent extends PlayerActionEvent { public final class FifthPlayerActionEvent extends PlayerActionEvent {
/** /**
* Creates a fifth player action event. * Creates a fifth player action event.
* *
* @param playerIndex The index of the clicked player. * @param playerIndex The index of the clicked player.
*/ */
public FifthPlayerActionEvent(int playerIndex) { public FifthPlayerActionEvent(int playerIndex) {
super(5, playerIndex); super(5, playerIndex);
} }
} }
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
*/ */
public final class FirstItemActionEvent extends ItemActionEvent { public final class FirstItemActionEvent extends ItemActionEvent {
/** /**
* Creates the first item action event. * Creates the first item action event.
* *
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param id The item id. * @param id The item id.
* @param slot The item slot. * @param slot The item slot.
*/ */
public FirstItemActionEvent(int interfaceId, int id, int slot) { public FirstItemActionEvent(int interfaceId, int id, int slot) {
super(1, interfaceId, id, slot); super(1, interfaceId, id, slot);
} }
} }
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
*/ */
public final class FirstItemOptionEvent extends ItemOptionEvent { public final class FirstItemOptionEvent extends ItemOptionEvent {
/** /**
* Creates the first item option event. * Creates the first item option event.
* *
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param id The id. * @param id The id.
* @param slot The slot. * @param slot The slot.
*/ */
public FirstItemOptionEvent(int interfaceId, int id, int slot) { public FirstItemOptionEvent(int interfaceId, int id, int slot) {
super(1, interfaceId, id, slot); super(1, interfaceId, id, slot);
} }
} }
@@ -7,13 +7,13 @@ package org.apollo.game.event.impl;
*/ */
public final class FirstNpcActionEvent extends NpcActionEvent { public final class FirstNpcActionEvent extends NpcActionEvent {
/** /**
* Creates a new first npc action event. * Creates a new first npc action event.
* *
* @param index The index of the npc. * @param index The index of the npc.
*/ */
public FirstNpcActionEvent(int index) { public FirstNpcActionEvent(int index) {
super(1, index); super(1, index);
} }
} }
@@ -9,14 +9,14 @@ import org.apollo.game.model.Position;
*/ */
public final class FirstObjectActionEvent extends ObjectActionEvent { public final class FirstObjectActionEvent extends ObjectActionEvent {
/** /**
* Creates the first object action event. * Creates the first object action event.
* *
* @param id The id. * @param id The id.
* @param position The position. * @param position The position.
*/ */
public FirstObjectActionEvent(int id, Position position) { public FirstObjectActionEvent(int id, Position position) {
super(1, id, position); super(1, id, position);
} }
} }
@@ -7,13 +7,13 @@ package org.apollo.game.event.impl;
*/ */
public final class FirstPlayerActionEvent extends PlayerActionEvent { public final class FirstPlayerActionEvent extends PlayerActionEvent {
/** /**
* Creates a first player action event. * Creates a first player action event.
* *
* @param playerIndex The index of the clicked player. * @param playerIndex The index of the clicked player.
*/ */
public FirstPlayerActionEvent(int playerIndex) { public FirstPlayerActionEvent(int playerIndex) {
super(1, playerIndex); super(1, playerIndex);
} }
} }
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class FocusUpdateEvent extends Event { public final class FocusUpdateEvent extends Event {
/** /**
* Indicates whether the client is focused or not. * Indicates whether the client is focused or not.
*/ */
private final boolean focused; private final boolean focused;
/** /**
* Creates a new focus update event. * Creates a new focus update event.
* *
* @param update The data received. * @param update The data received.
*/ */
public FocusUpdateEvent(boolean focused) { public FocusUpdateEvent(boolean focused) {
this.focused = focused; this.focused = focused;
} }
/** /**
* Indicates whether or not the client is focused. * Indicates whether or not the client is focused.
* *
* @return {@code true} if the client is focused, otherwise {@code false}. * @return {@code true} if the client is focused, otherwise {@code false}.
*/ */
public boolean isFocused() { public boolean isFocused() {
return focused; return focused;
} }
} }
@@ -10,58 +10,58 @@ import org.apollo.game.model.settings.PrivilegeLevel;
*/ */
public final class ForwardPrivateMessageEvent extends Event { public final class ForwardPrivateMessageEvent extends Event {
/** /**
* The username of the player sending the message. * The username of the player sending the message.
*/ */
private final String username; private final String username;
/** /**
* The privilege level of the player. * The privilege level of the player.
*/ */
private final PrivilegeLevel privilege; private final PrivilegeLevel privilege;
/** /**
* The message. * The message.
*/ */
private final byte[] message; private final byte[] message;
/** /**
* Creates a new forward private message event. * Creates a new forward private message event.
* *
* @param sender The player sending the message. * @param sender The player sending the message.
* @param message The compressed message. * @param message The compressed message.
*/ */
public ForwardPrivateMessageEvent(String username, PrivilegeLevel level, byte[] message) { public ForwardPrivateMessageEvent(String username, PrivilegeLevel level, byte[] message) {
this.username = username; this.username = username;
this.privilege = level; this.privilege = level;
this.message = message; this.message = message;
} }
/** /**
* Gets the username of the sender. * Gets the username of the sender.
* *
* @return The username. * @return The username.
*/ */
public String getSenderUsername() { public String getSenderUsername() {
return username; return username;
} }
/** /**
* Gets the {@link PrivilegeLevel} of the sender. * Gets the {@link PrivilegeLevel} of the sender.
* *
* @return The privilege level. * @return The privilege level.
*/ */
public PrivilegeLevel getSenderPrivilege() { public PrivilegeLevel getSenderPrivilege() {
return privilege; return privilege;
} }
/** /**
* Gets the compressed message. * Gets the compressed message.
* *
* @return The message. * @return The message.
*/ */
public byte[] getCompressedMessage() { public byte[] getCompressedMessage() {
return message; return message;
} }
} }
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
*/ */
public final class FourthItemActionEvent extends ItemActionEvent { public final class FourthItemActionEvent extends ItemActionEvent {
/** /**
* Creates the fourth item action event. * Creates the fourth item action event.
* *
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param id The item id. * @param id The item id.
* @param slot The item slot. * @param slot The item slot.
*/ */
public FourthItemActionEvent(int interfaceId, int id, int slot) { public FourthItemActionEvent(int interfaceId, int id, int slot) {
super(4, interfaceId, id, slot); super(4, interfaceId, id, slot);
} }
} }
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
*/ */
public final class FourthItemOptionEvent extends ItemOptionEvent { public final class FourthItemOptionEvent extends ItemOptionEvent {
/** /**
* Creates the fourth item option event. * Creates the fourth item option event.
* *
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param id The id. * @param id The id.
* @param slot The slot. * @param slot The slot.
*/ */
public FourthItemOptionEvent(int interfaceId, int id, int slot) { public FourthItemOptionEvent(int interfaceId, int id, int slot) {
super(4, interfaceId, id, slot); super(4, interfaceId, id, slot);
} }
} }
@@ -7,13 +7,13 @@ package org.apollo.game.event.impl;
*/ */
public final class FourthPlayerActionEvent extends PlayerActionEvent { public final class FourthPlayerActionEvent extends PlayerActionEvent {
/** /**
* Creates a fourth player action event. * Creates a fourth player action event.
* *
* @param playerIndex The index of the clicked player. * @param playerIndex The index of the clicked player.
*/ */
public FourthPlayerActionEvent(int playerIndex) { public FourthPlayerActionEvent(int playerIndex) {
super(4, playerIndex); super(4, playerIndex);
} }
} }
@@ -10,27 +10,27 @@ import org.apollo.game.model.settings.ServerStatus;
*/ */
public final class FriendServerStatusEvent extends Event { public final class FriendServerStatusEvent extends Event {
/** /**
* The status code of the friend server. * The status code of the friend server.
*/ */
private final int status; private final int status;
/** /**
* Creates a new friend server status event. * Creates a new friend server status event.
* *
* @param status The status. * @param status The status.
*/ */
public FriendServerStatusEvent(ServerStatus status) { public FriendServerStatusEvent(ServerStatus status) {
this.status = status.getCode(); this.status = status.getCode();
} }
/** /**
* Gets the status code of the friend server. * Gets the status code of the friend server.
* *
* @return The status code. * @return The status code.
*/ */
public int getStatusCode() { public int getStatusCode() {
return status; return status;
} }
} }
@@ -9,43 +9,43 @@ import org.apollo.game.event.Event;
*/ */
public final class IdAssignmentEvent extends Event { public final class IdAssignmentEvent extends Event {
/** /**
* The id of this player. * The id of this player.
*/ */
private final int id; private final int id;
/** /**
* The membership flag. * The membership flag.
*/ */
private final boolean members; private final boolean members;
/** /**
* Creates the local id event. * Creates the local id event.
* *
* @param id The id. * @param id The id.
* @param members The membership flag. * @param members The membership flag.
*/ */
public IdAssignmentEvent(int id, boolean members) { public IdAssignmentEvent(int id, boolean members) {
this.id = id; this.id = id;
this.members = members; this.members = members;
} }
/** /**
* Gets the id. * Gets the id.
* *
* @return The id. * @return The id.
*/ */
public int getId() { public int getId() {
return id; return id;
} }
/** /**
* Gets the membership flag. * Gets the membership flag.
* *
* @return The membership flag. * @return The membership flag.
*/ */
public boolean isMembers() { public boolean isMembers() {
return members; return members;
} }
} }
@@ -11,27 +11,27 @@ import org.apollo.game.event.Event;
*/ */
public final class IgnoreListEvent extends Event { public final class IgnoreListEvent extends Event {
/** /**
* The list of ignored player usernames. * The list of ignored player usernames.
*/ */
private final List<String> usernames; private final List<String> usernames;
/** /**
* Creates a new ignore list event. * Creates a new ignore list event.
* *
* @param player The player. * @param player The player.
*/ */
public IgnoreListEvent(List<String> usernames) { public IgnoreListEvent(List<String> usernames) {
this.usernames = usernames; this.usernames = usernames;
} }
/** /**
* Gets the list of ignored usernames. * Gets the list of ignored usernames.
* *
* @return The usernames. * @return The usernames.
*/ */
public List<String> getUsernames() { public List<String> getUsernames() {
return usernames; return usernames;
} }
} }
@@ -10,75 +10,75 @@ import org.apollo.game.event.Event;
*/ */
public abstract class InventoryItemEvent extends Event { public abstract class InventoryItemEvent extends Event {
/** /**
* The item id. * The item id.
*/ */
private final int id; private final int id;
/** /**
* The interface id. * The interface id.
*/ */
private final int interfaceId; private final int interfaceId;
/** /**
* The option number (1-5). * The option number (1-5).
*/ */
private final int option; private final int option;
/** /**
* The item's slot. * The item's slot.
*/ */
private final int slot; private final int slot;
/** /**
* Creates the item action event. * Creates the item action event.
* *
* @param option The option number. * @param option The option number.
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param id The id. * @param id The id.
* @param slot The slot. * @param slot The slot.
*/ */
protected InventoryItemEvent(int option, int interfaceId, int id, int slot) { protected InventoryItemEvent(int option, int interfaceId, int id, int slot) {
this.option = option; this.option = option;
this.interfaceId = interfaceId; this.interfaceId = interfaceId;
this.id = id; this.id = id;
this.slot = slot; this.slot = slot;
} }
/** /**
* Gets the item id. * Gets the item id.
* *
* @return The item id. * @return The item id.
*/ */
public final int getId() { public final int getId() {
return id; return id;
} }
/** /**
* Gets the interface id. * Gets the interface id.
* *
* @return The interface id. * @return The interface id.
*/ */
public final int getInterfaceId() { public final int getInterfaceId() {
return interfaceId; return interfaceId;
} }
/** /**
* Gets the option number. * Gets the option number.
* *
* @return The option number. * @return The option number.
*/ */
public final int getOption() { public final int getOption() {
return option; return option;
} }
/** /**
* Gets the slot. * Gets the slot.
* *
* @return The slot. * @return The slot.
*/ */
public final int getSlot() { public final int getSlot() {
return slot; return slot;
} }
} }
@@ -11,16 +11,16 @@ import org.apollo.game.event.Event;
*/ */
public abstract class ItemActionEvent extends InventoryItemEvent { public abstract class ItemActionEvent extends InventoryItemEvent {
/** /**
* Creates the item action event. * Creates the item action event.
* *
* @param option The option number. * @param option The option number.
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param id The id. * @param id The id.
* @param slot The slot. * @param slot The slot.
*/ */
public ItemActionEvent(int option, int interfaceId, int id, int slot) { public ItemActionEvent(int option, int interfaceId, int id, int slot) {
super(option, interfaceId, id, slot); super(option, interfaceId, id, slot);
} }
} }
@@ -7,64 +7,64 @@ package org.apollo.game.event.impl;
*/ */
public final class ItemOnItemEvent extends InventoryItemEvent { public final class ItemOnItemEvent extends InventoryItemEvent {
/** /**
* The id of the target item. * The id of the target item.
*/ */
private final int targetId; private final int targetId;
/** /**
* The interface id of the target item. * The interface id of the target item.
*/ */
private final int targetInterface; private final int targetInterface;
/** /**
* The slot of the target item. * The slot of the target item.
*/ */
private final int targetSlot; private final int targetSlot;
/** /**
* Creates a new item-on-item event. * Creates a new item-on-item event.
* *
* @param usedInterface The interface id of the used item. * @param usedInterface The interface id of the used item.
* @param usedId The id of the used item. * @param usedId The id of the used item.
* @param usedSlot The slot of the target item. * @param usedSlot The slot of the target item.
* @param targetInterface The interface id of the target item. * @param targetInterface The interface id of the target item.
* @param targetId The id of the target item. * @param targetId The id of the target item.
* @param targetSlot The slot of the target item. * @param targetSlot The slot of the target item.
*/ */
public ItemOnItemEvent(int usedInterface, int usedId, int usedSlot, int targetInterface, int targetId, public ItemOnItemEvent(int usedInterface, int usedId, int usedSlot, int targetInterface, int targetId,
int targetSlot) { int targetSlot) {
super(0, usedInterface, usedId, usedSlot); super(0, usedInterface, usedId, usedSlot);
this.targetInterface = targetInterface; this.targetInterface = targetInterface;
this.targetSlot = targetSlot; this.targetSlot = targetSlot;
this.targetId = targetId; this.targetId = targetId;
} }
/** /**
* Gets the id of the target item. * Gets the id of the target item.
* *
* @return The target item's interface id. * @return The target item's interface id.
*/ */
public int getTargetId() { public int getTargetId() {
return targetId; return targetId;
} }
/** /**
* Gets the interface id of the target item. * Gets the interface id of the target item.
* *
* @return The target item's interface id. * @return The target item's interface id.
*/ */
public int getTargetInterfaceId() { public int getTargetInterfaceId() {
return targetInterface; return targetInterface;
} }
/** /**
* Gets the slot of the target item. * Gets the slot of the target item.
* *
* @return The slot of the target item. * @return The slot of the target item.
*/ */
public int getTargetSlot() { public int getTargetSlot() {
return targetSlot; return targetSlot;
} }
} }
@@ -10,48 +10,48 @@ import org.apollo.game.model.Position;
*/ */
public final class ItemOnObjectEvent extends InventoryItemEvent { public final class ItemOnObjectEvent extends InventoryItemEvent {
/** /**
* The object id the item was used on. * The object id the item was used on.
*/ */
private final int objectId; private final int objectId;
/** /**
* The position of the object. * The position of the object.
*/ */
private final Position position; private final Position position;
/** /**
* Creates an item on object event. * Creates an item on object event.
* *
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param itemId The item id. * @param itemId The item id.
* @param itemSlot The slot the item is in. * @param itemSlot The slot the item is in.
* @param objectId The object id. * @param objectId The object id.
* @param x The x coordinate. * @param x The x coordinate.
* @param y The y coordinate. * @param y The y coordinate.
*/ */
public ItemOnObjectEvent(int interfaceId, int itemId, int itemSlot, int objectId, int x, int y) { public ItemOnObjectEvent(int interfaceId, int itemId, int itemSlot, int objectId, int x, int y) {
super(0, interfaceId, itemId, itemSlot); super(0, interfaceId, itemId, itemSlot);
this.objectId = objectId; this.objectId = objectId;
this.position = new Position(x, y); this.position = new Position(x, y);
} }
/** /**
* Gets the object id. * Gets the object id.
* *
* @return The object id. * @return The object id.
*/ */
public int getObjectId() { public int getObjectId() {
return objectId; return objectId;
} }
/** /**
* Gets the position of the object. * Gets the position of the object.
* *
* @return The position. * @return The position.
*/ */
public Position getPosition() { public Position getPosition() {
return position; return position;
} }
} }
@@ -9,16 +9,16 @@ package org.apollo.game.event.impl;
*/ */
public abstract class ItemOptionEvent extends InventoryItemEvent { public abstract class ItemOptionEvent extends InventoryItemEvent {
/** /**
* Creates the item option event. * Creates the item option event.
* *
* @param option The option number. * @param option The option number.
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param id The id. * @param id The id.
* @param slot The slot. * @param slot The slot.
*/ */
public ItemOptionEvent(int option, int interfaceId, int id, int slot) { public ItemOptionEvent(int option, int interfaceId, int id, int slot) {
super(option, interfaceId, id, slot); super(option, interfaceId, id, slot);
} }
} }
@@ -9,25 +9,25 @@ import org.apollo.game.event.Event;
*/ */
public final class KeepAliveEvent extends Event { public final class KeepAliveEvent extends Event {
/** /**
* The time this event was created. * The time this event was created.
*/ */
private final long createdAt; private final long createdAt;
/** /**
* Creates the keep alive event. * Creates the keep alive event.
*/ */
public KeepAliveEvent() { public KeepAliveEvent() {
createdAt = System.currentTimeMillis(); createdAt = System.currentTimeMillis();
} }
/** /**
* Gets the time when this event was created. * Gets the time when this event was created.
* *
* @return The time when this event was created. * @return The time when this event was created.
*/ */
public long getCreatedAt() { public long getCreatedAt() {
return createdAt; return createdAt;
} }
} }
@@ -7,31 +7,31 @@ package org.apollo.game.event.impl;
*/ */
public final class MagicOnItemEvent extends InventoryItemEvent { public final class MagicOnItemEvent extends InventoryItemEvent {
/** /**
* The spell id. * The spell id.
*/ */
private final int spell; private final int spell;
/** /**
* Creates a new magic on item event. * Creates a new magic on item event.
* *
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param id The item id. * @param id The item id.
* @param slot The item slot. * @param slot The item slot.
* @param spell The spell id. * @param spell The spell id.
*/ */
public MagicOnItemEvent(int interfaceId, int id, int slot, int spell) { public MagicOnItemEvent(int interfaceId, int id, int slot, int spell) {
super(0, interfaceId, id, slot); super(0, interfaceId, id, slot);
this.spell = spell; this.spell = spell;
} }
/** /**
* Gets the spell id. * Gets the spell id.
* *
* @return The spell id. * @return The spell id.
*/ */
public int getSpellId() { public int getSpellId() {
return spell; return spell;
} }
} }
@@ -9,77 +9,77 @@ import org.apollo.game.event.Event;
*/ */
public final class MouseClickEvent extends Event { public final class MouseClickEvent extends Event {
/** /**
* The number of clicks on this point (i.e. the point ({@link #x}, {@link #y})). * The number of clicks on this point (i.e. the point ({@link #x}, {@link #y})).
*/ */
private final int clickCount; private final int clickCount;
/** /**
* The x coordinate of the mouse click. * The x coordinate of the mouse click.
*/ */
private final int x; private final int x;
/** /**
* The y coordinate of the mouse click. * The y coordinate of the mouse click.
*/ */
private final int y; private final int y;
/** /**
* Indicates whether the {@link #x} and {@link #y} values represent the deviation from the last click or an actual * Indicates whether the {@link #x} and {@link #y} values represent the deviation from the last click or an actual
* point. * point.
*/ */
private final boolean delta; private final boolean delta;
/** /**
* Creates a new mouse click event. * Creates a new mouse click event.
* *
* @param clickCount The number of clicks on this point. * @param clickCount The number of clicks on this point.
* @param x The x coordinate of the mouse click. * @param x The x coordinate of the mouse click.
* @param y The y coordinate of the mouse click. * @param y The y coordinate of the mouse click.
* @param delta If the coordinates represent a change in x/y, rather than the values themselves. * @param delta If the coordinates represent a change in x/y, rather than the values themselves.
*/ */
public MouseClickEvent(int clickCount, int x, int y, boolean delta) { public MouseClickEvent(int clickCount, int x, int y, boolean delta) {
this.clickCount = clickCount; this.clickCount = clickCount;
this.x = x; this.x = x;
this.y = y; this.y = y;
this.delta = delta; this.delta = delta;
} }
/** /**
* Gets the number of clicks on this point - maximum value of 2047. * Gets the number of clicks on this point - maximum value of 2047.
* *
* @return The number of clicks. * @return The number of clicks.
*/ */
public int getClickCount() { public int getClickCount() {
return clickCount; return clickCount;
} }
/** /**
* The x coordinate of the click. * The x coordinate of the click.
* *
* @return The x coordinate. * @return The x coordinate.
*/ */
public int getX() { public int getX() {
return x; return x;
} }
/** /**
* The y coordinate of the click. * The y coordinate of the click.
* *
* @return The y coordinate. * @return The y coordinate.
*/ */
public int getY() { public int getY() {
return y; return y;
} }
/** /**
* Gets the value indicating whether the {@link #x} and {@link #y} values represent the deviation from the last * Gets the value indicating whether the {@link #x} and {@link #y} values represent the deviation from the last
* click or an actual point. * click or an actual point.
* *
* @return The value. * @return The value.
*/ */
public boolean getDelta() { public boolean getDelta() {
return delta; return delta;
} }
} }
@@ -11,43 +11,43 @@ import org.apollo.game.event.Event;
*/ */
public abstract class NpcActionEvent extends Event { public abstract class NpcActionEvent extends Event {
/** /**
* The option number. * The option number.
*/ */
private final int option; private final int option;
/** /**
* The index of the clicked npc. * The index of the clicked npc.
*/ */
private final int index; private final int index;
/** /**
* Creates an npc action event. * Creates an npc action event.
* *
* @param option The option number. * @param option The option number.
* @param index The index of the npc. * @param index The index of the npc.
*/ */
public NpcActionEvent(int option, int index) { public NpcActionEvent(int option, int index) {
this.option = option; this.option = option;
this.index = index - 1; this.index = index - 1;
} }
/** /**
* Gets the menu action number (i.e. the action event 'option') clicked. * Gets the menu action number (i.e. the action event 'option') clicked.
* *
* @return The option number. * @return The option number.
*/ */
public int getOption() { public int getOption() {
return option; return option;
} }
/** /**
* Gets the index of the npc clicked. * Gets the index of the npc clicked.
* *
* @return The npc index. * @return The npc index.
*/ */
public int getIndex() { public int getIndex() {
return index; return index;
} }
} }
@@ -14,59 +14,59 @@ import org.apollo.game.sync.seg.SynchronizationSegment;
*/ */
public final class NpcSynchronizationEvent extends Event { public final class NpcSynchronizationEvent extends Event {
/** /**
* The amount of local npcs. * The amount of local npcs.
*/ */
private final int localNpcs; private final int localNpcs;
/** /**
* The npc's position. * The npc's position.
*/ */
private final Position position; private final Position position;
/** /**
* A list of segments. * A list of segments.
*/ */
private final List<SynchronizationSegment> segments; private final List<SynchronizationSegment> segments;
/** /**
* Creates a new {@link NpcSynchronizationEvent}. * Creates a new {@link NpcSynchronizationEvent}.
* *
* @param position The position of the {@link Npc}. * @param position The position of the {@link Npc}.
* @param segments The list of segments. * @param segments The list of segments.
* @param localNpcs The amount of local npcs. * @param localNpcs The amount of local npcs.
*/ */
public NpcSynchronizationEvent(Position position, List<SynchronizationSegment> segments, int localNpcs) { public NpcSynchronizationEvent(Position position, List<SynchronizationSegment> segments, int localNpcs) {
this.position = position; this.position = position;
this.segments = segments; this.segments = segments;
this.localNpcs = localNpcs; this.localNpcs = localNpcs;
} }
/** /**
* Gets the number of local npcs. * Gets the number of local npcs.
* *
* @return The number of local npcs. * @return The number of local npcs.
*/ */
public int getLocalNpcCount() { public int getLocalNpcCount() {
return localNpcs; return localNpcs;
} }
/** /**
* Gets the npc's position. * Gets the npc's position.
* *
* @return The npc's position. * @return The npc's position.
*/ */
public Position getPosition() { public Position getPosition() {
return position; return position;
} }
/** /**
* Gets the synchronization segments. * Gets the synchronization segments.
* *
* @return The segments. * @return The segments.
*/ */
public List<SynchronizationSegment> getSegments() { public List<SynchronizationSegment> getSegments() {
return segments; return segments;
} }
} }
@@ -12,59 +12,59 @@ import org.apollo.game.model.Position;
*/ */
public abstract class ObjectActionEvent extends Event { public abstract class ObjectActionEvent extends Event {
/** /**
* The object's id. * The object's id.
*/ */
private final int id; private final int id;
/** /**
* The option number (1-3). * The option number (1-3).
*/ */
private final int option; private final int option;
/** /**
* The object's position. * The object's position.
*/ */
private final Position position; private final Position position;
/** /**
* Creates a new object action event. * Creates a new object action event.
* *
* @param option The option number. * @param option The option number.
* @param id The id of the object. * @param id The id of the object.
* @param position The position of the object. * @param position The position of the object.
*/ */
public ObjectActionEvent(int option, int id, Position position) { public ObjectActionEvent(int option, int id, Position position) {
this.option = option; this.option = option;
this.id = id; this.id = id;
this.position = position; this.position = position;
} }
/** /**
* Gets the id of the object. * Gets the id of the object.
* *
* @return The id of the object. * @return The id of the object.
*/ */
public int getId() { public int getId() {
return id; return id;
} }
/** /**
* Gets the option number. * Gets the option number.
* *
* @return The option number. * @return The option number.
*/ */
public int getOption() { public int getOption() {
return option; return option;
} }
/** /**
* Gets the position of the object. * Gets the position of the object.
* *
* @return The position of the object. * @return The position of the object.
*/ */
public Position getPosition() { public Position getPosition() {
return position; return position;
} }
} }
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class OpenDialogueInterfaceEvent extends Event { public final class OpenDialogueInterfaceEvent extends Event {
/** /**
* The interface id. * The interface id.
*/ */
private final int interfaceId; private final int interfaceId;
/** /**
* Creates a new event with the specified interface id. * Creates a new event with the specified interface id.
* *
* @param interfaceId The interface id. * @param interfaceId The interface id.
*/ */
public OpenDialogueInterfaceEvent(int interfaceId) { public OpenDialogueInterfaceEvent(int interfaceId) {
this.interfaceId = interfaceId; this.interfaceId = interfaceId;
} }
/** /**
* Gets the interface id. * Gets the interface id.
* *
* @return The interface id. * @return The interface id.
*/ */
public int getInterfaceId() { public int getInterfaceId() {
return interfaceId; return interfaceId;
} }
} }
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class OpenInterfaceEvent extends Event { public final class OpenInterfaceEvent extends Event {
/** /**
* The interface id. * The interface id.
*/ */
private final int id; private final int id;
/** /**
* Creates the event with the specified interface id. * Creates the event with the specified interface id.
* *
* @param id The interface id. * @param id The interface id.
*/ */
public OpenInterfaceEvent(int id) { public OpenInterfaceEvent(int id) {
this.id = id; this.id = id;
} }
/** /**
* Gets the interface id. * Gets the interface id.
* *
* @return The interface id. * @return The interface id.
*/ */
public int getId() { public int getId() {
return id; return id;
} }
} }
@@ -9,43 +9,43 @@ import org.apollo.game.event.Event;
*/ */
public final class OpenInterfaceSidebarEvent extends Event { public final class OpenInterfaceSidebarEvent extends Event {
/** /**
* The interface id. * The interface id.
*/ */
private final int interfaceId; private final int interfaceId;
/** /**
* The sidebar id. * The sidebar id.
*/ */
private final int sidebarId; private final int sidebarId;
/** /**
* Creates the open interface sidebar event. * Creates the open interface sidebar event.
* *
* @param interfaceId The interface id. * @param interfaceId The interface id.
* @param sidebarId The sidebar id. * @param sidebarId The sidebar id.
*/ */
public OpenInterfaceSidebarEvent(int interfaceId, int sidebarId) { public OpenInterfaceSidebarEvent(int interfaceId, int sidebarId) {
this.interfaceId = interfaceId; this.interfaceId = interfaceId;
this.sidebarId = sidebarId; this.sidebarId = sidebarId;
} }
/** /**
* Gets the interface id. * Gets the interface id.
* *
* @return The interface id. * @return The interface id.
*/ */
public int getInterfaceId() { public int getInterfaceId() {
return interfaceId; return interfaceId;
} }
/** /**
* Gets the sidebar id. * Gets the sidebar id.
* *
* @return The sidebar id. * @return The sidebar id.
*/ */
public int getSidebarId() { public int getSidebarId() {
return sidebarId; return sidebarId;
} }
} }
@@ -11,43 +11,43 @@ import org.apollo.game.event.Event;
*/ */
public abstract class PlayerActionEvent extends Event { public abstract class PlayerActionEvent extends Event {
/** /**
* The option number. * The option number.
*/ */
private final int option; private final int option;
/** /**
* The index of the clicked player. * The index of the clicked player.
*/ */
private final int index; private final int index;
/** /**
* Creates a player action event. * Creates a player action event.
* *
* @param option The option number. * @param option The option number.
* @param playerIndex The index of the player. * @param playerIndex The index of the player.
*/ */
public PlayerActionEvent(int option, int playerIndex) { public PlayerActionEvent(int option, int playerIndex) {
this.option = option; this.option = option;
this.index = playerIndex; this.index = playerIndex;
} }
/** /**
* Gets the menu action number (i.e. the action event 'option') clicked. * Gets the menu action number (i.e. the action event 'option') clicked.
* *
* @return The option number. * @return The option number.
*/ */
public int getOption() { public int getOption() {
return option; return option;
} }
/** /**
* Gets the index of the clicked player. * Gets the index of the clicked player.
* *
* @return The index. * @return The index.
*/ */
public int getIndex() { public int getIndex() {
return index; return index;
} }
} }
@@ -10,27 +10,27 @@ import org.apollo.game.model.Appearance;
*/ */
public final class PlayerDesignEvent extends Event { public final class PlayerDesignEvent extends Event {
/** /**
* The appearance. * The appearance.
*/ */
private final Appearance appearance; private final Appearance appearance;
/** /**
* Creates the player design event. * Creates the player design event.
* *
* @param appearance The appearance. * @param appearance The appearance.
*/ */
public PlayerDesignEvent(Appearance appearance) { public PlayerDesignEvent(Appearance appearance) {
this.appearance = appearance; this.appearance = appearance;
} }
/** /**
* Gets the appearance. * Gets the appearance.
* *
* @return The appearance. * @return The appearance.
*/ */
public Appearance getAppearance() { public Appearance getAppearance() {
return appearance; return appearance;
} }
} }
@@ -13,108 +13,108 @@ import org.apollo.game.sync.seg.SynchronizationSegment;
*/ */
public final class PlayerSynchronizationEvent extends Event { public final class PlayerSynchronizationEvent extends Event {
/** /**
* The last known region. * The last known region.
*/ */
private final Position lastKnownRegion; private final Position lastKnownRegion;
/** /**
* The number of local players. * The number of local players.
*/ */
private final int localPlayers; private final int localPlayers;
/** /**
* The player's position. * The player's position.
*/ */
private final Position position; private final Position position;
/** /**
* A flag indicating if the region has changed. * A flag indicating if the region has changed.
*/ */
private final boolean regionChanged; private final boolean regionChanged;
/** /**
* The current player's synchronization segment. * The current player's synchronization segment.
*/ */
private final SynchronizationSegment segment; private final SynchronizationSegment segment;
/** /**
* A list of segments. * A list of segments.
*/ */
private final List<SynchronizationSegment> segments; private final List<SynchronizationSegment> segments;
/** /**
* Creates the player synchronization event. * Creates the player synchronization event.
* *
* @param lastKnownRegion The last known region. * @param lastKnownRegion The last known region.
* @param position The player's current position. * @param position The player's current position.
* @param regionChanged A flag indicating if the region has changed. * @param regionChanged A flag indicating if the region has changed.
* @param segment The current player's synchronization segment. * @param segment The current player's synchronization segment.
* @param localPlayers The number of local players. * @param localPlayers The number of local players.
* @param segments A list of segments. * @param segments A list of segments.
*/ */
public PlayerSynchronizationEvent(Position lastKnownRegion, Position position, boolean regionChanged, public PlayerSynchronizationEvent(Position lastKnownRegion, Position position, boolean regionChanged,
SynchronizationSegment segment, int localPlayers, List<SynchronizationSegment> segments) { SynchronizationSegment segment, int localPlayers, List<SynchronizationSegment> segments) {
this.lastKnownRegion = lastKnownRegion; this.lastKnownRegion = lastKnownRegion;
this.position = position; this.position = position;
this.regionChanged = regionChanged; this.regionChanged = regionChanged;
this.segment = segment; this.segment = segment;
this.localPlayers = localPlayers; this.localPlayers = localPlayers;
this.segments = segments; this.segments = segments;
} }
/** /**
* Gets the last known region. * Gets the last known region.
* *
* @return The last known region. * @return The last known region.
*/ */
public Position getLastKnownRegion() { public Position getLastKnownRegion() {
return lastKnownRegion; return lastKnownRegion;
} }
/** /**
* Gets the number of local players. * Gets the number of local players.
* *
* @return The number of local players. * @return The number of local players.
*/ */
public int getLocalPlayers() { public int getLocalPlayers() {
return localPlayers; return localPlayers;
} }
/** /**
* Gets the player's position. * Gets the player's position.
* *
* @return The player's position. * @return The player's position.
*/ */
public Position getPosition() { public Position getPosition() {
return position; return position;
} }
/** /**
* Gets the current player's segment. * Gets the current player's segment.
* *
* @return The current player's segment. * @return The current player's segment.
*/ */
public SynchronizationSegment getSegment() { public SynchronizationSegment getSegment() {
return segment; return segment;
} }
/** /**
* Gets the synchronization segments. * Gets the synchronization segments.
* *
* @return The segments. * @return The segments.
*/ */
public List<SynchronizationSegment> getSegments() { public List<SynchronizationSegment> getSegments() {
return segments; return segments;
} }
/** /**
* Checks if the region has changed. * Checks if the region has changed.
* *
* @return {@code true} if so, {@code false} if not. * @return {@code true} if so, {@code false} if not.
*/ */
public boolean hasRegionChanged() { public boolean hasRegionChanged() {
return regionChanged; return regionChanged;
} }
} }
@@ -10,43 +10,43 @@ import org.apollo.game.model.Position;
*/ */
public final class PositionEvent extends Event { public final class PositionEvent extends Event {
/** /**
* The base position. * The base position.
*/ */
private final Position base; private final Position base;
/** /**
* The target position. * The target position.
*/ */
private final Position position; private final Position position;
/** /**
* Creates a new position event. * Creates a new position event.
* *
* @param base The base from which the position is being focused on. * @param base The base from which the position is being focused on.
* @param position The position to focus on. * @param position The position to focus on.
*/ */
public PositionEvent(Position base, Position position) { public PositionEvent(Position base, Position position) {
this.base = base; this.base = base;
this.position = position; this.position = position;
} }
/** /**
* Gets the base position. * Gets the base position.
* *
* @return The position. * @return The position.
*/ */
public Position getBase() { public Position getBase() {
return base; return base;
} }
/** /**
* Gets the position to focus on. * Gets the position to focus on.
* *
* @return The target position. * @return The target position.
*/ */
public Position getPosition() { public Position getPosition() {
return position; return position;
} }
} }
@@ -12,59 +12,59 @@ import org.apollo.game.model.settings.PrivacyState;
*/ */
public final class PrivacyOptionEvent extends Event { public final class PrivacyOptionEvent extends Event {
/** /**
* The privacy state of the player's chat. * The privacy state of the player's chat.
*/ */
private final PrivacyState chatPrivacy; private final PrivacyState chatPrivacy;
/** /**
* The privacy state of the player's friend chat. * The privacy state of the player's friend chat.
*/ */
private final PrivacyState friendPrivacy; private final PrivacyState friendPrivacy;
/** /**
* The privacy state of the player's trade chat. * The privacy state of the player's trade chat.
*/ */
private final PrivacyState tradePrivacy; private final PrivacyState tradePrivacy;
/** /**
* Creates a privacy option event. * Creates a privacy option event.
* *
* @param chatPrivacy The privacy state of the player's chat. * @param chatPrivacy The privacy state of the player's chat.
* @param friendPrivacy The privacy state of the player's friend chat. * @param friendPrivacy The privacy state of the player's friend chat.
* @param tradePrivacy The privacy state of the player's trade chat. * @param tradePrivacy The privacy state of the player's trade chat.
*/ */
public PrivacyOptionEvent(int chatPrivacy, int friendPrivacy, int tradePrivacy) { public PrivacyOptionEvent(int chatPrivacy, int friendPrivacy, int tradePrivacy) {
this.chatPrivacy = PrivacyState.valueOf(chatPrivacy, true); this.chatPrivacy = PrivacyState.valueOf(chatPrivacy, true);
this.friendPrivacy = PrivacyState.valueOf(friendPrivacy, false); this.friendPrivacy = PrivacyState.valueOf(friendPrivacy, false);
this.tradePrivacy = PrivacyState.valueOf(tradePrivacy, false); this.tradePrivacy = PrivacyState.valueOf(tradePrivacy, false);
} }
/** /**
* Gets the chat {@link PrivacyState}. * Gets the chat {@link PrivacyState}.
* *
* @return The privacy state. * @return The privacy state.
*/ */
public PrivacyState getChatPrivacy() { public PrivacyState getChatPrivacy() {
return chatPrivacy; return chatPrivacy;
} }
/** /**
* Gets the friend {@link PrivacyState}. * Gets the friend {@link PrivacyState}.
* *
* @return The privacy state. * @return The privacy state.
*/ */
public PrivacyState getFriendPrivacy() { public PrivacyState getFriendPrivacy() {
return friendPrivacy; return friendPrivacy;
} }
/** /**
* Gets the trade {@link PrivacyState}. * Gets the trade {@link PrivacyState}.
* *
* @return The privacy state. * @return The privacy state.
*/ */
public PrivacyState getTradePrivacy() { public PrivacyState getTradePrivacy() {
return tradePrivacy; return tradePrivacy;
} }
} }
@@ -9,59 +9,59 @@ import org.apollo.game.event.Event;
*/ */
public final class PrivateMessageEvent extends Event { public final class PrivateMessageEvent extends Event {
/** /**
* The username this message is being sent to. * The username this message is being sent to.
*/ */
private final String username; private final String username;
/** /**
* The message being sent. * The message being sent.
*/ */
private final String message; private final String message;
/** /**
* The compressed message. * The compressed message.
*/ */
private final byte[] compressedMessage; private final byte[] compressedMessage;
/** /**
* Creates a new private message event. * Creates a new private message event.
* *
* @param username The username of the player the message is being sent to. * @param username The username of the player the message is being sent to.
* @param message The message. * @param message The message.
* @param compressedMessage The message, in a compressed form. * @param compressedMessage The message, in a compressed form.
*/ */
public PrivateMessageEvent(String username, String message, byte[] compressedMessage) { public PrivateMessageEvent(String username, String message, byte[] compressedMessage) {
this.username = username; this.username = username;
this.message = message; this.message = message;
this.compressedMessage = compressedMessage; this.compressedMessage = compressedMessage;
} }
/** /**
* Gets the username of the player the message is being sent to. * Gets the username of the player the message is being sent to.
* *
* @return The username. * @return The username.
*/ */
public String getUsername() { public String getUsername() {
return username; return username;
} }
/** /**
* Gets the message being sent. * Gets the message being sent.
* *
* @return The message. * @return The message.
*/ */
public String getMessage() { public String getMessage() {
return message; return message;
} }
/** /**
* Gets the compressed message. * Gets the compressed message.
* *
* @return The compressed message. * @return The compressed message.
*/ */
public byte[] getCompressedMessage() { public byte[] getCompressedMessage() {
return compressedMessage; return compressedMessage;
} }
} }
@@ -10,27 +10,27 @@ import org.apollo.game.model.Position;
*/ */
public final class RegionChangeEvent extends Event { public final class RegionChangeEvent extends Event {
/** /**
* The position of the region to load. * The position of the region to load.
*/ */
private final Position position; private final Position position;
/** /**
* Creates the region changed event. * Creates the region changed event.
* *
* @param position The position of the region. * @param position The position of the region.
*/ */
public RegionChangeEvent(Position position) { public RegionChangeEvent(Position position) {
this.position = position; this.position = position;
} }
/** /**
* Gets the position of the region to load. * Gets the position of the region to load.
* *
* @return The position of the region to load. * @return The position of the region to load.
*/ */
public Position getPosition() { public Position getPosition() {
return position; return position;
} }
} }
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class RemoveFriendEvent extends Event { public final class RemoveFriendEvent extends Event {
/** /**
* The username of the defriended player. * The username of the defriended player.
*/ */
private final String username; private final String username;
/** /**
* Creates a new defriend user event. * Creates a new defriend user event.
* *
* @param username The defriended player's username. * @param username The defriended player's username.
*/ */
public RemoveFriendEvent(String username) { public RemoveFriendEvent(String username) {
this.username = username; this.username = username;
} }
/** /**
* Gets the username of the defriended player. * Gets the username of the defriended player.
* *
* @return The username. * @return The username.
*/ */
public String getUsername() { public String getUsername() {
return username; return username;
} }
} }
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
*/ */
public final class RemoveIgnoreEvent extends Event { public final class RemoveIgnoreEvent extends Event {
/** /**
* The username of the unignored player. * The username of the unignored player.
*/ */
private final String username; private final String username;
/** /**
* Creates a new unignore player event. * Creates a new unignore player event.
* *
* @param username The unignored player's username. * @param username The unignored player's username.
*/ */
public RemoveIgnoreEvent(String username) { public RemoveIgnoreEvent(String username) {
this.username = username; this.username = username;
} }
/** /**
* Gets the username of the unignored player. * Gets the username of the unignored player.
* *
* @return The username. * @return The username.
*/ */
public String getUsername() { public String getUsername() {
return username; return username;
} }
} }
@@ -9,52 +9,52 @@ import org.apollo.game.event.Event;
*/ */
public final class RemoveTileItemEvent extends Event { public final class RemoveTileItemEvent extends Event {
/** /**
* The item. * The item.
*/ */
private final int id; private final int id;
/** /**
* The offset from the client's base position. * The offset from the client's base position.
*/ */
private final int positionOffset; private final int positionOffset;
/** /**
* Creates a remove tile item event. * Creates a remove tile item event.
* *
* @param id The id of the item to remove. * @param id The id of the item to remove.
*/ */
public RemoveTileItemEvent(int id) { public RemoveTileItemEvent(int id) {
this(id, 0); this(id, 0);
} }
/** /**
* Creates a remove tile item event. * Creates a remove tile item event.
* *
* @param id The id of the item to remove. * @param id The id of the item to remove.
* @param positionOffset The offset from the 'base' position. * @param positionOffset The offset from the 'base' position.
*/ */
public RemoveTileItemEvent(int id, int positionOffset) { public RemoveTileItemEvent(int id, int positionOffset) {
this.id = id; this.id = id;
this.positionOffset = positionOffset; this.positionOffset = positionOffset;
} }
/** /**
* Gets the id of the item to remove. * Gets the id of the item to remove.
* *
* @return The id. * @return The id.
*/ */
public int getId() { public int getId() {
return id; return id;
} }
/** /**
* Gets the offset from the 'base' position. * Gets the offset from the 'base' position.
* *
* @return The offset. * @return The offset.
*/ */
public int getPositionOffset() { public int getPositionOffset() {
return positionOffset; return positionOffset;
} }
} }

Some files were not shown because too many files have changed in this diff Show More