Add many various quality improvements throughout the codebase.

This commit is contained in:
Major-
2015-01-07 15:45:15 +00:00
parent 2725d1258f
commit ab8ad2a556
48 changed files with 283 additions and 357 deletions
+3 -5
View File
@@ -112,10 +112,9 @@ public final class Server {
logger.fine("Binding HTTP listener to address: " + httpAddress + "..."); logger.fine("Binding HTTP listener to address: " + httpAddress + "...");
try { try {
// httpBootstrap.bind(httpAddress); httpBootstrap.bind(httpAddress);
} catch (Throwable t) { } catch (Throwable t) {
logger.log(Level.WARNING, logger.log(Level.WARNING, "Binding to HTTP failed: client will use JAGGRAB as a fallback (not recommended)!", t);
"Binding to HTTP failed: client will use JAGGRAB as a fallback (not recommended)!", t);
} }
logger.fine("Binding JAGGRAB listener to address: " + jagGrabAddress + "..."); logger.fine("Binding JAGGRAB listener to address: " + jagGrabAddress + "...");
@@ -132,8 +131,7 @@ public final class Server {
* @throws IllegalAccessException If the release class could not be accessed. * @throws IllegalAccessException If the release class could not be accessed.
* @throws InstantiationException If the release class could not be instantiated. * @throws InstantiationException If the release class could not be instantiated.
*/ */
public void init(String releaseClassName) throws ClassNotFoundException, InstantiationException, public void init(String releaseClassName) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
IllegalAccessException {
Class<?> clazz = Class.forName(releaseClassName); Class<?> clazz = Class.forName(releaseClassName);
Release release = (Release) clazz.newInstance(); Release release = (Release) clazz.newInstance();
+1 -2
View File
@@ -61,8 +61,7 @@ public final class ServiceManager {
* @throws ClassNotFoundException If the service could not be found. * @throws ClassNotFoundException If the service could not be found.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void init() throws SAXException, IOException, InstantiationException, IllegalAccessException, private void init() throws SAXException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
ClassNotFoundException {
logger.fine("Registering services..."); logger.fine("Registering services...");
XmlParser parser = new XmlParser(); XmlParser parser = new XmlParser();
@@ -80,7 +80,7 @@ public final class GameObjectDecoder {
* @param buffer The buffer which holds the area's data. * @param buffer The buffer which holds the area's data.
* @return A collection of all parsed objects. * @return A collection of all parsed objects.
*/ */
private Collection<GameObject> parseArea(int area, ByteBuffer buffer) { private static Collection<GameObject> parseArea(int area, ByteBuffer buffer) {
List<GameObject> objects = new ArrayList<>(); List<GameObject> objects = new ArrayList<>();
int x = (area >> 8 & 0xFF) * 64; int x = (area >> 8 & 0xFF) * 64;
@@ -63,7 +63,7 @@ public final class ItemDefinitionDecoder {
* @param buffer The buffer. * @param buffer The buffer.
* @return The {@link ItemDefinition}. * @return The {@link ItemDefinition}.
*/ */
private ItemDefinition decode(int id, ByteBuffer buffer) { private static ItemDefinition decode(int id, ByteBuffer buffer) {
ItemDefinition definition = new ItemDefinition(id); ItemDefinition definition = new ItemDefinition(id);
while (true) { while (true) {
int opcode = buffer.get() & 0xFF; int opcode = buffer.get() & 0xFF;
@@ -76,17 +76,7 @@ public final class ItemDefinitionDecoder {
definition.setName(BufferUtil.readString(buffer)); definition.setName(BufferUtil.readString(buffer));
} else if (opcode == 3) { } else if (opcode == 3) {
definition.setDescription(BufferUtil.readString(buffer)); definition.setDescription(BufferUtil.readString(buffer));
} else if (opcode == 4) { } else if (opcode >= 4 && opcode <= 8 || opcode == 10) {
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(); buffer.getShort();
} else if (opcode == 11) { } else if (opcode == 11) {
definition.setStackable(true); definition.setStackable(true);
@@ -118,19 +108,7 @@ public final class ItemDefinitionDecoder {
buffer.getShort(); buffer.getShort();
buffer.getShort(); buffer.getShort();
} }
} else if (opcode == 78) { } else if (opcode == 78 || opcode == 79 || opcode >= 90 || opcode <= 93 || opcode == 95) {
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(); buffer.getShort();
} else if (opcode == 97) { } else if (opcode == 97) {
definition.setNoteInfoId(buffer.getShort() & 0xFFFF); definition.setNoteInfoId(buffer.getShort() & 0xFFFF);
@@ -139,15 +117,9 @@ public final class ItemDefinitionDecoder {
} else if (opcode >= 100 && opcode < 110) { } else if (opcode >= 100 && opcode < 110) {
buffer.getShort(); buffer.getShort();
buffer.getShort(); buffer.getShort();
} else if (opcode == 110) { } else if (opcode >= 110 && opcode <= 112) {
buffer.getShort(); buffer.getShort();
} else if (opcode == 111) { } else if (opcode == 113 || opcode == 114) {
buffer.getShort();
} else if (opcode == 112) {
buffer.getShort();
} else if (opcode == 113) {
buffer.get();
} else if (opcode == 114) {
buffer.get(); buffer.get();
} else if (opcode == 115) { } else if (opcode == 115) {
definition.setTeam(buffer.get() & 0xFF); definition.setTeam(buffer.get() & 0xFF);
@@ -2,6 +2,7 @@ package org.apollo.fs.decoder;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Arrays;
import org.apollo.fs.IndexedFileSystem; import org.apollo.fs.IndexedFileSystem;
import org.apollo.fs.archive.Archive; import org.apollo.fs.archive.Archive;
@@ -63,7 +64,7 @@ public final class NpcDefinitionDecoder {
* @param buffer The buffer. * @param buffer The buffer.
* @return The {@link NpcDefinition}. * @return The {@link NpcDefinition}.
*/ */
private NpcDefinition decode(int id, ByteBuffer buffer) { private static NpcDefinition decode(int id, ByteBuffer buffer) {
NpcDefinition definition = new NpcDefinition(id); NpcDefinition definition = new NpcDefinition(id);
while (true) { while (true) {
@@ -109,45 +110,25 @@ public final class NpcDefinitionDecoder {
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
additionalModels[i] = buffer.getShort(); additionalModels[i] = buffer.getShort();
} }
} else if (opcode == 90) { } else if (opcode >= 90 && opcode <= 92) {
buffer.getShort(); // Dummy
} else if (opcode == 91) {
buffer.getShort(); // Dummy
} else if (opcode == 92) {
buffer.getShort(); // Dummy buffer.getShort(); // Dummy
} else if (opcode == 95) { } else if (opcode == 95) {
definition.setCombatLevel(buffer.getShort()); definition.setCombatLevel(buffer.getShort());
} else if (opcode == 97) { } else if (opcode == 97 || opcode == 98) {
buffer.getShort(); buffer.getShort();
} else if (opcode == 98) { } else if (opcode == 100 || opcode == 101) {
buffer.getShort();
} else if (opcode == 100) {
buffer.get(); buffer.get();
} else if (opcode == 101) { } else if (opcode == 102 || opcode == 103) {
buffer.get();
} else if (opcode == 102) {
buffer.getShort();
} else if (opcode == 103) {
buffer.getShort(); buffer.getShort();
} else if (opcode == 106) { } else if (opcode == 106) {
int morphVariableBitsIndex = buffer.getShort(); @SuppressWarnings("unused")
if (morphVariableBitsIndex == 65535) { int morphVariableBitsIndex = wrapMorphism(buffer.getShort());
morphVariableBitsIndex = -1; @SuppressWarnings("unused")
} int morphismCount = wrapMorphism(buffer.getShort());
int morphismCount = buffer.getShort();
if (morphismCount == 65535) {
morphismCount = -1;
}
int count = buffer.get() & 0xFF; int count = buffer.get() & 0xFF;
int[] morphisms = new int[count + 1]; int[] morphisms = new int[count + 1];
for (int i = 0; i <= count; i++) { Arrays.setAll(morphisms, index -> wrapMorphism(buffer.getShort()));
int morphism = buffer.getShort();
if (morphism == 65535) {
morphism = -1;
}
morphisms[i] = morphism;
}
} else if (opcode == 107) { } else if (opcode == 107) {
@SuppressWarnings("unused") @SuppressWarnings("unused")
boolean clickable = false; boolean clickable = false;
@@ -155,4 +136,14 @@ public final class NpcDefinitionDecoder {
} }
} }
/**
* Wraps a morphism value around, returning -1 if the specified value is 65,535. TODO name
*
* @param value The value.
* @return -1 if {@code value} is 65,535, otherwise {@code value}.
*/
private static int wrapMorphism(int value) {
return value == 65_535 ? -1 : value;
}
} }
@@ -62,7 +62,7 @@ public final class ObjectDefinitionDecoder {
* @param data The {@link ByteBuffer} containing the data. * @param data The {@link ByteBuffer} containing the data.
* @return The object definition. * @return The object definition.
*/ */
public ObjectDefinition decode(int id, ByteBuffer data) { public static ObjectDefinition decode(int id, ByteBuffer data) {
ObjectDefinition definition = new ObjectDefinition(id); ObjectDefinition definition = new ObjectDefinition(id);
while (true) { while (true) {
int opcode = data.get() & 0xFF; int opcode = data.get() & 0xFF;
@@ -96,9 +96,7 @@ public final class ObjectDefinitionDecoder {
definition.setInteractive((data.get() & 0xFF) == 1); definition.setInteractive((data.get() & 0xFF) == 1);
} else if (opcode == 24) { } else if (opcode == 24) {
data.getShort(); data.getShort();
} else if (opcode == 28) { } else if (opcode == 28 || opcode == 29) {
data.get();
} else if (opcode == 29) {
data.get(); data.get();
} else if (opcode >= 30 && opcode < 39) { } else if (opcode >= 30 && opcode < 39) {
String[] actions = definition.getMenuActions(); String[] actions = definition.getMenuActions();
@@ -116,23 +114,11 @@ public final class ObjectDefinitionDecoder {
data.getShort(); data.getShort();
data.getShort(); data.getShort();
} }
} else if (opcode == 60) { } else if (opcode == 60 || opcode >= 65 && opcode <= 68) {
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(); data.getShort();
} else if (opcode == 69) { } else if (opcode == 69) {
data.get(); data.get();
} else if (opcode == 70) { } else if (opcode >= 70 && opcode <= 72) {
data.getShort();
} else if (opcode == 71) {
data.getShort();
} else if (opcode == 72) {
data.getShort(); data.getShort();
} else if (opcode == 75) { } else if (opcode == 75) {
data.get(); data.get();
+5 -6
View File
@@ -49,8 +49,8 @@ public final class GameService extends Service {
/** /**
* The scheduled executor service. * The scheduled executor service.
*/ */
private final ScheduledExecutorService scheduledExecutor = Executors private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory(
.newSingleThreadScheduledExecutor(new NamedThreadFactory("GameService")); "GameService"));
/** /**
* The {@link ClientSynchronizer}. * The {@link ClientSynchronizer}.
@@ -96,8 +96,7 @@ public final class GameService extends Service {
* @throws InstantiationException If a message handler could not be instantiated. * @throws InstantiationException If a message handler could not be instantiated.
* @throws IllegalAccessException If a message handler could not be accessed. * @throws IllegalAccessException If a message handler could not be accessed.
*/ */
private void init() throws IOException, SAXException, ClassNotFoundException, InstantiationException, private void init() throws IOException, SAXException, ClassNotFoundException, InstantiationException, IllegalAccessException {
IllegalAccessException {
try (InputStream is = new FileInputStream("data/messages.xml")) { try (InputStream is = new FileInputStream("data/messages.xml")) {
MessageHandlerChainParser chainGroupParser = new MessageHandlerChainParser(is); MessageHandlerChainParser chainGroupParser = new MessageHandlerChainParser(is);
chainGroup = chainGroupParser.parse(); chainGroup = chainGroupParser.parse();
@@ -165,8 +164,8 @@ public final class GameService extends Service {
*/ */
@Override @Override
public void start() { public void start() {
scheduledExecutor.scheduleAtFixedRate(new GamePulseHandler(this), GameConstants.PULSE_DELAY, scheduledExecutor.scheduleAtFixedRate(new GamePulseHandler(this), GameConstants.PULSE_DELAY, GameConstants.PULSE_DELAY,
GameConstants.PULSE_DELAY, TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
} }
/** /**
@@ -4,10 +4,10 @@ import org.apollo.game.message.handler.MessageHandler;
import org.apollo.game.message.handler.MessageHandlerContext; import org.apollo.game.message.handler.MessageHandlerContext;
import org.apollo.game.message.impl.ItemActionMessage; import org.apollo.game.message.impl.ItemActionMessage;
import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.Player;
import org.apollo.game.model.inter.EnterAmountListener;
import org.apollo.game.model.inter.bank.BankConstants; import org.apollo.game.model.inter.bank.BankConstants;
import org.apollo.game.model.inter.bank.BankDepositEnterAmountListener; import org.apollo.game.model.inter.bank.BankDepositEnterAmountListener;
import org.apollo.game.model.inter.bank.BankUtils; import org.apollo.game.model.inter.bank.BankUtils;
import org.apollo.game.model.inter.bank.BankWithdrawEnterAmountListener;
/** /**
* A {@link MessageHandler} that handles withdrawing and depositing items from/to a player's bank. * A {@link MessageHandler} that handles withdrawing and depositing items from/to a player's bank.
@@ -36,6 +36,7 @@ public final class BankMessageHandler extends MessageHandler<ItemActionMessage>
case 5: case 5:
return -1; return -1;
} }
throw new IllegalArgumentException("Invalid option supplied."); throw new IllegalArgumentException("Invalid option supplied.");
} }
@@ -46,11 +47,12 @@ public final class BankMessageHandler extends MessageHandler<ItemActionMessage>
* @param player The player. * @param player The player.
* @param message The message. * @param message The message.
*/ */
private void deposit(MessageHandlerContext ctx, Player player, ItemActionMessage message) { private static void deposit(MessageHandlerContext ctx, Player player, ItemActionMessage message) {
int amount = optionToAmount(message.getOption()); int amount = optionToAmount(message.getOption());
if (amount == -1) { if (amount == -1) {
player.getInterfaceSet().openEnterAmountDialogue( EnterAmountListener listener = new BankDepositEnterAmountListener(player, message.getSlot(), message.getId());
new BankDepositEnterAmountListener(player, message.getSlot(), message.getId())); player.getInterfaceSet().openEnterAmountDialogue(listener);
} else if (!BankUtils.deposit(player, message.getSlot(), message.getId(), amount)) { } else if (!BankUtils.deposit(player, message.getSlot(), message.getId(), amount)) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
} }
@@ -74,11 +76,12 @@ public final class BankMessageHandler extends MessageHandler<ItemActionMessage>
* @param player The player. * @param player The player.
* @param message The message. * @param message The message.
*/ */
private void withdraw(MessageHandlerContext ctx, Player player, ItemActionMessage message) { private static void withdraw(MessageHandlerContext ctx, Player player, ItemActionMessage message) {
int amount = optionToAmount(message.getOption()); int amount = optionToAmount(message.getOption());
if (amount == -1) { if (amount == -1) {
player.getInterfaceSet().openEnterAmountDialogue( EnterAmountListener listener = new BankDepositEnterAmountListener(player, message.getSlot(), message.getId());
new BankWithdrawEnterAmountListener(player, message.getSlot(), message.getId())); player.getInterfaceSet().openEnterAmountDialogue(listener);
} else if (!BankUtils.withdraw(player, message.getSlot(), message.getId(), amount)) { } else if (!BankUtils.withdraw(player, message.getSlot(), message.getId(), amount)) {
ctx.breakHandlerChain(); ctx.breakHandlerChain();
} }
@@ -43,8 +43,7 @@ public final class EquipItemHandler extends MessageHandler<ItemOptionMessage> {
String skillName = Skill.getName(id); String skillName = Skill.getName(id);
String article = LanguageUtil.getIndefiniteArticle(skillName); String article = LanguageUtil.getIndefiniteArticle(skillName);
player.sendMessage("You need " + article + " " + skillName + " level of " + requirement player.sendMessage("You need " + article + " " + skillName + " level of " + requirement + " to equip this item.");
+ " to equip this item.");
ctx.breakHandlerChain(); ctx.breakHandlerChain();
return; return;
} }
@@ -56,8 +55,7 @@ public final class EquipItemHandler extends MessageHandler<ItemOptionMessage> {
int equipmentSlot = definition.getSlot(); int equipmentSlot = definition.getSlot();
Item currentlyEquipped = equipment.get(equipmentSlot); Item currentlyEquipped = equipment.get(equipmentSlot);
if (equipping.getDefinition().isStackable() if (equipping.getDefinition().isStackable() && (currentlyEquipped == null || currentlyEquipped.getId() == equippingId)) {
&& (currentlyEquipped == null || currentlyEquipped.getId() == equippingId)) {
equipment.set(definition.getSlot(), equipping); equipment.set(definition.getSlot(), equipping);
inventory.reset(inventorySlot); inventory.reset(inventorySlot);
return; return;
@@ -62,13 +62,8 @@ public final class ObjectActionVerificationHandler extends MessageHandler<Object
* @param objects The list of objects. * @param objects The list of objects.
* @return {@code true} if the list does contain the object with the specified id, otherwise {@code false}. * @return {@code true} if the list does contain the object with the specified id, otherwise {@code false}.
*/ */
private boolean containsObject(int id, List<GameObject> objects) { private static boolean containsObject(int id, List<GameObject> objects) {
for (GameObject object : objects) { return objects.stream().filter(object -> object.getId() == id).findAny().isPresent();
if (object.getId() == id) {
return true;
}
}
return false;
} }
} }
@@ -29,8 +29,7 @@ public final class PlayerActionVerificationHandler extends MessageHandler<Player
} }
Player other = repository.get(index); Player other = repository.get(index);
if (other == null if (other == null || !player.getPosition().isWithinDistance(other.getPosition(), player.getViewingDistance() + 1)) {
|| !player.getPosition().isWithinDistance(other.getPosition(), player.getViewingDistance() + 1)) {
// +1 in case it was decremented after the player clicked the action. // +1 in case it was decremented after the player clicked the action.
ctx.breakHandlerChain(); ctx.breakHandlerChain();
return; return;
@@ -27,21 +27,23 @@ public final class PlayerDesignVerificationHandler extends MessageHandler<Player
* @param appearance The appearance combination. * @param appearance The appearance combination.
* @return {@code true} if so, {@code false} if not. * @return {@code true} if so, {@code false} if not.
*/ */
private boolean valid(Appearance appearance) { private static boolean valid(Appearance appearance) {
int[] colors = appearance.getColors(); int[] colors = appearance.getColors();
int[] maxColors = new int[] { 11, 15, 15, 5, 7 }; int[] maxColors = new int[] { 11, 15, 15, 5, 7 };
for (int i = 0; i < colors.length; i++) { for (int i = 0; i < colors.length; i++) {
if (colors[i] < 0 || colors[i] > maxColors[i]) { if (colors[i] < 0 || colors[i] > maxColors[i]) {
return false; return false;
} }
} }
Gender gender = appearance.getGender(); switch (appearance.getGender()) {
if (gender == Gender.MALE) { case FEMALE:
return validMaleStyle(appearance); return validFemaleStyle(appearance);
} else if (gender == Gender.FEMALE) { case MALE:
return validFemaleStyle(appearance); return validMaleStyle(appearance);
} }
throw new IllegalArgumentException("Player can only be either male or female."); throw new IllegalArgumentException("Player can only be either male or female.");
} }
@@ -51,15 +53,17 @@ public final class PlayerDesignVerificationHandler extends MessageHandler<Player
* @param appearance The appearance combination. * @param appearance The appearance combination.
* @return {@code true} if so, {@code false} if not. * @return {@code true} if so, {@code false} if not.
*/ */
private boolean validFemaleStyle(Appearance appearance) { private static boolean validFemaleStyle(Appearance appearance) {
int[] styles = appearance.getStyle(); int[] styles = appearance.getStyle();
int[] minStyles = new int[] { 45, 255, 56, 61, 67, 70, 79 }; int[] minStyles = new int[] { 45, 255, 56, 61, 67, 70, 79 };
int[] maxStyles = new int[] { 54, 255, 60, 65, 68, 77, 80 }; int[] maxStyles = new int[] { 54, 255, 60, 65, 68, 77, 80 };
for (int i = 0; i < styles.length; i++) { for (int i = 0; i < styles.length; i++) {
if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) { if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) {
return false; return false;
} }
} }
return true; return true;
} }
@@ -69,15 +73,17 @@ public final class PlayerDesignVerificationHandler extends MessageHandler<Player
* @param appearance The appearance combination. * @param appearance The appearance combination.
* @return {@code true} if so, {@code false} if not. * @return {@code true} if so, {@code false} if not.
*/ */
private boolean validMaleStyle(Appearance appearance) { private static boolean validMaleStyle(Appearance appearance) {
int[] styles = appearance.getStyle(); int[] styles = appearance.getStyle();
int[] minStyles = new int[] { 0, 10, 18, 26, 33, 36, 42 }; int[] minStyles = new int[] { 0, 10, 18, 26, 33, 36, 42 };
int[] maxStyles = new int[] { 8, 17, 25, 31, 34, 40, 43 }; int[] maxStyles = new int[] { 8, 17, 25, 31, 34, 40, 43 };
for (int i = 0; i < styles.length; i++) { for (int i = 0; i < styles.length; i++) {
if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) { if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) {
return false; return false;
} }
} }
return true; return true;
} }
@@ -3,8 +3,8 @@ package org.apollo.game.message.impl;
import org.apollo.game.message.Message; import org.apollo.game.message.Message;
/** /**
* A {@link Message} that represents some sort of action on an item in an inventory. Note that this is the parent of both * A {@link Message} that represents some sort of action on an item in an inventory. Note that this is the parent of
* item option and item action message, and so cannot be used to determine when one of those messages is fired. * both item option and item action message, and so cannot be used to determine when one of those messages is fired.
* *
* @author Chris Fletcher * @author Chris Fletcher
*/ */
@@ -3,9 +3,9 @@ package org.apollo.game.message.impl;
import org.apollo.game.message.Message; import org.apollo.game.message.Message;
/** /**
* A {@link Message} sent by the client that represents some sort of action on an item. Note that the actual message sent * A {@link Message} sent by the client that represents some sort of action on an item. Note that the actual message
* by the client is one of the five item action messages, but this is the message that should be intercepted (and the option * sent by the client is one of the five item action messages, but this is the message that should be intercepted (and
* verified). * the option verified).
* *
* @author Chris Fletcher * @author Chris Fletcher
*/ */
@@ -1,9 +1,9 @@
package org.apollo.game.message.impl; package org.apollo.game.message.impl;
/** /**
* An {@link InventoryItemMessage} sent by the client when an item's option is clicked (e.g. equip, eat, drink, etc). Note * An {@link InventoryItemMessage} sent by the client when an item's option is clicked (e.g. equip, eat, drink, etc).
* that the actual message sent by the client is one of the five item option messages, but this is the message that should be * Note that the actual message sent by the client is one of the five item option messages, but this is the message that
* intercepted (and the option verified). * should be intercepted (and the option verified).
* *
* @author Chris Fletcher * @author Chris Fletcher
*/ */
@@ -3,9 +3,9 @@ package org.apollo.game.message.impl;
import org.apollo.game.message.Message; import org.apollo.game.message.Message;
/** /**
* A {@link Message} sent by the client representing the clicking of an npc menu action. Note that the actual message sent * A {@link Message} sent by the client representing the clicking of an npc menu action. Note that the actual message
* by the client is one of the three npc action messages, but this is the message that should be intercepted (and the option * sent by the client is one of the three npc action messages, but this is the message that should be intercepted (and
* verified). * the option verified).
* *
* @author Major * @author Major
*/ */
@@ -4,9 +4,9 @@ import org.apollo.game.message.Message;
import org.apollo.game.model.Position; import org.apollo.game.model.Position;
/** /**
* A {@link Message} sent by the client that represents some sort of action on an object. Note that the actual message sent * A {@link Message} sent by the client that represents some sort of action on an object. Note that the actual message
* by the client is one of the five object action messages, but this is the message that should be intercepted (and the * sent by the client is one of the five object action messages, but this is the message that should be intercepted (and
* option verified). * the option verified).
* *
* @author Graham * @author Graham
*/ */
@@ -4,8 +4,8 @@ import org.apollo.game.message.Message;
/** /**
* A {@link Message} sent by the client representing the clicking of a player menu action. Note that the actual message * A {@link Message} sent by the client representing the clicking of a player menu action. Note that the actual message
* sent by the client is one of the five player action messages, but this is the message that should be intercepted (and the * sent by the client is one of the five player action messages, but this is the message that should be intercepted (and
* option verified). * the option verified).
* *
* @author Major * @author Major
*/ */
@@ -4,7 +4,8 @@ import org.apollo.game.message.Message;
import org.apollo.game.model.Position; import org.apollo.game.model.Position;
/** /**
* A {@link Message} sent to the client to focus on a specific {@link Position} (on which an action should be performed). * A {@link Message} sent to the client to focus on a specific {@link Position} (on which an action should be
* performed).
* *
* @author Chris Fletcher * @author Chris Fletcher
*/ */
+5
View File
@@ -1,5 +1,9 @@
package org.apollo.game.model; package org.apollo.game.model;
/** /**
* Represents a single movement direction. * Represents a single movement direction.
* *
@@ -86,6 +90,7 @@ public enum Direction {
return Direction.WEST; return Direction.WEST;
} }
} }
return Direction.NONE; return Direction.NONE;
} }
+25 -40
View File
@@ -21,19 +21,9 @@ public final class Position {
public static final int MAX_DISTANCE = 15; public static final int MAX_DISTANCE = 15;
/** /**
* The height level. * The packed integer containing the {@code height, x}, and {@code y} variables.
*/ */
private final int height; private final int position;
/**
* The x coordinate.
*/
private final int x;
/**
* The y coordinate.
*/
private final int y;
/** /**
* Creates a position at the default height. * Creates a position at the default height.
@@ -54,23 +44,18 @@ public final class Position {
*/ */
public Position(int x, int y, int height) { public Position(int x, int y, int height) {
Preconditions.checkArgument(height >= 0 && height < HEIGHT_LEVELS, "Height level out of bounds."); Preconditions.checkArgument(height >= 0 && height < HEIGHT_LEVELS, "Height level out of bounds.");
this.x = x;
this.y = y; position = height << 30 | (y & 0x7FFF) << 15 | x & 0x7FFF;
this.height = height;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == null) { if (obj instanceof Position) {
return false; Position other = (Position) obj;
} else if (this == obj) { return position == other.position;
return true;
} else if (getClass() != obj.getClass()) {
return false;
} }
Position other = (Position) obj; return false;
return x == other.x && y == other.y && height == other.height;
} }
/** /**
@@ -79,7 +64,7 @@ public final class Position {
* @return The x coordinate of the central sector. * @return The x coordinate of the central sector.
*/ */
public int getCentralSectorX() { public int getCentralSectorX() {
return x / 8; return getX() / 8;
} }
/** /**
@@ -88,7 +73,7 @@ public final class Position {
* @return The y coordinate of the central sector. * @return The y coordinate of the central sector.
*/ */
public int getCentralSectorY() { public int getCentralSectorY() {
return y / 8; return getY() / 8;
} }
/** /**
@@ -98,8 +83,8 @@ public final class Position {
* @return The distance. * @return The distance.
*/ */
public int getDistance(Position other) { public int getDistance(Position other) {
int deltaX = x - other.x; int deltaX = getX() - other.getX();
int deltaY = y - other.y; int deltaY = getY() - other.getY();
return (int) Math.ceil(Math.sqrt(deltaX * deltaX + deltaY * deltaY)); return (int) Math.ceil(Math.sqrt(deltaX * deltaX + deltaY * deltaY));
} }
@@ -109,7 +94,7 @@ public final class Position {
* @return The height level. * @return The height level.
*/ */
public int getHeight() { public int getHeight() {
return height; return position >> 30;
} }
/** /**
@@ -128,7 +113,7 @@ public final class Position {
* @return The local x coordinate. * @return The local x coordinate.
*/ */
public int getLocalX(Position base) { public int getLocalX(Position base) {
return x - base.getTopLeftSectorX() * 8; return getX() - base.getTopLeftSectorX() * 8;
} }
/** /**
@@ -147,7 +132,7 @@ public final class Position {
* @return The local y coordinate. * @return The local y coordinate.
*/ */
public int getLocalY(Position base) { public int getLocalY(Position base) {
return y - base.getTopLeftSectorY() * 8; return getY() - base.getTopLeftSectorY() * 8;
} }
/** /**
@@ -157,8 +142,8 @@ public final class Position {
* @return The longest horizontal or vertical delta. * @return The longest horizontal or vertical delta.
*/ */
public int getLongestDelta(Position other) { public int getLongestDelta(Position other) {
int deltaX = Math.abs(x - other.x); int deltaX = Math.abs(getX() - other.getX());
int deltaY = Math.abs(y - other.y); int deltaY = Math.abs(getY() - other.getY());
return Math.max(deltaX, deltaY); return Math.max(deltaX, deltaY);
} }
@@ -168,7 +153,7 @@ public final class Position {
* @return The sector x coordinate. * @return The sector x coordinate.
*/ */
public int getTopLeftSectorX() { public int getTopLeftSectorX() {
return x / 8 - 6; return getX() / 8 - 6;
} }
/** /**
@@ -177,7 +162,7 @@ public final class Position {
* @return The sector y coordinate. * @return The sector y coordinate.
*/ */
public int getTopLeftSectorY() { public int getTopLeftSectorY() {
return y / 8 - 6; return getY() / 8 - 6;
} }
/** /**
@@ -186,7 +171,7 @@ public final class Position {
* @return The x coordinate. * @return The x coordinate.
*/ */
public int getX() { public int getX() {
return x; return position & 0x7FFF;
} }
/** /**
@@ -195,12 +180,12 @@ public final class Position {
* @return The y coordinate. * @return The y coordinate.
*/ */
public int getY() { public int getY() {
return y; return (position >> 15) & 0x7FFF;
} }
@Override @Override
public int hashCode() { public int hashCode() {
return height << 30 & 0xC0000000 | y << 15 & 0x3FFF8000 | x & 0x7FFF; return position;
} }
/** /**
@@ -211,14 +196,14 @@ public final class Position {
* @return {@code true} if so, {@code false} if not. * @return {@code true} if so, {@code false} if not.
*/ */
public boolean isWithinDistance(Position other, int distance) { public boolean isWithinDistance(Position other, int distance) {
int deltaX = Math.abs(x - other.x); int deltaX = Math.abs(getX() - other.getX());
int deltaY = Math.abs(y - other.y); int deltaY = Math.abs(getY() - other.getY());
return deltaX <= distance && deltaY <= distance; return deltaX <= distance && deltaY <= distance;
} }
@Override @Override
public String toString() { public String toString() {
return MoreObjects.toStringHelper(this).add("x", x).add("y", y).add("height", height) return MoreObjects.toStringHelper(this).add("x", getX()).add("y", getY()).add("height", getHeight())
.add("sector x", getTopLeftSectorX()).add("sector y", getTopLeftSectorY()).toString(); .add("sector x", getTopLeftSectorX()).add("sector y", getTopLeftSectorY()).toString();
} }
@@ -20,6 +20,15 @@ public final class EquipmentDefinition {
*/ */
private static final Map<Integer, EquipmentDefinition> definitions = new HashMap<>(); private static final Map<Integer, EquipmentDefinition> definitions = new HashMap<>();
/**
* Gets the total number of equipment definitions.
*
* @return The count.
*/
public static int count() {
return definitions.size();
}
/** /**
* Initialises the equipment definitions. * Initialises the equipment definitions.
* *
@@ -79,15 +88,6 @@ public final class EquipmentDefinition {
this.id = id; this.id = id;
} }
/**
* Gets the total number of equipment definitions.
*
* @return The count.
*/
public int count() {
return definitions.size();
}
/** /**
* Gets the minimum attack level required to equip this item. * Gets the minimum attack level required to equip this item.
* *
+3 -3
View File
@@ -115,9 +115,9 @@ public final class Skill {
/** /**
* The skill names. * The skill names.
*/ */
private static final String[] SKILL_NAMES = { "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", private static final String[] SKILL_NAMES = { "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic",
"Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore",
"Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft" }; "Agility", "Thieving", "Slayer", "Farming", "Runecraft" };
/** /**
* Gets the name of a skill. * Gets the name of a skill.
+14 -15
View File
@@ -57,8 +57,8 @@ public final class SkillSet {
* @return The minimum level. * @return The minimum level.
*/ */
public static int getLevelForExperience(double experience) { public static int getLevelForExperience(double experience) {
Preconditions.checkArgument(experience >= 0 && experience <= MAXIMUM_EXP, Preconditions.checkArgument(experience >= 0 && experience <= MAXIMUM_EXP, "Experience must be between 0 and "
"Experience must be between 0 and 200,000,000, inclusive."); + MAXIMUM_EXP + ", inclusive.");
for (int level = 1; level <= 98; level++) { for (int level = 1; level <= 98; level++) {
if (experience < EXPERIENCE_FOR_LEVEL[level + 1]) { if (experience < EXPERIENCE_FOR_LEVEL[level + 1]) {
@@ -69,17 +69,17 @@ public final class SkillSet {
} }
/** /**
* The combat level for this skill set. * The combat level of this skill set.
*/ */
private int combatLevel = 3; private int combat = 3;
/** /**
* A flag indicating if events are being fired. * Whether or not events are being fired.
*/ */
private boolean firingEvents = true; private boolean firingEvents = true;
/** /**
* A list of skill listeners. * The list of skill listeners.
*/ */
private final List<SkillListener> listeners = new ArrayList<>(); private final List<SkillListener> listeners = new ArrayList<>();
@@ -105,16 +105,15 @@ public final class SkillSet {
checkBounds(id); checkBounds(id);
Skill old = skills[id]; Skill old = skills[id];
double newExperience = old.getExperience() + experience; double newExperience = Math.min(old.getExperience() + experience, MAXIMUM_EXP);
newExperience = newExperience > MAXIMUM_EXP ? MAXIMUM_EXP : newExperience;
int newCurrentLevel = old.getCurrentLevel(); int current = old.getCurrentLevel();
int newMaximumLevel = getLevelForExperience(newExperience); int maximum = getLevelForExperience(newExperience);
int delta = newMaximumLevel - old.getMaximumLevel(); int delta = maximum - old.getMaximumLevel();
newCurrentLevel += delta > 0 ? delta : 0; current += delta;
setSkill(id, new Skill(newExperience, newCurrentLevel, newMaximumLevel)); setSkill(id, new Skill(newExperience, current, maximum));
if (delta > 0) { if (delta > 0) {
notifyLevelledUp(id); // here so it notifies using the updated skill notifyLevelledUp(id); // here so it notifies using the updated skill
@@ -145,7 +144,7 @@ public final class SkillSet {
double base = (defence + hitpoints + Math.floor(prayer / 2)) * 0.25; double base = (defence + hitpoints + Math.floor(prayer / 2)) * 0.25;
double melee = (attack + strength) * 0.325; double melee = (attack + strength) * 0.325;
this.combatLevel = (int) (base + Math.max(melee, Math.max(ranged, magic) * 0.4875)); this.combat = (int) (base + Math.max(melee, Math.max(ranged, magic) * 0.4875));
} }
/** /**
@@ -161,7 +160,7 @@ public final class SkillSet {
* @return The combat level. * @return The combat level.
*/ */
public int getCombatLevel() { public int getCombatLevel() {
return combatLevel; return combat;
} }
/** /**
@@ -15,7 +15,7 @@ public final class AttributeMap {
/** /**
* The map of attribute names to definitions. * The map of attribute names to definitions.
*/ */
private static Map<String, AttributeDefinition<?>> definitions = new HashMap<>(50); private static Map<String, AttributeDefinition<?>> definitions = new HashMap<>(1);
/** /**
* Registers an {@link AttributeDefinition}. * Registers an {@link AttributeDefinition}.
@@ -15,8 +15,8 @@ public class InterfaceConstants {
/** /**
* The default inventory tab ids. * The default inventory tab ids.
*/ */
public static final int[] DEFAULT_INVENTORY_TABS = { 2423, 3917, 638, 3213, 1644, 5608, 1151, -1, 5065, 5715, 2449, public static final int[] DEFAULT_INVENTORY_TABS = { 2423, 3917, 638, 3213, 1644, 5608, 1151, -1, 5065, 5715, 2449, 904, 147,
904, 147, 962, }; 962, };
// 6299 = music tab, music disabled // 6299 = music tab, music disabled
// 4445 = settings tab, music disabled // 4445 = settings tab, music disabled
// 12855 = ancients magic // 12855 = ancients magic
@@ -24,8 +24,8 @@ public class InterfaceConstants {
/** /**
* The level-up dialogue interface ids. * The level-up dialogue interface ids.
*/ */
public static final int[] LEVEL_UP_INTERFACES = { 6247, 6253, 6206, 6216, 4443, 6242, 6211, 6226, 4272, 6231, 6258, public static final int[] LEVEL_UP_INTERFACES = { 6247, 6253, 6206, 6216, 4443, 6242, 6211, 6226, 4272, 6231, 6258, 4282,
4282, 6263, 6221, 4416, 6237, 4277, 4261, 12122, 4887, 4267 }; 6263, 6221, 4416, 6237, 4277, 4261, 12122, 4887, 4267 };
/** /**
* The quest interface id. * The quest interface id.
@@ -40,13 +40,12 @@ public class InterfaceConstants {
/** /**
* The array of widgets that display the text. * The array of widgets that display the text.
*/ */
public static final int[] QUEST_TEXT = { 8144, 8145, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, public static final int[] QUEST_TEXT = { 8144, 8145, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158,
8157, 8158, 8159, 8160, 8161, 8162, 8163, 8164, 8165, 8166, 8167, 8168, 8169, 8170, 8171, 8172, 8173, 8174, 8159, 8160, 8161, 8162, 8163, 8164, 8165, 8166, 8167, 8168, 8169, 8170, 8171, 8172, 8173, 8174, 8175, 8176, 8177,
8175, 8176, 8177, 8178, 8179, 8180, 8181, 8182, 8183, 8184, 8185, 8186, 8187, 8188, 8189, 8190, 8191, 8192, 8178, 8179, 8180, 8181, 8182, 8183, 8184, 8185, 8186, 8187, 8188, 8189, 8190, 8191, 8192, 8193, 8194, 8195, 12174,
8193, 8194, 8195, 12174, 12175, 12176, 12177, 12178, 12179, 12180, 12181, 12182, 12183, 12184, 12185, 12175, 12176, 12177, 12178, 12179, 12180, 12181, 12182, 12183, 12184, 12185, 12186, 12187, 12188, 12189, 12190,
12186, 12187, 12188, 12189, 12190, 12191, 12192, 12193, 12194, 12195, 12196, 12197, 12198, 12199, 12200, 12191, 12192, 12193, 12194, 12195, 12196, 12197, 12198, 12199, 12200, 12201, 12202, 12203, 12204, 12205, 12206,
12201, 12202, 12203, 12204, 12205, 12206, 12207, 12208, 12209, 12210, 12211, 12212, 12213, 12214, 12215, 12207, 12208, 12209, 12210, 12211, 12212, 12213, 12214, 12215, 12216, 12217, 12218, 12219, 12220, 12221, 12222, 12223 };
12216, 12217, 12218, 12219, 12220, 12221, 12222, 12223 };
/** /**
* The quest title widget id. * The quest title widget id.
@@ -76,8 +76,7 @@ public final class BankUtils {
InterfaceListener interListener = new BankInterfaceListener(player, invListener, bankListener); InterfaceListener interListener = new BankInterfaceListener(player, invListener, bankListener);
player.getInterfaceSet().openWindowWithSidebar(interListener, BankConstants.BANK_WINDOW_ID, player.getInterfaceSet().openWindowWithSidebar(interListener, BankConstants.BANK_WINDOW_ID, BankConstants.SIDEBAR_ID);
BankConstants.SIDEBAR_ID);
} }
/** /**
@@ -61,8 +61,7 @@ public final class AppearanceBlock extends SynchronizationBlock {
* @param headIcon The head icon id of the player. * @param headIcon The head icon id of the player.
* @param isSkulled Whether or not the player is skulled. * @param isSkulled Whether or not the player is skulled.
*/ */
AppearanceBlock(long name, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, AppearanceBlock(long name, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, boolean isSkulled) {
boolean isSkulled) {
this(name, appearance, combat, skill, equipment, headIcon, isSkulled, -1); this(name, appearance, combat, skill, equipment, headIcon, isSkulled, -1);
} }
@@ -84,7 +83,7 @@ public final class AppearanceBlock extends SynchronizationBlock {
this.appearance = appearance; this.appearance = appearance;
this.combat = combat; this.combat = combat;
this.skill = skill; this.skill = skill;
this.equipment = equipment.clone(); this.equipment = equipment.duplicate();
this.headIcon = headIcon; this.headIcon = headIcon;
this.isSkulled = isSkulled; this.isSkulled = isSkulled;
this.npcId = npcId; this.npcId = npcId;
@@ -13,7 +13,7 @@ public final class SynchronizationBlockSet implements Cloneable {
/** /**
* A {@link Map} of {@link SynchronizationBlock}s. * A {@link Map} of {@link SynchronizationBlock}s.
*/ */
private final Map<Class<? extends SynchronizationBlock>, SynchronizationBlock> blocks = new HashMap<>(); private final Map<Class<? extends SynchronizationBlock>, SynchronizationBlock> blocks = new HashMap<>(8);
/** /**
* Adds a {@link SynchronizationBlock}. * Adds a {@link SynchronizationBlock}.
@@ -26,7 +26,8 @@ public final class MovementSegment extends SynchronizationSegment {
*/ */
public MovementSegment(SynchronizationBlockSet blockSet, Direction[] directions) { public MovementSegment(SynchronizationBlockSet blockSet, Direction[] directions) {
super(blockSet); super(blockSet);
Preconditions.checkArgument(directions.length >= 0 && directions.length < 3, "Directions length must be between 0 and 2 inclusive."); Preconditions.checkArgument(directions.length >= 0 && directions.length < 3,
"Directions length must be between 0 and 2 inclusive.");
this.directions = directions; this.directions = directions;
} }
@@ -53,8 +53,8 @@ public final class MessageHandlerChainParser {
* @return A {@link MessageHandlerChainGroup}. * @return A {@link MessageHandlerChainGroup}.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public MessageHandlerChainGroup parse() throws IOException, SAXException, ClassNotFoundException, public MessageHandlerChainGroup parse() throws IOException, SAXException, ClassNotFoundException, InstantiationException,
InstantiationException, IllegalAccessException { IllegalAccessException {
XmlNode messages = parser.parse(is); XmlNode messages = parser.parse(is);
if (!messages.getName().equals("messages")) { if (!messages.getName().equals("messages")) {
throw new IOException("Root node name is not 'messages'."); throw new IOException("Root node name is not 'messages'.");
+3 -6
View File
@@ -3,6 +3,7 @@ package org.apollo.io;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Objects;
import org.apollo.util.plugin.PluginMetaData; import org.apollo.util.plugin.PluginMetaData;
import org.apollo.util.xml.XmlNode; import org.apollo.util.xml.XmlNode;
@@ -50,12 +51,8 @@ public final class PluginMetaDataParser {
* @return The node object. * @return The node object.
* @throws IOException If the element does not exist. * @throws IOException If the element does not exist.
*/ */
private XmlNode getElement(XmlNode node, String name) throws IOException { private static XmlNode getElement(XmlNode node, String name) throws IOException {
XmlNode child = node.getChild(name); return Objects.requireNonNull(node.getChild(name), "No " + name + " element found.");
if (child == null) {
throw new IOException("No " + name + " element found.");
}
return child;
} }
/** /**
@@ -157,7 +157,7 @@ public final class BinaryPlayerLoader implements PlayerLoader {
* @return The {@link Map} of attribute names to attributes. * @return The {@link Map} of attribute names to attributes.
* @throws IOException If there is an error reading from the stream. * @throws IOException If there is an error reading from the stream.
*/ */
private Map<String, Attribute<?>> readAttributes(DataInputStream in) throws IOException { private static Map<String, Attribute<?>> readAttributes(DataInputStream in) throws IOException {
int count = in.readInt(); int count = in.readInt();
Map<String, Attribute<?>> attributes = new HashMap<>(count); Map<String, Attribute<?>> attributes = new HashMap<>(count);
Attribute<?> attribute; Attribute<?> attribute;
@@ -195,7 +195,7 @@ public final class BinaryPlayerLoader implements PlayerLoader {
* @param inventory The inventory. * @param inventory The inventory.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
private void readInventory(DataInputStream in, Inventory inventory) throws IOException { private static void readInventory(DataInputStream in, Inventory inventory) throws IOException {
int capacity = in.readUnsignedShort(); int capacity = in.readUnsignedShort();
inventory.stopFiringEvents(); inventory.stopFiringEvents();
@@ -113,7 +113,7 @@ public final class BinaryPlayerSaver implements PlayerSaver {
* @param attribute The attribute. * @param attribute The attribute.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
private void saveAttribute(DataOutputStream out, Attribute<?> attribute) throws IOException { private static void saveAttribute(DataOutputStream out, Attribute<?> attribute) throws IOException {
AttributeType type = attribute.getType(); AttributeType type = attribute.getType();
out.writeByte(type.getValue()); out.writeByte(type.getValue());
@@ -143,7 +143,7 @@ public final class BinaryPlayerSaver implements PlayerSaver {
* @param inventory The inventory. * @param inventory The inventory.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
private void writeInventory(DataOutputStream out, Inventory inventory) throws IOException { private static void writeInventory(DataOutputStream out, Inventory inventory) throws IOException {
int capacity = inventory.capacity(); int capacity = inventory.capacity();
out.writeShort(capacity); out.writeShort(capacity);
+1 -2
View File
@@ -61,8 +61,7 @@ public final class LoginService extends Service {
* @throws IllegalAccessException If the player loader/saver implementation could not be accessed. * @throws IllegalAccessException If the player loader/saver implementation could not be accessed.
* @throws InstantiationException If the player loader/saver implementation could not be instantiated. * @throws InstantiationException If the player loader/saver implementation could not be instantiated.
*/ */
private void init() throws SAXException, IOException, ClassNotFoundException, InstantiationException, private void init() throws SAXException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException {
IllegalAccessException {
XmlParser parser = new XmlParser(); XmlParser parser = new XmlParser();
XmlNode rootNode; XmlNode rootNode;
+1 -2
View File
@@ -56,8 +56,7 @@ public final class PlayerLoaderWorker implements Runnable {
session.handlePlayerLoaderResponse(request, response); session.handlePlayerLoaderResponse(request, response);
} catch (Exception e) { } catch (Exception e) {
logger.log(Level.SEVERE, "Unable to load player's game.", e); logger.log(Level.SEVERE, "Unable to load player's game.", e);
session.handlePlayerLoaderResponse(request, new PlayerLoaderResponse( session.handlePlayerLoaderResponse(request, new PlayerLoaderResponse(LoginConstants.STATUS_COULD_NOT_COMPLETE));
LoginConstants.STATUS_COULD_NOT_COMPLETE));
} }
} }
@@ -72,7 +72,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param message The message. * @param message The message.
* @param builder The builder. * @param builder The builder.
*/ */
private void putAddNpcUpdate(AddNpcSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) { private static void putAddNpcUpdate(AddNpcSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0; boolean updateRequired = seg.getBlockSet().size() > 0;
Position npc = message.getPosition(); Position npc = message.getPosition();
Position other = seg.getPosition(); Position other = seg.getPosition();
@@ -90,7 +90,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
Animation animation = block.getAnimation(); Animation animation = block.getAnimation();
builder.put(DataType.SHORT, DataOrder.LITTLE, animation.getId()); builder.put(DataType.SHORT, DataOrder.LITTLE, animation.getId());
builder.put(DataType.BYTE, animation.getDelay()); builder.put(DataType.BYTE, animation.getDelay());
@@ -102,7 +102,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param segment The segment. * @param segment The segment.
* @param builder The block builder. * @param builder The block builder.
*/ */
private void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
SynchronizationBlockSet blockSet = segment.getBlockSet(); SynchronizationBlockSet blockSet = segment.getBlockSet();
if (blockSet.size() > 0) { if (blockSet.size() > 0) {
int mask = 0; int mask = 0;
@@ -181,7 +181,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
builder.putString(block.getMessage()); builder.putString(block.getMessage());
} }
@@ -191,7 +191,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
Graphic graphic = block.getGraphic(); Graphic graphic = block.getGraphic();
builder.put(DataType.SHORT, graphic.getId()); builder.put(DataType.SHORT, graphic.getId());
builder.put(DataType.INT, graphic.getDelay()); builder.put(DataType.INT, graphic.getDelay());
@@ -203,7 +203,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) {
builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage()); builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage());
builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getType()); builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getType());
builder.put(DataType.BYTE, DataTransformation.ADD, block.getCurrentHealth()); builder.put(DataType.BYTE, DataTransformation.ADD, block.getCurrentHealth());
@@ -216,7 +216,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) {
builder.put(DataType.SHORT, block.getInteractingMobIndex()); builder.put(DataType.SHORT, block.getInteractingMobIndex());
} }
@@ -227,7 +227,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param message The message. * @param message The message.
* @param builder The builder. * @param builder The builder.
*/ */
private void putMovementUpdate(SynchronizationSegment segment, NpcSynchronizationMessage message, private static void putMovementUpdate(SynchronizationSegment segment, NpcSynchronizationMessage message,
GamePacketBuilder builder) { GamePacketBuilder builder) {
boolean updateRequired = segment.getBlockSet().size() > 0; boolean updateRequired = segment.getBlockSet().size() > 0;
if (segment.getType() == SegmentType.RUN) { if (segment.getType() == SegmentType.RUN) {
@@ -258,7 +258,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* *
* @param builder The builder. * @param builder The builder.
*/ */
private void putRemoveMobUpdate(GamePacketBuilder builder) { private static void putRemoveMobUpdate(GamePacketBuilder builder) {
builder.putBits(1, 1); builder.putBits(1, 1);
builder.putBits(2, 3); builder.putBits(2, 3);
} }
@@ -269,7 +269,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) {
builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getDamage()); builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getDamage());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getCurrentHealth()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getCurrentHealth());
@@ -282,7 +282,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putTransformBlock(TransformBlock block, GamePacketBuilder builder) { private static void putTransformBlock(TransformBlock block, GamePacketBuilder builder) {
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, block.getId()); builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, block.getId());
} }
@@ -292,7 +292,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
Position position = block.getPosition(); Position position = block.getPosition();
builder.put(DataType.SHORT, DataOrder.LITTLE, position.getX() * 2 + 1); builder.put(DataType.SHORT, DataOrder.LITTLE, position.getX() * 2 + 1);
builder.put(DataType.SHORT, DataOrder.LITTLE, position.getY() * 2 + 1); builder.put(DataType.SHORT, DataOrder.LITTLE, position.getY() * 2 + 1);
@@ -86,7 +86,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param message The message. * @param message The message.
* @param builder The builder. * @param builder The builder.
*/ */
private void putAddPlayerUpdate(AddPlayerSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) { private static void putAddPlayerUpdate(AddPlayerSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0; boolean updateRequired = seg.getBlockSet().size() > 0;
Position player = message.getPosition(); Position player = message.getPosition();
Position other = seg.getPosition(); Position other = seg.getPosition();
@@ -103,7 +103,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
Animation animation = block.getAnimation(); Animation animation = block.getAnimation();
builder.put(DataType.SHORT, DataOrder.LITTLE, animation.getId()); builder.put(DataType.SHORT, DataOrder.LITTLE, animation.getId());
builder.put(DataType.BYTE, DataTransformation.NEGATE, animation.getDelay()); builder.put(DataType.BYTE, DataTransformation.NEGATE, animation.getDelay());
@@ -115,7 +115,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) { private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) {
Appearance appearance = block.getAppearance(); Appearance appearance = block.getAppearance();
GamePacketBuilder playerProperties = new GamePacketBuilder(); GamePacketBuilder playerProperties = new GamePacketBuilder();
@@ -230,7 +230,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param segment The segment. * @param segment The segment.
* @param builder The block builder. * @param builder The block builder.
*/ */
private void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
SynchronizationBlockSet blockSet = segment.getBlockSet(); SynchronizationBlockSet blockSet = segment.getBlockSet();
if (blockSet.size() > 0) { if (blockSet.size() > 0) {
int mask = 0; int mask = 0;
@@ -312,7 +312,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putChatBlock(ChatBlock block, GamePacketBuilder builder) { private static void putChatBlock(ChatBlock block, GamePacketBuilder builder) {
byte[] bytes = block.getCompressedMessage(); byte[] bytes = block.getCompressedMessage();
builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTextColor() << 8 | block.getTextEffects()); builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTextColor() << 8 | block.getTextEffects());
builder.put(DataType.BYTE, block.getPrivilegeLevel().toInteger()); builder.put(DataType.BYTE, block.getPrivilegeLevel().toInteger());
@@ -326,7 +326,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
builder.putString(block.getMessage()); builder.putString(block.getMessage());
} }
@@ -336,7 +336,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) { private static void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) {
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getInitialX()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getInitialX());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getInitialY()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getInitialY());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalX()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalX());
@@ -352,7 +352,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
Graphic graphic = block.getGraphic(); Graphic graphic = block.getGraphic();
builder.put(DataType.SHORT, DataOrder.LITTLE, graphic.getId()); builder.put(DataType.SHORT, DataOrder.LITTLE, graphic.getId());
builder.put(DataType.INT, graphic.getHeight() << 16 | graphic.getDelay() & 0xFFFF); builder.put(DataType.INT, graphic.getHeight() << 16 | graphic.getDelay() & 0xFFFF);
@@ -364,7 +364,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) {
builder.put(DataType.BYTE, block.getDamage()); builder.put(DataType.BYTE, block.getDamage());
builder.put(DataType.BYTE, DataTransformation.ADD, block.getType()); builder.put(DataType.BYTE, DataTransformation.ADD, block.getType());
builder.put(DataType.BYTE, block.getCurrentHealth()); builder.put(DataType.BYTE, block.getCurrentHealth());
@@ -377,7 +377,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) {
builder.put(DataType.SHORT, DataOrder.LITTLE, block.getInteractingMobIndex()); builder.put(DataType.SHORT, DataOrder.LITTLE, block.getInteractingMobIndex());
} }
@@ -388,7 +388,8 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param message The message. * @param message The message.
* @param builder The builder. * @param builder The builder.
*/ */
private void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) { private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message,
GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0; boolean updateRequired = seg.getBlockSet().size() > 0;
if (seg.getType() == SegmentType.TELEPORT) { if (seg.getType() == SegmentType.TELEPORT) {
Position position = ((TeleportSegment) seg).getDestination(); Position position = ((TeleportSegment) seg).getDestination();
@@ -427,7 +428,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* *
* @param builder The builder. * @param builder The builder.
*/ */
private void putRemovePlayerUpdate(GamePacketBuilder builder) { private static void putRemovePlayerUpdate(GamePacketBuilder builder) {
builder.putBits(1, 1); builder.putBits(1, 1);
builder.putBits(2, 3); builder.putBits(2, 3);
} }
@@ -438,7 +439,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) {
builder.put(DataType.BYTE, block.getDamage()); builder.put(DataType.BYTE, block.getDamage());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType());
builder.put(DataType.BYTE, block.getCurrentHealth()); builder.put(DataType.BYTE, block.getCurrentHealth());
@@ -451,7 +452,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
Position pos = block.getPosition(); Position pos = block.getPosition();
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, pos.getX() * 2 + 1); builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, pos.getX() * 2 + 1);
builder.put(DataType.SHORT, DataOrder.LITTLE, pos.getY() * 2 + 1); builder.put(DataType.SHORT, DataOrder.LITTLE, pos.getY() * 2 + 1);
@@ -72,7 +72,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param message The message. * @param message The message.
* @param builder The builder. * @param builder The builder.
*/ */
private void putAddNpcUpdate(AddNpcSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) { private static void putAddNpcUpdate(AddNpcSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0; boolean updateRequired = seg.getBlockSet().size() > 0;
Position npc = message.getPosition(); Position npc = message.getPosition();
Position other = seg.getPosition(); Position other = seg.getPosition();
@@ -90,7 +90,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
Animation animation = block.getAnimation(); Animation animation = block.getAnimation();
builder.put(DataType.SHORT, animation.getId()); builder.put(DataType.SHORT, animation.getId());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, animation.getDelay()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, animation.getDelay());
@@ -102,7 +102,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param segment The segment. * @param segment The segment.
* @param builder The block builder. * @param builder The block builder.
*/ */
private void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
SynchronizationBlockSet blockSet = segment.getBlockSet(); SynchronizationBlockSet blockSet = segment.getBlockSet();
if (blockSet.size() > 0) { if (blockSet.size() > 0) {
int mask = 0; int mask = 0;
@@ -181,7 +181,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
builder.putString(block.getMessage()); builder.putString(block.getMessage());
} }
@@ -191,7 +191,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
Graphic graphic = block.getGraphic(); Graphic graphic = block.getGraphic();
builder.put(DataType.SHORT, graphic.getId()); builder.put(DataType.SHORT, graphic.getId());
builder.put(DataType.INT, DataOrder.MIDDLE, graphic.getDelay()); builder.put(DataType.INT, DataOrder.MIDDLE, graphic.getDelay());
@@ -203,7 +203,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) {
builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage()); builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage());
builder.put(DataType.BYTE, DataTransformation.ADD, block.getType()); builder.put(DataType.BYTE, DataTransformation.ADD, block.getType());
builder.put(DataType.BYTE, block.getCurrentHealth()); builder.put(DataType.BYTE, block.getCurrentHealth());
@@ -216,7 +216,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) {
builder.put(DataType.SHORT, DataOrder.LITTLE, block.getInteractingMobIndex()); builder.put(DataType.SHORT, DataOrder.LITTLE, block.getInteractingMobIndex());
} }
@@ -227,7 +227,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param message The message. * @param message The message.
* @param builder The builder. * @param builder The builder.
*/ */
private void putMovementUpdate(SynchronizationSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) { private static void putMovementUpdate(SynchronizationSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0; boolean updateRequired = seg.getBlockSet().size() > 0;
if (seg.getType() == SegmentType.RUN) { if (seg.getType() == SegmentType.RUN) {
Direction[] directions = ((MovementSegment) seg).getDirections(); Direction[] directions = ((MovementSegment) seg).getDirections();
@@ -257,7 +257,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* *
* @param builder The builder. * @param builder The builder.
*/ */
private void putRemoveNpcUpdate(GamePacketBuilder builder) { private static void putRemoveNpcUpdate(GamePacketBuilder builder) {
builder.putBits(1, 1); builder.putBits(1, 1);
builder.putBits(2, 3); builder.putBits(2, 3);
} }
@@ -268,7 +268,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) {
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getDamage()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getDamage());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType());
builder.put(DataType.BYTE, block.getCurrentHealth()); builder.put(DataType.BYTE, block.getCurrentHealth());
@@ -281,7 +281,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putTransformBlock(TransformBlock block, GamePacketBuilder builder) { private static void putTransformBlock(TransformBlock block, GamePacketBuilder builder) {
builder.put(DataType.SHORT, DataTransformation.ADD, block.getId()); builder.put(DataType.SHORT, DataTransformation.ADD, block.getId());
} }
@@ -291,7 +291,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
Position position = block.getPosition(); Position position = block.getPosition();
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, position.getX() * 2 + 1); builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, position.getX() * 2 + 1);
builder.put(DataType.SHORT, DataOrder.LITTLE, position.getY() * 2 + 1); builder.put(DataType.SHORT, DataOrder.LITTLE, position.getY() * 2 + 1);
@@ -86,7 +86,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param message The message. * @param message The message.
* @param builder The builder. * @param builder The builder.
*/ */
private void putAddPlayerUpdate(AddPlayerSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) { private static void putAddPlayerUpdate(AddPlayerSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0; boolean updateRequired = seg.getBlockSet().size() > 0;
Position player = message.getPosition(); Position player = message.getPosition();
Position other = seg.getPosition(); Position other = seg.getPosition();
@@ -103,7 +103,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) { private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
Animation animation = block.getAnimation(); Animation animation = block.getAnimation();
builder.put(DataType.SHORT, animation.getId()); builder.put(DataType.SHORT, animation.getId());
builder.put(DataType.BYTE, DataTransformation.ADD, animation.getDelay()); builder.put(DataType.BYTE, DataTransformation.ADD, animation.getDelay());
@@ -115,7 +115,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) { private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) {
Appearance appearance = block.getAppearance(); Appearance appearance = block.getAppearance();
GamePacketBuilder playerProperties = new GamePacketBuilder(); GamePacketBuilder playerProperties = new GamePacketBuilder();
@@ -230,7 +230,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param segment The segment. * @param segment The segment.
* @param builder The block builder. * @param builder The block builder.
*/ */
private void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) { private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
SynchronizationBlockSet blockSet = segment.getBlockSet(); SynchronizationBlockSet blockSet = segment.getBlockSet();
if (blockSet.size() > 0) { if (blockSet.size() > 0) {
int mask = 0; int mask = 0;
@@ -312,7 +312,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putChatBlock(ChatBlock block, GamePacketBuilder builder) { private static void putChatBlock(ChatBlock block, GamePacketBuilder builder) {
byte[] bytes = block.getCompressedMessage(); byte[] bytes = block.getCompressedMessage();
builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTextEffects() << 8 | block.getTextColor()); builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTextEffects() << 8 | block.getTextColor());
builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getPrivilegeLevel().toInteger()); builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getPrivilegeLevel().toInteger());
@@ -326,7 +326,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) { private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
builder.putString(block.getMessage()); builder.putString(block.getMessage());
} }
@@ -336,7 +336,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) { private static void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) {
builder.put(DataType.BYTE, DataTransformation.ADD, block.getInitialX()); builder.put(DataType.BYTE, DataTransformation.ADD, block.getInitialX());
builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getInitialY()); builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getInitialY());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalX()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalX());
@@ -352,11 +352,10 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) { private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
Graphic graphic = block.getGraphic(); Graphic graphic = block.getGraphic();
builder.put(DataType.SHORT, DataTransformation.ADD, graphic.getId()); builder.put(DataType.SHORT, DataTransformation.ADD, graphic.getId());
builder.put(DataType.INT, DataOrder.MIDDLE, graphic.getHeight() << 16 & 0xFFFF0000 | graphic.getDelay() builder.put(DataType.INT, DataOrder.MIDDLE, graphic.getHeight() << 16 & 0xFFFF0000 | graphic.getDelay() & 0x0000FFFF);
& 0x0000FFFF);
} }
/** /**
@@ -365,7 +364,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) { private static void putHitUpdateBlock(HitUpdateBlock block, GamePacketBuilder builder) {
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getDamage()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getDamage());
builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getType()); builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getType());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getCurrentHealth()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getCurrentHealth());
@@ -378,7 +377,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) { private static void putInteractingMobBlock(InteractingMobBlock block, GamePacketBuilder builder) {
builder.put(DataType.SHORT, DataTransformation.ADD, block.getInteractingMobIndex()); builder.put(DataType.SHORT, DataTransformation.ADD, block.getInteractingMobIndex());
} }
@@ -389,7 +388,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param message The message. * @param message The message.
* @param builder The builder. * @param builder The builder.
*/ */
private void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message,
GamePacketBuilder builder) { GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0; boolean updateRequired = seg.getBlockSet().size() > 0;
if (seg.getType() == SegmentType.TELEPORT) { if (seg.getType() == SegmentType.TELEPORT) {
@@ -429,7 +428,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* *
* @param builder The builder. * @param builder The builder.
*/ */
private void putRemovePlayerUpdate(GamePacketBuilder builder) { private static void putRemovePlayerUpdate(GamePacketBuilder builder) {
builder.putBits(1, 1); builder.putBits(1, 1);
builder.putBits(2, 3); builder.putBits(2, 3);
} }
@@ -440,7 +439,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) { private static void putSecondHitUpdateBlock(SecondaryHitUpdateBlock block, GamePacketBuilder builder) {
builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage()); builder.put(DataType.BYTE, DataTransformation.ADD, block.getDamage());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType()); builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getType());
builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getCurrentHealth()); builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getCurrentHealth());
@@ -453,7 +452,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) { private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
Position position = block.getPosition(); Position position = block.getPosition();
builder.put(DataType.SHORT, position.getX() * 2 + 1); builder.put(DataType.SHORT, position.getX() * 2 + 1);
builder.put(DataType.SHORT, position.getY() * 2 + 1); builder.put(DataType.SHORT, position.getY() * 2 + 1);
+11 -13
View File
@@ -22,9 +22,8 @@ public final class EquipmentConstants {
/** /**
* Bodies. * Bodies.
*/ */
public static final String[] BODY = { "platebody", "chainbody", "robetop", "leathertop", "platemail", "top", public static final String[] BODY = { "platebody", "chainbody", "robetop", "leathertop", "platemail", "top", "brassard",
"brassard", "Robe top", "body", "platebody (t)", "platebody (g)", "body(g)", "body_(g)", "chestplate", "Robe top", "body", "platebody (t)", "platebody (g)", "body(g)", "body_(g)", "chestplate", "torso", "shirt" };
"torso", "shirt" };
/** /**
* Boots. * Boots.
@@ -39,8 +38,8 @@ public final class EquipmentConstants {
/** /**
* Full bodies. * Full bodies.
*/ */
public static final String[] FULL_BODIES = { "top", "shirt", "platebody", "Ahrims robetop", "Karils leathertop", public static final String[] FULL_BODIES = { "top", "shirt", "platebody", "Ahrims robetop", "Karils leathertop", "brassard",
"brassard", "Robe top", "robetop", "platebody (t)", "platebody (g)", "chestplate", "torso" }; "Robe top", "robetop", "platebody (t)", "platebody (g)", "chestplate", "torso" };
/** /**
* Full hats. * Full hats.
@@ -51,8 +50,8 @@ public final class EquipmentConstants {
/** /**
* Full masks. * Full masks.
*/ */
public static final String[] FULL_MASKS = { "full helm", "mask", "Veracs helm", "Guthans helm", "Torags helm", public static final String[] FULL_MASKS = { "full helm", "mask", "Veracs helm", "Guthans helm", "Torags helm", "Karils coif",
"Karils coif", "full helm (t)", "full helm (g)", "mask" }; "full helm (t)", "full helm (g)", "mask" };
/** /**
* Gloves. * Gloves.
@@ -62,9 +61,8 @@ public final class EquipmentConstants {
/** /**
* Hats. * Hats.
*/ */
public static final String[] HATS = { "tiara", "helm", "hood", "coif", "Coif", "hat", "partyhat", "Hat", public static final String[] HATS = { "tiara", "helm", "hood", "coif", "Coif", "hat", "partyhat", "Hat", "full helm (t)",
"full helm (t)", "full helm (g)", "hat (t)", "hat (g)", "cav", "boater", "helmet", "mask", "full helm (g)", "hat (t)", "hat (g)", "cav", "boater", "helmet", "mask", "Helm of neitiznot" };
"Helm of neitiznot" };
/** /**
* Legs. * Legs.
@@ -89,9 +87,9 @@ public final class EquipmentConstants {
*/ */
public static final String[] WEAPONS = { "scimitar", "longsword", "sword", "longbow", "shortbow", "dagger", "mace", public static final String[] WEAPONS = { "scimitar", "longsword", "sword", "longbow", "shortbow", "dagger", "mace",
"halberd", "spear", "Abyssal whip", "axe", "flail", "crossbow", "Torags hammers", "dagger(p)", "dagger(+)", "halberd", "spear", "Abyssal whip", "axe", "flail", "crossbow", "Torags hammers", "dagger(p)", "dagger(+)",
"dagger(s)", "spear(p)", "spear(+)", "spear(s)", "spear(kp)", "maul", "dart", "dart(p)", "javelin", "dagger(s)", "spear(p)", "spear(+)", "spear(s)", "spear(kp)", "maul", "dart", "dart(p)", "javelin", "javelin(p)",
"javelin(p)", "knife", "knife(p)", "Longbow", "Shortbow", "Crossbow", "Toktz-xil", "Toktz-mej", "knife", "knife(p)", "Longbow", "Shortbow", "Crossbow", "Toktz-xil", "Toktz-mej", "Tzhaar-ket", "staff", "Staff",
"Tzhaar-ket", "staff", "Staff", "godsword", "c'bow", "Crystal bow", "Dark bow", "Magic butterfly net" }; "godsword", "c'bow", "Crystal bow", "Dark bow", "Magic butterfly net" };
/** /**
* Default private constructor to prevent instantiation. * Default private constructor to prevent instantiation.
+2 -2
View File
@@ -30,8 +30,8 @@ public final class NoteUpdater {
Preconditions.checkArgument(args.length == 1, "Usage:\njava -cp ... org.apollo.tools.NoteUpdater [release]."); Preconditions.checkArgument(args.length == 1, "Usage:\njava -cp ... org.apollo.tools.NoteUpdater [release].");
String release = args[0]; String release = args[0];
try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/note-" try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/note-" + release
+ release + ".dat"))); + ".dat")));
IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", release), true)) { IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", release), true)) {
ItemDefinitionDecoder decoder = new ItemDefinitionDecoder(fs); ItemDefinitionDecoder decoder = new ItemDefinitionDecoder(fs);
ItemDefinition[] defs = decoder.decode(); ItemDefinition[] defs = decoder.decode();
+5 -5
View File
@@ -61,12 +61,10 @@ public final class HttpRequestWorker extends RequestWorker<HttpRequest, Resource
* @param description The error description. * @param description The error description.
* @return The error page as a buffer. * @return The error page as a buffer.
*/ */
private ByteBuf createErrorPage(HttpResponseStatus status, String description) { private static ByteBuf createErrorPage(HttpResponseStatus status, String description) {
String title = status.code() + " " + status.reasonPhrase(); String title = status.code() + " " + status.reasonPhrase();
StringBuilder builder = new StringBuilder("<!DOCTYPE html><html><head><title>");
StringBuilder builder = new StringBuilder();
builder.append("<!DOCTYPE html><html><head><title>");
builder.append(title); builder.append(title);
builder.append("</title></head><body><h1>"); builder.append("</title></head><body><h1>");
builder.append(title); builder.append(title);
@@ -85,10 +83,11 @@ public final class HttpRequestWorker extends RequestWorker<HttpRequest, Resource
* @param name The file name. * @param name The file name.
* @return The MIME type. * @return The MIME type.
*/ */
private String getMimeType(String name) { private static String getMimeType(String name) {
if (name.endsWith("/")) { if (name.endsWith("/")) {
name = name.concat("index.html"); name = name.concat("index.html");
} }
if (name.endsWith(".htm") || name.endsWith(".html")) { if (name.endsWith(".htm") || name.endsWith(".html")) {
return "text/html"; return "text/html";
} else if (name.endsWith(".css")) { } else if (name.endsWith(".css")) {
@@ -104,6 +103,7 @@ public final class HttpRequestWorker extends RequestWorker<HttpRequest, Resource
} else if (name.endsWith(".txt")) { } else if (name.endsWith(".txt")) {
return "text/plain"; return "text/plain";
} }
return "application/octect-stream"; return "application/octect-stream";
} }
@@ -16,8 +16,8 @@ public final class VirtualResourceProvider extends ResourceProvider {
/** /**
* An array of valid prefixes. * An array of valid prefixes.
*/ */
private static final String[] VALID_PREFIXES = { "crc", "title", "config", "interface", "media", "versionlist", private static final String[] VALID_PREFIXES = { "crc", "title", "config", "interface", "media", "versionlist", "textures",
"textures", "wordenc", "sounds" }; "wordenc", "sounds" };
/** /**
* The file system. * The file system.
@@ -61,7 +61,8 @@ public abstract class StatefulFrameDecoder<T extends Enum<T>> extends ByteToMess
* @param ctx The current context of this handler. * @param ctx The current context of this handler.
* @param in The cumulative buffer, which may contain zero or more bytes. * @param in The cumulative buffer, which may contain zero or more bytes.
* @param out The {@link List} of objects to pass forward through the pipeline. * @param out The {@link List} of objects to pass forward through the pipeline.
* @param state The current state. The state may be changed by calling {@link #setState(Enum)}. * @param state The current state. The state may be changed by calling {@link #setState}.
* @throws Exception If there is an exception when decoding a frame.
*/ */
protected abstract void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, T state) throws Exception; protected abstract void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, T state) throws Exception;
+4 -4
View File
@@ -11,10 +11,10 @@ public final class TextUtil {
* An array of characters ordered by frequency - the elements with lower indices (generally) appear more often in * An array of characters ordered by frequency - the elements with lower indices (generally) appear more often in
* chat messages. * chat messages.
*/ */
public static final char[] FREQUENCY_ORDERED_CHARS = { ' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r', 'd', 'l', public static final char[] FREQUENCY_ORDERED_CHARS = { ' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r', 'd', 'l', 'u', 'm',
'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p', 'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2', '3', '4', '5', 'w', 'c', 'y', 'f', 'g', 'p', 'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'6', '7', '8', '9', ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\', '\'', '@', '#', '+', ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\', '\'', '@', '#', '+', '=', '\243', '$', '%', '"',
'=', '\243', '$', '%', '"', '[', ']' }; '[', ']' };
/** /**
* Capitalizes the string correctly. * Capitalizes the string correctly.
+28 -28
View File
@@ -19,6 +19,34 @@ import org.apollo.game.model.World;
*/ */
public final class PluginContext { public final class PluginContext {
/**
* Adds a {@link CommandListener}.
*
* @param name The name of the listener.
* @param listener The listener.
*/
public static void addCommandListener(String name, CommandListener listener) {
World.getWorld().getCommandDispatcher().register(name, listener);
}
/**
* Adds a {@link LoginListener}.
*
* @param listener The listener.
*/
public static void addLoginListener(LoginListener listener) {
World.getWorld().getLoginDispatcher().register(listener);
}
/**
* Adds a {@link LogoutListener}.
*
* @param listener The listener.
*/
public static void addLogoutListener(LogoutListener listener) {
World.getWorld().getLogoutDispatcher().register(listener);
}
/** /**
* The server context. * The server context.
*/ */
@@ -33,16 +61,6 @@ public final class PluginContext {
this.context = context; this.context = context;
} }
/**
* Adds a {@link CommandListener}.
*
* @param name The name of the listener.
* @param listener The listener.
*/
public void addCommandListener(String name, CommandListener listener) {
World.getWorld().getCommandDispatcher().register(name, listener);
}
/** /**
* Adds a {@link MessageHandler} to the end of the chain. * Adds a {@link MessageHandler} to the end of the chain.
* *
@@ -61,22 +79,4 @@ public final class PluginContext {
} }
} }
/**
* Adds a {@link LoginListener}.
*
* @param listener The listener.
*/
public void addLoginListener(LoginListener listener) {
World.getWorld().getLoginDispatcher().register(listener);
}
/**
* Adds a {@link LogoutListener}.
*
* @param listener The listener.
*/
public void addLogoutListener(LogoutListener listener) {
World.getWorld().getLogoutDispatcher().register(listener);
}
} }
@@ -7,12 +7,13 @@ import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.apollo.io.PluginMetaDataParser; import org.apollo.io.PluginMetaDataParser;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@@ -50,11 +51,8 @@ public final class PluginManager {
* @param plugins The plugin collection. * @param plugins The plugin collection.
* @return The plugin map. * @return The plugin map.
*/ */
private Map<String, PluginMetaData> createMap(Collection<PluginMetaData> plugins) { private static Map<String, PluginMetaData> createMap(Collection<PluginMetaData> plugins) {
Map<String, PluginMetaData> map = new HashMap<>(); Map<String, PluginMetaData> map = plugins.stream().collect(Collectors.toMap(PluginMetaData::getId, Function.identity()));
for (PluginMetaData plugin : plugins) {
map.put(plugin.getId(), plugin);
}
return Collections.unmodifiableMap(map); return Collections.unmodifiableMap(map);
} }