From ab8ad2a556bd9994664ad3c7def704a5478c333d Mon Sep 17 00:00:00 2001 From: Major- Date: Wed, 7 Jan 2015 15:45:15 +0000 Subject: [PATCH] Add many various quality improvements throughout the codebase. --- src/org/apollo/Server.java | 8 +-- src/org/apollo/ServiceManager.java | 3 +- .../apollo/fs/decoder/GameObjectDecoder.java | 2 +- .../fs/decoder/ItemDefinitionDecoder.java | 38 ++--------- .../fs/decoder/NpcDefinitionDecoder.java | 51 ++++++--------- .../fs/decoder/ObjectDefinitionDecoder.java | 22 ++----- src/org/apollo/game/GameService.java | 11 ++-- .../handler/impl/BankMessageHandler.java | 17 +++-- .../handler/impl/EquipItemHandler.java | 6 +- .../impl/ObjectActionVerificationHandler.java | 9 +-- .../impl/PlayerActionVerificationHandler.java | 3 +- .../impl/PlayerDesignVerificationHandler.java | 22 ++++--- .../message/impl/InventoryItemMessage.java | 4 +- .../game/message/impl/ItemActionMessage.java | 6 +- .../game/message/impl/ItemOptionMessage.java | 6 +- .../game/message/impl/NpcActionMessage.java | 6 +- .../message/impl/ObjectActionMessage.java | 6 +- .../message/impl/PlayerActionMessage.java | 4 +- .../game/message/impl/PositionMessage.java | 3 +- src/org/apollo/game/model/Direction.java | 5 ++ src/org/apollo/game/model/Position.java | 65 +++++++------------ .../game/model/def/EquipmentDefinition.java | 18 ++--- src/org/apollo/game/model/entity/Skill.java | 6 +- .../apollo/game/model/entity/SkillSet.java | 29 ++++----- .../game/model/entity/attr/AttributeMap.java | 2 +- .../game/model/inter/InterfaceConstants.java | 21 +++--- .../game/model/inter/bank/BankUtils.java | 3 +- .../game/sync/block/AppearanceBlock.java | 5 +- .../sync/block/SynchronizationBlockSet.java | 2 +- .../apollo/game/sync/seg/MovementSegment.java | 3 +- .../apollo/io/MessageHandlerChainParser.java | 4 +- src/org/apollo/io/PluginMetaDataParser.java | 9 +-- .../io/player/impl/BinaryPlayerLoader.java | 4 +- .../io/player/impl/BinaryPlayerSaver.java | 4 +- src/org/apollo/login/LoginService.java | 3 +- src/org/apollo/login/PlayerLoaderWorker.java | 3 +- .../NpcSynchronizationMessageEncoder.java | 24 +++---- .../PlayerSynchronizationMessageEncoder.java | 29 +++++---- .../NpcSynchronizationMessageEncoder.java | 24 +++---- .../PlayerSynchronizationMessageEncoder.java | 31 +++++---- src/org/apollo/tools/EquipmentConstants.java | 24 ++++--- src/org/apollo/tools/NoteUpdater.java | 4 +- src/org/apollo/update/HttpRequestWorker.java | 10 +-- .../resource/VirtualResourceProvider.java | 4 +- src/org/apollo/util/StatefulFrameDecoder.java | 3 +- src/org/apollo/util/TextUtil.java | 8 +-- src/org/apollo/util/plugin/PluginContext.java | 56 ++++++++-------- src/org/apollo/util/plugin/PluginManager.java | 10 ++- 48 files changed, 283 insertions(+), 357 deletions(-) diff --git a/src/org/apollo/Server.java b/src/org/apollo/Server.java index 4caa6a43..2534bd29 100644 --- a/src/org/apollo/Server.java +++ b/src/org/apollo/Server.java @@ -112,10 +112,9 @@ public final class Server { logger.fine("Binding HTTP listener to address: " + httpAddress + "..."); try { - // httpBootstrap.bind(httpAddress); + httpBootstrap.bind(httpAddress); } catch (Throwable t) { - logger.log(Level.WARNING, - "Binding to HTTP failed: client will use JAGGRAB as a fallback (not recommended)!", t); + logger.log(Level.WARNING, "Binding to HTTP failed: client will use JAGGRAB as a fallback (not recommended)!", t); } 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 InstantiationException If the release class could not be instantiated. */ - public void init(String releaseClassName) throws ClassNotFoundException, InstantiationException, - IllegalAccessException { + public void init(String releaseClassName) throws ClassNotFoundException, InstantiationException, IllegalAccessException { Class clazz = Class.forName(releaseClassName); Release release = (Release) clazz.newInstance(); diff --git a/src/org/apollo/ServiceManager.java b/src/org/apollo/ServiceManager.java index 1aaa724b..c060a51b 100644 --- a/src/org/apollo/ServiceManager.java +++ b/src/org/apollo/ServiceManager.java @@ -61,8 +61,7 @@ public final class ServiceManager { * @throws ClassNotFoundException If the service could not be found. */ @SuppressWarnings("unchecked") - private void init() throws SAXException, IOException, InstantiationException, IllegalAccessException, - ClassNotFoundException { + private void init() throws SAXException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException { logger.fine("Registering services..."); XmlParser parser = new XmlParser(); diff --git a/src/org/apollo/fs/decoder/GameObjectDecoder.java b/src/org/apollo/fs/decoder/GameObjectDecoder.java index e1f55dcd..bff8fc82 100644 --- a/src/org/apollo/fs/decoder/GameObjectDecoder.java +++ b/src/org/apollo/fs/decoder/GameObjectDecoder.java @@ -80,7 +80,7 @@ public final class GameObjectDecoder { * @param buffer The buffer which holds the area's data. * @return A collection of all parsed objects. */ - private Collection parseArea(int area, ByteBuffer buffer) { + private static Collection parseArea(int area, ByteBuffer buffer) { List objects = new ArrayList<>(); int x = (area >> 8 & 0xFF) * 64; diff --git a/src/org/apollo/fs/decoder/ItemDefinitionDecoder.java b/src/org/apollo/fs/decoder/ItemDefinitionDecoder.java index 05e26355..9124041f 100644 --- a/src/org/apollo/fs/decoder/ItemDefinitionDecoder.java +++ b/src/org/apollo/fs/decoder/ItemDefinitionDecoder.java @@ -63,7 +63,7 @@ public final class ItemDefinitionDecoder { * @param buffer The buffer. * @return The {@link ItemDefinition}. */ - private ItemDefinition decode(int id, ByteBuffer buffer) { + private static ItemDefinition decode(int id, ByteBuffer buffer) { ItemDefinition definition = new ItemDefinition(id); while (true) { int opcode = buffer.get() & 0xFF; @@ -76,17 +76,7 @@ public final class ItemDefinitionDecoder { definition.setName(BufferUtil.readString(buffer)); } else if (opcode == 3) { definition.setDescription(BufferUtil.readString(buffer)); - } else if (opcode == 4) { - buffer.getShort(); - } else if (opcode == 5) { - buffer.getShort(); - } else if (opcode == 6) { - buffer.getShort(); - } else if (opcode == 7) { - buffer.getShort(); - } else if (opcode == 8) { - buffer.getShort(); - } else if (opcode == 10) { + } else if (opcode >= 4 && opcode <= 8 || opcode == 10) { buffer.getShort(); } else if (opcode == 11) { definition.setStackable(true); @@ -118,19 +108,7 @@ public final class ItemDefinitionDecoder { buffer.getShort(); buffer.getShort(); } - } else if (opcode == 78) { - buffer.getShort(); - } else if (opcode == 79) { - buffer.getShort(); - } else if (opcode == 90) { - buffer.getShort(); - } else if (opcode == 91) { - buffer.getShort(); - } else if (opcode == 92) { - buffer.getShort(); - } else if (opcode == 93) { - buffer.getShort(); - } else if (opcode == 95) { + } else if (opcode == 78 || opcode == 79 || opcode >= 90 || opcode <= 93 || opcode == 95) { buffer.getShort(); } else if (opcode == 97) { definition.setNoteInfoId(buffer.getShort() & 0xFFFF); @@ -139,15 +117,9 @@ public final class ItemDefinitionDecoder { } else if (opcode >= 100 && opcode < 110) { buffer.getShort(); buffer.getShort(); - } else if (opcode == 110) { + } else if (opcode >= 110 && opcode <= 112) { buffer.getShort(); - } else if (opcode == 111) { - buffer.getShort(); - } else if (opcode == 112) { - buffer.getShort(); - } else if (opcode == 113) { - buffer.get(); - } else if (opcode == 114) { + } else if (opcode == 113 || opcode == 114) { buffer.get(); } else if (opcode == 115) { definition.setTeam(buffer.get() & 0xFF); diff --git a/src/org/apollo/fs/decoder/NpcDefinitionDecoder.java b/src/org/apollo/fs/decoder/NpcDefinitionDecoder.java index fd329f1f..6e95b63f 100644 --- a/src/org/apollo/fs/decoder/NpcDefinitionDecoder.java +++ b/src/org/apollo/fs/decoder/NpcDefinitionDecoder.java @@ -2,6 +2,7 @@ package org.apollo.fs.decoder; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.Arrays; import org.apollo.fs.IndexedFileSystem; import org.apollo.fs.archive.Archive; @@ -63,7 +64,7 @@ public final class NpcDefinitionDecoder { * @param buffer The buffer. * @return The {@link NpcDefinition}. */ - private NpcDefinition decode(int id, ByteBuffer buffer) { + private static NpcDefinition decode(int id, ByteBuffer buffer) { NpcDefinition definition = new NpcDefinition(id); while (true) { @@ -109,45 +110,25 @@ public final class NpcDefinitionDecoder { for (int i = 0; i < length; i++) { additionalModels[i] = buffer.getShort(); } - } else if (opcode == 90) { - buffer.getShort(); // Dummy - } else if (opcode == 91) { - buffer.getShort(); // Dummy - } else if (opcode == 92) { + } else if (opcode >= 90 && opcode <= 92) { buffer.getShort(); // Dummy } else if (opcode == 95) { definition.setCombatLevel(buffer.getShort()); - } else if (opcode == 97) { + } else if (opcode == 97 || opcode == 98) { buffer.getShort(); - } else if (opcode == 98) { - buffer.getShort(); - } else if (opcode == 100) { + } else if (opcode == 100 || opcode == 101) { buffer.get(); - } else if (opcode == 101) { - buffer.get(); - } else if (opcode == 102) { - buffer.getShort(); - } else if (opcode == 103) { + } else if (opcode == 102 || opcode == 103) { buffer.getShort(); } else if (opcode == 106) { - int morphVariableBitsIndex = buffer.getShort(); - if (morphVariableBitsIndex == 65535) { - morphVariableBitsIndex = -1; - } - int morphismCount = buffer.getShort(); - if (morphismCount == 65535) { - morphismCount = -1; - } + @SuppressWarnings("unused") + int morphVariableBitsIndex = wrapMorphism(buffer.getShort()); + @SuppressWarnings("unused") + int morphismCount = wrapMorphism(buffer.getShort()); int count = buffer.get() & 0xFF; int[] morphisms = new int[count + 1]; - for (int i = 0; i <= count; i++) { - int morphism = buffer.getShort(); - if (morphism == 65535) { - morphism = -1; - } - morphisms[i] = morphism; - } + Arrays.setAll(morphisms, index -> wrapMorphism(buffer.getShort())); } else if (opcode == 107) { @SuppressWarnings("unused") 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; + } + } \ No newline at end of file diff --git a/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java b/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java index b828f76e..765acfda 100644 --- a/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java +++ b/src/org/apollo/fs/decoder/ObjectDefinitionDecoder.java @@ -62,7 +62,7 @@ public final class ObjectDefinitionDecoder { * @param data The {@link ByteBuffer} containing the data. * @return The object definition. */ - public ObjectDefinition decode(int id, ByteBuffer data) { + public static ObjectDefinition decode(int id, ByteBuffer data) { ObjectDefinition definition = new ObjectDefinition(id); while (true) { int opcode = data.get() & 0xFF; @@ -96,9 +96,7 @@ public final class ObjectDefinitionDecoder { definition.setInteractive((data.get() & 0xFF) == 1); } else if (opcode == 24) { data.getShort(); - } else if (opcode == 28) { - data.get(); - } else if (opcode == 29) { + } else if (opcode == 28 || opcode == 29) { data.get(); } else if (opcode >= 30 && opcode < 39) { String[] actions = definition.getMenuActions(); @@ -116,23 +114,11 @@ public final class ObjectDefinitionDecoder { data.getShort(); data.getShort(); } - } else if (opcode == 60) { - data.getShort(); - } else if (opcode == 65) { - data.getShort(); - } else if (opcode == 66) { - data.getShort(); - } else if (opcode == 67) { - data.getShort(); - } else if (opcode == 68) { + } else if (opcode == 60 || opcode >= 65 && opcode <= 68) { data.getShort(); } else if (opcode == 69) { data.get(); - } else if (opcode == 70) { - data.getShort(); - } else if (opcode == 71) { - data.getShort(); - } else if (opcode == 72) { + } else if (opcode >= 70 && opcode <= 72) { data.getShort(); } else if (opcode == 75) { data.get(); diff --git a/src/org/apollo/game/GameService.java b/src/org/apollo/game/GameService.java index 654edb10..31cc3730 100644 --- a/src/org/apollo/game/GameService.java +++ b/src/org/apollo/game/GameService.java @@ -49,8 +49,8 @@ public final class GameService extends Service { /** * The scheduled executor service. */ - private final ScheduledExecutorService scheduledExecutor = Executors - .newSingleThreadScheduledExecutor(new NamedThreadFactory("GameService")); + private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new NamedThreadFactory( + "GameService")); /** * The {@link ClientSynchronizer}. @@ -96,8 +96,7 @@ public final class GameService extends Service { * @throws InstantiationException If a message handler could not be instantiated. * @throws IllegalAccessException If a message handler could not be accessed. */ - private void init() throws IOException, SAXException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + private void init() throws IOException, SAXException, ClassNotFoundException, InstantiationException, IllegalAccessException { try (InputStream is = new FileInputStream("data/messages.xml")) { MessageHandlerChainParser chainGroupParser = new MessageHandlerChainParser(is); chainGroup = chainGroupParser.parse(); @@ -165,8 +164,8 @@ public final class GameService extends Service { */ @Override public void start() { - scheduledExecutor.scheduleAtFixedRate(new GamePulseHandler(this), GameConstants.PULSE_DELAY, - GameConstants.PULSE_DELAY, TimeUnit.MILLISECONDS); + scheduledExecutor.scheduleAtFixedRate(new GamePulseHandler(this), GameConstants.PULSE_DELAY, GameConstants.PULSE_DELAY, + TimeUnit.MILLISECONDS); } /** diff --git a/src/org/apollo/game/message/handler/impl/BankMessageHandler.java b/src/org/apollo/game/message/handler/impl/BankMessageHandler.java index 226bc739..8e5c5925 100644 --- a/src/org/apollo/game/message/handler/impl/BankMessageHandler.java +++ b/src/org/apollo/game/message/handler/impl/BankMessageHandler.java @@ -4,10 +4,10 @@ import org.apollo.game.message.handler.MessageHandler; import org.apollo.game.message.handler.MessageHandlerContext; import org.apollo.game.message.impl.ItemActionMessage; 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.BankDepositEnterAmountListener; 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. @@ -36,6 +36,7 @@ public final class BankMessageHandler extends MessageHandler case 5: return -1; } + throw new IllegalArgumentException("Invalid option supplied."); } @@ -46,11 +47,12 @@ public final class BankMessageHandler extends MessageHandler * @param player The player. * @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()); + if (amount == -1) { - player.getInterfaceSet().openEnterAmountDialogue( - new BankDepositEnterAmountListener(player, message.getSlot(), message.getId())); + EnterAmountListener listener = new BankDepositEnterAmountListener(player, message.getSlot(), message.getId()); + player.getInterfaceSet().openEnterAmountDialogue(listener); } else if (!BankUtils.deposit(player, message.getSlot(), message.getId(), amount)) { ctx.breakHandlerChain(); } @@ -74,11 +76,12 @@ public final class BankMessageHandler extends MessageHandler * @param player The player. * @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()); + if (amount == -1) { - player.getInterfaceSet().openEnterAmountDialogue( - new BankWithdrawEnterAmountListener(player, message.getSlot(), message.getId())); + EnterAmountListener listener = new BankDepositEnterAmountListener(player, message.getSlot(), message.getId()); + player.getInterfaceSet().openEnterAmountDialogue(listener); } else if (!BankUtils.withdraw(player, message.getSlot(), message.getId(), amount)) { ctx.breakHandlerChain(); } diff --git a/src/org/apollo/game/message/handler/impl/EquipItemHandler.java b/src/org/apollo/game/message/handler/impl/EquipItemHandler.java index 793e99bc..a4b64c59 100644 --- a/src/org/apollo/game/message/handler/impl/EquipItemHandler.java +++ b/src/org/apollo/game/message/handler/impl/EquipItemHandler.java @@ -43,8 +43,7 @@ public final class EquipItemHandler extends MessageHandler { String skillName = Skill.getName(id); String article = LanguageUtil.getIndefiniteArticle(skillName); - player.sendMessage("You need " + article + " " + skillName + " level of " + requirement - + " to equip this item."); + player.sendMessage("You need " + article + " " + skillName + " level of " + requirement + " to equip this item."); ctx.breakHandlerChain(); return; } @@ -56,8 +55,7 @@ public final class EquipItemHandler extends MessageHandler { int equipmentSlot = definition.getSlot(); Item currentlyEquipped = equipment.get(equipmentSlot); - if (equipping.getDefinition().isStackable() - && (currentlyEquipped == null || currentlyEquipped.getId() == equippingId)) { + if (equipping.getDefinition().isStackable() && (currentlyEquipped == null || currentlyEquipped.getId() == equippingId)) { equipment.set(definition.getSlot(), equipping); inventory.reset(inventorySlot); return; diff --git a/src/org/apollo/game/message/handler/impl/ObjectActionVerificationHandler.java b/src/org/apollo/game/message/handler/impl/ObjectActionVerificationHandler.java index 38846a5b..e22a67c0 100644 --- a/src/org/apollo/game/message/handler/impl/ObjectActionVerificationHandler.java +++ b/src/org/apollo/game/message/handler/impl/ObjectActionVerificationHandler.java @@ -62,13 +62,8 @@ public final class ObjectActionVerificationHandler extends MessageHandler objects) { - for (GameObject object : objects) { - if (object.getId() == id) { - return true; - } - } - return false; + private static boolean containsObject(int id, List objects) { + return objects.stream().filter(object -> object.getId() == id).findAny().isPresent(); } } \ No newline at end of file diff --git a/src/org/apollo/game/message/handler/impl/PlayerActionVerificationHandler.java b/src/org/apollo/game/message/handler/impl/PlayerActionVerificationHandler.java index 849614f8..cc05c18d 100644 --- a/src/org/apollo/game/message/handler/impl/PlayerActionVerificationHandler.java +++ b/src/org/apollo/game/message/handler/impl/PlayerActionVerificationHandler.java @@ -29,8 +29,7 @@ public final class PlayerActionVerificationHandler extends MessageHandler maxColors[i]) { return false; } } - Gender gender = appearance.getGender(); - if (gender == Gender.MALE) { - return validMaleStyle(appearance); - } else if (gender == Gender.FEMALE) { - return validFemaleStyle(appearance); + switch (appearance.getGender()) { + case FEMALE: + return validFemaleStyle(appearance); + case MALE: + return validMaleStyle(appearance); } + throw new IllegalArgumentException("Player can only be either male or female."); } @@ -51,15 +53,17 @@ public final class PlayerDesignVerificationHandler extends MessageHandler maxStyles[i]) { return false; } } + return true; } @@ -69,15 +73,17 @@ public final class PlayerDesignVerificationHandler extends MessageHandler maxStyles[i]) { return false; } } + return true; } diff --git a/src/org/apollo/game/message/impl/InventoryItemMessage.java b/src/org/apollo/game/message/impl/InventoryItemMessage.java index d00f804a..49af4b5c 100644 --- a/src/org/apollo/game/message/impl/InventoryItemMessage.java +++ b/src/org/apollo/game/message/impl/InventoryItemMessage.java @@ -3,8 +3,8 @@ package org.apollo.game.message.impl; 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 - * item option and item action message, and so cannot be used to determine when one of those messages is fired. + * A {@link Message} that represents some sort of action on an item in an inventory. Note that this is the parent of + * both item option and item action message, and so cannot be used to determine when one of those messages is fired. * * @author Chris Fletcher */ diff --git a/src/org/apollo/game/message/impl/ItemActionMessage.java b/src/org/apollo/game/message/impl/ItemActionMessage.java index 545803b3..0ec8b5ef 100644 --- a/src/org/apollo/game/message/impl/ItemActionMessage.java +++ b/src/org/apollo/game/message/impl/ItemActionMessage.java @@ -3,9 +3,9 @@ package org.apollo.game.message.impl; 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 - * by the client is one of the five item action messages, but this is the message that should be intercepted (and the option - * verified). + * A {@link Message} sent by the client that represents some sort of action on an item. Note that the actual message + * sent by the client is one of the five item action messages, but this is the message that should be intercepted (and + * the option verified). * * @author Chris Fletcher */ diff --git a/src/org/apollo/game/message/impl/ItemOptionMessage.java b/src/org/apollo/game/message/impl/ItemOptionMessage.java index c6905b81..626c7e0e 100644 --- a/src/org/apollo/game/message/impl/ItemOptionMessage.java +++ b/src/org/apollo/game/message/impl/ItemOptionMessage.java @@ -1,9 +1,9 @@ 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 - * that the actual message sent by the client is one of the five item option messages, but this is the message that should be - * intercepted (and the option verified). + * An {@link InventoryItemMessage} sent by the client when an item's option is clicked (e.g. equip, eat, drink, etc). + * Note that the actual message sent by the client is one of the five item option messages, but this is the message that + * should be intercepted (and the option verified). * * @author Chris Fletcher */ diff --git a/src/org/apollo/game/message/impl/NpcActionMessage.java b/src/org/apollo/game/message/impl/NpcActionMessage.java index bb27db2f..181eb80b 100644 --- a/src/org/apollo/game/message/impl/NpcActionMessage.java +++ b/src/org/apollo/game/message/impl/NpcActionMessage.java @@ -3,9 +3,9 @@ package org.apollo.game.message.impl; 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 - * by the client is one of the three npc action messages, but this is the message that should be intercepted (and the option - * verified). + * A {@link Message} sent by the client representing the clicking of an npc menu action. Note that the actual message + * sent by the client is one of the three npc action messages, but this is the message that should be intercepted (and + * the option verified). * * @author Major */ diff --git a/src/org/apollo/game/message/impl/ObjectActionMessage.java b/src/org/apollo/game/message/impl/ObjectActionMessage.java index b9f5172f..ffbc210b 100644 --- a/src/org/apollo/game/message/impl/ObjectActionMessage.java +++ b/src/org/apollo/game/message/impl/ObjectActionMessage.java @@ -4,9 +4,9 @@ import org.apollo.game.message.Message; 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 - * by the client is one of the five object action messages, but this is the message that should be intercepted (and the - * option verified). + * A {@link Message} sent by the client that represents some sort of action on an object. Note that the actual message + * sent by the client is one of the five object action messages, but this is the message that should be intercepted (and + * the option verified). * * @author Graham */ diff --git a/src/org/apollo/game/message/impl/PlayerActionMessage.java b/src/org/apollo/game/message/impl/PlayerActionMessage.java index 265439d9..04bfa1e9 100644 --- a/src/org/apollo/game/message/impl/PlayerActionMessage.java +++ b/src/org/apollo/game/message/impl/PlayerActionMessage.java @@ -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 - * sent by the client is one of the five player action messages, but this is the message that should be intercepted (and the - * option verified). + * sent by the client is one of the five player action messages, but this is the message that should be intercepted (and + * the option verified). * * @author Major */ diff --git a/src/org/apollo/game/message/impl/PositionMessage.java b/src/org/apollo/game/message/impl/PositionMessage.java index b2c5eeff..3995d84b 100644 --- a/src/org/apollo/game/message/impl/PositionMessage.java +++ b/src/org/apollo/game/message/impl/PositionMessage.java @@ -4,7 +4,8 @@ import org.apollo.game.message.Message; 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 */ diff --git a/src/org/apollo/game/model/Direction.java b/src/org/apollo/game/model/Direction.java index f0096a7f..41f3ae6c 100644 --- a/src/org/apollo/game/model/Direction.java +++ b/src/org/apollo/game/model/Direction.java @@ -1,5 +1,9 @@ package org.apollo.game.model; + + + + /** * Represents a single movement direction. * @@ -86,6 +90,7 @@ public enum Direction { return Direction.WEST; } } + return Direction.NONE; } diff --git a/src/org/apollo/game/model/Position.java b/src/org/apollo/game/model/Position.java index 747143fc..64783f0d 100644 --- a/src/org/apollo/game/model/Position.java +++ b/src/org/apollo/game/model/Position.java @@ -21,19 +21,9 @@ public final class Position { 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; - - /** - * The x coordinate. - */ - private final int x; - - /** - * The y coordinate. - */ - private final int y; + private final int position; /** * Creates a position at the default height. @@ -54,23 +44,18 @@ public final class Position { */ public Position(int x, int y, int height) { Preconditions.checkArgument(height >= 0 && height < HEIGHT_LEVELS, "Height level out of bounds."); - this.x = x; - this.y = y; - this.height = height; + + position = height << 30 | (y & 0x7FFF) << 15 | x & 0x7FFF; } @Override public boolean equals(Object obj) { - if (obj == null) { - return false; - } else if (this == obj) { - return true; - } else if (getClass() != obj.getClass()) { - return false; + if (obj instanceof Position) { + Position other = (Position) obj; + return position == other.position; } - Position other = (Position) obj; - return x == other.x && y == other.y && height == other.height; + return false; } /** @@ -79,7 +64,7 @@ public final class Position { * @return The x coordinate of the central sector. */ 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. */ public int getCentralSectorY() { - return y / 8; + return getY() / 8; } /** @@ -98,8 +83,8 @@ public final class Position { * @return The distance. */ public int getDistance(Position other) { - int deltaX = x - other.x; - int deltaY = y - other.y; + int deltaX = getX() - other.getX(); + int deltaY = getY() - other.getY(); return (int) Math.ceil(Math.sqrt(deltaX * deltaX + deltaY * deltaY)); } @@ -109,7 +94,7 @@ public final class Position { * @return The height level. */ public int getHeight() { - return height; + return position >> 30; } /** @@ -128,7 +113,7 @@ public final class Position { * @return The local x coordinate. */ 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. */ 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. */ public int getLongestDelta(Position other) { - int deltaX = Math.abs(x - other.x); - int deltaY = Math.abs(y - other.y); + int deltaX = Math.abs(getX() - other.getX()); + int deltaY = Math.abs(getY() - other.getY()); return Math.max(deltaX, deltaY); } @@ -168,7 +153,7 @@ public final class Position { * @return The sector x coordinate. */ public int getTopLeftSectorX() { - return x / 8 - 6; + return getX() / 8 - 6; } /** @@ -177,7 +162,7 @@ public final class Position { * @return The sector y coordinate. */ public int getTopLeftSectorY() { - return y / 8 - 6; + return getY() / 8 - 6; } /** @@ -186,7 +171,7 @@ public final class Position { * @return The x coordinate. */ public int getX() { - return x; + return position & 0x7FFF; } /** @@ -195,12 +180,12 @@ public final class Position { * @return The y coordinate. */ public int getY() { - return y; + return (position >> 15) & 0x7FFF; } @Override 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. */ public boolean isWithinDistance(Position other, int distance) { - int deltaX = Math.abs(x - other.x); - int deltaY = Math.abs(y - other.y); + int deltaX = Math.abs(getX() - other.getX()); + int deltaY = Math.abs(getY() - other.getY()); return deltaX <= distance && deltaY <= distance; } @Override 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(); } diff --git a/src/org/apollo/game/model/def/EquipmentDefinition.java b/src/org/apollo/game/model/def/EquipmentDefinition.java index 3e0246a7..84e66d69 100644 --- a/src/org/apollo/game/model/def/EquipmentDefinition.java +++ b/src/org/apollo/game/model/def/EquipmentDefinition.java @@ -20,6 +20,15 @@ public final class EquipmentDefinition { */ private static final Map definitions = new HashMap<>(); + /** + * Gets the total number of equipment definitions. + * + * @return The count. + */ + public static int count() { + return definitions.size(); + } + /** * Initialises the equipment definitions. * @@ -79,15 +88,6 @@ public final class EquipmentDefinition { 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. * diff --git a/src/org/apollo/game/model/entity/Skill.java b/src/org/apollo/game/model/entity/Skill.java index 5db56e22..f9f9c54b 100644 --- a/src/org/apollo/game/model/entity/Skill.java +++ b/src/org/apollo/game/model/entity/Skill.java @@ -115,9 +115,9 @@ public final class Skill { /** * The skill names. */ - private static final String[] SKILL_NAMES = { "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", - "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", - "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft" }; + private static final String[] SKILL_NAMES = { "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", + "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", + "Agility", "Thieving", "Slayer", "Farming", "Runecraft" }; /** * Gets the name of a skill. diff --git a/src/org/apollo/game/model/entity/SkillSet.java b/src/org/apollo/game/model/entity/SkillSet.java index c7339d0c..9cfbf2aa 100644 --- a/src/org/apollo/game/model/entity/SkillSet.java +++ b/src/org/apollo/game/model/entity/SkillSet.java @@ -57,8 +57,8 @@ public final class SkillSet { * @return The minimum level. */ public static int getLevelForExperience(double experience) { - Preconditions.checkArgument(experience >= 0 && experience <= MAXIMUM_EXP, - "Experience must be between 0 and 200,000,000, inclusive."); + Preconditions.checkArgument(experience >= 0 && experience <= MAXIMUM_EXP, "Experience must be between 0 and " + + MAXIMUM_EXP + ", inclusive."); for (int level = 1; level <= 98; level++) { 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; /** - * A list of skill listeners. + * The list of skill listeners. */ private final List listeners = new ArrayList<>(); @@ -105,16 +105,15 @@ public final class SkillSet { checkBounds(id); Skill old = skills[id]; - double newExperience = old.getExperience() + experience; - newExperience = newExperience > MAXIMUM_EXP ? MAXIMUM_EXP : newExperience; + double newExperience = Math.min(old.getExperience() + experience, MAXIMUM_EXP); - int newCurrentLevel = old.getCurrentLevel(); - int newMaximumLevel = getLevelForExperience(newExperience); + int current = old.getCurrentLevel(); + int maximum = getLevelForExperience(newExperience); - int delta = newMaximumLevel - old.getMaximumLevel(); - newCurrentLevel += delta > 0 ? delta : 0; + int delta = maximum - old.getMaximumLevel(); + current += delta; - setSkill(id, new Skill(newExperience, newCurrentLevel, newMaximumLevel)); + setSkill(id, new Skill(newExperience, current, maximum)); if (delta > 0) { 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 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. */ public int getCombatLevel() { - return combatLevel; + return combat; } /** diff --git a/src/org/apollo/game/model/entity/attr/AttributeMap.java b/src/org/apollo/game/model/entity/attr/AttributeMap.java index fd404de3..0d79d68e 100644 --- a/src/org/apollo/game/model/entity/attr/AttributeMap.java +++ b/src/org/apollo/game/model/entity/attr/AttributeMap.java @@ -15,7 +15,7 @@ public final class AttributeMap { /** * The map of attribute names to definitions. */ - private static Map> definitions = new HashMap<>(50); + private static Map> definitions = new HashMap<>(1); /** * Registers an {@link AttributeDefinition}. diff --git a/src/org/apollo/game/model/inter/InterfaceConstants.java b/src/org/apollo/game/model/inter/InterfaceConstants.java index 41758107..d16e6cbb 100644 --- a/src/org/apollo/game/model/inter/InterfaceConstants.java +++ b/src/org/apollo/game/model/inter/InterfaceConstants.java @@ -15,8 +15,8 @@ public class InterfaceConstants { /** * The default inventory tab ids. */ - public static final int[] DEFAULT_INVENTORY_TABS = { 2423, 3917, 638, 3213, 1644, 5608, 1151, -1, 5065, 5715, 2449, - 904, 147, 962, }; + public static final int[] DEFAULT_INVENTORY_TABS = { 2423, 3917, 638, 3213, 1644, 5608, 1151, -1, 5065, 5715, 2449, 904, 147, + 962, }; // 6299 = music tab, music disabled // 4445 = settings tab, music disabled // 12855 = ancients magic @@ -24,8 +24,8 @@ public class InterfaceConstants { /** * The level-up dialogue interface ids. */ - public static final int[] LEVEL_UP_INTERFACES = { 6247, 6253, 6206, 6216, 4443, 6242, 6211, 6226, 4272, 6231, 6258, - 4282, 6263, 6221, 4416, 6237, 4277, 4261, 12122, 4887, 4267 }; + public static final int[] LEVEL_UP_INTERFACES = { 6247, 6253, 6206, 6216, 4443, 6242, 6211, 6226, 4272, 6231, 6258, 4282, + 6263, 6221, 4416, 6237, 4277, 4261, 12122, 4887, 4267 }; /** * The quest interface id. @@ -40,13 +40,12 @@ public class InterfaceConstants { /** * 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, - 8157, 8158, 8159, 8160, 8161, 8162, 8163, 8164, 8165, 8166, 8167, 8168, 8169, 8170, 8171, 8172, 8173, 8174, - 8175, 8176, 8177, 8178, 8179, 8180, 8181, 8182, 8183, 8184, 8185, 8186, 8187, 8188, 8189, 8190, 8191, 8192, - 8193, 8194, 8195, 12174, 12175, 12176, 12177, 12178, 12179, 12180, 12181, 12182, 12183, 12184, 12185, - 12186, 12187, 12188, 12189, 12190, 12191, 12192, 12193, 12194, 12195, 12196, 12197, 12198, 12199, 12200, - 12201, 12202, 12203, 12204, 12205, 12206, 12207, 12208, 12209, 12210, 12211, 12212, 12213, 12214, 12215, - 12216, 12217, 12218, 12219, 12220, 12221, 12222, 12223 }; + public static final int[] QUEST_TEXT = { 8144, 8145, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158, + 8159, 8160, 8161, 8162, 8163, 8164, 8165, 8166, 8167, 8168, 8169, 8170, 8171, 8172, 8173, 8174, 8175, 8176, 8177, + 8178, 8179, 8180, 8181, 8182, 8183, 8184, 8185, 8186, 8187, 8188, 8189, 8190, 8191, 8192, 8193, 8194, 8195, 12174, + 12175, 12176, 12177, 12178, 12179, 12180, 12181, 12182, 12183, 12184, 12185, 12186, 12187, 12188, 12189, 12190, + 12191, 12192, 12193, 12194, 12195, 12196, 12197, 12198, 12199, 12200, 12201, 12202, 12203, 12204, 12205, 12206, + 12207, 12208, 12209, 12210, 12211, 12212, 12213, 12214, 12215, 12216, 12217, 12218, 12219, 12220, 12221, 12222, 12223 }; /** * The quest title widget id. diff --git a/src/org/apollo/game/model/inter/bank/BankUtils.java b/src/org/apollo/game/model/inter/bank/BankUtils.java index 01702ba9..faa81818 100644 --- a/src/org/apollo/game/model/inter/bank/BankUtils.java +++ b/src/org/apollo/game/model/inter/bank/BankUtils.java @@ -76,8 +76,7 @@ public final class BankUtils { InterfaceListener interListener = new BankInterfaceListener(player, invListener, bankListener); - player.getInterfaceSet().openWindowWithSidebar(interListener, BankConstants.BANK_WINDOW_ID, - BankConstants.SIDEBAR_ID); + player.getInterfaceSet().openWindowWithSidebar(interListener, BankConstants.BANK_WINDOW_ID, BankConstants.SIDEBAR_ID); } /** diff --git a/src/org/apollo/game/sync/block/AppearanceBlock.java b/src/org/apollo/game/sync/block/AppearanceBlock.java index 5e008191..c37e8cb8 100644 --- a/src/org/apollo/game/sync/block/AppearanceBlock.java +++ b/src/org/apollo/game/sync/block/AppearanceBlock.java @@ -61,8 +61,7 @@ public final class AppearanceBlock extends SynchronizationBlock { * @param headIcon The head icon id of the player. * @param isSkulled Whether or not the player is skulled. */ - AppearanceBlock(long name, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, - boolean isSkulled) { + AppearanceBlock(long name, Appearance appearance, int combat, int skill, Inventory equipment, int headIcon, boolean isSkulled) { this(name, appearance, combat, skill, equipment, headIcon, isSkulled, -1); } @@ -84,7 +83,7 @@ public final class AppearanceBlock extends SynchronizationBlock { this.appearance = appearance; this.combat = combat; this.skill = skill; - this.equipment = equipment.clone(); + this.equipment = equipment.duplicate(); this.headIcon = headIcon; this.isSkulled = isSkulled; this.npcId = npcId; diff --git a/src/org/apollo/game/sync/block/SynchronizationBlockSet.java b/src/org/apollo/game/sync/block/SynchronizationBlockSet.java index d07c1a20..39f7bc23 100644 --- a/src/org/apollo/game/sync/block/SynchronizationBlockSet.java +++ b/src/org/apollo/game/sync/block/SynchronizationBlockSet.java @@ -13,7 +13,7 @@ public final class SynchronizationBlockSet implements Cloneable { /** * A {@link Map} of {@link SynchronizationBlock}s. */ - private final Map, SynchronizationBlock> blocks = new HashMap<>(); + private final Map, SynchronizationBlock> blocks = new HashMap<>(8); /** * Adds a {@link SynchronizationBlock}. diff --git a/src/org/apollo/game/sync/seg/MovementSegment.java b/src/org/apollo/game/sync/seg/MovementSegment.java index 2ee71ba8..cbbaadf0 100644 --- a/src/org/apollo/game/sync/seg/MovementSegment.java +++ b/src/org/apollo/game/sync/seg/MovementSegment.java @@ -26,7 +26,8 @@ public final class MovementSegment extends SynchronizationSegment { */ public MovementSegment(SynchronizationBlockSet blockSet, Direction[] directions) { 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; } diff --git a/src/org/apollo/io/MessageHandlerChainParser.java b/src/org/apollo/io/MessageHandlerChainParser.java index 993b0ad9..96aa7b8c 100644 --- a/src/org/apollo/io/MessageHandlerChainParser.java +++ b/src/org/apollo/io/MessageHandlerChainParser.java @@ -53,8 +53,8 @@ public final class MessageHandlerChainParser { * @return A {@link MessageHandlerChainGroup}. */ @SuppressWarnings("unchecked") - public MessageHandlerChainGroup parse() throws IOException, SAXException, ClassNotFoundException, - InstantiationException, IllegalAccessException { + public MessageHandlerChainGroup parse() throws IOException, SAXException, ClassNotFoundException, InstantiationException, + IllegalAccessException { XmlNode messages = parser.parse(is); if (!messages.getName().equals("messages")) { throw new IOException("Root node name is not 'messages'."); diff --git a/src/org/apollo/io/PluginMetaDataParser.java b/src/org/apollo/io/PluginMetaDataParser.java index 56e6c343..45e8ccac 100644 --- a/src/org/apollo/io/PluginMetaDataParser.java +++ b/src/org/apollo/io/PluginMetaDataParser.java @@ -3,6 +3,7 @@ package org.apollo.io; import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.util.Objects; import org.apollo.util.plugin.PluginMetaData; import org.apollo.util.xml.XmlNode; @@ -50,12 +51,8 @@ public final class PluginMetaDataParser { * @return The node object. * @throws IOException If the element does not exist. */ - private XmlNode getElement(XmlNode node, String name) throws IOException { - XmlNode child = node.getChild(name); - if (child == null) { - throw new IOException("No " + name + " element found."); - } - return child; + private static XmlNode getElement(XmlNode node, String name) throws IOException { + return Objects.requireNonNull(node.getChild(name), "No " + name + " element found."); } /** diff --git a/src/org/apollo/io/player/impl/BinaryPlayerLoader.java b/src/org/apollo/io/player/impl/BinaryPlayerLoader.java index a96b53ad..ada3d857 100644 --- a/src/org/apollo/io/player/impl/BinaryPlayerLoader.java +++ b/src/org/apollo/io/player/impl/BinaryPlayerLoader.java @@ -157,7 +157,7 @@ public final class BinaryPlayerLoader implements PlayerLoader { * @return The {@link Map} of attribute names to attributes. * @throws IOException If there is an error reading from the stream. */ - private Map> readAttributes(DataInputStream in) throws IOException { + private static Map> readAttributes(DataInputStream in) throws IOException { int count = in.readInt(); Map> attributes = new HashMap<>(count); Attribute attribute; @@ -195,7 +195,7 @@ public final class BinaryPlayerLoader implements PlayerLoader { * @param inventory The inventory. * @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(); inventory.stopFiringEvents(); diff --git a/src/org/apollo/io/player/impl/BinaryPlayerSaver.java b/src/org/apollo/io/player/impl/BinaryPlayerSaver.java index d60f2381..082731cf 100644 --- a/src/org/apollo/io/player/impl/BinaryPlayerSaver.java +++ b/src/org/apollo/io/player/impl/BinaryPlayerSaver.java @@ -113,7 +113,7 @@ public final class BinaryPlayerSaver implements PlayerSaver { * @param attribute The attribute. * @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(); out.writeByte(type.getValue()); @@ -143,7 +143,7 @@ public final class BinaryPlayerSaver implements PlayerSaver { * @param inventory The inventory. * @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(); out.writeShort(capacity); diff --git a/src/org/apollo/login/LoginService.java b/src/org/apollo/login/LoginService.java index b60a29c7..fc45797f 100644 --- a/src/org/apollo/login/LoginService.java +++ b/src/org/apollo/login/LoginService.java @@ -61,8 +61,7 @@ public final class LoginService extends Service { * @throws IllegalAccessException If the player loader/saver implementation could not be accessed. * @throws InstantiationException If the player loader/saver implementation could not be instantiated. */ - private void init() throws SAXException, IOException, ClassNotFoundException, InstantiationException, - IllegalAccessException { + private void init() throws SAXException, IOException, ClassNotFoundException, InstantiationException, IllegalAccessException { XmlParser parser = new XmlParser(); XmlNode rootNode; diff --git a/src/org/apollo/login/PlayerLoaderWorker.java b/src/org/apollo/login/PlayerLoaderWorker.java index 92fd66cb..9c9bfabe 100644 --- a/src/org/apollo/login/PlayerLoaderWorker.java +++ b/src/org/apollo/login/PlayerLoaderWorker.java @@ -56,8 +56,7 @@ public final class PlayerLoaderWorker implements Runnable { session.handlePlayerLoaderResponse(request, response); } catch (Exception e) { logger.log(Level.SEVERE, "Unable to load player's game.", e); - session.handlePlayerLoaderResponse(request, new PlayerLoaderResponse( - LoginConstants.STATUS_COULD_NOT_COMPLETE)); + session.handlePlayerLoaderResponse(request, new PlayerLoaderResponse(LoginConstants.STATUS_COULD_NOT_COMPLETE)); } } diff --git a/src/org/apollo/net/release/r317/NpcSynchronizationMessageEncoder.java b/src/org/apollo/net/release/r317/NpcSynchronizationMessageEncoder.java index 05447f70..89299192 100644 --- a/src/org/apollo/net/release/r317/NpcSynchronizationMessageEncoder.java +++ b/src/org/apollo/net/release/r317/NpcSynchronizationMessageEncoder.java @@ -72,7 +72,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder 0; Position npc = message.getPosition(); Position other = seg.getPosition(); @@ -90,7 +90,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder 0) { int mask = 0; @@ -181,7 +181,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder 0; if (segment.getType() == SegmentType.RUN) { @@ -258,7 +258,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder 0; Position player = message.getPosition(); Position other = seg.getPosition(); @@ -103,7 +103,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder 0) { int mask = 0; @@ -312,7 +312,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder 0; if (seg.getType() == SegmentType.TELEPORT) { Position position = ((TeleportSegment) seg).getDestination(); @@ -427,7 +428,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder 0; Position npc = message.getPosition(); Position other = seg.getPosition(); @@ -90,7 +90,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder 0) { int mask = 0; @@ -181,7 +181,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder 0; if (seg.getType() == SegmentType.RUN) { Direction[] directions = ((MovementSegment) seg).getDirections(); @@ -257,7 +257,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder 0; Position player = message.getPosition(); Position other = seg.getPosition(); @@ -103,7 +103,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder 0) { int mask = 0; @@ -312,7 +312,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder 0; if (seg.getType() == SegmentType.TELEPORT) { @@ -429,7 +428,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder"); - StringBuilder builder = new StringBuilder(); - - builder.append("<!DOCTYPE html><html><head><title>"); builder.append(title); builder.append("

"); builder.append(title); @@ -85,10 +83,11 @@ public final class HttpRequestWorker extends RequestWorker> extends ByteToMess * @param ctx The current context of this handler. * @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 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 out, T state) throws Exception; diff --git a/src/org/apollo/util/TextUtil.java b/src/org/apollo/util/TextUtil.java index a46cb24c..8ea9e4ad 100644 --- a/src/org/apollo/util/TextUtil.java +++ b/src/org/apollo/util/TextUtil.java @@ -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 * chat messages. */ - public static final char[] FREQUENCY_ORDERED_CHARS = { ' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r', 'd', 'l', - 'u', 'm', 'w', 'c', 'y', 'f', 'g', 'p', 'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2', '3', '4', '5', - '6', '7', '8', '9', ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\', '\'', '@', '#', '+', - '=', '\243', '$', '%', '"', '[', ']' }; + public static final char[] FREQUENCY_ORDERED_CHARS = { ' ', 'e', 't', 'a', 'o', 'i', 'h', 'n', 's', 'r', 'd', 'l', 'u', 'm', + 'w', 'c', 'y', 'f', 'g', 'p', 'b', 'v', 'k', 'x', 'j', 'q', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', + ' ', '!', '?', '.', ',', ':', ';', '(', ')', '-', '&', '*', '\\', '\'', '@', '#', '+', '=', '\243', '$', '%', '"', + '[', ']' }; /** * Capitalizes the string correctly. diff --git a/src/org/apollo/util/plugin/PluginContext.java b/src/org/apollo/util/plugin/PluginContext.java index 5ed06e4b..c9d78686 100644 --- a/src/org/apollo/util/plugin/PluginContext.java +++ b/src/org/apollo/util/plugin/PluginContext.java @@ -19,6 +19,34 @@ import org.apollo.game.model.World; */ 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. */ @@ -33,16 +61,6 @@ public final class PluginContext { 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. * @@ -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); - } - } \ No newline at end of file diff --git a/src/org/apollo/util/plugin/PluginManager.java b/src/org/apollo/util/plugin/PluginManager.java index a5e3cff3..f4d58d52 100644 --- a/src/org/apollo/util/plugin/PluginManager.java +++ b/src/org/apollo/util/plugin/PluginManager.java @@ -7,12 +7,13 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import java.util.function.Function; +import java.util.stream.Collectors; import org.apollo.io.PluginMetaDataParser; import org.xml.sax.SAXException; @@ -50,11 +51,8 @@ public final class PluginManager { * @param plugins The plugin collection. * @return The plugin map. */ - private Map createMap(Collection plugins) { - Map map = new HashMap<>(); - for (PluginMetaData plugin : plugins) { - map.put(plugin.getId(), plugin); - } + private static Map createMap(Collection plugins) { + Map map = plugins.stream().collect(Collectors.toMap(PluginMetaData::getId, Function.identity())); return Collections.unmodifiableMap(map); }