mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Clean-up and format; use diamond operator.
This commit is contained in:
@@ -25,281 +25,281 @@ package net.burtleburtle.bob.rand;
|
||||
*/
|
||||
public final class IsaacRandom {
|
||||
|
||||
/**
|
||||
* The golden ratio.
|
||||
*/
|
||||
private static final int GOLDEN_RATIO = 0x9e3779b9;
|
||||
/**
|
||||
* The golden ratio.
|
||||
*/
|
||||
private static final int GOLDEN_RATIO = 0x9e3779b9;
|
||||
|
||||
/**
|
||||
* The log of the size of the result and memory arrays.
|
||||
*/
|
||||
private static final int LOG_SIZE = 8;
|
||||
/**
|
||||
* The log of the size of the result and memory arrays.
|
||||
*/
|
||||
private static final int LOG_SIZE = 8;
|
||||
|
||||
/**
|
||||
* The size of the result and memory arrays.
|
||||
*/
|
||||
private static final int SIZE = 1 << LOG_SIZE;
|
||||
/**
|
||||
* The size of the result and memory arrays.
|
||||
*/
|
||||
private static final int SIZE = 1 << LOG_SIZE;
|
||||
|
||||
/**
|
||||
* A mask for pseudorandom lookup.
|
||||
*/
|
||||
private static int MASK = SIZE - 1 << 2;
|
||||
/**
|
||||
* A mask for pseudorandom lookup.
|
||||
*/
|
||||
private static int MASK = SIZE - 1 << 2;
|
||||
|
||||
/**
|
||||
* The accumulator.
|
||||
*/
|
||||
private int a;
|
||||
/**
|
||||
* The accumulator.
|
||||
*/
|
||||
private int a;
|
||||
|
||||
/**
|
||||
* The last result.
|
||||
*/
|
||||
private int b;
|
||||
/**
|
||||
* The last result.
|
||||
*/
|
||||
private int b;
|
||||
|
||||
/**
|
||||
* The counter.
|
||||
*/
|
||||
private int c;
|
||||
/**
|
||||
* The counter.
|
||||
*/
|
||||
private int c;
|
||||
|
||||
/**
|
||||
* The count through the results in the results array.
|
||||
*/
|
||||
private int count;
|
||||
/**
|
||||
* The count through the results in the results array.
|
||||
*/
|
||||
private int count;
|
||||
|
||||
/**
|
||||
* The internal state.
|
||||
*/
|
||||
private int[] mem;
|
||||
/**
|
||||
* The internal state.
|
||||
*/
|
||||
private int[] mem;
|
||||
|
||||
/**
|
||||
* The results given to the user.
|
||||
*/
|
||||
private int[] rsl;
|
||||
/**
|
||||
* The results given to the user.
|
||||
*/
|
||||
private int[] rsl;
|
||||
|
||||
/**
|
||||
* Creates the random number generator without an initial seed.
|
||||
*/
|
||||
public IsaacRandom() {
|
||||
mem = new int[SIZE];
|
||||
rsl = new int[SIZE];
|
||||
init(false);
|
||||
/**
|
||||
* Creates the random number generator without an initial seed.
|
||||
*/
|
||||
public IsaacRandom() {
|
||||
mem = new int[SIZE];
|
||||
rsl = new int[SIZE];
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
for (i = 0; i < SIZE; i += 8) { /* fill in mem[] with messy stuff */
|
||||
if (hasSeed) {
|
||||
a += rsl[i];
|
||||
b += rsl[i + 1];
|
||||
c += rsl[i + 2];
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 */
|
||||
if (hasSeed) {
|
||||
a += rsl[i];
|
||||
b += rsl[i + 1];
|
||||
c += rsl[i + 2];
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates 256 results.
|
||||
*/
|
||||
private void isaac() {
|
||||
int i, j, x, y;
|
||||
isaac();
|
||||
count = SIZE;
|
||||
}
|
||||
|
||||
b += ++c;
|
||||
for (i = 0, j = SIZE / 2; i < SIZE / 2;) {
|
||||
x = mem[i];
|
||||
a ^= a << 13;
|
||||
a += mem[j++];
|
||||
mem[i] = y = mem[(x & MASK) >> 2] + a + b;
|
||||
rsl[i++] = b = mem[(y >> LOG_SIZE & MASK) >> 2] + x;
|
||||
/**
|
||||
* Generates 256 results.
|
||||
*/
|
||||
private void isaac() {
|
||||
int i, j, x, y;
|
||||
|
||||
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;
|
||||
b += ++c;
|
||||
for (i = 0, j = SIZE / 2; i < SIZE / 2;) {
|
||||
x = mem[i];
|
||||
a ^= a << 13;
|
||||
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 >>> 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 >>> 16;
|
||||
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;
|
||||
|
||||
for (j = 0; j < SIZE / 2;) {
|
||||
x = mem[i];
|
||||
a ^= a << 13;
|
||||
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 >>> 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;
|
||||
}
|
||||
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];
|
||||
for (j = 0; j < SIZE / 2;) {
|
||||
x = mem[i];
|
||||
a ^= a << 13;
|
||||
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 >>> 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
@@ -32,144 +32,144 @@ import org.apollo.util.plugin.PluginManager;
|
||||
*/
|
||||
public final class Server {
|
||||
|
||||
/**
|
||||
* The logger for this class.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(Server.class.getName());
|
||||
/**
|
||||
* The logger for this class.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(Server.class.getName());
|
||||
|
||||
/**
|
||||
* The entry point of the Apollo server application.
|
||||
*
|
||||
* @param args The command-line arguments passed to the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Server server = new Server();
|
||||
server.init(args.length == 1 ? args[0] : Release317.class.getName());
|
||||
/**
|
||||
* The entry point of the Apollo server application.
|
||||
*
|
||||
* @param args The command-line arguments passed to the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
Server server = new Server();
|
||||
server.init(args.length == 1 ? args[0] : Release317.class.getName());
|
||||
|
||||
SocketAddress service = new InetSocketAddress(NetworkConstants.SERVICE_PORT);
|
||||
SocketAddress http = new InetSocketAddress(NetworkConstants.HTTP_PORT);
|
||||
SocketAddress jaggrab = new InetSocketAddress(NetworkConstants.JAGGRAB_PORT);
|
||||
SocketAddress service = new InetSocketAddress(NetworkConstants.SERVICE_PORT);
|
||||
SocketAddress http = new InetSocketAddress(NetworkConstants.HTTP_PORT);
|
||||
SocketAddress jaggrab = new InetSocketAddress(NetworkConstants.JAGGRAB_PORT);
|
||||
|
||||
server.start();
|
||||
server.bind(service, http, jaggrab);
|
||||
} catch (Throwable t) {
|
||||
logger.log(Level.SEVERE, "Error whilst starting server.", t);
|
||||
}
|
||||
server.start();
|
||||
server.bind(service, http, jaggrab);
|
||||
} catch (Throwable 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* The server's context.
|
||||
*/
|
||||
private ServerContext context;
|
||||
logger.info("Binding JAGGRAB listener to address: " + jagGrabAddress + "...");
|
||||
jagGrabBootstrap.bind(jagGrabAddress);
|
||||
|
||||
/**
|
||||
* The {@link ServerBootstrap} for the HTTP listener.
|
||||
*/
|
||||
private final ServerBootstrap httpBootstrap = new ServerBootstrap();
|
||||
logger.info("Ready for connections.");
|
||||
}
|
||||
|
||||
/**
|
||||
* The {@link ServerBootstrap} for the JAGGRAB listener.
|
||||
*/
|
||||
private final ServerBootstrap jagGrabBootstrap = new ServerBootstrap();
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* The {@link ServerBootstrap} for the service listener.
|
||||
*/
|
||||
private final ServerBootstrap serviceBootstrap = new ServerBootstrap();
|
||||
logger.info("Initialized release #" + release.getReleaseNumber() + ".");
|
||||
|
||||
/**
|
||||
* The event loop group.
|
||||
*/
|
||||
private final EventLoopGroup loopGroup = new NioEventLoopGroup();
|
||||
serviceBootstrap.group(loopGroup);
|
||||
httpBootstrap.group(loopGroup);
|
||||
jagGrabBootstrap.group(loopGroup);
|
||||
|
||||
/**
|
||||
* The service manager.
|
||||
*/
|
||||
private final ServiceManager serviceManager;
|
||||
context = new ServerContext(release, serviceManager);
|
||||
ApolloHandler handler = new ApolloHandler(context);
|
||||
|
||||
/**
|
||||
* Creates the Apollo server.
|
||||
*
|
||||
* @throws Exception If an error occurs whilst creating services.
|
||||
*/
|
||||
public Server() throws Exception {
|
||||
logger.info("Starting Apollo...");
|
||||
serviceManager = new ServiceManager();
|
||||
}
|
||||
ChannelInitializer<SocketChannel> serviceInitializer = new ServiceChannelInitializer(handler);
|
||||
serviceBootstrap.channel(NioServerSocketChannel.class);
|
||||
serviceBootstrap.childHandler(serviceInitializer);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
ChannelInitializer<SocketChannel> httpInitializer = new HttpChannelInitializer(handler);
|
||||
httpBootstrap.channel(NioServerSocketChannel.class);
|
||||
httpBootstrap.childHandler(httpInitializer);
|
||||
|
||||
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);
|
||||
}
|
||||
ChannelInitializer<SocketChannel> jagGrabInitializer = new JagGrabChannelInitializer(handler);
|
||||
jagGrabBootstrap.channel(NioServerSocketChannel.class);
|
||||
jagGrabBootstrap.childHandler(jagGrabInitializer);
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
int releaseNo = context.getRelease().getReleaseNumber();
|
||||
IndexedFileSystem fs = new IndexedFileSystem(new File("data/fs/" + releaseNo), true);
|
||||
World.getWorld().init(releaseNo, fs, manager);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,55 +11,55 @@ import org.apollo.net.release.Release;
|
||||
*/
|
||||
public final class ServerContext {
|
||||
|
||||
/**
|
||||
* The current release.
|
||||
*/
|
||||
private final Release release;
|
||||
/**
|
||||
* The current release.
|
||||
*/
|
||||
private final Release release;
|
||||
|
||||
/**
|
||||
* The service manager.
|
||||
*/
|
||||
private final ServiceManager serviceManager;
|
||||
/**
|
||||
* The service manager.
|
||||
*/
|
||||
private final ServiceManager serviceManager;
|
||||
|
||||
/**
|
||||
* Creates a new server context.
|
||||
*
|
||||
* @param release The current release.
|
||||
* @param serviceManager The service manager.
|
||||
*/
|
||||
ServerContext(Release release, ServiceManager serviceManager) {
|
||||
this.release = release;
|
||||
this.serviceManager = serviceManager;
|
||||
this.serviceManager.setContext(this);
|
||||
}
|
||||
/**
|
||||
* Creates a new server context.
|
||||
*
|
||||
* @param release The current release.
|
||||
* @param serviceManager The service manager.
|
||||
*/
|
||||
ServerContext(Release release, ServiceManager serviceManager) {
|
||||
this.release = release;
|
||||
this.serviceManager = serviceManager;
|
||||
this.serviceManager.setContext(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current release.
|
||||
*
|
||||
* @return The current release.
|
||||
*/
|
||||
public Release getRelease() {
|
||||
return release;
|
||||
}
|
||||
/**
|
||||
* Gets the current release.
|
||||
*
|
||||
* @return The current release.
|
||||
*/
|
||||
public Release getRelease() {
|
||||
return release;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a service. This method is shorthand for {@code getServiceManager().getService(...)}.
|
||||
*
|
||||
* @param <S> The type of service.
|
||||
* @param clazz The service class.
|
||||
* @return The service, or {@code null} if it could not be found.
|
||||
*/
|
||||
public <S extends Service> S getService(Class<S> clazz) {
|
||||
return serviceManager.getService(clazz);
|
||||
}
|
||||
/**
|
||||
* Gets a service. This method is shorthand for {@code getServiceManager().getService(...)}.
|
||||
*
|
||||
* @param <S> The type of service.
|
||||
* @param clazz The service class.
|
||||
* @return The service, or {@code null} if it could not be found.
|
||||
*/
|
||||
public <S extends Service> S getService(Class<S> clazz) {
|
||||
return serviceManager.getService(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the service manager.
|
||||
*
|
||||
* @return The service manager.
|
||||
*/
|
||||
public ServiceManager getServiceManager() {
|
||||
return serviceManager;
|
||||
}
|
||||
/**
|
||||
* Gets the service manager.
|
||||
*
|
||||
* @return The service manager.
|
||||
*/
|
||||
public ServiceManager getServiceManager() {
|
||||
return serviceManager;
|
||||
}
|
||||
|
||||
}
|
||||
+24
-24
@@ -7,32 +7,32 @@ package org.apollo;
|
||||
*/
|
||||
public abstract class Service {
|
||||
|
||||
/**
|
||||
* The server context.
|
||||
*/
|
||||
private ServerContext context;
|
||||
/**
|
||||
* The server context.
|
||||
*/
|
||||
private ServerContext context;
|
||||
|
||||
/**
|
||||
* Gets the {@link ServerContext}.
|
||||
*
|
||||
* @return The context.
|
||||
*/
|
||||
public final ServerContext getContext() {
|
||||
return context;
|
||||
}
|
||||
/**
|
||||
* Gets the {@link ServerContext}.
|
||||
*
|
||||
* @return The context.
|
||||
*/
|
||||
public final ServerContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the {@link ServerContext}.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public final void setContext(ServerContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
/**
|
||||
* Sets the {@link ServerContext}.
|
||||
*
|
||||
* @param context The context.
|
||||
*/
|
||||
public final void setContext(ServerContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the service.
|
||||
*/
|
||||
public abstract void start();
|
||||
/**
|
||||
* Starts the service.
|
||||
*/
|
||||
public abstract void start();
|
||||
|
||||
}
|
||||
@@ -18,108 +18,108 @@ import org.xml.sax.SAXException;
|
||||
*/
|
||||
public final class ServiceManager {
|
||||
|
||||
/**
|
||||
* The logger for this class.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(ServiceManager.class.getName());
|
||||
/**
|
||||
* The logger for this class.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(ServiceManager.class.getName());
|
||||
|
||||
/**
|
||||
* The service map.
|
||||
*/
|
||||
private Map<Class<? extends Service>, Service> services = new HashMap<Class<? extends Service>, Service>();
|
||||
/**
|
||||
* The service map.
|
||||
*/
|
||||
private Map<Class<? extends Service>, Service> services = new HashMap<Class<? extends Service>, Service>();
|
||||
|
||||
/**
|
||||
* Creates and initializes the {@link ServiceManager}.
|
||||
*
|
||||
* @throws Exception If an error occurs.
|
||||
*/
|
||||
public ServiceManager() throws Exception {
|
||||
init();
|
||||
/**
|
||||
* Creates and initializes the {@link ServiceManager}.
|
||||
*
|
||||
* @throws Exception If an error occurs.
|
||||
*/
|
||||
public ServiceManager() throws Exception {
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
if (!rootNode.getName().equals("services")) {
|
||||
throw new IOException("Unexpected name of root node.");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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...");
|
||||
for (XmlNode childNode : rootNode) {
|
||||
if (!childNode.getName().equals("service")) {
|
||||
throw new IOException("Unexpected name of child node.");
|
||||
}
|
||||
|
||||
XmlParser parser = new XmlParser();
|
||||
XmlNode rootNode;
|
||||
if (!childNode.hasValue()) {
|
||||
throw new IOException("Child node must have a value.");
|
||||
}
|
||||
|
||||
try (InputStream is = new FileInputStream("data/services.xml")) {
|
||||
rootNode = parser.parse(is);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
Class<? extends Service> clazz = (Class<? extends Service>) Class.forName(childNode.getValue());
|
||||
register((Class<Service>) clazz, clazz.newInstance());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a service.
|
||||
*
|
||||
* @param <S> The type of service.
|
||||
* @param clazz The service's class.
|
||||
* @param service The service.
|
||||
*/
|
||||
private <S extends Service> void register(Class<S> clazz, S service) {
|
||||
logger.fine("Registering service: " + clazz + "...");
|
||||
services.put(clazz, service);
|
||||
}
|
||||
/**
|
||||
* Registers a service.
|
||||
*
|
||||
* @param <S> The type of service.
|
||||
* @param clazz The service's class.
|
||||
* @param service The service.
|
||||
*/
|
||||
private <S extends Service> void register(Class<S> clazz, S service) {
|
||||
logger.fine("Registering service: " + clazz + "...");
|
||||
services.put(clazz, service);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the context of all services.
|
||||
*
|
||||
* @param ctx The server context.
|
||||
*/
|
||||
public void setContext(ServerContext ctx) {
|
||||
for (Service service : services.values()) {
|
||||
service.setContext(ctx);
|
||||
}
|
||||
/**
|
||||
* Sets the context of all services.
|
||||
*
|
||||
* @param ctx The server context.
|
||||
*/
|
||||
public void setContext(ServerContext ctx) {
|
||||
for (Service service : services.values()) {
|
||||
service.setContext(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts all the services.
|
||||
*/
|
||||
public void startAll() {
|
||||
logger.info("Starting services...");
|
||||
for (Service service : services.values()) {
|
||||
logger.fine("Starting service: " + service.getClass().getName() + "...");
|
||||
service.start();
|
||||
}
|
||||
/**
|
||||
* Starts all the services.
|
||||
*/
|
||||
public void startAll() {
|
||||
logger.info("Starting services...");
|
||||
for (Service service : services.values()) {
|
||||
logger.fine("Starting service: " + service.getClass().getName() + "...");
|
||||
service.start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,43 +7,43 @@ package org.apollo.fs;
|
||||
*/
|
||||
public final class FileDescriptor {
|
||||
|
||||
/**
|
||||
* The file id.
|
||||
*/
|
||||
private final int file;
|
||||
/**
|
||||
* The file id.
|
||||
*/
|
||||
private final int file;
|
||||
|
||||
/**
|
||||
* The file type.
|
||||
*/
|
||||
private final int type;
|
||||
/**
|
||||
* The file type.
|
||||
*/
|
||||
private final int type;
|
||||
|
||||
/**
|
||||
* Creates the file descriptor.
|
||||
*
|
||||
* @param type The file type.
|
||||
* @param file The file id.
|
||||
*/
|
||||
public FileDescriptor(int type, int file) {
|
||||
this.type = type;
|
||||
this.file = file;
|
||||
}
|
||||
/**
|
||||
* Creates the file descriptor.
|
||||
*
|
||||
* @param type The file type.
|
||||
* @param file The file id.
|
||||
*/
|
||||
public FileDescriptor(int type, int file) {
|
||||
this.type = type;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file id.
|
||||
*
|
||||
* @return The file id.
|
||||
*/
|
||||
public int getFile() {
|
||||
return file;
|
||||
}
|
||||
/**
|
||||
* Gets the file id.
|
||||
*
|
||||
* @return The file id.
|
||||
*/
|
||||
public int getFile() {
|
||||
return file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file type.
|
||||
*
|
||||
* @return The file type.
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
/**
|
||||
* Gets the file type.
|
||||
*
|
||||
* @return The file type.
|
||||
*/
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,41 +7,41 @@ package org.apollo.fs;
|
||||
*/
|
||||
public final class FileSystemConstants {
|
||||
|
||||
/**
|
||||
* The number of archives in cache 0.
|
||||
*/
|
||||
public static final int ARCHIVE_COUNT = 9;
|
||||
/**
|
||||
* The number of archives in cache 0.
|
||||
*/
|
||||
public static final int ARCHIVE_COUNT = 9;
|
||||
|
||||
/**
|
||||
* The size of a chunk.
|
||||
*/
|
||||
public static final int CHUNK_SIZE = 512;
|
||||
/**
|
||||
* The size of a chunk.
|
||||
*/
|
||||
public static final int CHUNK_SIZE = 512;
|
||||
|
||||
/**
|
||||
* The size of a header.
|
||||
*/
|
||||
public static final int HEADER_SIZE = 8;
|
||||
/**
|
||||
* The size of a header.
|
||||
*/
|
||||
public static final int HEADER_SIZE = 8;
|
||||
|
||||
/**
|
||||
* The size of a block.
|
||||
*/
|
||||
public static final int BLOCK_SIZE = HEADER_SIZE + CHUNK_SIZE;
|
||||
/**
|
||||
* The size of a block.
|
||||
*/
|
||||
public static final int BLOCK_SIZE = HEADER_SIZE + CHUNK_SIZE;
|
||||
|
||||
/**
|
||||
* The number of caches.
|
||||
*/
|
||||
public static final int CACHE_COUNT = 5;
|
||||
/**
|
||||
* The number of caches.
|
||||
*/
|
||||
public static final int CACHE_COUNT = 5;
|
||||
|
||||
/**
|
||||
* The size of an index.
|
||||
*/
|
||||
public static final int INDEX_SIZE = 6;
|
||||
/**
|
||||
* The size of an index.
|
||||
*/
|
||||
public static final int INDEX_SIZE = 6;
|
||||
|
||||
/**
|
||||
* Default private constructor to prevent instantiation.
|
||||
*/
|
||||
private FileSystemConstants() {
|
||||
|
||||
}
|
||||
/**
|
||||
* Default private constructor to prevent instantiation.
|
||||
*/
|
||||
private FileSystemConstants() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,61 +7,61 @@ package org.apollo.fs;
|
||||
*/
|
||||
public final class Index {
|
||||
|
||||
/**
|
||||
* Decodes a buffer into an index.
|
||||
*
|
||||
* @param buffer The buffer.
|
||||
* @return The decoded {@link Index}.
|
||||
* @throws IllegalArgumentException If the buffer length is invalid.
|
||||
*/
|
||||
public static Index decode(byte[] buffer) {
|
||||
if (buffer.length != FileSystemConstants.INDEX_SIZE) {
|
||||
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);
|
||||
/**
|
||||
* Decodes a buffer into an index.
|
||||
*
|
||||
* @param buffer The buffer.
|
||||
* @return The decoded {@link Index}.
|
||||
* @throws IllegalArgumentException If the buffer length is invalid.
|
||||
*/
|
||||
public static Index decode(byte[] buffer) {
|
||||
if (buffer.length != FileSystemConstants.INDEX_SIZE) {
|
||||
throw new IllegalArgumentException("Incorrect buffer length.");
|
||||
}
|
||||
|
||||
/**
|
||||
* The first block of the file.
|
||||
*/
|
||||
private final int block;
|
||||
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;
|
||||
|
||||
/**
|
||||
* The size of the file.
|
||||
*/
|
||||
private final int size;
|
||||
return new Index(size, block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the index.
|
||||
*
|
||||
* @param size The size of the file.
|
||||
* @param block The first block of the file.
|
||||
*/
|
||||
public Index(int size, int block) {
|
||||
this.size = size;
|
||||
this.block = block;
|
||||
}
|
||||
/**
|
||||
* The first block of the file.
|
||||
*/
|
||||
private final int block;
|
||||
|
||||
/**
|
||||
* Gets the first block of the file.
|
||||
*
|
||||
* @return The first block of the file.
|
||||
*/
|
||||
public int getBlock() {
|
||||
return block;
|
||||
}
|
||||
/**
|
||||
* The size of the file.
|
||||
*/
|
||||
private final int size;
|
||||
|
||||
/**
|
||||
* Gets the size of the file.
|
||||
*
|
||||
* @return The size of the file.
|
||||
*/
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
/**
|
||||
* Creates the index.
|
||||
*
|
||||
* @param size The size of the file.
|
||||
* @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.
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,275 +16,275 @@ import java.util.zip.CRC32;
|
||||
*/
|
||||
public final class IndexedFileSystem implements Closeable {
|
||||
|
||||
/**
|
||||
* The cached CRC table.
|
||||
*/
|
||||
private ByteBuffer crcTable;
|
||||
/**
|
||||
* The cached CRC table.
|
||||
*/
|
||||
private ByteBuffer crcTable;
|
||||
|
||||
/**
|
||||
* The data file.
|
||||
*/
|
||||
private RandomAccessFile data;
|
||||
/**
|
||||
* The data file.
|
||||
*/
|
||||
private RandomAccessFile data;
|
||||
|
||||
/**
|
||||
* The index files.
|
||||
*/
|
||||
private RandomAccessFile[] indices = new RandomAccessFile[256];
|
||||
/**
|
||||
* The index files.
|
||||
*/
|
||||
private RandomAccessFile[] indices = new RandomAccessFile[256];
|
||||
|
||||
/**
|
||||
* Read only flag.
|
||||
*/
|
||||
private final boolean readOnly;
|
||||
/**
|
||||
* Read only flag.
|
||||
*/
|
||||
private final boolean readOnly;
|
||||
|
||||
/**
|
||||
* Creates the file system with the specified base directory.
|
||||
*
|
||||
* @param base The base directory.
|
||||
* @param readOnly Indicates whether the file system will be read only or not.
|
||||
* @throws FileNotFoundException If the data files could not be found.
|
||||
*/
|
||||
public IndexedFileSystem(File base, boolean readOnly) throws FileNotFoundException {
|
||||
this.readOnly = readOnly;
|
||||
detectLayout(base);
|
||||
/**
|
||||
* Creates the file system with the specified base directory.
|
||||
*
|
||||
* @param base The base directory.
|
||||
* @param readOnly Indicates whether the file system will be read only or not.
|
||||
* @throws FileNotFoundException If the data files could not be found.
|
||||
*/
|
||||
public IndexedFileSystem(File base, boolean readOnly) throws FileNotFoundException {
|
||||
this.readOnly = readOnly;
|
||||
detectLayout(base);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (data != null) {
|
||||
synchronized (data) {
|
||||
data.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (data != null) {
|
||||
synchronized (data) {
|
||||
data.close();
|
||||
}
|
||||
for (RandomAccessFile index : indices) {
|
||||
if (index != null) {
|
||||
synchronized (index) {
|
||||
index.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (RandomAccessFile index : indices) {
|
||||
if (index != null) {
|
||||
synchronized (index) {
|
||||
index.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Automatically detect the layout of the specified directory.
|
||||
*
|
||||
* @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.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Automatically detect the layout of the specified directory.
|
||||
*
|
||||
* @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");
|
||||
File newEngineData = new File(base.getAbsolutePath() + "/main_file_cache.dat2");
|
||||
if (oldEngineData.exists() && !oldEngineData.isDirectory()) {
|
||||
data = new RandomAccessFile(oldEngineData, readOnly ? "r" : "rw");
|
||||
} else if (newEngineData.exists() && !oldEngineData.isDirectory()) {
|
||||
data = new RandomAccessFile(newEngineData, readOnly ? "r" : "rw");
|
||||
} else {
|
||||
throw new FileNotFoundException("No data file present.");
|
||||
}
|
||||
}
|
||||
|
||||
File oldEngineData = new File(base.getAbsolutePath() + "/main_file_cache.dat");
|
||||
File newEngineData = new File(base.getAbsolutePath() + "/main_file_cache.dat2");
|
||||
if (oldEngineData.exists() && !oldEngineData.isDirectory()) {
|
||||
data = new RandomAccessFile(oldEngineData, readOnly ? "r" : "rw");
|
||||
} else if (newEngineData.exists() && !oldEngineData.isDirectory()) {
|
||||
data = new RandomAccessFile(newEngineData, readOnly ? "r" : "rw");
|
||||
} else {
|
||||
throw new FileNotFoundException("No data file present.");
|
||||
/**
|
||||
* Gets the CRC table.
|
||||
*
|
||||
* @return The CRC table.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
*/
|
||||
public ByteBuffer getCrcTable() throws IOException {
|
||||
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++;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the CRC table.
|
||||
*
|
||||
* @return The CRC table.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
*/
|
||||
public ByteBuffer getCrcTable() throws IOException {
|
||||
if (readOnly) {
|
||||
synchronized (this) {
|
||||
if (crcTable != null) {
|
||||
return crcTable.duplicate();
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < blocks; i++) {
|
||||
// read header
|
||||
byte[] header = new byte[FileSystemConstants.HEADER_SIZE];
|
||||
synchronized (data) {
|
||||
data.seek(ptr);
|
||||
data.readFully(header);
|
||||
}
|
||||
|
||||
int archives = getFileCount(0);
|
||||
int hash = 1234;
|
||||
int[] crcs = new int[archives];
|
||||
// increment pointers
|
||||
ptr += FileSystemConstants.HEADER_SIZE;
|
||||
|
||||
// calculate the CRCs
|
||||
CRC32 crc32 = new CRC32();
|
||||
for (int i = 1; i < crcs.length; i++) {
|
||||
crc32.reset();
|
||||
// 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;
|
||||
|
||||
ByteBuffer buffer = getFile(0, i);
|
||||
byte[] bytes = new byte[buffer.remaining()];
|
||||
buffer.get(bytes, 0, bytes.length);
|
||||
crc32.update(bytes, 0, bytes.length);
|
||||
// check expected chunk id is correct
|
||||
if (i != curChunk) {
|
||||
throw new IOException("Chunk id mismatch.");
|
||||
}
|
||||
|
||||
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
|
||||
ByteBuffer buffer = ByteBuffer.allocate(crcs.length * 4 + 4);
|
||||
for (int crc : crcs) {
|
||||
hash = (hash << 1) + crc;
|
||||
buffer.putInt(crc);
|
||||
}
|
||||
// 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);
|
||||
|
||||
buffer.putInt(hash);
|
||||
buffer.flip();
|
||||
// increment pointers
|
||||
read += chunkSize;
|
||||
ptr = (long) nextBlock * (long) FileSystemConstants.BLOCK_SIZE;
|
||||
|
||||
synchronized (this) {
|
||||
crcTable = buffer.asReadOnlyBuffer();
|
||||
return crcTable.duplicate();
|
||||
}
|
||||
// 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.");
|
||||
}
|
||||
throw new IOException("Cannot get CRC table from a writable file system.");
|
||||
|
||||
if (nextFile != descriptor.getFile()) {
|
||||
throw new IOException("File id mismatch.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
buffer.flip();
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// 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++;
|
||||
}
|
||||
/**
|
||||
* Gets a file.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public ByteBuffer getFile(int type, int file) throws IOException {
|
||||
return getFile(new FileDescriptor(type, file));
|
||||
}
|
||||
|
||||
for (int i = 0; i < blocks; i++) {
|
||||
// read header
|
||||
byte[] header = new byte[FileSystemConstants.HEADER_SIZE];
|
||||
synchronized (data) {
|
||||
data.seek(ptr);
|
||||
data.readFully(header);
|
||||
}
|
||||
|
||||
// increment pointers
|
||||
ptr += FileSystemConstants.HEADER_SIZE;
|
||||
|
||||
// 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;
|
||||
/**
|
||||
* Gets the number of files with the specified type.
|
||||
*
|
||||
* @param type The type.
|
||||
* @return The number of files.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
*/
|
||||
private int getFileCount(int type) throws IOException {
|
||||
if (type < 0 || type >= indices.length) {
|
||||
throw new IndexOutOfBoundsException("File type out of bounds.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a file.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public ByteBuffer getFile(int type, int file) throws IOException {
|
||||
return getFile(new FileDescriptor(type, file));
|
||||
RandomAccessFile indexFile = indices[type];
|
||||
synchronized (indexFile) {
|
||||
return (int) (indexFile.length() / FileSystemConstants.INDEX_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of files with the specified type.
|
||||
*
|
||||
* @param type The type.
|
||||
* @return The number of files.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
*/
|
||||
private int getFileCount(int type) throws IOException {
|
||||
if (type < 0 || type >= indices.length) {
|
||||
throw new IndexOutOfBoundsException("File type out of bounds.");
|
||||
}
|
||||
|
||||
RandomAccessFile indexFile = indices[type];
|
||||
synchronized (indexFile) {
|
||||
return (int) (indexFile.length() / FileSystemConstants.INDEX_SIZE);
|
||||
}
|
||||
byte[] buffer = new byte[FileSystemConstants.INDEX_SIZE];
|
||||
RandomAccessFile indexFile = indices[index];
|
||||
synchronized (indexFile) {
|
||||
long ptr = descriptor.getFile() * FileSystemConstants.INDEX_SIZE;
|
||||
if (ptr >= 0 && indexFile.length() >= ptr + FileSystemConstants.INDEX_SIZE) {
|
||||
indexFile.seek(ptr);
|
||||
indexFile.readFully(buffer);
|
||||
} else {
|
||||
throw new FileNotFoundException("Could not find find index.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.");
|
||||
}
|
||||
return Index.decode(buffer);
|
||||
}
|
||||
|
||||
byte[] buffer = new byte[FileSystemConstants.INDEX_SIZE];
|
||||
RandomAccessFile indexFile = indices[index];
|
||||
synchronized (indexFile) {
|
||||
long ptr = descriptor.getFile() * FileSystemConstants.INDEX_SIZE;
|
||||
if (ptr >= 0 && indexFile.length() >= ptr + FileSystemConstants.INDEX_SIZE) {
|
||||
indexFile.seek(ptr);
|
||||
indexFile.readFully(buffer);
|
||||
} 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;
|
||||
}
|
||||
/**
|
||||
* Checks if this {@link IndexedFileSystem} is read only.
|
||||
*
|
||||
* @return {@code true} if so, {@code false} if not.
|
||||
*/
|
||||
public boolean isReadOnly() {
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,92 +14,92 @@ import org.apollo.util.CompressionUtil;
|
||||
*/
|
||||
public final class Archive {
|
||||
|
||||
/**
|
||||
* Decodes the archive in the specified buffer.
|
||||
*
|
||||
* @param buffer The buffer.
|
||||
* @return The archive.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
*/
|
||||
public static Archive decode(ByteBuffer buffer) throws IOException {
|
||||
int extractedSize = BufferUtil.readUnsignedTriByte(buffer);
|
||||
int size = BufferUtil.readUnsignedTriByte(buffer);
|
||||
boolean extracted = false;
|
||||
/**
|
||||
* Decodes the archive in the specified buffer.
|
||||
*
|
||||
* @param buffer The buffer.
|
||||
* @return The archive.
|
||||
* @throws IOException If an I/O error occurs.
|
||||
*/
|
||||
public static Archive decode(ByteBuffer buffer) throws IOException {
|
||||
int extractedSize = BufferUtil.readUnsignedTriByte(buffer);
|
||||
int size = BufferUtil.readUnsignedTriByte(buffer);
|
||||
boolean extracted = false;
|
||||
|
||||
if (size != extractedSize) {
|
||||
byte[] compressed = new byte[size];
|
||||
byte[] uncompressed = new byte[extractedSize];
|
||||
buffer.get(compressed);
|
||||
CompressionUtil.unbzip2(compressed, uncompressed);
|
||||
buffer = ByteBuffer.wrap(uncompressed);
|
||||
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);
|
||||
if (size != extractedSize) {
|
||||
byte[] compressed = new byte[size];
|
||||
byte[] uncompressed = new byte[extractedSize];
|
||||
buffer.get(compressed);
|
||||
CompressionUtil.unbzip2(compressed, uncompressed);
|
||||
buffer = ByteBuffer.wrap(uncompressed);
|
||||
extracted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The entries in this archive.
|
||||
*/
|
||||
private final ArchiveEntry[] entries;
|
||||
int entries = buffer.getShort() & 0xFFFF;
|
||||
int[] identifiers = new int[entries];
|
||||
int[] extractedSizes = new int[entries];
|
||||
int[] sizes = new int[entries];
|
||||
|
||||
/**
|
||||
* Creates a new archive.
|
||||
*
|
||||
* @param entries The entries in this archive.
|
||||
*/
|
||||
public Archive(ArchiveEntry[] entries) {
|
||||
this.entries = entries;
|
||||
for (int i = 0; i < entries; i++) {
|
||||
identifiers[i] = buffer.getInt();
|
||||
extractedSizes[i] = BufferUtil.readUnsignedTriByte(buffer);
|
||||
sizes[i] = BufferUtil.readUnsignedTriByte(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 + ".");
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 + ".");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,43 +9,43 @@ import java.nio.ByteBuffer;
|
||||
*/
|
||||
public final class ArchiveEntry {
|
||||
|
||||
/**
|
||||
* The buffer of this entry.
|
||||
*/
|
||||
private final ByteBuffer buffer;
|
||||
/**
|
||||
* The buffer of this entry.
|
||||
*/
|
||||
private final ByteBuffer buffer;
|
||||
|
||||
/**
|
||||
* The identifier of this entry.
|
||||
*/
|
||||
private final int identifier;
|
||||
/**
|
||||
* The identifier of this entry.
|
||||
*/
|
||||
private final int identifier;
|
||||
|
||||
/**
|
||||
* Creates a new archive entry.
|
||||
*
|
||||
* @param identifier The identifier.
|
||||
* @param buffer The buffer.
|
||||
*/
|
||||
public ArchiveEntry(int identifier, ByteBuffer buffer) {
|
||||
this.identifier = identifier;
|
||||
this.buffer = buffer.asReadOnlyBuffer();
|
||||
}
|
||||
/**
|
||||
* Creates a new archive entry.
|
||||
*
|
||||
* @param identifier The identifier.
|
||||
* @param buffer The buffer.
|
||||
*/
|
||||
public ArchiveEntry(int identifier, ByteBuffer buffer) {
|
||||
this.identifier = identifier;
|
||||
this.buffer = buffer.asReadOnlyBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the buffer of this entry.
|
||||
*
|
||||
* @return This buffer of this entry.
|
||||
*/
|
||||
public ByteBuffer getBuffer() {
|
||||
return buffer.duplicate();
|
||||
}
|
||||
/**
|
||||
* Gets the buffer of this entry.
|
||||
*
|
||||
* @return This buffer of this entry.
|
||||
*/
|
||||
public ByteBuffer getBuffer() {
|
||||
return buffer.duplicate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the identifier of this entry.
|
||||
*
|
||||
* @return The identifier of this entry.
|
||||
*/
|
||||
public int getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
/**
|
||||
* Gets the identifier of this entry.
|
||||
*
|
||||
* @return The identifier of this entry.
|
||||
*/
|
||||
public int getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,144 +15,144 @@ import org.apollo.util.BufferUtil;
|
||||
*/
|
||||
public final class ItemDefinitionDecoder {
|
||||
|
||||
/**
|
||||
* The {@link IndexedFileSystem}.
|
||||
*/
|
||||
private final IndexedFileSystem fs;
|
||||
/**
|
||||
* The {@link IndexedFileSystem}.
|
||||
*/
|
||||
private final IndexedFileSystem fs;
|
||||
|
||||
/**
|
||||
* Creates the item definition decoder.
|
||||
*
|
||||
* @param fs The indexed file system.
|
||||
*/
|
||||
public ItemDefinitionDecoder(IndexedFileSystem fs) {
|
||||
this.fs = fs;
|
||||
/**
|
||||
* Creates the item definition decoder.
|
||||
*
|
||||
* @param fs The indexed file system.
|
||||
*/
|
||||
public ItemDefinitionDecoder(IndexedFileSystem 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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];
|
||||
for (int i = 0; i < count; i++) {
|
||||
data.position(indices[i]);
|
||||
defs[i] = decode(i, data);
|
||||
}
|
||||
|
||||
return defs;
|
||||
ItemDefinition[] defs = new ItemDefinition[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
data.position(indices[i]);
|
||||
defs[i] = decode(i, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
return defs;
|
||||
}
|
||||
|
||||
if (opcode == 0) {
|
||||
return definition;
|
||||
} else if (opcode == 1) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 2) {
|
||||
definition.setName(BufferUtil.readString(buffer));
|
||||
} else if (opcode == 3) {
|
||||
definition.setDescription(BufferUtil.readString(buffer));
|
||||
} else if (opcode == 4) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 5) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 6) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 7) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 8) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 10) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 11) {
|
||||
definition.setStackable(true);
|
||||
} else if (opcode == 12) {
|
||||
definition.setValue(buffer.getInt());
|
||||
} else if (opcode == 16) {
|
||||
definition.setMembersOnly(true);
|
||||
} else if (opcode == 23) {
|
||||
buffer.getShort();
|
||||
buffer.get();
|
||||
} else if (opcode == 24) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 25) {
|
||||
buffer.getShort();
|
||||
buffer.get();
|
||||
} else if (opcode == 26) {
|
||||
buffer.getShort();
|
||||
} else if (opcode >= 30 && opcode < 35) {
|
||||
String str = BufferUtil.readString(buffer);
|
||||
if (str.equalsIgnoreCase("hidden")) {
|
||||
str = null;
|
||||
}
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
} else if (opcode == 1) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 2) {
|
||||
definition.setName(BufferUtil.readString(buffer));
|
||||
} else if (opcode == 3) {
|
||||
definition.setDescription(BufferUtil.readString(buffer));
|
||||
} else if (opcode == 4) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 5) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 6) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 7) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 8) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 10) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 11) {
|
||||
definition.setStackable(true);
|
||||
} else if (opcode == 12) {
|
||||
definition.setValue(buffer.getInt());
|
||||
} else if (opcode == 16) {
|
||||
definition.setMembersOnly(true);
|
||||
} else if (opcode == 23) {
|
||||
buffer.getShort();
|
||||
buffer.get();
|
||||
} else if (opcode == 24) {
|
||||
buffer.getShort();
|
||||
} else if (opcode == 25) {
|
||||
buffer.getShort();
|
||||
buffer.get();
|
||||
} else if (opcode == 26) {
|
||||
buffer.getShort();
|
||||
} else if (opcode >= 30 && opcode < 35) {
|
||||
String str = BufferUtil.readString(buffer);
|
||||
if (str.equalsIgnoreCase("hidden")) {
|
||||
str = null;
|
||||
}
|
||||
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 {
|
||||
|
||||
/**
|
||||
* The {@link IndexedFileSystem}.
|
||||
*/
|
||||
private final IndexedFileSystem fs;
|
||||
/**
|
||||
* The {@link IndexedFileSystem}.
|
||||
*/
|
||||
private final IndexedFileSystem fs;
|
||||
|
||||
/**
|
||||
* Creates the npc definition decoder.
|
||||
*
|
||||
* @param fs The indexed file system.
|
||||
*/
|
||||
public NpcDefinitionDecoder(IndexedFileSystem fs) {
|
||||
this.fs = fs;
|
||||
/**
|
||||
* Creates the npc definition decoder.
|
||||
*
|
||||
* @param fs The indexed file system.
|
||||
*/
|
||||
public NpcDefinitionDecoder(IndexedFileSystem 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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];
|
||||
for (int i = 0; i < count; i++) {
|
||||
data.position(indices[i]);
|
||||
defs[i] = decode(i, data);
|
||||
}
|
||||
|
||||
return defs;
|
||||
NpcDefinition[] defs = new NpcDefinition[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
data.position(indices[i]);
|
||||
defs[i] = decode(i, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
return defs;
|
||||
}
|
||||
|
||||
if (opcode == 0) {
|
||||
return definition;
|
||||
} else if (opcode == 1) {
|
||||
int length = buffer.get() & 0xFF;
|
||||
int[] models = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
models[i] = buffer.getShort();
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
/**
|
||||
* 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;
|
||||
|
||||
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;
|
||||
}
|
||||
if (opcode == 0) {
|
||||
return definition;
|
||||
} else if (opcode == 1) {
|
||||
int length = buffer.get() & 0xFF;
|
||||
int[] models = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
models[i] = buffer.getShort();
|
||||
}
|
||||
} 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 {
|
||||
|
||||
/**
|
||||
* The {@link IndexedFileSystem}.
|
||||
*/
|
||||
private final IndexedFileSystem fs;
|
||||
/**
|
||||
* The {@link IndexedFileSystem}.
|
||||
*/
|
||||
private final IndexedFileSystem fs;
|
||||
|
||||
/**
|
||||
* Creates the decoder.
|
||||
*
|
||||
* @param fs The {@link IndexedFileSystem}.
|
||||
*/
|
||||
public ObjectDefinitionDecoder(IndexedFileSystem fs) {
|
||||
this.fs = fs;
|
||||
/**
|
||||
* Creates the decoder.
|
||||
*
|
||||
* @param fs The {@link IndexedFileSystem}.
|
||||
*/
|
||||
public ObjectDefinitionDecoder(IndexedFileSystem 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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];
|
||||
for (int i = 0; i < count; i++) {
|
||||
data.position(indices[i]);
|
||||
defs[i] = decode(i, data);
|
||||
}
|
||||
return defs;
|
||||
ObjectDefinition[] defs = new ObjectDefinition[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
data.position(indices[i]);
|
||||
defs[i] = decode(i, data);
|
||||
}
|
||||
return defs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes data from the cache into an {@link ObjectDefinition}.
|
||||
*
|
||||
* @param id The id of the object.
|
||||
* @param data The {@link ByteBuffer} containing the data.
|
||||
* @return The object definition.
|
||||
*/
|
||||
public ObjectDefinition decode(int id, ByteBuffer data) {
|
||||
ObjectDefinition definition = new ObjectDefinition(id);
|
||||
while (true) {
|
||||
int opcode = data.get() & 0xFF;
|
||||
/**
|
||||
* Decodes data from the cache into an {@link ObjectDefinition}.
|
||||
*
|
||||
* @param id The id of the object.
|
||||
* @param data The {@link ByteBuffer} containing the data.
|
||||
* @return The object definition.
|
||||
*/
|
||||
public ObjectDefinition decode(int id, ByteBuffer data) {
|
||||
ObjectDefinition definition = new ObjectDefinition(id);
|
||||
while (true) {
|
||||
int opcode = data.get() & 0xFF;
|
||||
|
||||
if (opcode == 0) {
|
||||
return definition;
|
||||
} else if (opcode == 1) {
|
||||
int amount = data.get() & 0xFF;
|
||||
for (int i = 0; i < amount; i++) {
|
||||
data.getShort();
|
||||
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;
|
||||
}
|
||||
if (opcode == 0) {
|
||||
return definition;
|
||||
} else if (opcode == 1) {
|
||||
int amount = data.get() & 0xFF;
|
||||
for (int i = 0; i < amount; i++) {
|
||||
data.getShort();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,100 +20,100 @@ import org.apollo.util.CompressionUtil;
|
||||
*/
|
||||
public final class StaticObjectDecoder {
|
||||
|
||||
/**
|
||||
* The {@link IndexedFileSystem}.
|
||||
*/
|
||||
private final IndexedFileSystem fs;
|
||||
/**
|
||||
* The {@link IndexedFileSystem}.
|
||||
*/
|
||||
private final IndexedFileSystem fs;
|
||||
|
||||
/**
|
||||
* Creates the decoder.
|
||||
*
|
||||
* @param fs The indexed file system.
|
||||
*/
|
||||
public StaticObjectDecoder(IndexedFileSystem fs) {
|
||||
this.fs = fs;
|
||||
/**
|
||||
* Creates the decoder.
|
||||
*
|
||||
* @param fs The indexed file system.
|
||||
*/
|
||||
public StaticObjectDecoder(IndexedFileSystem 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
List<GameObject> objects = new ArrayList<>();
|
||||
|
||||
int indices = buffer.remaining() / 7;
|
||||
int[] areas = new int[indices];
|
||||
int[] landscapes = new int[indices];
|
||||
for (int i = 0; i < indices; i++) {
|
||||
ByteBuffer compressed = fs.getFile(4, landscapes[i]);
|
||||
ByteBuffer uncompressed = ByteBuffer.wrap(CompressionUtil.ungzip(compressed));
|
||||
|
||||
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<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()]);
|
||||
Collection<GameObject> areaObjects = parseArea(areas[i], uncompressed);
|
||||
objects.addAll(areaObjects);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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>();
|
||||
return objects.toArray(new GameObject[objects.size()]);
|
||||
}
|
||||
|
||||
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 idOffset;
|
||||
int x = (area >> 8 & 0xFF) * 64;
|
||||
int y = (area & 0xFF) * 64;
|
||||
|
||||
while ((idOffset = BufferUtil.readSmart(buffer)) != 0) {
|
||||
id += idOffset;
|
||||
int id = -1;
|
||||
int idOffset;
|
||||
|
||||
int position = 0;
|
||||
int positionOffset;
|
||||
while ((idOffset = BufferUtil.readSmart(buffer)) != 0) {
|
||||
id += idOffset;
|
||||
|
||||
while ((positionOffset = BufferUtil.readSmart(buffer)) != 0) {
|
||||
position += positionOffset - 1;
|
||||
int position = 0;
|
||||
int positionOffset;
|
||||
|
||||
int localX = position >> 6 & 0x3F;
|
||||
int localY = position & 0x3F;
|
||||
int height = position >> 12;
|
||||
while ((positionOffset = BufferUtil.readSmart(buffer)) != 0) {
|
||||
position += positionOffset - 1;
|
||||
|
||||
int info = buffer.get() & 0xFF;
|
||||
int type = info >> 2;
|
||||
int rotation = info & 3;
|
||||
int localX = position >> 6 & 0x3F;
|
||||
int localY = position & 0x3F;
|
||||
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);
|
||||
objects.add(object);
|
||||
}
|
||||
}
|
||||
Position pos = new Position(x + localX, y + localY, height);
|
||||
|
||||
return objects;
|
||||
GameObject object = new GameObject(id, pos, type, rotation);
|
||||
objects.add(object);
|
||||
}
|
||||
}
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,21 +7,21 @@ package org.apollo.game;
|
||||
*/
|
||||
public final class GameConstants {
|
||||
|
||||
/**
|
||||
* The maximum events per pulse per session.
|
||||
*/
|
||||
public static final int EVENTS_PER_PULSE = 10;
|
||||
/**
|
||||
* The maximum events per pulse per session.
|
||||
*/
|
||||
public static final int EVENTS_PER_PULSE = 10;
|
||||
|
||||
/**
|
||||
* The delay between consecutive pulses, in milliseconds.
|
||||
*/
|
||||
public static final int PULSE_DELAY = 600;
|
||||
/**
|
||||
* The delay between consecutive pulses, in milliseconds.
|
||||
*/
|
||||
public static final int PULSE_DELAY = 600;
|
||||
|
||||
/**
|
||||
* Default private constructor to prevent instantiation by other classes.
|
||||
*/
|
||||
private GameConstants() {
|
||||
/**
|
||||
* Default private constructor to prevent instantiation by other classes.
|
||||
*/
|
||||
private GameConstants() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,32 +10,32 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public final class GamePulseHandler implements Runnable {
|
||||
|
||||
/**
|
||||
* The logger for this class.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(GamePulseHandler.class.getName());
|
||||
/**
|
||||
* The logger for this class.
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(GamePulseHandler.class.getName());
|
||||
|
||||
/**
|
||||
* The {@link GameService}.
|
||||
*/
|
||||
private final GameService service;
|
||||
/**
|
||||
* The {@link GameService}.
|
||||
*/
|
||||
private final GameService service;
|
||||
|
||||
/**
|
||||
* Creates the game pulse handler object.
|
||||
*
|
||||
* @param service The {@link GameService}.
|
||||
*/
|
||||
GamePulseHandler(GameService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
service.pulse();
|
||||
} catch (Throwable t) {
|
||||
logger.log(Level.SEVERE, "Exception during pulse.", t);
|
||||
}
|
||||
/**
|
||||
* Creates the game pulse handler object.
|
||||
*
|
||||
* @param service The {@link GameService}.
|
||||
*/
|
||||
GamePulseHandler(GameService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
service.pulse();
|
||||
} catch (Throwable t) {
|
||||
logger.log(Level.SEVERE, "Exception during pulse.", t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,157 +31,157 @@ import org.xml.sax.SAXException;
|
||||
*/
|
||||
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
|
||||
* requests and slow everything down.
|
||||
*/
|
||||
private static final int UNREGISTERS_PER_CYCLE = 50;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
private static final int UNREGISTERS_PER_CYCLE = 50;
|
||||
|
||||
/**
|
||||
* The {@link EventHandlerChainGroup}.
|
||||
*/
|
||||
private EventHandlerChainGroup chainGroup;
|
||||
/**
|
||||
* The {@link EventHandlerChainGroup}.
|
||||
*/
|
||||
private EventHandlerChainGroup chainGroup;
|
||||
|
||||
/**
|
||||
* A queue of players to remove.
|
||||
*/
|
||||
private final Queue<Player> oldPlayers = new ConcurrentLinkedQueue<Player>();
|
||||
/**
|
||||
* A queue of players to remove.
|
||||
*/
|
||||
private final Queue<Player> oldPlayers = new ConcurrentLinkedQueue<>();
|
||||
|
||||
/**
|
||||
* The scheduled executor service.
|
||||
*/
|
||||
private final ScheduledExecutorService scheduledExecutor = Executors
|
||||
.newSingleThreadScheduledExecutor(new NamedThreadFactory("GameService"));
|
||||
/**
|
||||
* The scheduled executor service.
|
||||
*/
|
||||
private final ScheduledExecutorService scheduledExecutor = Executors
|
||||
.newSingleThreadScheduledExecutor(new NamedThreadFactory("GameService"));
|
||||
|
||||
/**
|
||||
* The {@link ClientSynchronizer}.
|
||||
*/
|
||||
private ClientSynchronizer synchronizer;
|
||||
/**
|
||||
* The {@link ClientSynchronizer}.
|
||||
*/
|
||||
private ClientSynchronizer synchronizer;
|
||||
|
||||
/**
|
||||
* Creates the game service.
|
||||
*
|
||||
* @throws Exception If an error occurs during initialization.
|
||||
*/
|
||||
public GameService() throws Exception {
|
||||
init();
|
||||
/**
|
||||
* Creates the game service.
|
||||
*
|
||||
* @throws Exception If an error occurs during initialization.
|
||||
*/
|
||||
public GameService() throws Exception {
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalizes the unregistration of a player.
|
||||
*
|
||||
* @param player The player.
|
||||
*/
|
||||
public void finalizePlayerUnregistration(Player player) {
|
||||
synchronized (this) {
|
||||
World.getWorld().unregister(player);
|
||||
try (InputStream is = new FileInputStream("data/synchronizer.xml")) {
|
||||
XmlParser parser = new XmlParser();
|
||||
XmlNode rootNode = parser.parse(is);
|
||||
|
||||
if (!rootNode.getName().equals("synchronizer")) {
|
||||
throw new IOException("Invalid root node name.");
|
||||
}
|
||||
|
||||
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.
|
||||
*
|
||||
* @return The event handler chains.
|
||||
*/
|
||||
public EventHandlerChainGroup getEventHandlerChains() {
|
||||
return chainGroup;
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
/**
|
||||
* Starts the game service.
|
||||
*/
|
||||
@Override
|
||||
public void start() {
|
||||
scheduledExecutor.scheduleAtFixedRate(new GamePulseHandler(this), GameConstants.PULSE_DELAY,
|
||||
GameConstants.PULSE_DELAY, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
try (InputStream is = new FileInputStream("data/synchronizer.xml")) {
|
||||
XmlParser parser = new XmlParser();
|
||||
XmlNode rootNode = parser.parse(is);
|
||||
|
||||
if (!rootNode.getName().equals("synchronizer")) {
|
||||
throw new IOException("Invalid root node name.");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,44 +14,44 @@ import org.apollo.game.scheduling.ScheduledTask;
|
||||
*/
|
||||
public abstract class Action<T extends Mob> extends ScheduledTask {
|
||||
|
||||
/**
|
||||
* The mob performing the action.
|
||||
*/
|
||||
protected final T mob;
|
||||
/**
|
||||
* The mob performing the action.
|
||||
*/
|
||||
protected final T mob;
|
||||
|
||||
/**
|
||||
* A flag indicating if this action is stopping.
|
||||
*/
|
||||
private boolean stopping = false;
|
||||
/**
|
||||
* A flag indicating if this action is stopping.
|
||||
*/
|
||||
private boolean stopping = false;
|
||||
|
||||
/**
|
||||
* Creates a new action.
|
||||
*
|
||||
* @param delay The delay in pulses.
|
||||
* @param immediate A flag indicating if the action should happen immediately.
|
||||
* @param mob The mob performing the action.
|
||||
*/
|
||||
public Action(int delay, boolean immediate, T mob) {
|
||||
super(delay, immediate);
|
||||
this.mob = mob;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mob which performed the action.
|
||||
*
|
||||
* @return The mob.
|
||||
*/
|
||||
public T getMob() {
|
||||
return mob;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
if (!stopping) {
|
||||
stopping = true;
|
||||
mob.stopAction();
|
||||
}
|
||||
/**
|
||||
* Creates a new action.
|
||||
*
|
||||
* @param delay The delay in pulses.
|
||||
* @param immediate A flag indicating if the action should happen immediately.
|
||||
* @param mob The mob performing the action.
|
||||
*/
|
||||
public Action(int delay, boolean immediate, T mob) {
|
||||
super(delay, immediate);
|
||||
this.mob = mob;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the mob which performed the action.
|
||||
*
|
||||
* @return The mob.
|
||||
*/
|
||||
public T getMob() {
|
||||
return mob;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
super.stop();
|
||||
if (!stopping) {
|
||||
stopping = true;
|
||||
mob.stopAction();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,66 +11,66 @@ import org.apollo.game.model.entity.Mob;
|
||||
*/
|
||||
public abstract class DistancedAction<T extends Mob> extends Action<T> {
|
||||
|
||||
/**
|
||||
* The delay once the threshold is reached.
|
||||
*/
|
||||
private final int delay;
|
||||
/**
|
||||
* The delay once the threshold is reached.
|
||||
*/
|
||||
private final int delay;
|
||||
|
||||
/**
|
||||
* The minimum distance before the action fires.
|
||||
*/
|
||||
private final int distance;
|
||||
/**
|
||||
* The minimum distance before the action fires.
|
||||
*/
|
||||
private final int distance;
|
||||
|
||||
/**
|
||||
* A flag indicating if this action fires immediately after the threshold is reached.
|
||||
*/
|
||||
private final boolean immediate;
|
||||
/**
|
||||
* A flag indicating if this action fires immediately after the threshold is reached.
|
||||
*/
|
||||
private final boolean immediate;
|
||||
|
||||
/**
|
||||
* The position to distance check with.
|
||||
*/
|
||||
private final Position position;
|
||||
/**
|
||||
* The position to distance check with.
|
||||
*/
|
||||
private final Position position;
|
||||
|
||||
/**
|
||||
* A flag indicating if the distance has been reached yet.
|
||||
*/
|
||||
private boolean reached = false;
|
||||
/**
|
||||
* A flag indicating if the distance has been reached yet.
|
||||
*/
|
||||
private boolean reached = false;
|
||||
|
||||
/**
|
||||
* Creates a new DistancedAction.
|
||||
*
|
||||
* @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 mob The mob.
|
||||
* @param position The position.
|
||||
* @param distance The distance.
|
||||
*/
|
||||
public DistancedAction(int delay, boolean immediate, T mob, Position position, int distance) {
|
||||
super(0, true, mob);
|
||||
this.position = position;
|
||||
this.distance = distance;
|
||||
this.delay = delay;
|
||||
this.immediate = immediate;
|
||||
/**
|
||||
* Creates a new DistancedAction.
|
||||
*
|
||||
* @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 mob The mob.
|
||||
* @param position The position.
|
||||
* @param distance The distance.
|
||||
*/
|
||||
public DistancedAction(int delay, boolean immediate, T mob, Position position, int distance) {
|
||||
super(0, true, mob);
|
||||
this.position = position;
|
||||
this.distance = distance;
|
||||
this.delay = delay;
|
||||
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() {
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the actual action. Called when the distance requirement is met.
|
||||
*/
|
||||
public abstract void executeAction();
|
||||
/**
|
||||
* Executes the actual action. Called when the distance requirement is met.
|
||||
*/
|
||||
public abstract void executeAction();
|
||||
|
||||
}
|
||||
@@ -7,43 +7,43 @@ package org.apollo.game.command;
|
||||
*/
|
||||
public final class Command {
|
||||
|
||||
/**
|
||||
* The command's arguments.
|
||||
*/
|
||||
private final String[] arguments;
|
||||
/**
|
||||
* The command's arguments.
|
||||
*/
|
||||
private final String[] arguments;
|
||||
|
||||
/**
|
||||
* The name of the command.
|
||||
*/
|
||||
private final String name;
|
||||
/**
|
||||
* The name of the command.
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Creates the command.
|
||||
*
|
||||
* @param name The name of the command.
|
||||
* @param arguments The command's arguments.
|
||||
*/
|
||||
public Command(String name, String[] arguments) {
|
||||
this.name = name;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
/**
|
||||
* Creates the command.
|
||||
*
|
||||
* @param name The name of the command.
|
||||
* @param arguments The command's arguments.
|
||||
*/
|
||||
public Command(String name, String[] arguments) {
|
||||
this.name = name;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command's arguments.
|
||||
*
|
||||
* @return The command's arguments.
|
||||
*/
|
||||
public String[] getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
/**
|
||||
* Gets the command's arguments.
|
||||
*
|
||||
* @return The command's arguments.
|
||||
*/
|
||||
public String[] getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the command.
|
||||
*
|
||||
* @return The name of the command.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* Gets the name of the command.
|
||||
*
|
||||
* @return The name of the command.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,39 +12,39 @@ import org.apollo.game.model.entity.Player;
|
||||
*/
|
||||
public final class CommandDispatcher {
|
||||
|
||||
/**
|
||||
* A map of event listeners.
|
||||
*/
|
||||
private final Map<String, CommandListener> listeners = new HashMap<String, CommandListener>();
|
||||
/**
|
||||
* A map of event listeners.
|
||||
*/
|
||||
private final Map<String, CommandListener> listeners = new HashMap<String, CommandListener>();
|
||||
|
||||
/**
|
||||
* Creates the command dispatcher and registers a listener for the credits command.
|
||||
*/
|
||||
public CommandDispatcher() {
|
||||
listeners.put("credits", new CreditsCommandListener());
|
||||
}
|
||||
/**
|
||||
* Creates the command dispatcher and registers a listener for the credits command.
|
||||
*/
|
||||
public CommandDispatcher() {
|
||||
listeners.put("credits", new CreditsCommandListener());
|
||||
}
|
||||
|
||||
/**
|
||||
* Dispatches a command to the appropriate listener.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param command The command.
|
||||
*/
|
||||
public void dispatch(Player player, Command command) {
|
||||
CommandListener listener = listeners.get(command.getName().toLowerCase());
|
||||
if (listener != null) {
|
||||
listener.executePrivileged(player, command);
|
||||
}
|
||||
/**
|
||||
* Dispatches a command to the appropriate listener.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param command The command.
|
||||
*/
|
||||
public void dispatch(Player player, Command command) {
|
||||
CommandListener listener = listeners.get(command.getName().toLowerCase());
|
||||
if (listener != null) {
|
||||
listener.executePrivileged(player, command);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a listener with the dispatcher.
|
||||
*
|
||||
* @param command The command's name.
|
||||
* @param listener The listener.
|
||||
*/
|
||||
public void register(String command, CommandListener listener) {
|
||||
listeners.put(command.toLowerCase(), listener);
|
||||
}
|
||||
/**
|
||||
* Registers a listener with the dispatcher.
|
||||
*
|
||||
* @param command The command's name.
|
||||
* @param listener The listener.
|
||||
*/
|
||||
public void register(String command, CommandListener listener) {
|
||||
listeners.put(command.toLowerCase(), listener);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,45 +11,45 @@ import org.apollo.game.model.settings.PrivilegeLevel;
|
||||
*/
|
||||
public abstract class CommandListener {
|
||||
|
||||
/**
|
||||
* The minimum privilege level.
|
||||
*/
|
||||
private final PrivilegeLevel level;
|
||||
/**
|
||||
* The minimum privilege level.
|
||||
*/
|
||||
private final PrivilegeLevel level;
|
||||
|
||||
/**
|
||||
* Creates a new command listener with a {@link PrivilegeLevel#STANDARD} requirement.
|
||||
*/
|
||||
public CommandListener() {
|
||||
this(PrivilegeLevel.STANDARD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new command listener.
|
||||
*
|
||||
* @param level The required {@link PrivilegeLevel}.
|
||||
*/
|
||||
public CommandListener(PrivilegeLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the action for this command.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param command The command.
|
||||
*/
|
||||
public abstract void execute(Player player, Command command);
|
||||
|
||||
/**
|
||||
* Executes a privileged command.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param command The command.
|
||||
*/
|
||||
public final void executePrivileged(Player player, Command command) {
|
||||
if (player.getPrivilegeLevel().toInteger() >= level.toInteger()) {
|
||||
execute(player, command);
|
||||
}
|
||||
/**
|
||||
* Creates a new command listener with a {@link PrivilegeLevel#STANDARD} requirement.
|
||||
*/
|
||||
public CommandListener() {
|
||||
this(PrivilegeLevel.STANDARD);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new command listener.
|
||||
*
|
||||
* @param level The required {@link PrivilegeLevel}.
|
||||
*/
|
||||
public CommandListener(PrivilegeLevel level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the action for this command.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param command The command.
|
||||
*/
|
||||
public abstract void execute(Player player, Command command);
|
||||
|
||||
/**
|
||||
* Executes a privileged command.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param command The command.
|
||||
*/
|
||||
public final void executePrivileged(Player player, Command command) {
|
||||
if (player.getPrivilegeLevel().toInteger() >= level.toInteger()) {
|
||||
execute(player, command);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,36 +15,36 @@ import org.apollo.util.plugin.PluginManager;
|
||||
*/
|
||||
public final class CreditsCommandListener extends CommandListener {
|
||||
|
||||
/*
|
||||
* 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
|
||||
* 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
|
||||
* name to the plugin.xml file and it'll appear here automatically!
|
||||
*/
|
||||
/*
|
||||
* 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
|
||||
* 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
|
||||
* name to the plugin.xml file and it'll appear here automatically!
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void execute(Player player, Command command) {
|
||||
PluginManager mgr = World.getWorld().getPluginManager();
|
||||
final Set<String> authors = mgr.getAuthors();
|
||||
@Override
|
||||
public void execute(Player player, Command command) {
|
||||
PluginManager mgr = World.getWorld().getPluginManager();
|
||||
final Set<String> authors = mgr.getAuthors();
|
||||
|
||||
List<String> text = new ArrayList<String>(12 + authors.size());
|
||||
text.add("@dre@Apollo");
|
||||
text.add("@dre@Introduction");
|
||||
text.add("");
|
||||
text.add("This server is based on Apollo, a lightweight, fast, secure");
|
||||
text.add("and open-source RuneScape emulator. For more");
|
||||
text.add("information about Apollo, visit the website at:");
|
||||
text.add("@dbl@https://github.com/apollo-rsps/apollo");
|
||||
text.add("");
|
||||
text.add("Apollo is released under the terms of the ISC license.");
|
||||
text.add("");
|
||||
text.add("@dre@Credits");
|
||||
text.add("");
|
||||
text.addAll(authors);
|
||||
List<String> text = new ArrayList<>(12 + authors.size());
|
||||
text.add("@dre@Apollo");
|
||||
text.add("@dre@Introduction");
|
||||
text.add("");
|
||||
text.add("This server is based on Apollo, a lightweight, fast, secure");
|
||||
text.add("and open-source RuneScape emulator. For more");
|
||||
text.add("information about Apollo, visit the website at:");
|
||||
text.add("@dbl@https://github.com/apollo-rsps/apollo");
|
||||
text.add("");
|
||||
text.add("Apollo is released under the terms of the ISC license.");
|
||||
text.add("");
|
||||
text.add("@dre@Credits");
|
||||
text.add("");
|
||||
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> {
|
||||
|
||||
/**
|
||||
* Handles an event.
|
||||
*
|
||||
* @param ctx The context.
|
||||
* @param player The player.
|
||||
* @param event The event.
|
||||
*/
|
||||
public abstract void handle(EventHandlerContext ctx, Player player, E event);
|
||||
/**
|
||||
* Handles an event.
|
||||
*
|
||||
* @param ctx The context.
|
||||
* @param player The player.
|
||||
* @param event The 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 {
|
||||
|
||||
/**
|
||||
* Breaks the handler chain.
|
||||
*/
|
||||
public abstract void breakHandlerChain();
|
||||
/**
|
||||
* Breaks the handler chain.
|
||||
*/
|
||||
public abstract void breakHandlerChain();
|
||||
|
||||
}
|
||||
@@ -13,58 +13,58 @@ import org.apollo.game.model.entity.Player;
|
||||
*/
|
||||
public final class EventHandlerChain<E extends Event> {
|
||||
|
||||
/**
|
||||
* The handlers.
|
||||
*/
|
||||
private EventHandler<E>[] handlers;
|
||||
/**
|
||||
* The handlers.
|
||||
*/
|
||||
private EventHandler<E>[] handlers;
|
||||
|
||||
/**
|
||||
* Creates the event handler chain.
|
||||
*
|
||||
* @param handlers The handlers.
|
||||
*/
|
||||
@SafeVarargs
|
||||
public EventHandlerChain(EventHandler<E>... handlers) {
|
||||
this.handlers = handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically adds an event handler to the end of the chain.
|
||||
*
|
||||
* @param handler The handler.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addLast(EventHandler<E> handler) {
|
||||
EventHandler<E>[] old = handlers;
|
||||
handlers = new EventHandler[old.length + 1];
|
||||
System.arraycopy(old, 0, handlers, 0, old.length);
|
||||
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.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param event The event.
|
||||
*/
|
||||
public void handle(Player player, E event) {
|
||||
final boolean[] running = new boolean[1];
|
||||
running[0] = true;
|
||||
|
||||
EventHandlerContext ctx = new EventHandlerContext() {
|
||||
|
||||
@Override
|
||||
public void breakHandlerChain() {
|
||||
running[0] = false;
|
||||
}
|
||||
};
|
||||
|
||||
for (EventHandler<E> handler : handlers) {
|
||||
handler.handle(ctx, player, event);
|
||||
if (!running[0]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Creates the event handler chain.
|
||||
*
|
||||
* @param handlers The handlers.
|
||||
*/
|
||||
@SafeVarargs
|
||||
public EventHandlerChain(EventHandler<E>... handlers) {
|
||||
this.handlers = handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamically adds an event handler to the end of the chain.
|
||||
*
|
||||
* @param handler The handler.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void addLast(EventHandler<E> handler) {
|
||||
EventHandler<E>[] old = handlers;
|
||||
handlers = new EventHandler[old.length + 1];
|
||||
System.arraycopy(old, 0, handlers, 0, old.length);
|
||||
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.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param event The event.
|
||||
*/
|
||||
public void handle(Player player, E event) {
|
||||
final boolean[] running = new boolean[1];
|
||||
running[0] = true;
|
||||
|
||||
EventHandlerContext ctx = new EventHandlerContext() {
|
||||
|
||||
@Override
|
||||
public void breakHandlerChain() {
|
||||
running[0] = false;
|
||||
}
|
||||
};
|
||||
|
||||
for (EventHandler<E> handler : handlers) {
|
||||
handler.handle(ctx, player, event);
|
||||
if (!running[0]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,40 +11,40 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class EventHandlerChainGroup {
|
||||
|
||||
/**
|
||||
* The map of event classes to event handler chains.
|
||||
*/
|
||||
private final Map<Class<? extends Event>, EventHandlerChain<?>> chains;
|
||||
/**
|
||||
* The map of event classes to event handler chains.
|
||||
*/
|
||||
private final Map<Class<? extends Event>, EventHandlerChain<?>> chains;
|
||||
|
||||
/**
|
||||
* Creates the event handler chain group.
|
||||
*
|
||||
* @param chains The chains map.
|
||||
*/
|
||||
public EventHandlerChainGroup(Map<Class<? extends Event>, EventHandlerChain<?>> chains) {
|
||||
this.chains = chains;
|
||||
}
|
||||
/**
|
||||
* Creates the event handler chain group.
|
||||
*
|
||||
* @param chains The chains map.
|
||||
*/
|
||||
public EventHandlerChainGroup(Map<Class<? extends Event>, EventHandlerChain<?>> chains) {
|
||||
this.chains = chains;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link EventHandlerChain} from this group.
|
||||
*
|
||||
* @param <E> The type of event.
|
||||
* @param clazz The event class.
|
||||
* @return The {@link EventHandlerChain} if one was found, {@code null} otherwise.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E extends Event> EventHandlerChain<E> getChain(Class<E> clazz) {
|
||||
return (EventHandlerChain<E>) chains.get(clazz);
|
||||
}
|
||||
/**
|
||||
* Gets an {@link EventHandlerChain} from this group.
|
||||
*
|
||||
* @param <E> The type of event.
|
||||
* @param clazz The event class.
|
||||
* @return The {@link EventHandlerChain} if one was found, {@code null} otherwise.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E extends Event> EventHandlerChain<E> getChain(Class<E> clazz) {
|
||||
return (EventHandlerChain<E>) chains.get(clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers an {@link EventHandlerChain} associated with the specified {@link Class} to this group.
|
||||
*
|
||||
* @param clazz The event class.
|
||||
* @param chain The event handler chain.
|
||||
*/
|
||||
public <E extends Event> void register(Class<E> clazz, EventHandlerChain<E> chain) {
|
||||
chains.put(clazz, chain);
|
||||
}
|
||||
/**
|
||||
* Registers an {@link EventHandlerChain} associated with the specified {@link Class} to this group.
|
||||
*
|
||||
* @param clazz The event class.
|
||||
* @param chain The event handler chain.
|
||||
*/
|
||||
public <E extends Event> void register(Class<E> clazz, EventHandlerChain<E> chain) {
|
||||
chains.put(clazz, chain);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,23 +12,23 @@ import org.apollo.game.model.entity.Player;
|
||||
*/
|
||||
public final class BankButtonEventHandler extends EventHandler<ButtonEvent> {
|
||||
|
||||
/**
|
||||
* The withdraw as item button id.
|
||||
*/
|
||||
private static final int WITHDRAW_AS_ITEM = 5387;
|
||||
/**
|
||||
* The withdraw as item button id.
|
||||
*/
|
||||
private static final int WITHDRAW_AS_ITEM = 5387;
|
||||
|
||||
/**
|
||||
* The withdraw as note button id.
|
||||
*/
|
||||
private static final int WITHDRAW_AS_NOTE = 5386;
|
||||
/**
|
||||
* The withdraw as note button id.
|
||||
*/
|
||||
private static final int WITHDRAW_AS_NOTE = 5386;
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ButtonEvent event) {
|
||||
if (event.getWidgetId() == WITHDRAW_AS_ITEM) {
|
||||
player.setWithdrawingNotes(false);
|
||||
} else if (event.getWidgetId() == WITHDRAW_AS_NOTE) {
|
||||
player.setWithdrawingNotes(true);
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ButtonEvent event) {
|
||||
if (event.getWidgetId() == WITHDRAW_AS_ITEM) {
|
||||
player.setWithdrawingNotes(false);
|
||||
} else if (event.getWidgetId() == WITHDRAW_AS_NOTE) {
|
||||
player.setWithdrawingNotes(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,72 +16,72 @@ import org.apollo.game.model.inter.bank.BankWithdrawEnterAmountListener;
|
||||
*/
|
||||
public final class BankEventHandler extends EventHandler<ItemActionEvent> {
|
||||
|
||||
/**
|
||||
* Converts an option to an amount.
|
||||
*
|
||||
* @param option The option.
|
||||
* @return The amount.
|
||||
* @throws IllegalArgumentException If the option is invalid.
|
||||
*/
|
||||
private static final int optionToAmount(int option) {
|
||||
switch (option) {
|
||||
case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
return 5;
|
||||
case 3:
|
||||
return 10;
|
||||
case 4:
|
||||
return Integer.MAX_VALUE;
|
||||
case 5:
|
||||
return -1;
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid option supplied.");
|
||||
/**
|
||||
* Converts an option to an amount.
|
||||
*
|
||||
* @param option The option.
|
||||
* @return The amount.
|
||||
* @throws IllegalArgumentException If the option is invalid.
|
||||
*/
|
||||
private static final int optionToAmount(int option) {
|
||||
switch (option) {
|
||||
case 1:
|
||||
return 1;
|
||||
case 2:
|
||||
return 5;
|
||||
case 3:
|
||||
return 10;
|
||||
case 4:
|
||||
return Integer.MAX_VALUE;
|
||||
case 5:
|
||||
return -1;
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid option supplied.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a deposit action.
|
||||
*
|
||||
* @param ctx The event handler context.
|
||||
* @param player The player.
|
||||
* @param event The event.
|
||||
*/
|
||||
private void deposit(EventHandlerContext ctx, Player player, ItemActionEvent event) {
|
||||
int amount = optionToAmount(event.getOption());
|
||||
if (amount == -1) {
|
||||
player.getInterfaceSet().openEnterAmountDialogue(
|
||||
new BankDepositEnterAmountListener(player, event.getSlot(), event.getId()));
|
||||
} else if (!BankUtils.deposit(player, event.getSlot(), event.getId(), amount)) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
/**
|
||||
* Handles a deposit action.
|
||||
*
|
||||
* @param ctx The event handler context.
|
||||
* @param player The player.
|
||||
* @param event The event.
|
||||
*/
|
||||
private void deposit(EventHandlerContext ctx, Player player, ItemActionEvent event) {
|
||||
int amount = optionToAmount(event.getOption());
|
||||
if (amount == -1) {
|
||||
player.getInterfaceSet().openEnterAmountDialogue(
|
||||
new BankDepositEnterAmountListener(player, event.getSlot(), event.getId()));
|
||||
} else if (!BankUtils.deposit(player, event.getSlot(), event.getId(), amount)) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) {
|
||||
if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) {
|
||||
if (event.getInterfaceId() == BankConstants.SIDEBAR_INVENTORY_ID) {
|
||||
deposit(ctx, player, event);
|
||||
} else if (event.getInterfaceId() == BankConstants.BANK_INVENTORY_ID) {
|
||||
withdraw(ctx, player, event);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) {
|
||||
if (player.getInterfaceSet().contains(BankConstants.BANK_WINDOW_ID)) {
|
||||
if (event.getInterfaceId() == BankConstants.SIDEBAR_INVENTORY_ID) {
|
||||
deposit(ctx, player, event);
|
||||
} else if (event.getInterfaceId() == BankConstants.BANK_INVENTORY_ID) {
|
||||
withdraw(ctx, player, event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a withdraw action.
|
||||
*
|
||||
* @param ctx The event handler context.
|
||||
* @param player The player.
|
||||
* @param event The event.
|
||||
*/
|
||||
private void withdraw(EventHandlerContext ctx, Player player, ItemActionEvent event) {
|
||||
int amount = optionToAmount(event.getOption());
|
||||
if (amount == -1) {
|
||||
player.getInterfaceSet().openEnterAmountDialogue(
|
||||
new BankWithdrawEnterAmountListener(player, event.getSlot(), event.getId()));
|
||||
} else if (!BankUtils.withdraw(player, event.getSlot(), event.getId(), amount)) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
/**
|
||||
* Handles a withdraw action.
|
||||
*
|
||||
* @param ctx The event handler context.
|
||||
* @param player The player.
|
||||
* @param event The event.
|
||||
*/
|
||||
private void withdraw(EventHandlerContext ctx, Player player, ItemActionEvent event) {
|
||||
int amount = optionToAmount(event.getOption());
|
||||
if (amount == -1) {
|
||||
player.getInterfaceSet().openEnterAmountDialogue(
|
||||
new BankWithdrawEnterAmountListener(player, event.getSlot(), event.getId()));
|
||||
} else if (!BankUtils.withdraw(player, event.getSlot(), event.getId(), amount)) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,9 +13,9 @@ import org.apollo.game.sync.block.SynchronizationBlock;
|
||||
*/
|
||||
public final class ChatEventHandler extends EventHandler<ChatEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ChatEvent event) {
|
||||
player.getBlockSet().add(SynchronizationBlock.createChatBlock(player, event));
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ChatEvent 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> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ChatEvent event) {
|
||||
int color = event.getTextColor();
|
||||
int effects = event.getTextEffects();
|
||||
if (color < 0 || color > 11 || effects < 0 || effects > 5) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ChatEvent event) {
|
||||
int color = event.getTextColor();
|
||||
int effects = event.getTextEffects();
|
||||
if (color < 0 || color > 11 || effects < 0 || effects > 5) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,10 +12,10 @@ import org.apollo.game.model.entity.Player;
|
||||
*/
|
||||
public final class ClosedInterfaceEventHandler extends EventHandler<ClosedInterfaceEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ClosedInterfaceEvent event) {
|
||||
System.out.println("closing interface");
|
||||
player.getInterfaceSet().interfaceClosed();
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ClosedInterfaceEvent event) {
|
||||
System.out.println("closing interface");
|
||||
player.getInterfaceSet().interfaceClosed();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,16 +14,16 @@ import org.apollo.game.model.entity.Player;
|
||||
*/
|
||||
public final class CommandEventHandler extends EventHandler<CommandEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, CommandEvent event) {
|
||||
String[] components = event.getCommand().split(" ");
|
||||
String name = components[0];
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, CommandEvent event) {
|
||||
String[] components = event.getCommand().split(" ");
|
||||
String name = components[0];
|
||||
|
||||
String[] arguments = new String[components.length - 1];
|
||||
System.arraycopy(components, 1, arguments, 0, arguments.length);
|
||||
String[] arguments = new String[components.length - 1];
|
||||
System.arraycopy(components, 1, arguments, 0, arguments.length);
|
||||
|
||||
Command command = new Command(name, arguments);
|
||||
World.getWorld().getCommandDispatcher().dispatch(player, command);
|
||||
}
|
||||
Command command = new Command(name, arguments);
|
||||
World.getWorld().getCommandDispatcher().dispatch(player, command);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,15 +13,15 @@ import org.apollo.game.model.inter.InterfaceType;
|
||||
*/
|
||||
public final class DialogueButtonHandler extends EventHandler<ButtonEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ButtonEvent event) {
|
||||
if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) {
|
||||
boolean breakChain = player.getInterfaceSet().buttonClicked(event.getWidgetId());
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ButtonEvent event) {
|
||||
if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) {
|
||||
boolean breakChain = player.getInterfaceSet().buttonClicked(event.getWidgetId());
|
||||
|
||||
if (breakChain) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
}
|
||||
if (breakChain) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,11 +13,11 @@ import org.apollo.game.model.inter.InterfaceType;
|
||||
*/
|
||||
public final class DialogueContinueEventHandler extends EventHandler<DialogueContinueEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, DialogueContinueEvent event) {
|
||||
if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) {
|
||||
player.getInterfaceSet().continueRequested();
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, DialogueContinueEvent event) {
|
||||
if (player.getInterfaceSet().contains(InterfaceType.DIALOGUE)) {
|
||||
player.getInterfaceSet().continueRequested();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,9 +12,9 @@ import org.apollo.game.model.entity.Player;
|
||||
*/
|
||||
public final class EnteredAmountEventHandler extends EventHandler<EnteredAmountEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, EnteredAmountEvent event) {
|
||||
player.getInterfaceSet().enteredAmount(event.getAmount());
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, EnteredAmountEvent event) {
|
||||
player.getInterfaceSet().enteredAmount(event.getAmount());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,81 +20,81 @@ import org.apollo.util.LanguageUtil;
|
||||
*/
|
||||
public final class EquipEventHandler extends EventHandler<ItemOptionEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemOptionEvent event) {
|
||||
if (event.getOption() != 2 || event.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemOptionEvent event) {
|
||||
if (event.getOption() != 2 || event.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,36 +16,36 @@ import org.apollo.game.model.inv.SynchronizationInventoryListener;
|
||||
*/
|
||||
public final class ItemOnItemVerificationHandler extends EventHandler<ItemOnItemEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemOnItemEvent event) {
|
||||
Inventory inventory;
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemOnItemEvent event) {
|
||||
Inventory inventory;
|
||||
|
||||
switch (event.getInterfaceId()) {
|
||||
case SynchronizationInventoryListener.INVENTORY_ID:
|
||||
case BankConstants.SIDEBAR_INVENTORY_ID:
|
||||
inventory = player.getInventory();
|
||||
break;
|
||||
case SynchronizationInventoryListener.EQUIPMENT_ID:
|
||||
inventory = player.getEquipment();
|
||||
break;
|
||||
case BankConstants.BANK_INVENTORY_ID:
|
||||
inventory = player.getBank();
|
||||
break;
|
||||
default:
|
||||
ctx.breakHandlerChain();
|
||||
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();
|
||||
}
|
||||
switch (event.getInterfaceId()) {
|
||||
case SynchronizationInventoryListener.INVENTORY_ID:
|
||||
case BankConstants.SIDEBAR_INVENTORY_ID:
|
||||
inventory = player.getInventory();
|
||||
break;
|
||||
case SynchronizationInventoryListener.EQUIPMENT_ID:
|
||||
inventory = player.getEquipment();
|
||||
break;
|
||||
case BankConstants.BANK_INVENTORY_ID:
|
||||
inventory = player.getBank();
|
||||
break;
|
||||
default:
|
||||
ctx.breakHandlerChain();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,27 +16,27 @@ import org.apollo.game.model.inv.SynchronizationInventoryListener;
|
||||
*/
|
||||
public final class ItemOnObjectVerificationHandler extends EventHandler<ItemOnObjectEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemOnObjectEvent event) {
|
||||
if (event.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID
|
||||
&& event.getInterfaceId() != BankConstants.SIDEBAR_INVENTORY_ID) {
|
||||
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;
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemOnObjectEvent event) {
|
||||
if (event.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID
|
||||
&& event.getInterfaceId() != BankConstants.SIDEBAR_INVENTORY_ID) {
|
||||
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> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, InventoryItemEvent event) {
|
||||
Inventory inventory;
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, InventoryItemEvent event) {
|
||||
Inventory inventory;
|
||||
|
||||
switch (event.getInterfaceId()) {
|
||||
case SynchronizationInventoryListener.INVENTORY_ID:
|
||||
case BankConstants.SIDEBAR_INVENTORY_ID:
|
||||
inventory = player.getInventory();
|
||||
break;
|
||||
case SynchronizationInventoryListener.EQUIPMENT_ID:
|
||||
inventory = player.getEquipment();
|
||||
break;
|
||||
case BankConstants.BANK_INVENTORY_ID:
|
||||
inventory = player.getBank();
|
||||
break;
|
||||
default:
|
||||
ctx.breakHandlerChain();
|
||||
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();
|
||||
}
|
||||
switch (event.getInterfaceId()) {
|
||||
case SynchronizationInventoryListener.INVENTORY_ID:
|
||||
case BankConstants.SIDEBAR_INVENTORY_ID:
|
||||
inventory = player.getInventory();
|
||||
break;
|
||||
case SynchronizationInventoryListener.EQUIPMENT_ID:
|
||||
inventory = player.getEquipment();
|
||||
break;
|
||||
case BankConstants.BANK_INVENTORY_ID:
|
||||
inventory = player.getBank();
|
||||
break;
|
||||
default:
|
||||
ctx.breakHandlerChain();
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,18 +15,18 @@ import org.apollo.game.model.entity.Player;
|
||||
*/
|
||||
public final class NpcActionVerificationHandler extends EventHandler<NpcActionEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, NpcActionEvent event) {
|
||||
if (event.getIndex() < 0 || event.getIndex() >= WorldConstants.MAXIMUM_NPCS) {
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
|
||||
Npc npc = World.getWorld().getNpcRepository().get(event.getIndex());
|
||||
|
||||
if (npc == null || !player.getPosition().isWithinDistance(npc.getPosition(), 15)) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, NpcActionEvent event) {
|
||||
if (event.getIndex() < 0 || event.getIndex() >= WorldConstants.MAXIMUM_NPCS) {
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
|
||||
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> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) {
|
||||
player.setAppearance(event.getAppearance());
|
||||
player.setNew(true);
|
||||
player.send(new CloseInterfaceEvent());
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) {
|
||||
player.setAppearance(event.getAppearance());
|
||||
player.setNew(true);
|
||||
player.send(new CloseInterfaceEvent());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,71 +14,71 @@ import org.apollo.game.model.settings.Gender;
|
||||
*/
|
||||
public final class PlayerDesignVerificationHandler extends EventHandler<PlayerDesignEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) {
|
||||
if (!valid(event.getAppearance())) {
|
||||
ctx.breakHandlerChain();
|
||||
}
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, PlayerDesignEvent event) {
|
||||
if (!valid(event.getAppearance())) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
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.");
|
||||
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.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a {@link Gender#FEMALE} style combination is valid.
|
||||
*
|
||||
* @param appearance The appearance combination.
|
||||
* @return {@code true} if so, {@code false} if not.
|
||||
*/
|
||||
private boolean validFemaleStyle(Appearance appearance) {
|
||||
int[] styles = appearance.getStyle();
|
||||
int[] minStyles = new int[] { 45, 255, 56, 61, 67, 70, 79 };
|
||||
int[] maxStyles = new int[] { 54, 255, 60, 65, 68, 77, 80 };
|
||||
for (int i = 0; i < styles.length; i++) {
|
||||
if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
/**
|
||||
* Checks if a {@link Gender#FEMALE} style combination is valid.
|
||||
*
|
||||
* @param appearance The appearance combination.
|
||||
* @return {@code true} if so, {@code false} if not.
|
||||
*/
|
||||
private boolean validFemaleStyle(Appearance appearance) {
|
||||
int[] styles = appearance.getStyle();
|
||||
int[] minStyles = new int[] { 45, 255, 56, 61, 67, 70, 79 };
|
||||
int[] maxStyles = new int[] { 54, 255, 60, 65, 68, 77, 80 };
|
||||
for (int i = 0; i < styles.length; i++) {
|
||||
if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a {@link Gender#MALE} style combination is valid.
|
||||
*
|
||||
* @param appearance The appearance combination.
|
||||
* @return {@code true} if so, {@code false} if not.
|
||||
*/
|
||||
private boolean validMaleStyle(Appearance appearance) {
|
||||
int[] styles = appearance.getStyle();
|
||||
int[] minStyles = new int[] { 0, 10, 18, 26, 33, 36, 42 };
|
||||
int[] maxStyles = new int[] { 8, 17, 25, 31, 34, 40, 43 };
|
||||
for (int i = 0; i < styles.length; i++) {
|
||||
if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
/**
|
||||
* Checks if a {@link Gender#MALE} style combination is valid.
|
||||
*
|
||||
* @param appearance The appearance combination.
|
||||
* @return {@code true} if so, {@code false} if not.
|
||||
*/
|
||||
private boolean validMaleStyle(Appearance appearance) {
|
||||
int[] styles = appearance.getStyle();
|
||||
int[] minStyles = new int[] { 0, 10, 18, 26, 33, 36, 42 };
|
||||
int[] maxStyles = new int[] { 8, 17, 25, 31, 34, 40, 43 };
|
||||
for (int i = 0; i < styles.length; i++) {
|
||||
if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,43 +16,43 @@ import org.apollo.game.model.inv.SynchronizationInventoryListener;
|
||||
*/
|
||||
public final class RemoveEventHandler extends EventHandler<ItemActionEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) {
|
||||
if (event.getOption() == 1 && event.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) {
|
||||
Inventory inventory = player.getInventory();
|
||||
Inventory equipment = player.getEquipment();
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, ItemActionEvent event) {
|
||||
if (event.getOption() == 1 && event.getInterfaceId() == SynchronizationInventoryListener.EQUIPMENT_ID) {
|
||||
Inventory inventory = player.getInventory();
|
||||
Inventory equipment = player.getEquipment();
|
||||
|
||||
int slot = event.getSlot();
|
||||
Item item = equipment.get(slot);
|
||||
int id = item.getId();
|
||||
int slot = event.getSlot();
|
||||
Item item = equipment.get(slot);
|
||||
int id = item.getId();
|
||||
|
||||
if (inventory.freeSlots() == 0 && !item.getDefinition().isStackable()) {
|
||||
inventory.forceCapacityExceeded();
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
if (inventory.freeSlots() == 0 && !item.getDefinition().isStackable()) {
|
||||
inventory.forceCapacityExceeded();
|
||||
ctx.breakHandlerChain();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean removed = true;
|
||||
boolean removed = true;
|
||||
|
||||
inventory.stopFiringEvents();
|
||||
equipment.stopFiringEvents();
|
||||
inventory.stopFiringEvents();
|
||||
equipment.stopFiringEvents();
|
||||
|
||||
try {
|
||||
int remaining = inventory.add(id, item.getAmount());
|
||||
removed = remaining == 0;
|
||||
equipment.set(slot, removed ? null : new Item(id, remaining));
|
||||
} finally {
|
||||
inventory.startFiringEvents();
|
||||
equipment.startFiringEvents();
|
||||
}
|
||||
try {
|
||||
int remaining = inventory.add(id, item.getAmount());
|
||||
removed = remaining == 0;
|
||||
equipment.set(slot, removed ? null : new Item(id, remaining));
|
||||
} finally {
|
||||
inventory.startFiringEvents();
|
||||
equipment.startFiringEvents();
|
||||
}
|
||||
|
||||
if (removed) {
|
||||
inventory.forceRefresh();
|
||||
equipment.forceRefresh(slot);
|
||||
} else {
|
||||
inventory.forceCapacityExceeded();
|
||||
}
|
||||
}
|
||||
if (removed) {
|
||||
inventory.forceRefresh();
|
||||
equipment.forceRefresh(slot);
|
||||
} else {
|
||||
inventory.forceCapacityExceeded();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,32 +16,32 @@ import org.apollo.game.model.inv.SynchronizationInventoryListener;
|
||||
*/
|
||||
public final class SwitchItemEventHandler extends EventHandler<SwitchItemEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, SwitchItemEvent event) {
|
||||
Inventory inventory;
|
||||
boolean insertPermitted = false;
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, SwitchItemEvent event) {
|
||||
Inventory inventory;
|
||||
boolean insertPermitted = false;
|
||||
|
||||
switch (event.getInterfaceId()) {
|
||||
case SynchronizationInventoryListener.INVENTORY_ID:
|
||||
case BankConstants.SIDEBAR_INVENTORY_ID:
|
||||
inventory = player.getInventory();
|
||||
break;
|
||||
case SynchronizationInventoryListener.EQUIPMENT_ID:
|
||||
inventory = player.getEquipment();
|
||||
break;
|
||||
case BankConstants.BANK_INVENTORY_ID:
|
||||
inventory = player.getBank();
|
||||
insertPermitted = true;
|
||||
break;
|
||||
default:
|
||||
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());
|
||||
}
|
||||
switch (event.getInterfaceId()) {
|
||||
case SynchronizationInventoryListener.INVENTORY_ID:
|
||||
case BankConstants.SIDEBAR_INVENTORY_ID:
|
||||
inventory = player.getInventory();
|
||||
break;
|
||||
case SynchronizationInventoryListener.EQUIPMENT_ID:
|
||||
inventory = player.getEquipment();
|
||||
break;
|
||||
case BankConstants.BANK_INVENTORY_ID:
|
||||
inventory = player.getBank();
|
||||
insertPermitted = true;
|
||||
break;
|
||||
default:
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,28 +14,28 @@ import org.apollo.game.model.entity.WalkingQueue;
|
||||
*/
|
||||
public final class WalkEventHandler extends EventHandler<WalkEvent> {
|
||||
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, WalkEvent event) {
|
||||
WalkingQueue queue = player.getWalkingQueue();
|
||||
@Override
|
||||
public void handle(EventHandlerContext ctx, Player player, WalkEvent event) {
|
||||
WalkingQueue queue = player.getWalkingQueue();
|
||||
|
||||
Position[] steps = event.getSteps();
|
||||
for (int i = 0; i < steps.length; i++) {
|
||||
Position step = steps[i];
|
||||
if (i == 0) {
|
||||
if (!queue.addFirstStep(step)) {
|
||||
return; // ignore packet
|
||||
}
|
||||
} else {
|
||||
queue.addStep(step);
|
||||
}
|
||||
Position[] steps = event.getSteps();
|
||||
for (int i = 0; i < steps.length; i++) {
|
||||
Position step = steps[i];
|
||||
if (i == 0) {
|
||||
if (!queue.addFirstStep(step)) {
|
||||
return; // ignore packet
|
||||
}
|
||||
|
||||
queue.setRunningQueue(event.isRunning() || player.isRunning());
|
||||
|
||||
if (queue.size() > 0) {
|
||||
player.stopAction();
|
||||
}
|
||||
player.getInterfaceSet().close();
|
||||
} else {
|
||||
queue.addStep(step);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
/**
|
||||
* The username of the befriended player.
|
||||
*/
|
||||
private final String username;
|
||||
/**
|
||||
* The username of the befriended player.
|
||||
*/
|
||||
private final String username;
|
||||
|
||||
/**
|
||||
* Creates a new befriend user event.
|
||||
*
|
||||
* @param username The befriended player's username.
|
||||
*/
|
||||
public AddFriendEvent(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
/**
|
||||
* Creates a new befriend user event.
|
||||
*
|
||||
* @param username The befriended player's username.
|
||||
*/
|
||||
public AddFriendEvent(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username of the befriended player.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
/**
|
||||
* Gets the username of the befriended player.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,78 +5,78 @@ import org.apollo.game.model.Item;
|
||||
|
||||
public final class AddGlobalTileItemEvent extends Event {
|
||||
|
||||
/**
|
||||
* The item to add to the tile.
|
||||
*/
|
||||
private final Item item;
|
||||
/**
|
||||
* The item to add to the tile.
|
||||
*/
|
||||
private final Item item;
|
||||
|
||||
/**
|
||||
* The position offset
|
||||
*/
|
||||
private final int positionOffset;
|
||||
/**
|
||||
* The position offset
|
||||
*/
|
||||
private final int positionOffset;
|
||||
|
||||
/**
|
||||
* The index of the player who dropped the item.
|
||||
*/
|
||||
private final int index;
|
||||
/**
|
||||
* The index of the player who dropped the item.
|
||||
*/
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Creates the add global tile item event.
|
||||
*
|
||||
* @param item The item to add to the tile.
|
||||
* @param index The index of the player who dropped the item.
|
||||
*/
|
||||
public AddGlobalTileItemEvent(Item item, int index) {
|
||||
this(item, index, 0);
|
||||
}
|
||||
/**
|
||||
* Creates the add global tile item event.
|
||||
*
|
||||
* @param item The item to add to the tile.
|
||||
* @param index The index of the player who dropped the item.
|
||||
*/
|
||||
public AddGlobalTileItemEvent(Item item, int index) {
|
||||
this(item, index, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the add global tile item event.
|
||||
*
|
||||
* @param item The item to add to the tile.
|
||||
* @param index The index of the player who dropped the item.
|
||||
* @param positionOffset The offset from the 'base' position.
|
||||
*/
|
||||
public AddGlobalTileItemEvent(Item item, int index, int positionOffset) {
|
||||
this.item = item;
|
||||
this.index = index;
|
||||
this.positionOffset = positionOffset;
|
||||
}
|
||||
/**
|
||||
* Creates the add global tile item event.
|
||||
*
|
||||
* @param item The item to add to the tile.
|
||||
* @param index The index of the player who dropped the item.
|
||||
* @param positionOffset The offset from the 'base' position.
|
||||
*/
|
||||
public AddGlobalTileItemEvent(Item item, int index, int positionOffset) {
|
||||
this.item = item;
|
||||
this.index = index;
|
||||
this.positionOffset = positionOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of the item.
|
||||
*
|
||||
* @return The id.
|
||||
*/
|
||||
public int getId() {
|
||||
return item.getId();
|
||||
}
|
||||
/**
|
||||
* Gets the id of the item.
|
||||
*
|
||||
* @return The id.
|
||||
*/
|
||||
public int getId() {
|
||||
return item.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of the item.
|
||||
*
|
||||
* @return The amount.
|
||||
*/
|
||||
public int getAmount() {
|
||||
return item.getAmount();
|
||||
}
|
||||
/**
|
||||
* Gets the amount of the item.
|
||||
*
|
||||
* @return The amount.
|
||||
*/
|
||||
public int getAmount() {
|
||||
return item.getAmount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of the player who dropped the item.
|
||||
*
|
||||
* @return The index.
|
||||
*/
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
/**
|
||||
* Gets the index of the player who dropped the item.
|
||||
*
|
||||
* @return The index.
|
||||
*/
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the offset from the 'base' position.
|
||||
*
|
||||
* @return The offset.
|
||||
*/
|
||||
public int getPositionOffset() {
|
||||
return positionOffset;
|
||||
}
|
||||
/**
|
||||
* Gets the offset from the 'base' position.
|
||||
*
|
||||
* @return The offset.
|
||||
*/
|
||||
public int getPositionOffset() {
|
||||
return positionOffset;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class AddIgnoreEvent extends Event {
|
||||
|
||||
/**
|
||||
* The username of the ignored player.
|
||||
*/
|
||||
private final String username;
|
||||
/**
|
||||
* The username of the ignored player.
|
||||
*/
|
||||
private final String username;
|
||||
|
||||
/**
|
||||
* Creates a new ignore player event.
|
||||
*
|
||||
* @param username The ignored player's username.
|
||||
*/
|
||||
public AddIgnoreEvent(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
/**
|
||||
* Creates a new ignore player event.
|
||||
*
|
||||
* @param username The ignored player's username.
|
||||
*/
|
||||
public AddIgnoreEvent(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username of the ignored player.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
/**
|
||||
* Gets the username of the ignored player.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,61 +10,61 @@ import org.apollo.game.model.Item;
|
||||
*/
|
||||
public final class AddTileItemEvent extends Event {
|
||||
|
||||
/**
|
||||
* The item to add to the tile.
|
||||
*/
|
||||
private final Item item;
|
||||
/**
|
||||
* The item to add to the tile.
|
||||
*/
|
||||
private final Item item;
|
||||
|
||||
/**
|
||||
* The position offset
|
||||
*/
|
||||
private final int positionOffset;
|
||||
/**
|
||||
* The position offset
|
||||
*/
|
||||
private final int positionOffset;
|
||||
|
||||
/**
|
||||
* Creates an add tile item event.
|
||||
*
|
||||
* @param item The item to add to the tile.
|
||||
*/
|
||||
public AddTileItemEvent(Item item) {
|
||||
this(item, 0);
|
||||
}
|
||||
/**
|
||||
* Creates an add tile item event.
|
||||
*
|
||||
* @param item The item to add to the tile.
|
||||
*/
|
||||
public AddTileItemEvent(Item item) {
|
||||
this(item, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an add tile item event.
|
||||
*
|
||||
* @param item The item to add to the tile.
|
||||
* @param positionOffset The offset from the 'base' position.
|
||||
*/
|
||||
public AddTileItemEvent(Item item, int positionOffset) {
|
||||
this.item = item;
|
||||
this.positionOffset = positionOffset;
|
||||
}
|
||||
/**
|
||||
* Creates an add tile item event.
|
||||
*
|
||||
* @param item The item to add to the tile.
|
||||
* @param positionOffset The offset from the 'base' position.
|
||||
*/
|
||||
public AddTileItemEvent(Item item, int positionOffset) {
|
||||
this.item = item;
|
||||
this.positionOffset = positionOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of the item.
|
||||
*
|
||||
* @return The id.
|
||||
*/
|
||||
public int getId() {
|
||||
return item.getId();
|
||||
}
|
||||
/**
|
||||
* Gets the id of the item.
|
||||
*
|
||||
* @return The id.
|
||||
*/
|
||||
public int getId() {
|
||||
return item.getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of the item.
|
||||
*
|
||||
* @return The amount.
|
||||
*/
|
||||
public int getAmount() {
|
||||
return item.getAmount();
|
||||
}
|
||||
/**
|
||||
* Gets the amount of the item.
|
||||
*
|
||||
* @return The amount.
|
||||
*/
|
||||
public int getAmount() {
|
||||
return item.getAmount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the offset from the 'base' position.
|
||||
*
|
||||
* @return The offset.
|
||||
*/
|
||||
public int getPositionOffset() {
|
||||
return positionOffset;
|
||||
}
|
||||
/**
|
||||
* Gets the offset from the 'base' position.
|
||||
*
|
||||
* @return The offset.
|
||||
*/
|
||||
public int getPositionOffset() {
|
||||
return positionOffset;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,40 +9,40 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class ArrowKeyEvent extends Event {
|
||||
|
||||
/**
|
||||
* The camera roll.
|
||||
*/
|
||||
private final int roll;
|
||||
/**
|
||||
* The camera roll.
|
||||
*/
|
||||
private final int roll;
|
||||
|
||||
/**
|
||||
* The camera yaw.
|
||||
*/
|
||||
private final int yaw;
|
||||
/**
|
||||
* The camera yaw.
|
||||
*/
|
||||
private final int yaw;
|
||||
|
||||
/**
|
||||
* Creates a new arrow key event.
|
||||
*/
|
||||
public ArrowKeyEvent(int roll, int yaw) {
|
||||
this.roll = roll;
|
||||
this.yaw = yaw;
|
||||
}
|
||||
/**
|
||||
* Creates a new arrow key event.
|
||||
*/
|
||||
public ArrowKeyEvent(int roll, int yaw) {
|
||||
this.roll = roll;
|
||||
this.yaw = yaw;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the roll of the camera.
|
||||
*
|
||||
* @return The roll.
|
||||
*/
|
||||
public int getRoll() {
|
||||
return roll;
|
||||
}
|
||||
/**
|
||||
* Gets the roll of the camera.
|
||||
*
|
||||
* @return The roll.
|
||||
*/
|
||||
public int getRoll() {
|
||||
return roll;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the yaw of the camera.
|
||||
*
|
||||
* @return The yaw.
|
||||
*/
|
||||
public int getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
/**
|
||||
* Gets the yaw of the camera.
|
||||
*
|
||||
* @return The yaw.
|
||||
*/
|
||||
public int getYaw() {
|
||||
return yaw;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class ButtonEvent extends Event {
|
||||
|
||||
/**
|
||||
* The widget id.
|
||||
*/
|
||||
private final int widgetId;
|
||||
/**
|
||||
* The widget id.
|
||||
*/
|
||||
private final int widgetId;
|
||||
|
||||
/**
|
||||
* Creates the button event.
|
||||
*
|
||||
* @param widgetId The widget id.
|
||||
*/
|
||||
public ButtonEvent(int widgetId) {
|
||||
this.widgetId = widgetId;
|
||||
}
|
||||
/**
|
||||
* Creates the button event.
|
||||
*
|
||||
* @param widgetId The widget id.
|
||||
*/
|
||||
public ButtonEvent(int widgetId) {
|
||||
this.widgetId = widgetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the widget id.
|
||||
*
|
||||
* @return The widget id.
|
||||
*/
|
||||
public int getWidgetId() {
|
||||
return widgetId;
|
||||
}
|
||||
/**
|
||||
* Gets the widget id.
|
||||
*
|
||||
* @return The widget id.
|
||||
*/
|
||||
public int getWidgetId() {
|
||||
return widgetId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,75 +9,75 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class ChatEvent extends Event {
|
||||
|
||||
/**
|
||||
* The text color.
|
||||
*/
|
||||
private final int color;
|
||||
/**
|
||||
* The text color.
|
||||
*/
|
||||
private final int color;
|
||||
|
||||
/**
|
||||
* The compressed message.
|
||||
*/
|
||||
private final byte[] compressedMessage;
|
||||
/**
|
||||
* The compressed message.
|
||||
*/
|
||||
private final byte[] compressedMessage;
|
||||
|
||||
/**
|
||||
* The text effects.
|
||||
*/
|
||||
private final int effects;
|
||||
/**
|
||||
* The text effects.
|
||||
*/
|
||||
private final int effects;
|
||||
|
||||
/**
|
||||
* The message.
|
||||
*/
|
||||
private final String message;
|
||||
/**
|
||||
* The message.
|
||||
*/
|
||||
private final String message;
|
||||
|
||||
/**
|
||||
* Creates a new chat event.
|
||||
*
|
||||
* @param message The message.
|
||||
* @param compressedMessage The compressed message.
|
||||
* @param color The text color.
|
||||
* @param effects The text effects.
|
||||
*/
|
||||
public ChatEvent(String message, byte[] compressedMessage, int color, int effects) {
|
||||
this.message = message;
|
||||
this.compressedMessage = compressedMessage;
|
||||
this.color = color;
|
||||
this.effects = effects;
|
||||
}
|
||||
/**
|
||||
* Creates a new chat event.
|
||||
*
|
||||
* @param message The message.
|
||||
* @param compressedMessage The compressed message.
|
||||
* @param color The text color.
|
||||
* @param effects The text effects.
|
||||
*/
|
||||
public ChatEvent(String message, byte[] compressedMessage, int color, int effects) {
|
||||
this.message = message;
|
||||
this.compressedMessage = compressedMessage;
|
||||
this.color = color;
|
||||
this.effects = effects;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compressed message.
|
||||
*
|
||||
* @return The compressed message.
|
||||
*/
|
||||
public byte[] getCompressedMessage() {
|
||||
return compressedMessage;
|
||||
}
|
||||
/**
|
||||
* Gets the compressed message.
|
||||
*
|
||||
* @return The compressed message.
|
||||
*/
|
||||
public byte[] getCompressedMessage() {
|
||||
return compressedMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message.
|
||||
*
|
||||
* @return The message.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
/**
|
||||
* Gets the message.
|
||||
*
|
||||
* @return The message.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text color.
|
||||
*
|
||||
* @return The text color.
|
||||
*/
|
||||
public int getTextColor() {
|
||||
return color;
|
||||
}
|
||||
/**
|
||||
* Gets the text color.
|
||||
*
|
||||
* @return The text color.
|
||||
*/
|
||||
public int getTextColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the text effects.
|
||||
*
|
||||
* @return The text effects.
|
||||
*/
|
||||
public int getTextEffects() {
|
||||
return effects;
|
||||
}
|
||||
/**
|
||||
* Gets the text effects.
|
||||
*
|
||||
* @return The text effects.
|
||||
*/
|
||||
public int getTextEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class CommandEvent extends Event {
|
||||
|
||||
/**
|
||||
* The command.
|
||||
*/
|
||||
private final String command;
|
||||
/**
|
||||
* The command.
|
||||
*/
|
||||
private final String command;
|
||||
|
||||
/**
|
||||
* Creates the command event.
|
||||
*
|
||||
* @param command The command.
|
||||
*/
|
||||
public CommandEvent(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
/**
|
||||
* Creates the command event.
|
||||
*
|
||||
* @param command The command.
|
||||
*/
|
||||
public CommandEvent(String command) {
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the command.
|
||||
*
|
||||
* @return The command.
|
||||
*/
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
/**
|
||||
* Gets the command.
|
||||
*
|
||||
* @return The command.
|
||||
*/
|
||||
public String getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,43 +9,43 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class ConfigEvent extends Event {
|
||||
|
||||
/**
|
||||
* The identifier.
|
||||
*/
|
||||
private final int id;
|
||||
/**
|
||||
* The identifier.
|
||||
*/
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* The value.
|
||||
*/
|
||||
private final int value;
|
||||
/**
|
||||
* The value.
|
||||
*/
|
||||
private final int value;
|
||||
|
||||
/**
|
||||
* Creates a new config event.
|
||||
*
|
||||
* @param id The config's identifier.
|
||||
* @param value The value.
|
||||
*/
|
||||
public ConfigEvent(int id, int value) {
|
||||
this.id = id;
|
||||
this.value = value;
|
||||
}
|
||||
/**
|
||||
* Creates a new config event.
|
||||
*
|
||||
* @param id The config's identifier.
|
||||
* @param value The value.
|
||||
*/
|
||||
public ConfigEvent(int id, int value) {
|
||||
this.id = id;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the config's identifier.
|
||||
*
|
||||
* @return The config id.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* Gets the config's identifier.
|
||||
*
|
||||
* @return The config id.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the config's value.
|
||||
*
|
||||
* @return The config value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
/**
|
||||
* Gets the config's value.
|
||||
*
|
||||
* @return The config value.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,27 +10,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class DialogueContinueEvent extends Event {
|
||||
|
||||
/**
|
||||
* The interface id.
|
||||
*/
|
||||
private final int interfaceId;
|
||||
/**
|
||||
* The interface id.
|
||||
*/
|
||||
private final int interfaceId;
|
||||
|
||||
/**
|
||||
* Creates a new dialogue continue event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
*/
|
||||
public DialogueContinueEvent(int interfaceId) {
|
||||
this.interfaceId = interfaceId;
|
||||
}
|
||||
/**
|
||||
* Creates a new dialogue continue event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
*/
|
||||
public DialogueContinueEvent(int interfaceId) {
|
||||
this.interfaceId = interfaceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the interface id of the button.
|
||||
*
|
||||
* @return The interface id.
|
||||
*/
|
||||
public int getInterfaceId() {
|
||||
return interfaceId;
|
||||
}
|
||||
/**
|
||||
* Gets the interface id of the button.
|
||||
*
|
||||
* @return The interface id.
|
||||
*/
|
||||
public int getInterfaceId() {
|
||||
return interfaceId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class DisplayCrossbonesEvent extends Event {
|
||||
|
||||
/**
|
||||
* Whether or not the crossbones should be displayed.
|
||||
*/
|
||||
private final boolean display;
|
||||
/**
|
||||
* Whether or not the crossbones should be displayed.
|
||||
*/
|
||||
private final boolean display;
|
||||
|
||||
/**
|
||||
* Creates a display crossbones event.
|
||||
*
|
||||
* @param display Whether or not the crossbones should be displayed.
|
||||
*/
|
||||
public DisplayCrossbonesEvent(boolean display) {
|
||||
this.display = display;
|
||||
}
|
||||
/**
|
||||
* Creates a display crossbones event.
|
||||
*
|
||||
* @param display Whether or not the crossbones should be displayed.
|
||||
*/
|
||||
public DisplayCrossbonesEvent(boolean display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the crossbones will be displayed.
|
||||
*
|
||||
* @return {@code true} if the crossbones will be displayed, otherwise {@code false}.
|
||||
*/
|
||||
public boolean isDisplayed() {
|
||||
return display;
|
||||
}
|
||||
/**
|
||||
* Indicates whether the crossbones will be displayed.
|
||||
*
|
||||
* @return {@code true} if the crossbones will be displayed, otherwise {@code false}.
|
||||
*/
|
||||
public boolean isDisplayed() {
|
||||
return display;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class DisplayTabInterfaceEvent extends Event {
|
||||
|
||||
/**
|
||||
* The tab index.
|
||||
*/
|
||||
private final int tab;
|
||||
/**
|
||||
* The tab index.
|
||||
*/
|
||||
private final int tab;
|
||||
|
||||
/**
|
||||
* Creates a new display tab interface event.
|
||||
*
|
||||
* @param tab The index of the tab to display.
|
||||
*/
|
||||
public DisplayTabInterfaceEvent(int tab) {
|
||||
this.tab = tab;
|
||||
}
|
||||
/**
|
||||
* Creates a new display tab interface event.
|
||||
*
|
||||
* @param tab The index of the tab to display.
|
||||
*/
|
||||
public DisplayTabInterfaceEvent(int tab) {
|
||||
this.tab = tab;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of the tab to display.
|
||||
*
|
||||
* @return The tab index.
|
||||
*/
|
||||
public int getTab() {
|
||||
return tab;
|
||||
}
|
||||
/**
|
||||
* Gets the index of the tab to display.
|
||||
*
|
||||
* @return The tab index.
|
||||
*/
|
||||
public int getTab() {
|
||||
return tab;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class EnteredAmountEvent extends Event {
|
||||
|
||||
/**
|
||||
* The amount.
|
||||
*/
|
||||
private final int amount;
|
||||
/**
|
||||
* The amount.
|
||||
*/
|
||||
private final int amount;
|
||||
|
||||
/**
|
||||
* Creates the entered amount event.
|
||||
*
|
||||
* @param amount The amount.
|
||||
*/
|
||||
public EnteredAmountEvent(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
/**
|
||||
* Creates the entered amount event.
|
||||
*
|
||||
* @param amount The amount.
|
||||
*/
|
||||
public EnteredAmountEvent(int amount) {
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount.
|
||||
*
|
||||
* @return The amount.
|
||||
*/
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
/**
|
||||
* Gets the amount.
|
||||
*
|
||||
* @return The amount.
|
||||
*/
|
||||
public int getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class FifthItemActionEvent extends ItemActionEvent {
|
||||
|
||||
/**
|
||||
* Creates the fifth item action event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The item id.
|
||||
* @param slot The item slot.
|
||||
*/
|
||||
public FifthItemActionEvent(int interfaceId, int id, int slot) {
|
||||
super(5, interfaceId, id, slot);
|
||||
}
|
||||
/**
|
||||
* Creates the fifth item action event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The item id.
|
||||
* @param slot The item slot.
|
||||
*/
|
||||
public FifthItemActionEvent(int interfaceId, int id, int slot) {
|
||||
super(5, interfaceId, id, slot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class FifthItemOptionEvent extends ItemOptionEvent {
|
||||
|
||||
/**
|
||||
* Creates the fifth item option event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
public FifthItemOptionEvent(int interfaceId, int id, int slot) {
|
||||
super(5, interfaceId, id, slot);
|
||||
}
|
||||
/**
|
||||
* Creates the fifth item option event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
public FifthItemOptionEvent(int interfaceId, int id, int slot) {
|
||||
super(5, interfaceId, id, slot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,13 +7,13 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class FifthPlayerActionEvent extends PlayerActionEvent {
|
||||
|
||||
/**
|
||||
* Creates a fifth player action event.
|
||||
*
|
||||
* @param playerIndex The index of the clicked player.
|
||||
*/
|
||||
public FifthPlayerActionEvent(int playerIndex) {
|
||||
super(5, playerIndex);
|
||||
}
|
||||
/**
|
||||
* Creates a fifth player action event.
|
||||
*
|
||||
* @param playerIndex The index of the clicked player.
|
||||
*/
|
||||
public FifthPlayerActionEvent(int playerIndex) {
|
||||
super(5, playerIndex);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class FirstItemActionEvent extends ItemActionEvent {
|
||||
|
||||
/**
|
||||
* Creates the first item action event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The item id.
|
||||
* @param slot The item slot.
|
||||
*/
|
||||
public FirstItemActionEvent(int interfaceId, int id, int slot) {
|
||||
super(1, interfaceId, id, slot);
|
||||
}
|
||||
/**
|
||||
* Creates the first item action event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The item id.
|
||||
* @param slot The item slot.
|
||||
*/
|
||||
public FirstItemActionEvent(int interfaceId, int id, int slot) {
|
||||
super(1, interfaceId, id, slot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class FirstItemOptionEvent extends ItemOptionEvent {
|
||||
|
||||
/**
|
||||
* Creates the first item option event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
public FirstItemOptionEvent(int interfaceId, int id, int slot) {
|
||||
super(1, interfaceId, id, slot);
|
||||
}
|
||||
/**
|
||||
* Creates the first item option event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
public FirstItemOptionEvent(int interfaceId, int id, int slot) {
|
||||
super(1, interfaceId, id, slot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,13 +7,13 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class FirstNpcActionEvent extends NpcActionEvent {
|
||||
|
||||
/**
|
||||
* Creates a new first npc action event.
|
||||
*
|
||||
* @param index The index of the npc.
|
||||
*/
|
||||
public FirstNpcActionEvent(int index) {
|
||||
super(1, index);
|
||||
}
|
||||
/**
|
||||
* Creates a new first npc action event.
|
||||
*
|
||||
* @param index The index of the npc.
|
||||
*/
|
||||
public FirstNpcActionEvent(int index) {
|
||||
super(1, index);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,14 +9,14 @@ import org.apollo.game.model.Position;
|
||||
*/
|
||||
public final class FirstObjectActionEvent extends ObjectActionEvent {
|
||||
|
||||
/**
|
||||
* Creates the first object action event.
|
||||
*
|
||||
* @param id The id.
|
||||
* @param position The position.
|
||||
*/
|
||||
public FirstObjectActionEvent(int id, Position position) {
|
||||
super(1, id, position);
|
||||
}
|
||||
/**
|
||||
* Creates the first object action event.
|
||||
*
|
||||
* @param id The id.
|
||||
* @param position The position.
|
||||
*/
|
||||
public FirstObjectActionEvent(int id, Position position) {
|
||||
super(1, id, position);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,13 +7,13 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class FirstPlayerActionEvent extends PlayerActionEvent {
|
||||
|
||||
/**
|
||||
* Creates a first player action event.
|
||||
*
|
||||
* @param playerIndex The index of the clicked player.
|
||||
*/
|
||||
public FirstPlayerActionEvent(int playerIndex) {
|
||||
super(1, playerIndex);
|
||||
}
|
||||
/**
|
||||
* Creates a first player action event.
|
||||
*
|
||||
* @param playerIndex The index of the clicked player.
|
||||
*/
|
||||
public FirstPlayerActionEvent(int playerIndex) {
|
||||
super(1, playerIndex);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class FocusUpdateEvent extends Event {
|
||||
|
||||
/**
|
||||
* Indicates whether the client is focused or not.
|
||||
*/
|
||||
private final boolean focused;
|
||||
/**
|
||||
* Indicates whether the client is focused or not.
|
||||
*/
|
||||
private final boolean focused;
|
||||
|
||||
/**
|
||||
* Creates a new focus update event.
|
||||
*
|
||||
* @param update The data received.
|
||||
*/
|
||||
public FocusUpdateEvent(boolean focused) {
|
||||
this.focused = focused;
|
||||
}
|
||||
/**
|
||||
* Creates a new focus update event.
|
||||
*
|
||||
* @param update The data received.
|
||||
*/
|
||||
public FocusUpdateEvent(boolean focused) {
|
||||
this.focused = focused;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether or not the client is focused.
|
||||
*
|
||||
* @return {@code true} if the client is focused, otherwise {@code false}.
|
||||
*/
|
||||
public boolean isFocused() {
|
||||
return focused;
|
||||
}
|
||||
/**
|
||||
* Indicates whether or not the client is focused.
|
||||
*
|
||||
* @return {@code true} if the client is focused, otherwise {@code false}.
|
||||
*/
|
||||
public boolean isFocused() {
|
||||
return focused;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,58 +10,58 @@ import org.apollo.game.model.settings.PrivilegeLevel;
|
||||
*/
|
||||
public final class ForwardPrivateMessageEvent extends Event {
|
||||
|
||||
/**
|
||||
* The username of the player sending the message.
|
||||
*/
|
||||
private final String username;
|
||||
/**
|
||||
* The username of the player sending the message.
|
||||
*/
|
||||
private final String username;
|
||||
|
||||
/**
|
||||
* The privilege level of the player.
|
||||
*/
|
||||
private final PrivilegeLevel privilege;
|
||||
/**
|
||||
* The privilege level of the player.
|
||||
*/
|
||||
private final PrivilegeLevel privilege;
|
||||
|
||||
/**
|
||||
* The message.
|
||||
*/
|
||||
private final byte[] message;
|
||||
/**
|
||||
* The message.
|
||||
*/
|
||||
private final byte[] message;
|
||||
|
||||
/**
|
||||
* Creates a new forward private message event.
|
||||
*
|
||||
* @param sender The player sending the message.
|
||||
* @param message The compressed message.
|
||||
*/
|
||||
public ForwardPrivateMessageEvent(String username, PrivilegeLevel level, byte[] message) {
|
||||
this.username = username;
|
||||
this.privilege = level;
|
||||
this.message = message;
|
||||
}
|
||||
/**
|
||||
* Creates a new forward private message event.
|
||||
*
|
||||
* @param sender The player sending the message.
|
||||
* @param message The compressed message.
|
||||
*/
|
||||
public ForwardPrivateMessageEvent(String username, PrivilegeLevel level, byte[] message) {
|
||||
this.username = username;
|
||||
this.privilege = level;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username of the sender.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getSenderUsername() {
|
||||
return username;
|
||||
}
|
||||
/**
|
||||
* Gets the username of the sender.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getSenderUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link PrivilegeLevel} of the sender.
|
||||
*
|
||||
* @return The privilege level.
|
||||
*/
|
||||
public PrivilegeLevel getSenderPrivilege() {
|
||||
return privilege;
|
||||
}
|
||||
/**
|
||||
* Gets the {@link PrivilegeLevel} of the sender.
|
||||
*
|
||||
* @return The privilege level.
|
||||
*/
|
||||
public PrivilegeLevel getSenderPrivilege() {
|
||||
return privilege;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compressed message.
|
||||
*
|
||||
* @return The message.
|
||||
*/
|
||||
public byte[] getCompressedMessage() {
|
||||
return message;
|
||||
}
|
||||
/**
|
||||
* Gets the compressed message.
|
||||
*
|
||||
* @return The message.
|
||||
*/
|
||||
public byte[] getCompressedMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class FourthItemActionEvent extends ItemActionEvent {
|
||||
|
||||
/**
|
||||
* Creates the fourth item action event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The item id.
|
||||
* @param slot The item slot.
|
||||
*/
|
||||
public FourthItemActionEvent(int interfaceId, int id, int slot) {
|
||||
super(4, interfaceId, id, slot);
|
||||
}
|
||||
/**
|
||||
* Creates the fourth item action event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The item id.
|
||||
* @param slot The item slot.
|
||||
*/
|
||||
public FourthItemActionEvent(int interfaceId, int id, int slot) {
|
||||
super(4, interfaceId, id, slot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,15 +7,15 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class FourthItemOptionEvent extends ItemOptionEvent {
|
||||
|
||||
/**
|
||||
* Creates the fourth item option event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
public FourthItemOptionEvent(int interfaceId, int id, int slot) {
|
||||
super(4, interfaceId, id, slot);
|
||||
}
|
||||
/**
|
||||
* Creates the fourth item option event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
public FourthItemOptionEvent(int interfaceId, int id, int slot) {
|
||||
super(4, interfaceId, id, slot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,13 +7,13 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class FourthPlayerActionEvent extends PlayerActionEvent {
|
||||
|
||||
/**
|
||||
* Creates a fourth player action event.
|
||||
*
|
||||
* @param playerIndex The index of the clicked player.
|
||||
*/
|
||||
public FourthPlayerActionEvent(int playerIndex) {
|
||||
super(4, playerIndex);
|
||||
}
|
||||
/**
|
||||
* Creates a fourth player action event.
|
||||
*
|
||||
* @param playerIndex The index of the clicked player.
|
||||
*/
|
||||
public FourthPlayerActionEvent(int playerIndex) {
|
||||
super(4, playerIndex);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,27 +10,27 @@ import org.apollo.game.model.settings.ServerStatus;
|
||||
*/
|
||||
public final class FriendServerStatusEvent extends Event {
|
||||
|
||||
/**
|
||||
* The status code of the friend server.
|
||||
*/
|
||||
private final int status;
|
||||
/**
|
||||
* The status code of the friend server.
|
||||
*/
|
||||
private final int status;
|
||||
|
||||
/**
|
||||
* Creates a new friend server status event.
|
||||
*
|
||||
* @param status The status.
|
||||
*/
|
||||
public FriendServerStatusEvent(ServerStatus status) {
|
||||
this.status = status.getCode();
|
||||
}
|
||||
/**
|
||||
* Creates a new friend server status event.
|
||||
*
|
||||
* @param status The status.
|
||||
*/
|
||||
public FriendServerStatusEvent(ServerStatus status) {
|
||||
this.status = status.getCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the status code of the friend server.
|
||||
*
|
||||
* @return The status code.
|
||||
*/
|
||||
public int getStatusCode() {
|
||||
return status;
|
||||
}
|
||||
/**
|
||||
* Gets the status code of the friend server.
|
||||
*
|
||||
* @return The status code.
|
||||
*/
|
||||
public int getStatusCode() {
|
||||
return status;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,43 +9,43 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class IdAssignmentEvent extends Event {
|
||||
|
||||
/**
|
||||
* The id of this player.
|
||||
*/
|
||||
private final int id;
|
||||
/**
|
||||
* The id of this player.
|
||||
*/
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* The membership flag.
|
||||
*/
|
||||
private final boolean members;
|
||||
/**
|
||||
* The membership flag.
|
||||
*/
|
||||
private final boolean members;
|
||||
|
||||
/**
|
||||
* Creates the local id event.
|
||||
*
|
||||
* @param id The id.
|
||||
* @param members The membership flag.
|
||||
*/
|
||||
public IdAssignmentEvent(int id, boolean members) {
|
||||
this.id = id;
|
||||
this.members = members;
|
||||
}
|
||||
/**
|
||||
* Creates the local id event.
|
||||
*
|
||||
* @param id The id.
|
||||
* @param members The membership flag.
|
||||
*/
|
||||
public IdAssignmentEvent(int id, boolean members) {
|
||||
this.id = id;
|
||||
this.members = members;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return The id.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* Gets the id.
|
||||
*
|
||||
* @return The id.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the membership flag.
|
||||
*
|
||||
* @return The membership flag.
|
||||
*/
|
||||
public boolean isMembers() {
|
||||
return members;
|
||||
}
|
||||
/**
|
||||
* Gets the membership flag.
|
||||
*
|
||||
* @return The membership flag.
|
||||
*/
|
||||
public boolean isMembers() {
|
||||
return members;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,27 +11,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class IgnoreListEvent extends Event {
|
||||
|
||||
/**
|
||||
* The list of ignored player usernames.
|
||||
*/
|
||||
private final List<String> usernames;
|
||||
/**
|
||||
* The list of ignored player usernames.
|
||||
*/
|
||||
private final List<String> usernames;
|
||||
|
||||
/**
|
||||
* Creates a new ignore list event.
|
||||
*
|
||||
* @param player The player.
|
||||
*/
|
||||
public IgnoreListEvent(List<String> usernames) {
|
||||
this.usernames = usernames;
|
||||
}
|
||||
/**
|
||||
* Creates a new ignore list event.
|
||||
*
|
||||
* @param player The player.
|
||||
*/
|
||||
public IgnoreListEvent(List<String> usernames) {
|
||||
this.usernames = usernames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of ignored usernames.
|
||||
*
|
||||
* @return The usernames.
|
||||
*/
|
||||
public List<String> getUsernames() {
|
||||
return usernames;
|
||||
}
|
||||
/**
|
||||
* Gets the list of ignored usernames.
|
||||
*
|
||||
* @return The usernames.
|
||||
*/
|
||||
public List<String> getUsernames() {
|
||||
return usernames;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,75 +10,75 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public abstract class InventoryItemEvent extends Event {
|
||||
|
||||
/**
|
||||
* The item id.
|
||||
*/
|
||||
private final int id;
|
||||
/**
|
||||
* The item id.
|
||||
*/
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* The interface id.
|
||||
*/
|
||||
private final int interfaceId;
|
||||
/**
|
||||
* The interface id.
|
||||
*/
|
||||
private final int interfaceId;
|
||||
|
||||
/**
|
||||
* The option number (1-5).
|
||||
*/
|
||||
private final int option;
|
||||
/**
|
||||
* The option number (1-5).
|
||||
*/
|
||||
private final int option;
|
||||
|
||||
/**
|
||||
* The item's slot.
|
||||
*/
|
||||
private final int slot;
|
||||
/**
|
||||
* The item's slot.
|
||||
*/
|
||||
private final int slot;
|
||||
|
||||
/**
|
||||
* Creates the item action event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
protected InventoryItemEvent(int option, int interfaceId, int id, int slot) {
|
||||
this.option = option;
|
||||
this.interfaceId = interfaceId;
|
||||
this.id = id;
|
||||
this.slot = slot;
|
||||
}
|
||||
/**
|
||||
* Creates the item action event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
protected InventoryItemEvent(int option, int interfaceId, int id, int slot) {
|
||||
this.option = option;
|
||||
this.interfaceId = interfaceId;
|
||||
this.id = id;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item id.
|
||||
*
|
||||
* @return The item id.
|
||||
*/
|
||||
public final int getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* Gets the item id.
|
||||
*
|
||||
* @return The item id.
|
||||
*/
|
||||
public final int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the interface id.
|
||||
*
|
||||
* @return The interface id.
|
||||
*/
|
||||
public final int getInterfaceId() {
|
||||
return interfaceId;
|
||||
}
|
||||
/**
|
||||
* Gets the interface id.
|
||||
*
|
||||
* @return The interface id.
|
||||
*/
|
||||
public final int getInterfaceId() {
|
||||
return interfaceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the option number.
|
||||
*
|
||||
* @return The option number.
|
||||
*/
|
||||
public final int getOption() {
|
||||
return option;
|
||||
}
|
||||
/**
|
||||
* Gets the option number.
|
||||
*
|
||||
* @return The option number.
|
||||
*/
|
||||
public final int getOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the slot.
|
||||
*
|
||||
* @return The slot.
|
||||
*/
|
||||
public final int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
/**
|
||||
* Gets the slot.
|
||||
*
|
||||
* @return The slot.
|
||||
*/
|
||||
public final int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,16 +11,16 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public abstract class ItemActionEvent extends InventoryItemEvent {
|
||||
|
||||
/**
|
||||
* Creates the item action event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
public ItemActionEvent(int option, int interfaceId, int id, int slot) {
|
||||
super(option, interfaceId, id, slot);
|
||||
}
|
||||
/**
|
||||
* Creates the item action event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
public ItemActionEvent(int option, int interfaceId, int id, int slot) {
|
||||
super(option, interfaceId, id, slot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,64 +7,64 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class ItemOnItemEvent extends InventoryItemEvent {
|
||||
|
||||
/**
|
||||
* The id of the target item.
|
||||
*/
|
||||
private final int targetId;
|
||||
/**
|
||||
* The id of the target item.
|
||||
*/
|
||||
private final int targetId;
|
||||
|
||||
/**
|
||||
* The interface id of the target item.
|
||||
*/
|
||||
private final int targetInterface;
|
||||
/**
|
||||
* The interface id of the target item.
|
||||
*/
|
||||
private final int targetInterface;
|
||||
|
||||
/**
|
||||
* The slot of the target item.
|
||||
*/
|
||||
private final int targetSlot;
|
||||
/**
|
||||
* The slot of the target item.
|
||||
*/
|
||||
private final int targetSlot;
|
||||
|
||||
/**
|
||||
* Creates a new item-on-item event.
|
||||
*
|
||||
* @param usedInterface The interface id of the used item.
|
||||
* @param usedId The id of the used item.
|
||||
* @param usedSlot The slot of the target item.
|
||||
* @param targetInterface The interface id of the target item.
|
||||
* @param targetId The id of the target item.
|
||||
* @param targetSlot The slot of the target item.
|
||||
*/
|
||||
public ItemOnItemEvent(int usedInterface, int usedId, int usedSlot, int targetInterface, int targetId,
|
||||
int targetSlot) {
|
||||
super(0, usedInterface, usedId, usedSlot);
|
||||
this.targetInterface = targetInterface;
|
||||
this.targetSlot = targetSlot;
|
||||
this.targetId = targetId;
|
||||
}
|
||||
/**
|
||||
* Creates a new item-on-item event.
|
||||
*
|
||||
* @param usedInterface The interface id of the used item.
|
||||
* @param usedId The id of the used item.
|
||||
* @param usedSlot The slot of the target item.
|
||||
* @param targetInterface The interface id of the target item.
|
||||
* @param targetId The id of the target item.
|
||||
* @param targetSlot The slot of the target item.
|
||||
*/
|
||||
public ItemOnItemEvent(int usedInterface, int usedId, int usedSlot, int targetInterface, int targetId,
|
||||
int targetSlot) {
|
||||
super(0, usedInterface, usedId, usedSlot);
|
||||
this.targetInterface = targetInterface;
|
||||
this.targetSlot = targetSlot;
|
||||
this.targetId = targetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of the target item.
|
||||
*
|
||||
* @return The target item's interface id.
|
||||
*/
|
||||
public int getTargetId() {
|
||||
return targetId;
|
||||
}
|
||||
/**
|
||||
* Gets the id of the target item.
|
||||
*
|
||||
* @return The target item's interface id.
|
||||
*/
|
||||
public int getTargetId() {
|
||||
return targetId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the interface id of the target item.
|
||||
*
|
||||
* @return The target item's interface id.
|
||||
*/
|
||||
public int getTargetInterfaceId() {
|
||||
return targetInterface;
|
||||
}
|
||||
/**
|
||||
* Gets the interface id of the target item.
|
||||
*
|
||||
* @return The target item's interface id.
|
||||
*/
|
||||
public int getTargetInterfaceId() {
|
||||
return targetInterface;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the slot of the target item.
|
||||
*
|
||||
* @return The slot of the target item.
|
||||
*/
|
||||
public int getTargetSlot() {
|
||||
return targetSlot;
|
||||
}
|
||||
/**
|
||||
* Gets the slot of the target item.
|
||||
*
|
||||
* @return The slot of the target item.
|
||||
*/
|
||||
public int getTargetSlot() {
|
||||
return targetSlot;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,48 +10,48 @@ import org.apollo.game.model.Position;
|
||||
*/
|
||||
public final class ItemOnObjectEvent extends InventoryItemEvent {
|
||||
|
||||
/**
|
||||
* The object id the item was used on.
|
||||
*/
|
||||
private final int objectId;
|
||||
/**
|
||||
* The object id the item was used on.
|
||||
*/
|
||||
private final int objectId;
|
||||
|
||||
/**
|
||||
* The position of the object.
|
||||
*/
|
||||
private final Position position;
|
||||
/**
|
||||
* The position of the object.
|
||||
*/
|
||||
private final Position position;
|
||||
|
||||
/**
|
||||
* Creates an item on object event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param itemId The item id.
|
||||
* @param itemSlot The slot the item is in.
|
||||
* @param objectId The object id.
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
*/
|
||||
public ItemOnObjectEvent(int interfaceId, int itemId, int itemSlot, int objectId, int x, int y) {
|
||||
super(0, interfaceId, itemId, itemSlot);
|
||||
this.objectId = objectId;
|
||||
this.position = new Position(x, y);
|
||||
}
|
||||
/**
|
||||
* Creates an item on object event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param itemId The item id.
|
||||
* @param itemSlot The slot the item is in.
|
||||
* @param objectId The object id.
|
||||
* @param x The x coordinate.
|
||||
* @param y The y coordinate.
|
||||
*/
|
||||
public ItemOnObjectEvent(int interfaceId, int itemId, int itemSlot, int objectId, int x, int y) {
|
||||
super(0, interfaceId, itemId, itemSlot);
|
||||
this.objectId = objectId;
|
||||
this.position = new Position(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the object id.
|
||||
*
|
||||
* @return The object id.
|
||||
*/
|
||||
public int getObjectId() {
|
||||
return objectId;
|
||||
}
|
||||
/**
|
||||
* Gets the object id.
|
||||
*
|
||||
* @return The object id.
|
||||
*/
|
||||
public int getObjectId() {
|
||||
return objectId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position of the object.
|
||||
*
|
||||
* @return The position.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
/**
|
||||
* Gets the position of the object.
|
||||
*
|
||||
* @return The position.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,16 +9,16 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public abstract class ItemOptionEvent extends InventoryItemEvent {
|
||||
|
||||
/**
|
||||
* Creates the item option event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
public ItemOptionEvent(int option, int interfaceId, int id, int slot) {
|
||||
super(option, interfaceId, id, slot);
|
||||
}
|
||||
/**
|
||||
* Creates the item option event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The id.
|
||||
* @param slot The slot.
|
||||
*/
|
||||
public ItemOptionEvent(int option, int interfaceId, int id, int slot) {
|
||||
super(option, interfaceId, id, slot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,25 +9,25 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class KeepAliveEvent extends Event {
|
||||
|
||||
/**
|
||||
* The time this event was created.
|
||||
*/
|
||||
private final long createdAt;
|
||||
/**
|
||||
* The time this event was created.
|
||||
*/
|
||||
private final long createdAt;
|
||||
|
||||
/**
|
||||
* Creates the keep alive event.
|
||||
*/
|
||||
public KeepAliveEvent() {
|
||||
createdAt = System.currentTimeMillis();
|
||||
}
|
||||
/**
|
||||
* Creates the keep alive event.
|
||||
*/
|
||||
public KeepAliveEvent() {
|
||||
createdAt = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time when this event was created.
|
||||
*
|
||||
* @return The time when this event was created.
|
||||
*/
|
||||
public long getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
/**
|
||||
* Gets the time when this event was created.
|
||||
*
|
||||
* @return The time when this event was created.
|
||||
*/
|
||||
public long getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,31 +7,31 @@ package org.apollo.game.event.impl;
|
||||
*/
|
||||
public final class MagicOnItemEvent extends InventoryItemEvent {
|
||||
|
||||
/**
|
||||
* The spell id.
|
||||
*/
|
||||
private final int spell;
|
||||
/**
|
||||
* The spell id.
|
||||
*/
|
||||
private final int spell;
|
||||
|
||||
/**
|
||||
* Creates a new magic on item event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The item id.
|
||||
* @param slot The item slot.
|
||||
* @param spell The spell id.
|
||||
*/
|
||||
public MagicOnItemEvent(int interfaceId, int id, int slot, int spell) {
|
||||
super(0, interfaceId, id, slot);
|
||||
this.spell = spell;
|
||||
}
|
||||
/**
|
||||
* Creates a new magic on item event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param id The item id.
|
||||
* @param slot The item slot.
|
||||
* @param spell The spell id.
|
||||
*/
|
||||
public MagicOnItemEvent(int interfaceId, int id, int slot, int spell) {
|
||||
super(0, interfaceId, id, slot);
|
||||
this.spell = spell;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the spell id.
|
||||
*
|
||||
* @return The spell id.
|
||||
*/
|
||||
public int getSpellId() {
|
||||
return spell;
|
||||
}
|
||||
/**
|
||||
* Gets the spell id.
|
||||
*
|
||||
* @return The spell id.
|
||||
*/
|
||||
public int getSpellId() {
|
||||
return spell;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,77 +9,77 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class MouseClickEvent extends Event {
|
||||
|
||||
/**
|
||||
* The number of clicks on this point (i.e. the point ({@link #x}, {@link #y})).
|
||||
*/
|
||||
private final int clickCount;
|
||||
/**
|
||||
* The number of clicks on this point (i.e. the point ({@link #x}, {@link #y})).
|
||||
*/
|
||||
private final int clickCount;
|
||||
|
||||
/**
|
||||
* The x coordinate of the mouse click.
|
||||
*/
|
||||
private final int x;
|
||||
/**
|
||||
* The x coordinate of the mouse click.
|
||||
*/
|
||||
private final int x;
|
||||
|
||||
/**
|
||||
* The y coordinate of the mouse click.
|
||||
*/
|
||||
private final int y;
|
||||
/**
|
||||
* The y coordinate of the mouse click.
|
||||
*/
|
||||
private final int y;
|
||||
|
||||
/**
|
||||
* Indicates whether the {@link #x} and {@link #y} values represent the deviation from the last click or an actual
|
||||
* point.
|
||||
*/
|
||||
private final boolean delta;
|
||||
/**
|
||||
* Indicates whether the {@link #x} and {@link #y} values represent the deviation from the last click or an actual
|
||||
* point.
|
||||
*/
|
||||
private final boolean delta;
|
||||
|
||||
/**
|
||||
* Creates a new mouse click event.
|
||||
*
|
||||
* @param clickCount The number of clicks on this point.
|
||||
* @param x The x 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.
|
||||
*/
|
||||
public MouseClickEvent(int clickCount, int x, int y, boolean delta) {
|
||||
this.clickCount = clickCount;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.delta = delta;
|
||||
}
|
||||
/**
|
||||
* Creates a new mouse click event.
|
||||
*
|
||||
* @param clickCount The number of clicks on this point.
|
||||
* @param x The x 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.
|
||||
*/
|
||||
public MouseClickEvent(int clickCount, int x, int y, boolean delta) {
|
||||
this.clickCount = clickCount;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.delta = delta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of clicks on this point - maximum value of 2047.
|
||||
*
|
||||
* @return The number of clicks.
|
||||
*/
|
||||
public int getClickCount() {
|
||||
return clickCount;
|
||||
}
|
||||
/**
|
||||
* Gets the number of clicks on this point - maximum value of 2047.
|
||||
*
|
||||
* @return The number of clicks.
|
||||
*/
|
||||
public int getClickCount() {
|
||||
return clickCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* The x coordinate of the click.
|
||||
*
|
||||
* @return The x coordinate.
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
/**
|
||||
* The x coordinate of the click.
|
||||
*
|
||||
* @return The x coordinate.
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* The y coordinate of the click.
|
||||
*
|
||||
* @return The y coordinate.
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
/**
|
||||
* The y coordinate of the click.
|
||||
*
|
||||
* @return The y coordinate.
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value indicating whether the {@link #x} and {@link #y} values represent the deviation from the last
|
||||
* click or an actual point.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
public boolean getDelta() {
|
||||
return delta;
|
||||
}
|
||||
/**
|
||||
* Gets the value indicating whether the {@link #x} and {@link #y} values represent the deviation from the last
|
||||
* click or an actual point.
|
||||
*
|
||||
* @return The value.
|
||||
*/
|
||||
public boolean getDelta() {
|
||||
return delta;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,43 +11,43 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public abstract class NpcActionEvent extends Event {
|
||||
|
||||
/**
|
||||
* The option number.
|
||||
*/
|
||||
private final int option;
|
||||
/**
|
||||
* The option number.
|
||||
*/
|
||||
private final int option;
|
||||
|
||||
/**
|
||||
* The index of the clicked npc.
|
||||
*/
|
||||
private final int index;
|
||||
/**
|
||||
* The index of the clicked npc.
|
||||
*/
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Creates an npc action event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param index The index of the npc.
|
||||
*/
|
||||
public NpcActionEvent(int option, int index) {
|
||||
this.option = option;
|
||||
this.index = index - 1;
|
||||
}
|
||||
/**
|
||||
* Creates an npc action event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param index The index of the npc.
|
||||
*/
|
||||
public NpcActionEvent(int option, int index) {
|
||||
this.option = option;
|
||||
this.index = index - 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the menu action number (i.e. the action event 'option') clicked.
|
||||
*
|
||||
* @return The option number.
|
||||
*/
|
||||
public int getOption() {
|
||||
return option;
|
||||
}
|
||||
/**
|
||||
* Gets the menu action number (i.e. the action event 'option') clicked.
|
||||
*
|
||||
* @return The option number.
|
||||
*/
|
||||
public int getOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of the npc clicked.
|
||||
*
|
||||
* @return The npc index.
|
||||
*/
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
/**
|
||||
* Gets the index of the npc clicked.
|
||||
*
|
||||
* @return The npc index.
|
||||
*/
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,59 +14,59 @@ import org.apollo.game.sync.seg.SynchronizationSegment;
|
||||
*/
|
||||
public final class NpcSynchronizationEvent extends Event {
|
||||
|
||||
/**
|
||||
* The amount of local npcs.
|
||||
*/
|
||||
private final int localNpcs;
|
||||
/**
|
||||
* The amount of local npcs.
|
||||
*/
|
||||
private final int localNpcs;
|
||||
|
||||
/**
|
||||
* The npc's position.
|
||||
*/
|
||||
private final Position position;
|
||||
/**
|
||||
* The npc's position.
|
||||
*/
|
||||
private final Position position;
|
||||
|
||||
/**
|
||||
* A list of segments.
|
||||
*/
|
||||
private final List<SynchronizationSegment> segments;
|
||||
/**
|
||||
* A list of segments.
|
||||
*/
|
||||
private final List<SynchronizationSegment> segments;
|
||||
|
||||
/**
|
||||
* Creates a new {@link NpcSynchronizationEvent}.
|
||||
*
|
||||
* @param position The position of the {@link Npc}.
|
||||
* @param segments The list of segments.
|
||||
* @param localNpcs The amount of local npcs.
|
||||
*/
|
||||
public NpcSynchronizationEvent(Position position, List<SynchronizationSegment> segments, int localNpcs) {
|
||||
this.position = position;
|
||||
this.segments = segments;
|
||||
this.localNpcs = localNpcs;
|
||||
}
|
||||
/**
|
||||
* Creates a new {@link NpcSynchronizationEvent}.
|
||||
*
|
||||
* @param position The position of the {@link Npc}.
|
||||
* @param segments The list of segments.
|
||||
* @param localNpcs The amount of local npcs.
|
||||
*/
|
||||
public NpcSynchronizationEvent(Position position, List<SynchronizationSegment> segments, int localNpcs) {
|
||||
this.position = position;
|
||||
this.segments = segments;
|
||||
this.localNpcs = localNpcs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of local npcs.
|
||||
*
|
||||
* @return The number of local npcs.
|
||||
*/
|
||||
public int getLocalNpcCount() {
|
||||
return localNpcs;
|
||||
}
|
||||
/**
|
||||
* Gets the number of local npcs.
|
||||
*
|
||||
* @return The number of local npcs.
|
||||
*/
|
||||
public int getLocalNpcCount() {
|
||||
return localNpcs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the npc's position.
|
||||
*
|
||||
* @return The npc's position.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
/**
|
||||
* Gets the npc's position.
|
||||
*
|
||||
* @return The npc's position.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the synchronization segments.
|
||||
*
|
||||
* @return The segments.
|
||||
*/
|
||||
public List<SynchronizationSegment> getSegments() {
|
||||
return segments;
|
||||
}
|
||||
/**
|
||||
* Gets the synchronization segments.
|
||||
*
|
||||
* @return The segments.
|
||||
*/
|
||||
public List<SynchronizationSegment> getSegments() {
|
||||
return segments;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,59 +12,59 @@ import org.apollo.game.model.Position;
|
||||
*/
|
||||
public abstract class ObjectActionEvent extends Event {
|
||||
|
||||
/**
|
||||
* The object's id.
|
||||
*/
|
||||
private final int id;
|
||||
/**
|
||||
* The object's id.
|
||||
*/
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* The option number (1-3).
|
||||
*/
|
||||
private final int option;
|
||||
/**
|
||||
* The option number (1-3).
|
||||
*/
|
||||
private final int option;
|
||||
|
||||
/**
|
||||
* The object's position.
|
||||
*/
|
||||
private final Position position;
|
||||
/**
|
||||
* The object's position.
|
||||
*/
|
||||
private final Position position;
|
||||
|
||||
/**
|
||||
* Creates a new object action event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param id The id of the object.
|
||||
* @param position The position of the object.
|
||||
*/
|
||||
public ObjectActionEvent(int option, int id, Position position) {
|
||||
this.option = option;
|
||||
this.id = id;
|
||||
this.position = position;
|
||||
}
|
||||
/**
|
||||
* Creates a new object action event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param id The id of the object.
|
||||
* @param position The position of the object.
|
||||
*/
|
||||
public ObjectActionEvent(int option, int id, Position position) {
|
||||
this.option = option;
|
||||
this.id = id;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of the object.
|
||||
*
|
||||
* @return The id of the object.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* Gets the id of the object.
|
||||
*
|
||||
* @return The id of the object.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the option number.
|
||||
*
|
||||
* @return The option number.
|
||||
*/
|
||||
public int getOption() {
|
||||
return option;
|
||||
}
|
||||
/**
|
||||
* Gets the option number.
|
||||
*
|
||||
* @return The option number.
|
||||
*/
|
||||
public int getOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position of the object.
|
||||
*
|
||||
* @return The position of the object.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
/**
|
||||
* Gets the position of the object.
|
||||
*
|
||||
* @return The position of the object.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class OpenDialogueInterfaceEvent extends Event {
|
||||
|
||||
/**
|
||||
* The interface id.
|
||||
*/
|
||||
private final int interfaceId;
|
||||
/**
|
||||
* The interface id.
|
||||
*/
|
||||
private final int interfaceId;
|
||||
|
||||
/**
|
||||
* Creates a new event with the specified interface id.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
*/
|
||||
public OpenDialogueInterfaceEvent(int interfaceId) {
|
||||
this.interfaceId = interfaceId;
|
||||
}
|
||||
/**
|
||||
* Creates a new event with the specified interface id.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
*/
|
||||
public OpenDialogueInterfaceEvent(int interfaceId) {
|
||||
this.interfaceId = interfaceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the interface id.
|
||||
*
|
||||
* @return The interface id.
|
||||
*/
|
||||
public int getInterfaceId() {
|
||||
return interfaceId;
|
||||
}
|
||||
/**
|
||||
* Gets the interface id.
|
||||
*
|
||||
* @return The interface id.
|
||||
*/
|
||||
public int getInterfaceId() {
|
||||
return interfaceId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class OpenInterfaceEvent extends Event {
|
||||
|
||||
/**
|
||||
* The interface id.
|
||||
*/
|
||||
private final int id;
|
||||
/**
|
||||
* The interface id.
|
||||
*/
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* Creates the event with the specified interface id.
|
||||
*
|
||||
* @param id The interface id.
|
||||
*/
|
||||
public OpenInterfaceEvent(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
/**
|
||||
* Creates the event with the specified interface id.
|
||||
*
|
||||
* @param id The interface id.
|
||||
*/
|
||||
public OpenInterfaceEvent(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the interface id.
|
||||
*
|
||||
* @return The interface id.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* Gets the interface id.
|
||||
*
|
||||
* @return The interface id.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,43 +9,43 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class OpenInterfaceSidebarEvent extends Event {
|
||||
|
||||
/**
|
||||
* The interface id.
|
||||
*/
|
||||
private final int interfaceId;
|
||||
/**
|
||||
* The interface id.
|
||||
*/
|
||||
private final int interfaceId;
|
||||
|
||||
/**
|
||||
* The sidebar id.
|
||||
*/
|
||||
private final int sidebarId;
|
||||
/**
|
||||
* The sidebar id.
|
||||
*/
|
||||
private final int sidebarId;
|
||||
|
||||
/**
|
||||
* Creates the open interface sidebar event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param sidebarId The sidebar id.
|
||||
*/
|
||||
public OpenInterfaceSidebarEvent(int interfaceId, int sidebarId) {
|
||||
this.interfaceId = interfaceId;
|
||||
this.sidebarId = sidebarId;
|
||||
}
|
||||
/**
|
||||
* Creates the open interface sidebar event.
|
||||
*
|
||||
* @param interfaceId The interface id.
|
||||
* @param sidebarId The sidebar id.
|
||||
*/
|
||||
public OpenInterfaceSidebarEvent(int interfaceId, int sidebarId) {
|
||||
this.interfaceId = interfaceId;
|
||||
this.sidebarId = sidebarId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the interface id.
|
||||
*
|
||||
* @return The interface id.
|
||||
*/
|
||||
public int getInterfaceId() {
|
||||
return interfaceId;
|
||||
}
|
||||
/**
|
||||
* Gets the interface id.
|
||||
*
|
||||
* @return The interface id.
|
||||
*/
|
||||
public int getInterfaceId() {
|
||||
return interfaceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the sidebar id.
|
||||
*
|
||||
* @return The sidebar id.
|
||||
*/
|
||||
public int getSidebarId() {
|
||||
return sidebarId;
|
||||
}
|
||||
/**
|
||||
* Gets the sidebar id.
|
||||
*
|
||||
* @return The sidebar id.
|
||||
*/
|
||||
public int getSidebarId() {
|
||||
return sidebarId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,43 +11,43 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public abstract class PlayerActionEvent extends Event {
|
||||
|
||||
/**
|
||||
* The option number.
|
||||
*/
|
||||
private final int option;
|
||||
/**
|
||||
* The option number.
|
||||
*/
|
||||
private final int option;
|
||||
|
||||
/**
|
||||
* The index of the clicked player.
|
||||
*/
|
||||
private final int index;
|
||||
/**
|
||||
* The index of the clicked player.
|
||||
*/
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* Creates a player action event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param playerIndex The index of the player.
|
||||
*/
|
||||
public PlayerActionEvent(int option, int playerIndex) {
|
||||
this.option = option;
|
||||
this.index = playerIndex;
|
||||
}
|
||||
/**
|
||||
* Creates a player action event.
|
||||
*
|
||||
* @param option The option number.
|
||||
* @param playerIndex The index of the player.
|
||||
*/
|
||||
public PlayerActionEvent(int option, int playerIndex) {
|
||||
this.option = option;
|
||||
this.index = playerIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the menu action number (i.e. the action event 'option') clicked.
|
||||
*
|
||||
* @return The option number.
|
||||
*/
|
||||
public int getOption() {
|
||||
return option;
|
||||
}
|
||||
/**
|
||||
* Gets the menu action number (i.e. the action event 'option') clicked.
|
||||
*
|
||||
* @return The option number.
|
||||
*/
|
||||
public int getOption() {
|
||||
return option;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of the clicked player.
|
||||
*
|
||||
* @return The index.
|
||||
*/
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
/**
|
||||
* Gets the index of the clicked player.
|
||||
*
|
||||
* @return The index.
|
||||
*/
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,27 +10,27 @@ import org.apollo.game.model.Appearance;
|
||||
*/
|
||||
public final class PlayerDesignEvent extends Event {
|
||||
|
||||
/**
|
||||
* The appearance.
|
||||
*/
|
||||
private final Appearance appearance;
|
||||
/**
|
||||
* The appearance.
|
||||
*/
|
||||
private final Appearance appearance;
|
||||
|
||||
/**
|
||||
* Creates the player design event.
|
||||
*
|
||||
* @param appearance The appearance.
|
||||
*/
|
||||
public PlayerDesignEvent(Appearance appearance) {
|
||||
this.appearance = appearance;
|
||||
}
|
||||
/**
|
||||
* Creates the player design event.
|
||||
*
|
||||
* @param appearance The appearance.
|
||||
*/
|
||||
public PlayerDesignEvent(Appearance appearance) {
|
||||
this.appearance = appearance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the appearance.
|
||||
*
|
||||
* @return The appearance.
|
||||
*/
|
||||
public Appearance getAppearance() {
|
||||
return appearance;
|
||||
}
|
||||
/**
|
||||
* Gets the appearance.
|
||||
*
|
||||
* @return The appearance.
|
||||
*/
|
||||
public Appearance getAppearance() {
|
||||
return appearance;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,108 +13,108 @@ import org.apollo.game.sync.seg.SynchronizationSegment;
|
||||
*/
|
||||
public final class PlayerSynchronizationEvent extends Event {
|
||||
|
||||
/**
|
||||
* The last known region.
|
||||
*/
|
||||
private final Position lastKnownRegion;
|
||||
/**
|
||||
* The last known region.
|
||||
*/
|
||||
private final Position lastKnownRegion;
|
||||
|
||||
/**
|
||||
* The number of local players.
|
||||
*/
|
||||
private final int localPlayers;
|
||||
/**
|
||||
* The number of local players.
|
||||
*/
|
||||
private final int localPlayers;
|
||||
|
||||
/**
|
||||
* The player's position.
|
||||
*/
|
||||
private final Position position;
|
||||
/**
|
||||
* The player's position.
|
||||
*/
|
||||
private final Position position;
|
||||
|
||||
/**
|
||||
* A flag indicating if the region has changed.
|
||||
*/
|
||||
private final boolean regionChanged;
|
||||
/**
|
||||
* A flag indicating if the region has changed.
|
||||
*/
|
||||
private final boolean regionChanged;
|
||||
|
||||
/**
|
||||
* The current player's synchronization segment.
|
||||
*/
|
||||
private final SynchronizationSegment segment;
|
||||
/**
|
||||
* The current player's synchronization segment.
|
||||
*/
|
||||
private final SynchronizationSegment segment;
|
||||
|
||||
/**
|
||||
* A list of segments.
|
||||
*/
|
||||
private final List<SynchronizationSegment> segments;
|
||||
/**
|
||||
* A list of segments.
|
||||
*/
|
||||
private final List<SynchronizationSegment> segments;
|
||||
|
||||
/**
|
||||
* Creates the player synchronization event.
|
||||
*
|
||||
* @param lastKnownRegion The last known region.
|
||||
* @param position The player's current position.
|
||||
* @param regionChanged A flag indicating if the region has changed.
|
||||
* @param segment The current player's synchronization segment.
|
||||
* @param localPlayers The number of local players.
|
||||
* @param segments A list of segments.
|
||||
*/
|
||||
public PlayerSynchronizationEvent(Position lastKnownRegion, Position position, boolean regionChanged,
|
||||
SynchronizationSegment segment, int localPlayers, List<SynchronizationSegment> segments) {
|
||||
this.lastKnownRegion = lastKnownRegion;
|
||||
this.position = position;
|
||||
this.regionChanged = regionChanged;
|
||||
this.segment = segment;
|
||||
this.localPlayers = localPlayers;
|
||||
this.segments = segments;
|
||||
}
|
||||
/**
|
||||
* Creates the player synchronization event.
|
||||
*
|
||||
* @param lastKnownRegion The last known region.
|
||||
* @param position The player's current position.
|
||||
* @param regionChanged A flag indicating if the region has changed.
|
||||
* @param segment The current player's synchronization segment.
|
||||
* @param localPlayers The number of local players.
|
||||
* @param segments A list of segments.
|
||||
*/
|
||||
public PlayerSynchronizationEvent(Position lastKnownRegion, Position position, boolean regionChanged,
|
||||
SynchronizationSegment segment, int localPlayers, List<SynchronizationSegment> segments) {
|
||||
this.lastKnownRegion = lastKnownRegion;
|
||||
this.position = position;
|
||||
this.regionChanged = regionChanged;
|
||||
this.segment = segment;
|
||||
this.localPlayers = localPlayers;
|
||||
this.segments = segments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the last known region.
|
||||
*
|
||||
* @return The last known region.
|
||||
*/
|
||||
public Position getLastKnownRegion() {
|
||||
return lastKnownRegion;
|
||||
}
|
||||
/**
|
||||
* Gets the last known region.
|
||||
*
|
||||
* @return The last known region.
|
||||
*/
|
||||
public Position getLastKnownRegion() {
|
||||
return lastKnownRegion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of local players.
|
||||
*
|
||||
* @return The number of local players.
|
||||
*/
|
||||
public int getLocalPlayers() {
|
||||
return localPlayers;
|
||||
}
|
||||
/**
|
||||
* Gets the number of local players.
|
||||
*
|
||||
* @return The number of local players.
|
||||
*/
|
||||
public int getLocalPlayers() {
|
||||
return localPlayers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player's position.
|
||||
*
|
||||
* @return The player's position.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
/**
|
||||
* Gets the player's position.
|
||||
*
|
||||
* @return The player's position.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current player's segment.
|
||||
*
|
||||
* @return The current player's segment.
|
||||
*/
|
||||
public SynchronizationSegment getSegment() {
|
||||
return segment;
|
||||
}
|
||||
/**
|
||||
* Gets the current player's segment.
|
||||
*
|
||||
* @return The current player's segment.
|
||||
*/
|
||||
public SynchronizationSegment getSegment() {
|
||||
return segment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the synchronization segments.
|
||||
*
|
||||
* @return The segments.
|
||||
*/
|
||||
public List<SynchronizationSegment> getSegments() {
|
||||
return segments;
|
||||
}
|
||||
/**
|
||||
* Gets the synchronization segments.
|
||||
*
|
||||
* @return The segments.
|
||||
*/
|
||||
public List<SynchronizationSegment> getSegments() {
|
||||
return segments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the region has changed.
|
||||
*
|
||||
* @return {@code true} if so, {@code false} if not.
|
||||
*/
|
||||
public boolean hasRegionChanged() {
|
||||
return regionChanged;
|
||||
}
|
||||
/**
|
||||
* Checks if the region has changed.
|
||||
*
|
||||
* @return {@code true} if so, {@code false} if not.
|
||||
*/
|
||||
public boolean hasRegionChanged() {
|
||||
return regionChanged;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,43 +10,43 @@ import org.apollo.game.model.Position;
|
||||
*/
|
||||
public final class PositionEvent extends Event {
|
||||
|
||||
/**
|
||||
* The base position.
|
||||
*/
|
||||
private final Position base;
|
||||
/**
|
||||
* The base position.
|
||||
*/
|
||||
private final Position base;
|
||||
|
||||
/**
|
||||
* The target position.
|
||||
*/
|
||||
private final Position position;
|
||||
/**
|
||||
* The target position.
|
||||
*/
|
||||
private final Position position;
|
||||
|
||||
/**
|
||||
* Creates a new position event.
|
||||
*
|
||||
* @param base The base from which the position is being focused on.
|
||||
* @param position The position to focus on.
|
||||
*/
|
||||
public PositionEvent(Position base, Position position) {
|
||||
this.base = base;
|
||||
this.position = position;
|
||||
}
|
||||
/**
|
||||
* Creates a new position event.
|
||||
*
|
||||
* @param base The base from which the position is being focused on.
|
||||
* @param position The position to focus on.
|
||||
*/
|
||||
public PositionEvent(Position base, Position position) {
|
||||
this.base = base;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the base position.
|
||||
*
|
||||
* @return The position.
|
||||
*/
|
||||
public Position getBase() {
|
||||
return base;
|
||||
}
|
||||
/**
|
||||
* Gets the base position.
|
||||
*
|
||||
* @return The position.
|
||||
*/
|
||||
public Position getBase() {
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position to focus on.
|
||||
*
|
||||
* @return The target position.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
/**
|
||||
* Gets the position to focus on.
|
||||
*
|
||||
* @return The target position.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,59 +12,59 @@ import org.apollo.game.model.settings.PrivacyState;
|
||||
*/
|
||||
public final class PrivacyOptionEvent extends Event {
|
||||
|
||||
/**
|
||||
* The privacy state of the player's chat.
|
||||
*/
|
||||
private final PrivacyState chatPrivacy;
|
||||
/**
|
||||
* The privacy state of the player's chat.
|
||||
*/
|
||||
private final PrivacyState chatPrivacy;
|
||||
|
||||
/**
|
||||
* The privacy state of the player's friend chat.
|
||||
*/
|
||||
private final PrivacyState friendPrivacy;
|
||||
/**
|
||||
* The privacy state of the player's friend chat.
|
||||
*/
|
||||
private final PrivacyState friendPrivacy;
|
||||
|
||||
/**
|
||||
* The privacy state of the player's trade chat.
|
||||
*/
|
||||
private final PrivacyState tradePrivacy;
|
||||
/**
|
||||
* The privacy state of the player's trade chat.
|
||||
*/
|
||||
private final PrivacyState tradePrivacy;
|
||||
|
||||
/**
|
||||
* Creates a privacy option event.
|
||||
*
|
||||
* @param chatPrivacy The privacy state of the player's chat.
|
||||
* @param friendPrivacy The privacy state of the player's friend chat.
|
||||
* @param tradePrivacy The privacy state of the player's trade chat.
|
||||
*/
|
||||
public PrivacyOptionEvent(int chatPrivacy, int friendPrivacy, int tradePrivacy) {
|
||||
this.chatPrivacy = PrivacyState.valueOf(chatPrivacy, true);
|
||||
this.friendPrivacy = PrivacyState.valueOf(friendPrivacy, false);
|
||||
this.tradePrivacy = PrivacyState.valueOf(tradePrivacy, false);
|
||||
}
|
||||
/**
|
||||
* Creates a privacy option event.
|
||||
*
|
||||
* @param chatPrivacy The privacy state of the player's chat.
|
||||
* @param friendPrivacy The privacy state of the player's friend chat.
|
||||
* @param tradePrivacy The privacy state of the player's trade chat.
|
||||
*/
|
||||
public PrivacyOptionEvent(int chatPrivacy, int friendPrivacy, int tradePrivacy) {
|
||||
this.chatPrivacy = PrivacyState.valueOf(chatPrivacy, true);
|
||||
this.friendPrivacy = PrivacyState.valueOf(friendPrivacy, false);
|
||||
this.tradePrivacy = PrivacyState.valueOf(tradePrivacy, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the chat {@link PrivacyState}.
|
||||
*
|
||||
* @return The privacy state.
|
||||
*/
|
||||
public PrivacyState getChatPrivacy() {
|
||||
return chatPrivacy;
|
||||
}
|
||||
/**
|
||||
* Gets the chat {@link PrivacyState}.
|
||||
*
|
||||
* @return The privacy state.
|
||||
*/
|
||||
public PrivacyState getChatPrivacy() {
|
||||
return chatPrivacy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the friend {@link PrivacyState}.
|
||||
*
|
||||
* @return The privacy state.
|
||||
*/
|
||||
public PrivacyState getFriendPrivacy() {
|
||||
return friendPrivacy;
|
||||
}
|
||||
/**
|
||||
* Gets the friend {@link PrivacyState}.
|
||||
*
|
||||
* @return The privacy state.
|
||||
*/
|
||||
public PrivacyState getFriendPrivacy() {
|
||||
return friendPrivacy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the trade {@link PrivacyState}.
|
||||
*
|
||||
* @return The privacy state.
|
||||
*/
|
||||
public PrivacyState getTradePrivacy() {
|
||||
return tradePrivacy;
|
||||
}
|
||||
/**
|
||||
* Gets the trade {@link PrivacyState}.
|
||||
*
|
||||
* @return The privacy state.
|
||||
*/
|
||||
public PrivacyState getTradePrivacy() {
|
||||
return tradePrivacy;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,59 +9,59 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class PrivateMessageEvent extends Event {
|
||||
|
||||
/**
|
||||
* The username this message is being sent to.
|
||||
*/
|
||||
private final String username;
|
||||
/**
|
||||
* The username this message is being sent to.
|
||||
*/
|
||||
private final String username;
|
||||
|
||||
/**
|
||||
* The message being sent.
|
||||
*/
|
||||
private final String message;
|
||||
/**
|
||||
* The message being sent.
|
||||
*/
|
||||
private final String message;
|
||||
|
||||
/**
|
||||
* The compressed message.
|
||||
*/
|
||||
private final byte[] compressedMessage;
|
||||
/**
|
||||
* The compressed message.
|
||||
*/
|
||||
private final byte[] compressedMessage;
|
||||
|
||||
/**
|
||||
* Creates a new private message event.
|
||||
*
|
||||
* @param username The username of the player the message is being sent to.
|
||||
* @param message The message.
|
||||
* @param compressedMessage The message, in a compressed form.
|
||||
*/
|
||||
public PrivateMessageEvent(String username, String message, byte[] compressedMessage) {
|
||||
this.username = username;
|
||||
this.message = message;
|
||||
this.compressedMessage = compressedMessage;
|
||||
}
|
||||
/**
|
||||
* Creates a new private message event.
|
||||
*
|
||||
* @param username The username of the player the message is being sent to.
|
||||
* @param message The message.
|
||||
* @param compressedMessage The message, in a compressed form.
|
||||
*/
|
||||
public PrivateMessageEvent(String username, String message, byte[] compressedMessage) {
|
||||
this.username = username;
|
||||
this.message = message;
|
||||
this.compressedMessage = compressedMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username of the player the message is being sent to.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
/**
|
||||
* Gets the username of the player the message is being sent to.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message being sent.
|
||||
*
|
||||
* @return The message.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
/**
|
||||
* Gets the message being sent.
|
||||
*
|
||||
* @return The message.
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the compressed message.
|
||||
*
|
||||
* @return The compressed message.
|
||||
*/
|
||||
public byte[] getCompressedMessage() {
|
||||
return compressedMessage;
|
||||
}
|
||||
/**
|
||||
* Gets the compressed message.
|
||||
*
|
||||
* @return The compressed message.
|
||||
*/
|
||||
public byte[] getCompressedMessage() {
|
||||
return compressedMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,27 +10,27 @@ import org.apollo.game.model.Position;
|
||||
*/
|
||||
public final class RegionChangeEvent extends Event {
|
||||
|
||||
/**
|
||||
* The position of the region to load.
|
||||
*/
|
||||
private final Position position;
|
||||
/**
|
||||
* The position of the region to load.
|
||||
*/
|
||||
private final Position position;
|
||||
|
||||
/**
|
||||
* Creates the region changed event.
|
||||
*
|
||||
* @param position The position of the region.
|
||||
*/
|
||||
public RegionChangeEvent(Position position) {
|
||||
this.position = position;
|
||||
}
|
||||
/**
|
||||
* Creates the region changed event.
|
||||
*
|
||||
* @param position The position of the region.
|
||||
*/
|
||||
public RegionChangeEvent(Position position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position of the region to load.
|
||||
*
|
||||
* @return The position of the region to load.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
/**
|
||||
* Gets the position of the region to load.
|
||||
*
|
||||
* @return The position of the region to load.
|
||||
*/
|
||||
public Position getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class RemoveFriendEvent extends Event {
|
||||
|
||||
/**
|
||||
* The username of the defriended player.
|
||||
*/
|
||||
private final String username;
|
||||
/**
|
||||
* The username of the defriended player.
|
||||
*/
|
||||
private final String username;
|
||||
|
||||
/**
|
||||
* Creates a new defriend user event.
|
||||
*
|
||||
* @param username The defriended player's username.
|
||||
*/
|
||||
public RemoveFriendEvent(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
/**
|
||||
* Creates a new defriend user event.
|
||||
*
|
||||
* @param username The defriended player's username.
|
||||
*/
|
||||
public RemoveFriendEvent(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username of the defriended player.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
/**
|
||||
* Gets the username of the defriended player.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,27 +9,27 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class RemoveIgnoreEvent extends Event {
|
||||
|
||||
/**
|
||||
* The username of the unignored player.
|
||||
*/
|
||||
private final String username;
|
||||
/**
|
||||
* The username of the unignored player.
|
||||
*/
|
||||
private final String username;
|
||||
|
||||
/**
|
||||
* Creates a new unignore player event.
|
||||
*
|
||||
* @param username The unignored player's username.
|
||||
*/
|
||||
public RemoveIgnoreEvent(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
/**
|
||||
* Creates a new unignore player event.
|
||||
*
|
||||
* @param username The unignored player's username.
|
||||
*/
|
||||
public RemoveIgnoreEvent(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the username of the unignored player.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
/**
|
||||
* Gets the username of the unignored player.
|
||||
*
|
||||
* @return The username.
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,52 +9,52 @@ import org.apollo.game.event.Event;
|
||||
*/
|
||||
public final class RemoveTileItemEvent extends Event {
|
||||
|
||||
/**
|
||||
* The item.
|
||||
*/
|
||||
private final int id;
|
||||
/**
|
||||
* The item.
|
||||
*/
|
||||
private final int id;
|
||||
|
||||
/**
|
||||
* The offset from the client's base position.
|
||||
*/
|
||||
private final int positionOffset;
|
||||
/**
|
||||
* The offset from the client's base position.
|
||||
*/
|
||||
private final int positionOffset;
|
||||
|
||||
/**
|
||||
* Creates a remove tile item event.
|
||||
*
|
||||
* @param id The id of the item to remove.
|
||||
*/
|
||||
public RemoveTileItemEvent(int id) {
|
||||
this(id, 0);
|
||||
}
|
||||
/**
|
||||
* Creates a remove tile item event.
|
||||
*
|
||||
* @param id The id of the item to remove.
|
||||
*/
|
||||
public RemoveTileItemEvent(int id) {
|
||||
this(id, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a remove tile item event.
|
||||
*
|
||||
* @param id The id of the item to remove.
|
||||
* @param positionOffset The offset from the 'base' position.
|
||||
*/
|
||||
public RemoveTileItemEvent(int id, int positionOffset) {
|
||||
this.id = id;
|
||||
this.positionOffset = positionOffset;
|
||||
}
|
||||
/**
|
||||
* Creates a remove tile item event.
|
||||
*
|
||||
* @param id The id of the item to remove.
|
||||
* @param positionOffset The offset from the 'base' position.
|
||||
*/
|
||||
public RemoveTileItemEvent(int id, int positionOffset) {
|
||||
this.id = id;
|
||||
this.positionOffset = positionOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of the item to remove.
|
||||
*
|
||||
* @return The id.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* Gets the id of the item to remove.
|
||||
*
|
||||
* @return The id.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the offset from the 'base' position.
|
||||
*
|
||||
* @return The offset.
|
||||
*/
|
||||
public int getPositionOffset() {
|
||||
return positionOffset;
|
||||
}
|
||||
/**
|
||||
* Gets the offset from the 'base' position.
|
||||
*
|
||||
* @return The offset.
|
||||
*/
|
||||
public int getPositionOffset() {
|
||||
return positionOffset;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user