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 + "...");
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();
+1 -2
View File
@@ -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();
@@ -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<GameObject> parseArea(int area, ByteBuffer buffer) {
private static Collection<GameObject> parseArea(int area, ByteBuffer buffer) {
List<GameObject> objects = new ArrayList<>();
int x = (area >> 8 & 0xFF) * 64;
@@ -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);
@@ -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;
}
}
@@ -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();
+5 -6
View File
@@ -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);
}
/**
@@ -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<ItemActionMessage>
case 5:
return -1;
}
throw new IllegalArgumentException("Invalid option supplied.");
}
@@ -46,11 +47,12 @@ public final class BankMessageHandler extends MessageHandler<ItemActionMessage>
* @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<ItemActionMessage>
* @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();
}
@@ -43,8 +43,7 @@ public final class EquipItemHandler extends MessageHandler<ItemOptionMessage> {
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<ItemOptionMessage> {
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;
@@ -62,13 +62,8 @@ public final class ObjectActionVerificationHandler extends MessageHandler<Object
* @param objects The list of objects.
* @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) {
for (GameObject object : objects) {
if (object.getId() == id) {
return true;
}
}
return false;
private static boolean containsObject(int id, List<GameObject> objects) {
return objects.stream().filter(object -> object.getId() == id).findAny().isPresent();
}
}
@@ -29,8 +29,7 @@ public final class PlayerActionVerificationHandler extends MessageHandler<Player
}
Player other = repository.get(index);
if (other == null
|| !player.getPosition().isWithinDistance(other.getPosition(), player.getViewingDistance() + 1)) {
if (other == null || !player.getPosition().isWithinDistance(other.getPosition(), player.getViewingDistance() + 1)) {
// +1 in case it was decremented after the player clicked the action.
ctx.breakHandlerChain();
return;
@@ -27,21 +27,23 @@ public final class PlayerDesignVerificationHandler extends MessageHandler<Player
* @param appearance The appearance combination.
* @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[] maxColors = new int[] { 11, 15, 15, 5, 7 };
for (int i = 0; i < colors.length; i++) {
if (colors[i] < 0 || colors[i] > maxColors[i]) {
return false;
}
}
Gender gender = appearance.getGender();
if (gender == Gender.MALE) {
return validMaleStyle(appearance);
} else if (gender == Gender.FEMALE) {
return validFemaleStyle(appearance);
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<Player
* @param appearance The appearance combination.
* @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[] minStyles = new int[] { 45, 255, 56, 61, 67, 70, 79 };
int[] maxStyles = new int[] { 54, 255, 60, 65, 68, 77, 80 };
for (int i = 0; i < styles.length; i++) {
if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) {
return false;
}
}
return true;
}
@@ -69,15 +73,17 @@ public final class PlayerDesignVerificationHandler extends MessageHandler<Player
* @param appearance The appearance combination.
* @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[] minStyles = new int[] { 0, 10, 18, 26, 33, 36, 42 };
int[] maxStyles = new int[] { 8, 17, 25, 31, 34, 40, 43 };
for (int i = 0; i < styles.length; i++) {
if (styles[i] < minStyles[i] || styles[i] > maxStyles[i]) {
return false;
}
}
return true;
}
@@ -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
*/
@@ -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
*/
@@ -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
*/
@@ -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
*/
@@ -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
*/
@@ -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
*/
@@ -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
*/
+5
View File
@@ -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;
}
+25 -40
View File
@@ -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();
}
@@ -20,6 +20,15 @@ public final class EquipmentDefinition {
*/
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.
*
@@ -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.
*
+3 -3
View File
@@ -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.
+14 -15
View File
@@ -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<SkillListener> 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;
}
/**
@@ -15,7 +15,7 @@ public final class AttributeMap {
/**
* 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}.
@@ -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.
@@ -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);
}
/**
@@ -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;
@@ -13,7 +13,7 @@ public final class SynchronizationBlockSet implements Cloneable {
/**
* 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}.
@@ -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;
}
@@ -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'.");
+3 -6
View File
@@ -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.");
}
/**
@@ -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<String, Attribute<?>> readAttributes(DataInputStream in) throws IOException {
private static Map<String, Attribute<?>> readAttributes(DataInputStream in) throws IOException {
int count = in.readInt();
Map<String, Attribute<?>> 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();
@@ -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);
+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 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;
+1 -2
View File
@@ -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));
}
}
@@ -72,7 +72,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param message The message.
* @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;
Position npc = message.getPosition();
Position other = seg.getPosition();
@@ -90,7 +90,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @param builder The builder.
*/
private void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
Animation animation = block.getAnimation();
builder.put(DataType.SHORT, DataOrder.LITTLE, animation.getId());
builder.put(DataType.BYTE, animation.getDelay());
@@ -102,7 +102,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param segment The segment.
* @param builder The block builder.
*/
private void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
SynchronizationBlockSet blockSet = segment.getBlockSet();
if (blockSet.size() > 0) {
int mask = 0;
@@ -181,7 +181,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @param builder The builder.
*/
private void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
builder.putString(block.getMessage());
}
@@ -191,7 +191,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @param builder The builder.
*/
private void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
Graphic graphic = block.getGraphic();
builder.put(DataType.SHORT, graphic.getId());
builder.put(DataType.INT, graphic.getDelay());
@@ -203,7 +203,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @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.NEGATE, block.getType());
builder.put(DataType.BYTE, DataTransformation.ADD, block.getCurrentHealth());
@@ -216,7 +216,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @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());
}
@@ -227,7 +227,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param message The message.
* @param builder The builder.
*/
private void putMovementUpdate(SynchronizationSegment segment, NpcSynchronizationMessage message,
private static void putMovementUpdate(SynchronizationSegment segment, NpcSynchronizationMessage message,
GamePacketBuilder builder) {
boolean updateRequired = segment.getBlockSet().size() > 0;
if (segment.getType() == SegmentType.RUN) {
@@ -258,7 +258,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
*
* @param builder The builder.
*/
private void putRemoveMobUpdate(GamePacketBuilder builder) {
private static void putRemoveMobUpdate(GamePacketBuilder builder) {
builder.putBits(1, 1);
builder.putBits(2, 3);
}
@@ -269,7 +269,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @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.SUBTRACT, block.getType());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getCurrentHealth());
@@ -282,7 +282,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @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());
}
@@ -292,7 +292,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @param builder The builder.
*/
private void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
Position position = block.getPosition();
builder.put(DataType.SHORT, DataOrder.LITTLE, position.getX() * 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 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;
Position player = message.getPosition();
Position other = seg.getPosition();
@@ -103,7 +103,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @param builder The builder.
*/
private void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
Animation animation = block.getAnimation();
builder.put(DataType.SHORT, DataOrder.LITTLE, animation.getId());
builder.put(DataType.BYTE, DataTransformation.NEGATE, animation.getDelay());
@@ -115,7 +115,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @param builder The builder.
*/
private void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) {
private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) {
Appearance appearance = block.getAppearance();
GamePacketBuilder playerProperties = new GamePacketBuilder();
@@ -230,7 +230,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param segment The segment.
* @param builder The block builder.
*/
private void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
SynchronizationBlockSet blockSet = segment.getBlockSet();
if (blockSet.size() > 0) {
int mask = 0;
@@ -312,7 +312,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @param builder The builder.
*/
private void putChatBlock(ChatBlock block, GamePacketBuilder builder) {
private static void putChatBlock(ChatBlock block, GamePacketBuilder builder) {
byte[] bytes = block.getCompressedMessage();
builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTextColor() << 8 | block.getTextEffects());
builder.put(DataType.BYTE, block.getPrivilegeLevel().toInteger());
@@ -326,7 +326,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @param builder The builder.
*/
private void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
builder.putString(block.getMessage());
}
@@ -336,7 +336,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @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.getInitialY());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalX());
@@ -352,7 +352,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @param builder The builder.
*/
private void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
Graphic graphic = block.getGraphic();
builder.put(DataType.SHORT, DataOrder.LITTLE, graphic.getId());
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 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, DataTransformation.ADD, block.getType());
builder.put(DataType.BYTE, block.getCurrentHealth());
@@ -377,7 +377,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @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());
}
@@ -388,7 +388,8 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param message The message.
* @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;
if (seg.getType() == SegmentType.TELEPORT) {
Position position = ((TeleportSegment) seg).getDestination();
@@ -427,7 +428,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
*
* @param builder The builder.
*/
private void putRemovePlayerUpdate(GamePacketBuilder builder) {
private static void putRemovePlayerUpdate(GamePacketBuilder builder) {
builder.putBits(1, 1);
builder.putBits(2, 3);
}
@@ -438,7 +439,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @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, DataTransformation.SUBTRACT, block.getType());
builder.put(DataType.BYTE, block.getCurrentHealth());
@@ -451,7 +452,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @param builder The builder.
*/
private void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
Position pos = block.getPosition();
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, pos.getX() * 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 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;
Position npc = message.getPosition();
Position other = seg.getPosition();
@@ -90,7 +90,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @param builder The builder.
*/
private void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
Animation animation = block.getAnimation();
builder.put(DataType.SHORT, animation.getId());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, animation.getDelay());
@@ -102,7 +102,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param segment The segment.
* @param builder The block builder.
*/
private void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
SynchronizationBlockSet blockSet = segment.getBlockSet();
if (blockSet.size() > 0) {
int mask = 0;
@@ -181,7 +181,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @param builder The builder.
*/
private void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
builder.putString(block.getMessage());
}
@@ -191,7 +191,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @param builder The builder.
*/
private void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
Graphic graphic = block.getGraphic();
builder.put(DataType.SHORT, graphic.getId());
builder.put(DataType.INT, DataOrder.MIDDLE, graphic.getDelay());
@@ -203,7 +203,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @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.getType());
builder.put(DataType.BYTE, block.getCurrentHealth());
@@ -216,7 +216,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @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());
}
@@ -227,7 +227,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param message The message.
* @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;
if (seg.getType() == SegmentType.RUN) {
Direction[] directions = ((MovementSegment) seg).getDirections();
@@ -257,7 +257,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
*
* @param builder The builder.
*/
private void putRemoveNpcUpdate(GamePacketBuilder builder) {
private static void putRemoveNpcUpdate(GamePacketBuilder builder) {
builder.putBits(1, 1);
builder.putBits(2, 3);
}
@@ -268,7 +268,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @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.getType());
builder.put(DataType.BYTE, block.getCurrentHealth());
@@ -281,7 +281,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @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());
}
@@ -291,7 +291,7 @@ public final class NpcSynchronizationMessageEncoder extends MessageEncoder<NpcSy
* @param block The block.
* @param builder The builder.
*/
private void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
Position position = block.getPosition();
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, position.getX() * 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 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;
Position player = message.getPosition();
Position other = seg.getPosition();
@@ -103,7 +103,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @param builder The builder.
*/
private void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
private static void putAnimationBlock(AnimationBlock block, GamePacketBuilder builder) {
Animation animation = block.getAnimation();
builder.put(DataType.SHORT, animation.getId());
builder.put(DataType.BYTE, DataTransformation.ADD, animation.getDelay());
@@ -115,7 +115,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @param builder The builder.
*/
private void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) {
private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) {
Appearance appearance = block.getAppearance();
GamePacketBuilder playerProperties = new GamePacketBuilder();
@@ -230,7 +230,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param segment The segment.
* @param builder The block builder.
*/
private void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
private static void putBlocks(SynchronizationSegment segment, GamePacketBuilder builder) {
SynchronizationBlockSet blockSet = segment.getBlockSet();
if (blockSet.size() > 0) {
int mask = 0;
@@ -312,7 +312,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @param builder The builder.
*/
private void putChatBlock(ChatBlock block, GamePacketBuilder builder) {
private static void putChatBlock(ChatBlock block, GamePacketBuilder builder) {
byte[] bytes = block.getCompressedMessage();
builder.put(DataType.SHORT, DataOrder.LITTLE, block.getTextEffects() << 8 | block.getTextColor());
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 builder The builder.
*/
private void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
private static void putForceChatBlock(ForceChatBlock block, GamePacketBuilder builder) {
builder.putString(block.getMessage());
}
@@ -336,7 +336,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @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.NEGATE, block.getInitialY());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getFinalX());
@@ -352,11 +352,10 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @param builder The builder.
*/
private void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
private static void putGraphicBlock(GraphicBlock block, GamePacketBuilder builder) {
Graphic graphic = block.getGraphic();
builder.put(DataType.SHORT, DataTransformation.ADD, graphic.getId());
builder.put(DataType.INT, DataOrder.MIDDLE, graphic.getHeight() << 16 & 0xFFFF0000 | graphic.getDelay()
& 0x0000FFFF);
builder.put(DataType.INT, DataOrder.MIDDLE, graphic.getHeight() << 16 & 0xFFFF0000 | graphic.getDelay() & 0x0000FFFF);
}
/**
@@ -365,7 +364,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @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.NEGATE, block.getType());
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, block.getCurrentHealth());
@@ -378,7 +377,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @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());
}
@@ -389,7 +388,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param message The message.
* @param builder The builder.
*/
private void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message,
private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message,
GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0;
if (seg.getType() == SegmentType.TELEPORT) {
@@ -429,7 +428,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
*
* @param builder The builder.
*/
private void putRemovePlayerUpdate(GamePacketBuilder builder) {
private static void putRemovePlayerUpdate(GamePacketBuilder builder) {
builder.putBits(1, 1);
builder.putBits(2, 3);
}
@@ -440,7 +439,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @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.SUBTRACT, block.getType());
builder.put(DataType.BYTE, DataTransformation.NEGATE, block.getCurrentHealth());
@@ -453,7 +452,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param block The block.
* @param builder The builder.
*/
private void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
Position position = block.getPosition();
builder.put(DataType.SHORT, position.getX() * 2 + 1);
builder.put(DataType.SHORT, position.getY() * 2 + 1);
+11 -13
View File
@@ -22,9 +22,8 @@ public final class EquipmentConstants {
/**
* Bodies.
*/
public static final String[] BODY = { "platebody", "chainbody", "robetop", "leathertop", "platemail", "top",
"brassard", "Robe top", "body", "platebody (t)", "platebody (g)", "body(g)", "body_(g)", "chestplate",
"torso", "shirt" };
public static final String[] BODY = { "platebody", "chainbody", "robetop", "leathertop", "platemail", "top", "brassard",
"Robe top", "body", "platebody (t)", "platebody (g)", "body(g)", "body_(g)", "chestplate", "torso", "shirt" };
/**
* Boots.
@@ -39,8 +38,8 @@ public final class EquipmentConstants {
/**
* Full bodies.
*/
public static final String[] FULL_BODIES = { "top", "shirt", "platebody", "Ahrims robetop", "Karils leathertop",
"brassard", "Robe top", "robetop", "platebody (t)", "platebody (g)", "chestplate", "torso" };
public static final String[] FULL_BODIES = { "top", "shirt", "platebody", "Ahrims robetop", "Karils leathertop", "brassard",
"Robe top", "robetop", "platebody (t)", "platebody (g)", "chestplate", "torso" };
/**
* Full hats.
@@ -51,8 +50,8 @@ public final class EquipmentConstants {
/**
* Full masks.
*/
public static final String[] FULL_MASKS = { "full helm", "mask", "Veracs helm", "Guthans helm", "Torags helm",
"Karils coif", "full helm (t)", "full helm (g)", "mask" };
public static final String[] FULL_MASKS = { "full helm", "mask", "Veracs helm", "Guthans helm", "Torags helm", "Karils coif",
"full helm (t)", "full helm (g)", "mask" };
/**
* Gloves.
@@ -62,9 +61,8 @@ public final class EquipmentConstants {
/**
* Hats.
*/
public static final String[] HATS = { "tiara", "helm", "hood", "coif", "Coif", "hat", "partyhat", "Hat",
"full helm (t)", "full helm (g)", "hat (t)", "hat (g)", "cav", "boater", "helmet", "mask",
"Helm of neitiznot" };
public static final String[] HATS = { "tiara", "helm", "hood", "coif", "Coif", "hat", "partyhat", "Hat", "full helm (t)",
"full helm (g)", "hat (t)", "hat (g)", "cav", "boater", "helmet", "mask", "Helm of neitiznot" };
/**
* Legs.
@@ -89,9 +87,9 @@ public final class EquipmentConstants {
*/
public static final String[] WEAPONS = { "scimitar", "longsword", "sword", "longbow", "shortbow", "dagger", "mace",
"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",
"javelin(p)", "knife", "knife(p)", "Longbow", "Shortbow", "Crossbow", "Toktz-xil", "Toktz-mej",
"Tzhaar-ket", "staff", "Staff", "godsword", "c'bow", "Crystal bow", "Dark bow", "Magic butterfly net" };
"dagger(s)", "spear(p)", "spear(+)", "spear(s)", "spear(kp)", "maul", "dart", "dart(p)", "javelin", "javelin(p)",
"knife", "knife(p)", "Longbow", "Shortbow", "Crossbow", "Toktz-xil", "Toktz-mej", "Tzhaar-ket", "staff", "Staff",
"godsword", "c'bow", "Crystal bow", "Dark bow", "Magic butterfly net" };
/**
* 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].");
String release = args[0];
try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/note-"
+ release + ".dat")));
try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/note-" + release
+ ".dat")));
IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", release), true)) {
ItemDefinitionDecoder decoder = new ItemDefinitionDecoder(fs);
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.
* @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();
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></head><body><h1>");
builder.append(title);
@@ -85,10 +83,11 @@ public final class HttpRequestWorker extends RequestWorker<HttpRequest, Resource
* @param name The file name.
* @return The MIME type.
*/
private String getMimeType(String name) {
private static String getMimeType(String name) {
if (name.endsWith("/")) {
name = name.concat("index.html");
}
if (name.endsWith(".htm") || name.endsWith(".html")) {
return "text/html";
} else if (name.endsWith(".css")) {
@@ -104,6 +103,7 @@ public final class HttpRequestWorker extends RequestWorker<HttpRequest, Resource
} else if (name.endsWith(".txt")) {
return "text/plain";
}
return "application/octect-stream";
}
@@ -16,8 +16,8 @@ public final class VirtualResourceProvider extends ResourceProvider {
/**
* An array of valid prefixes.
*/
private static final String[] VALID_PREFIXES = { "crc", "title", "config", "interface", "media", "versionlist",
"textures", "wordenc", "sounds" };
private static final String[] VALID_PREFIXES = { "crc", "title", "config", "interface", "media", "versionlist", "textures",
"wordenc", "sounds" };
/**
* 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 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<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
* 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.
+28 -28
View File
@@ -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);
}
}
@@ -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<String, PluginMetaData> createMap(Collection<PluginMetaData> plugins) {
Map<String, PluginMetaData> map = new HashMap<>();
for (PluginMetaData plugin : plugins) {
map.put(plugin.getId(), plugin);
}
private static Map<String, PluginMetaData> createMap(Collection<PluginMetaData> plugins) {
Map<String, PluginMetaData> map = plugins.stream().collect(Collectors.toMap(PluginMetaData::getId, Function.identity()));
return Collections.unmodifiableMap(map);
}