This commit is contained in:
Major-
2014-09-11 21:23:21 +01:00
parent 1d1375bd3a
commit 238e6236a7
40 changed files with 187 additions and 173 deletions
+1 -1
View File
@@ -112,7 +112,7 @@ public final class Server {
logger.fine("Binding HTTP listener to address: " + httpAddress + "..."); logger.fine("Binding HTTP listener to address: " + httpAddress + "...");
try { try {
httpBootstrap.bind(httpAddress); // httpBootstrap.bind(httpAddress);
} catch (Throwable t) { } catch (Throwable t) {
logger.log(Level.WARNING, logger.log(Level.WARNING,
"Binding to HTTP failed: client will use JAGGRAB as a fallback (not recommended)!", t); "Binding to HTTP failed: client will use JAGGRAB as a fallback (not recommended)!", t);
@@ -65,6 +65,7 @@ public final class NpcDefinitionDecoder {
*/ */
private NpcDefinition decode(int id, ByteBuffer buffer) { private NpcDefinition decode(int id, ByteBuffer buffer) {
NpcDefinition definition = new NpcDefinition(id); NpcDefinition definition = new NpcDefinition(id);
while (true) { while (true) {
int opcode = buffer.get() & 0xFF; int opcode = buffer.get() & 0xFF;
@@ -87,8 +88,7 @@ public final class NpcDefinitionDecoder {
} else if (opcode == 14) { } else if (opcode == 14) {
definition.setWalkAnimation(buffer.getShort()); definition.setWalkAnimation(buffer.getShort());
} else if (opcode == 17) { } else if (opcode == 17) {
definition definition.setWalkAnimations(buffer.getShort(), buffer.getShort(), buffer.getShort(), buffer.getShort());
.setWalkAnimations(buffer.getShort(), buffer.getShort(), buffer.getShort(), buffer.getShort());
} else if (opcode >= 30 && opcode < 40) { } else if (opcode >= 30 && opcode < 40) {
String str = BufferUtil.readString(buffer); String str = BufferUtil.readString(buffer);
if (str.equals("hidden")) { if (str.equals("hidden")) {
@@ -36,6 +36,7 @@ public final class GamePulseHandler implements Runnable {
} catch (Throwable t) { } catch (Throwable t) {
logger.log(Level.SEVERE, "Exception during pulse.", t); logger.log(Level.SEVERE, "Exception during pulse.", t);
} }
} }
} }
+2 -1
View File
@@ -4,13 +4,14 @@ import org.apollo.game.model.entity.Mob;
import org.apollo.game.scheduling.ScheduledTask; import org.apollo.game.scheduling.ScheduledTask;
/** /**
* An action is a specialised {@link ScheduledTask} which is specific to a mob. * An action is a specialised {@link ScheduledTask} that is specific to a {@link Mob}.
* <p> * <p>
* <strong>ALL</strong> actions <strong>MUST</strong> implement the {@link #equals(Object)} method. This is to check if * <strong>ALL</strong> actions <strong>MUST</strong> implement the {@link #equals(Object)} method. This is to check if
* two actions are identical: if they are, then the new action does not replace the old one (so spam/accidental clicking * two actions are identical: if they are, then the new action does not replace the old one (so spam/accidental clicking
* won't cancel your action, and start another from scratch). * won't cancel your action, and start another from scratch).
* *
* @author Graham * @author Graham
* @param <T> The type of mob.
*/ */
public abstract class Action<T extends Mob> extends ScheduledTask { public abstract class Action<T extends Mob> extends ScheduledTask {
@@ -8,6 +8,7 @@ import org.apollo.game.model.entity.Mob;
* *
* @author Blake * @author Blake
* @author Graham * @author Graham
* @param <T> The type of {@link Mob}.
*/ */
public abstract class DistancedAction<T extends Mob> extends Action<T> { public abstract class DistancedAction<T extends Mob> extends Action<T> {
@@ -3,6 +3,11 @@ package org.apollo.game.message.impl;
import org.apollo.game.message.Message; import org.apollo.game.message.Message;
import org.apollo.game.model.Item; import org.apollo.game.model.Item;
/**
* A {@link Message} sent to the client to display an item on a tile for every player.
*
* @author Major
*/
public final class AddGlobalTileItemMessage extends Message { public final class AddGlobalTileItemMessage extends Message {
/** /**
@@ -21,6 +21,9 @@ public final class ArrowKeyMessage extends Message {
/** /**
* Creates a new arrow key message. * Creates a new arrow key message.
*
* @param roll The camera roll.
* @param yaw The camera yaw.
*/ */
public ArrowKeyMessage(int roll, int yaw) { public ArrowKeyMessage(int roll, int yaw) {
this.roll = roll; this.roll = roll;
@@ -17,7 +17,7 @@ public final class FocusUpdateMessage extends Message {
/** /**
* Creates a new focus update message. * Creates a new focus update message.
* *
* @param update The data received. * @param focused The data received.
*/ */
public FocusUpdateMessage(boolean focused) { public FocusUpdateMessage(boolean focused) {
this.focused = focused; this.focused = focused;
@@ -28,7 +28,8 @@ public final class ForwardPrivateChatMessage extends Message {
/** /**
* Creates a new forward private message message. * Creates a new forward private message message.
* *
* @param sender The player sending the message. * @param username The username of the player sending the message.
* @param level The {@link PrivilegeLevel} of the player sending the message.
* @param message The compressed message. * @param message The compressed message.
*/ */
public ForwardPrivateChatMessage(String username, PrivilegeLevel level, byte[] message) { public ForwardPrivateChatMessage(String username, PrivilegeLevel level, byte[] message) {
@@ -19,7 +19,7 @@ public final class IgnoreListMessage extends Message {
/** /**
* Creates a new ignore list message. * Creates a new ignore list message.
* *
* @param player The player. * @param usernames The {@link List} of usernames to send.
*/ */
public IgnoreListMessage(List<String> usernames) { public IgnoreListMessage(List<String> usernames) {
this.usernames = usernames; this.usernames = usernames;
@@ -1,7 +1,7 @@
package org.apollo.game.message.impl; package org.apollo.game.message.impl;
/** /**
* A {@link Message} sent by the client when a player uses one inventory item on another. * A {@link InventoryItemMessage} sent by the client when a player uses one inventory item on another.
* *
* @author Chris Fletcher * @author Chris Fletcher
*/ */
@@ -32,8 +32,7 @@ public final class ItemOnItemMessage extends InventoryItemMessage {
* @param targetId The id of the target item. * @param targetId The id of the target item.
* @param targetSlot The slot of the target item. * @param targetSlot The slot of the target item.
*/ */
public ItemOnItemMessage(int usedInterface, int usedId, int usedSlot, int targetInterface, int targetId, public ItemOnItemMessage(int usedInterface, int usedId, int usedSlot, int targetInterface, int targetId, int targetSlot) {
int targetSlot) {
super(0, usedInterface, usedId, usedSlot); super(0, usedInterface, usedId, usedSlot);
this.targetInterface = targetInterface; this.targetInterface = targetInterface;
this.targetSlot = targetSlot; this.targetSlot = targetSlot;
@@ -1,7 +1,7 @@
package org.apollo.game.message.impl; package org.apollo.game.message.impl;
/** /**
* A {@link Message} sent by the client when a player casts a spell on an inventory item. * A {@link InventoryItemMessage} sent by the client when a player casts a spell on an inventory item.
* *
* @author Chris Fletcher * @author Chris Fletcher
*/ */
@@ -4,7 +4,7 @@ import org.apollo.game.message.Message;
import org.apollo.game.model.Position; import org.apollo.game.model.Position;
/** /**
* A {@link Message sent to the client instructing it to load the specified region. * A {@link Message} sent to the client instructing it to load the specified region.
* *
* @author Graham * @author Graham
*/ */
@@ -28,7 +28,7 @@ public final class UpdateTileItemMessage extends Message {
/** /**
* Creates a new message that updates the previous amount of the item. * Creates a new message that updates the previous amount of the item.
* *
* @param id The item to be placed. * @param item The item to be placed.
* @param previousAmount The previous amount of the item. * @param previousAmount The previous amount of the item.
*/ */
public UpdateTileItemMessage(Item item, int previousAmount) { public UpdateTileItemMessage(Item item, int previousAmount) {
@@ -38,7 +38,7 @@ public final class UpdateTileItemMessage extends Message {
/** /**
* Creates a new set tile item message. * Creates a new set tile item message.
* *
* @param id The item to be placed. * @param item The item to be placed.
* @param previousAmount The previous amount of the item. * @param previousAmount The previous amount of the item.
* @param positionOffset The offset from the client's base position. * @param positionOffset The offset from the client's base position.
*/ */
+2 -2
View File
@@ -1,6 +1,6 @@
package org.apollo.game.model; package org.apollo.game.model;
import com.google.common.base.Objects; import com.google.common.base.MoreObjects;
/** /**
* Represents a position in the world. * Represents a position in the world.
@@ -219,7 +219,7 @@ public final class Position {
@Override @Override
public String toString() { public String toString() {
return Objects.toStringHelper(this).add("x", x).add("y", y).add("height", height) return MoreObjects.toStringHelper(this).add("x", x).add("y", y).add("height", height)
.add("sector x", getTopLeftSectorX()).add("sector y", getTopLeftSectorY()).toString(); .add("sector x", getTopLeftSectorX()).add("sector y", getTopLeftSectorY()).toString();
} }
+2 -2
View File
@@ -2,7 +2,6 @@ package org.apollo.game.model;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@@ -232,7 +231,7 @@ public final class World {
* @param release The release number. * @param release The release number.
* @param fs The file system. * @param fs The file system.
* @param manager The plugin manager. TODO move this. * @param manager The plugin manager. TODO move this.
* @throws IOException If an I/O error occurs. * @throws Exception If any definitions could not be loaded or there was a failure when loading plugins.
*/ */
public void init(int release, IndexedFileSystem fs, PluginManager manager) throws Exception { public void init(int release, IndexedFileSystem fs, PluginManager manager) throws Exception {
this.releaseNumber = release; this.releaseNumber = release;
@@ -345,6 +344,7 @@ public final class World {
* Schedules a new task. * Schedules a new task.
* *
* @param task The {@link ScheduledTask}. * @param task The {@link ScheduledTask}.
* @return {@code true} if the task was added successfully.
*/ */
public boolean schedule(ScheduledTask task) { public boolean schedule(ScheduledTask task) {
return scheduler.schedule(task); return scheduler.schedule(task);
@@ -51,14 +51,13 @@ public final class NpcDefinition {
/** /**
* Gets the NPC definition for the specified id. * Gets the NPC definition for the specified id.
* *
* @param The id. * @param id The id.
* @return The definition. * @return The definition.
* @throws IndexOutOfBoundsException If the id is out of bounds. * @throws IndexOutOfBoundsException If the id is out of bounds.
*/ */
public static NpcDefinition lookup(int id) { public static NpcDefinition lookup(int id) {
if (id < 0 || id >= definitions.length) { if (id < 0 || id >= definitions.length) {
throw new IndexOutOfBoundsException(NpcDefinition.class.getName() + " lookup index " + id throw new IndexOutOfBoundsException(NpcDefinition.class.getName() + " lookup index " + id + " out of bounds.");
+ " out of bounds.");
} }
return definitions[id]; return definitions[id];
} }
+3 -3
View File
@@ -167,7 +167,7 @@ public abstract class Mob extends Entity {
/** /**
* Gets this mob's {@link NpcDefinition}. * Gets this mob's {@link NpcDefinition}.
* *
* @param definition The definition. * @return The npc definition.
*/ */
public final NpcDefinition getDefinition() { public final NpcDefinition getDefinition() {
return definition; return definition;
@@ -180,8 +180,8 @@ public abstract class Mob extends Entity {
*/ */
public final Direction[] getDirections() { public final Direction[] getDirections() {
if (firstDirection != Direction.NONE) { if (firstDirection != Direction.NONE) {
return secondDirection == Direction.NONE ? new Direction[] { firstDirection } : new Direction[] { return secondDirection == Direction.NONE ? new Direction[] { firstDirection } : new Direction[] { firstDirection,
firstDirection, secondDirection }; secondDirection };
} }
return Direction.EMPTY_DIRECTION_ARRAY; return Direction.EMPTY_DIRECTION_ARRAY;
} }
+10 -8
View File
@@ -221,8 +221,8 @@ public final class Player extends Mob {
* *
* @param username The username. * @param username The username.
*/ */
public boolean addFriend(String username) { public void addFriend(String username) {
return friends.add(username.toLowerCase()); friends.add(username.toLowerCase());
} }
/** /**
@@ -230,8 +230,8 @@ public final class Player extends Mob {
* *
* @param username The username. * @param username The username.
*/ */
public boolean addIgnore(String username) { public void addIgnore(String username) {
return ignores.add(username.toLowerCase()); ignores.add(username.toLowerCase());
} }
/** /**
@@ -606,6 +606,7 @@ public final class Player extends Mob {
* Removes the specified username from this player's friend list. * Removes the specified username from this player's friend list.
* *
* @param username The username. * @param username The username.
* @return {@code true} if the player's friend list contained the specified user, {@code false} if not.
*/ */
public boolean removeFriend(String username) { public boolean removeFriend(String username) {
return friends.remove(username.toLowerCase()); return friends.remove(username.toLowerCase());
@@ -615,6 +616,7 @@ public final class Player extends Mob {
* Removes the specified username from this player's ignore list. * Removes the specified username from this player's ignore list.
* *
* @param username The username. * @param username The username.
* @return {@code true} if the player's ignore list contained the specified user, {@code false} if not.
*/ */
public boolean removeIgnore(String username) { public boolean removeIgnore(String username) {
return ignores.remove(username.toLowerCase()); return ignores.remove(username.toLowerCase());
@@ -666,6 +668,7 @@ public final class Player extends Mob {
* Sends a message to the player. * Sends a message to the player.
* *
* @param message The message. * @param message The message.
* @param filterable Whether or not the message can be filtered.
*/ */
public void sendMessage(String message, boolean filterable) { public void sendMessage(String message, boolean filterable) {
if (clientVersion > 0) { if (clientVersion > 0) {
@@ -909,8 +912,8 @@ public final class Player extends Mob {
@Override @Override
public String toString() { public String toString() {
return Player.class.getName() + " [username=" + getUsername() + ", privilege=" + privilegeLevel return Player.class.getName() + " [username=" + getUsername() + ", privilege=" + privilegeLevel + ", clientVersion="
+ ", clientVersion=" + clientVersion + "]"; + clientVersion + "]";
} }
/** /**
@@ -925,8 +928,7 @@ public final class Player extends Mob {
* Initialises the player's inventories. * Initialises the player's inventories.
*/ */
private void initInventories() { private void initInventories() {
InventoryListener fullInventoryListener = new FullInventoryListener(this, InventoryListener fullInventoryListener = new FullInventoryListener(this, FullInventoryListener.FULL_INVENTORY_MESSAGE);
FullInventoryListener.FULL_INVENTORY_MESSAGE);
InventoryListener fullBankListener = new FullInventoryListener(this, FullInventoryListener.FULL_BANK_MESSAGE); InventoryListener fullBankListener = new FullInventoryListener(this, FullInventoryListener.FULL_BANK_MESSAGE);
InventoryListener appearanceListener = new AppearanceInventoryListener(this); InventoryListener appearanceListener = new AppearanceInventoryListener(this);
@@ -125,14 +125,12 @@ public final class SkillSet {
* *
* @param listener The listener. * @param listener The listener.
*/ */
public boolean addListener(SkillListener listener) { public void addListener(SkillListener listener) {
return listeners.add(listener); listeners.add(listener);
} }
/** /**
* Calculates the combat level for this skill set. * Calculates the combat level for this skill set.
*
* @return The combat level.
*/ */
public void calculateCombatLevel() { public void calculateCombatLevel() {
int attack = skills[Skill.ATTACK].getMaximumLevel(); int attack = skills[Skill.ATTACK].getMaximumLevel();
@@ -249,8 +247,8 @@ public final class SkillSet {
* *
* @param listener The listener to remove. * @param listener The listener to remove.
*/ */
public boolean removeListener(SkillListener listener) { public void removeListener(SkillListener listener) {
return listeners.remove(listener); listeners.remove(listener);
} }
/** /**
@@ -3,77 +3,82 @@ package org.apollo.game.model.entity.attr;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
/**
* A {@link Map} wrapper used to store {@link Attribute Attributes} and their {@link AttributeDefinition definitions}.
*
* @author Major
*/
public final class AttributeMap { public final class AttributeMap {
/** /**
* The map of attribute names to definitions. * The map of attribute names to definitions.
*/ */
private static Map<String, AttributeDefinition<?>> definitions = new HashMap<>(50); private static Map<String, AttributeDefinition<?>> definitions = new HashMap<>(50);
/** /**
* Registers an {@link AttributeDefinition}. * Registers an {@link AttributeDefinition}.
* *
* @param name The name of the attribute. * @param name The name of the attribute.
* @param definition The definition. * @param definition The definition.
*/ */
public static void addDefinition(String name, AttributeDefinition<?> definition) { public static void addDefinition(String name, AttributeDefinition<?> definition) {
definitions.put(name, definition); definitions.put(name, definition);
} }
/** /**
* Gets the {@link AttributeDefinition} with the specified name, or {@code null} if it is not defined. * Gets the {@link AttributeDefinition} with the specified name, or {@code null} if it is not defined.
* *
* @param name The name of the attribute. * @param name The name of the attribute.
* @return The attribute definition. * @return The attribute definition.
*/ */
public static AttributeDefinition<?> getDefinition(String name) { public static AttributeDefinition<?> getDefinition(String name) {
return definitions.get(name); return definitions.get(name);
} }
/** /**
* Gets the {@link AttributeDefinitions}, as a {@link Map}. * Gets the {@link AttributeDefinition}s, as a {@link Map}.
* *
* @return The map of attribute names to definitions. * @return The map of attribute names to definitions.
*/ */
public static Map<String, AttributeDefinition<?>> getDefinitions() { public static Map<String, AttributeDefinition<?>> getDefinitions() {
return new HashMap<>(definitions); return new HashMap<>(definitions);
} }
/** /**
* The map of attribute names to attributes. * The map of attribute names to attributes.
*/ */
private Map<String, Attribute<?>> attributes = new HashMap<>(); private Map<String, Attribute<?>> attributes = new HashMap<>();
/** /**
* Gets the {@link Attribute} with the specified name. * Gets the {@link Attribute} with the specified name.
* *
* @param name The name of the attribute. * @param name The name of the attribute.
* @return The attribute. * @return The attribute.
*/ */
public Attribute<?> getAttribute(String name) { public Attribute<?> getAttribute(String name) {
return attributes.get(name); return attributes.get(name);
} }
/** /**
* Gets a shallow copy of the map of attributes. * Gets a shallow copy of the map of attributes.
* *
* @return The attributes. * @return The attributes.
*/ */
public Map<String, Attribute<?>> getAttributes() { public Map<String, Attribute<?>> getAttributes() {
return new HashMap<>(attributes); return new HashMap<>(attributes);
} }
/** /**
* Sets the value of the {@link Attribute} with the specified name. * Sets the value of the {@link Attribute} with the specified name.
* *
* @param name The name of the attribute. * @param name The name of the attribute.
* @param attribute The attribute. * @param attribute The attribute.
*/ */
public void setAttribute(String name, Attribute<?> attribute) { public void setAttribute(String name, Attribute<?> attribute) {
if (getDefinition(name) == null) { if (getDefinition(name) == null) {
throw new IllegalArgumentException("Attributes must be defined before their value can be set."); throw new IllegalArgumentException("Attributes must be defined before their value can be set.");
}
attributes.put(name, attribute);
} }
attributes.put(name, attribute);
}
} }
@@ -2,7 +2,7 @@ package org.apollo.game.model.entity.attr;
/** /**
* The type of attribute. The functionality of this enum (and other classes) is dependent on the ordering of the values * The type of attribute. The functionality of this enum (and other classes) is dependent on the ordering of the values
* - the expected order is {@link #BOOLEAN}, {@link#DOUBLE}, {@link #LONG}, {@link #STRING}, {@link #SYMBOL}. * - the expected order is {@link #BOOLEAN}, {@link #DOUBLE}, {@link #LONG}, {@link #STRING}, {@link #SYMBOL}.
* *
* @author Major * @author Major
*/ */
+1 -2
View File
@@ -460,7 +460,6 @@ public final class Inventory implements Cloneable {
* under no circumstances make any changes to other slots. * under no circumstances make any changes to other slots.
* *
* @param slot The slot. * @param slot The slot.
* @param id The item id.
* @param amount The amount to remove. * @param amount The amount to remove.
* @return The amount that was removed (0 if nothing was removed). * @return The amount that was removed (0 if nothing was removed).
*/ */
@@ -488,7 +487,7 @@ public final class Inventory implements Cloneable {
/** /**
* Removes the item (if any) that is in the specified slot. * Removes the item (if any) that is in the specified slot.
* *
* @param slot * @param slot The slot to reset.
* @return The item that was in the slot. * @return The item that was in the slot.
*/ */
public Item reset(int slot) { public Item reset(int slot) {
@@ -40,6 +40,7 @@ public enum PrivacyState {
* Gets the privacy state for the specified numerical value. * Gets the privacy state for the specified numerical value.
* *
* @param value The numerical value. * @param value The numerical value.
* @param chat Whether or not the value is for public chat.
* @return The privacy state. * @return The privacy state.
* @throws IllegalArgumentException If the specified value is out of bounds. * @throws IllegalArgumentException If the specified value is out of bounds.
*/ */
@@ -77,6 +78,7 @@ public enum PrivacyState {
/** /**
* Converts this privacy state to an integer. * Converts this privacy state to an integer.
* *
* @param chat Whether or not the value is for public chat.
* @return The numerical value used by the client. * @return The numerical value used by the client.
*/ */
public int toInteger(boolean chat) { public int toInteger(boolean chat) {
@@ -45,6 +45,7 @@ public final class Scheduler {
* Schedules a new task. * Schedules a new task.
* *
* @param task The task to schedule. * @param task The task to schedule.
* @return {@code true} if the task was added successfully.
*/ */
public boolean schedule(ScheduledTask task) { public boolean schedule(ScheduledTask task) {
return newTasks.add(task); return newTasks.add(task);
@@ -34,9 +34,9 @@ public abstract class SynchronizationBlock {
* @return The appearance block. * @return The appearance block.
*/ */
public static SynchronizationBlock createAppearanceBlock(Player player) { public static SynchronizationBlock createAppearanceBlock(Player player) {
return new AppearanceBlock(player.getEncodedName(), player.getAppearance(), player.getSkillSet() return new AppearanceBlock(player.getEncodedName(), player.getAppearance(), player.getSkillSet().getCombatLevel(), 0,
.getCombatLevel(), 0, player.getEquipment(), player.getPrayerIcon(), player.isSkulled(), player.getEquipment(), player.getPrayerIcon(), player.isSkulled(), player.getDefinition() == null ? -1 : player
player.getDefinition() == null ? -1 : player.getDefinition().getId()); .getDefinition().getId());
} }
/** /**
@@ -61,7 +61,7 @@ public abstract class SynchronizationBlock {
} }
/** /**
* Creates a {@link ForceMovement} block with the specified parameters. * Creates a {@link ForceMovementBlock} with the specified parameters.
* *
* @param initialPosition The initial {@link Position} of the player. * @param initialPosition The initial {@link Position} of the player.
* @param finalPosition The final position of the player * @param finalPosition The final position of the player
@@ -98,8 +98,8 @@ public abstract class SynchronizationBlock {
*/ */
public static SynchronizationBlock createHitUpdateBlock(int damage, int type, int currentHealth, int maximumHealth, public static SynchronizationBlock createHitUpdateBlock(int damage, int type, int currentHealth, int maximumHealth,
boolean secondary) { boolean secondary) {
return secondary ? new SecondaryHitUpdateBlock(damage, type, currentHealth, maximumHealth) return secondary ? new SecondaryHitUpdateBlock(damage, type, currentHealth, maximumHealth) : new HitUpdateBlock(damage,
: new HitUpdateBlock(damage, type, currentHealth, maximumHealth); type, currentHealth, maximumHealth);
} }
/** /**
@@ -65,6 +65,7 @@ public final class SynchronizationBlockSet implements Cloneable {
* Removes a {@link SynchronizationBlock} from this set. * Removes a {@link SynchronizationBlock} from this set.
* *
* @param clazz The block's class. * @param clazz The block's class.
* @return The removed block.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends SynchronizationBlock> T remove(Class<? extends SynchronizationBlock> clazz) { public <T extends SynchronizationBlock> T remove(Class<? extends SynchronizationBlock> clazz) {
@@ -95,8 +95,7 @@ public final class BinaryPlayerSaver implements PlayerSaver {
} }
Set<Entry<String, Attribute<?>>> attributes = player.getAttributes().entrySet(); Set<Entry<String, Attribute<?>>> attributes = player.getAttributes().entrySet();
attributes attributes.removeIf(e -> AttributeMap.getDefinition(e.getKey()).getPersistence() != AttributePersistence.SERIALIZED);
.removeIf(e -> AttributeMap.getDefinition(e.getKey()).getPersistence() != AttributePersistence.SERIALIZED);
out.writeInt(attributes.size()); out.writeInt(attributes.size());
for (Entry<String, Attribute<?>> entry : attributes) { for (Entry<String, Attribute<?>> entry : attributes) {
@@ -108,10 +107,10 @@ public final class BinaryPlayerSaver implements PlayerSaver {
} }
/** /**
* Writes an attribute map entry to the specified output stream. * Writes an {@link Attribute} to the specified output stream.
* *
* @param out The output stream. * @param out The output stream.
* @param entry The map entry. * @param attribute The attribute.
* @throws IOException If an I/O error occurs. * @throws IOException If an I/O error occurs.
*/ */
private void saveAttribute(DataOutputStream out, Attribute<?> attribute) throws IOException { private void saveAttribute(DataOutputStream out, Attribute<?> attribute) throws IOException {
@@ -4,11 +4,16 @@ import org.apollo.io.player.PlayerLoader;
import org.apollo.io.player.PlayerLoaderResponse; import org.apollo.io.player.PlayerLoaderResponse;
import org.apollo.security.PlayerCredentials; import org.apollo.security.PlayerCredentials;
/**
* A {@link PlayerLoader} that utilises {@code JDBC} to load player files.
*
* @author Major
*/
public final class JdbcPlayerLoader implements PlayerLoader { public final class JdbcPlayerLoader implements PlayerLoader {
@Override @Override
public PlayerLoaderResponse loadPlayer(PlayerCredentials credentials) throws Exception { public PlayerLoaderResponse loadPlayer(PlayerCredentials credentials) throws Exception {
return null; throw new UnsupportedOperationException("JDBC loading is not supported at this time.");
} }
} }
@@ -3,11 +3,16 @@ package org.apollo.io.player.impl;
import org.apollo.game.model.entity.Player; import org.apollo.game.model.entity.Player;
import org.apollo.io.player.PlayerSaver; import org.apollo.io.player.PlayerSaver;
/**
* A {@link PlayerSaver} that utilises {@code JDBC} to save the player.
*
* @author Major
*/
public final class JdbcPlayerSaver implements PlayerSaver { public final class JdbcPlayerSaver implements PlayerSaver {
@Override @Override
public void savePlayer(Player player) throws Exception { public void savePlayer(Player player) throws Exception {
throw new UnsupportedOperationException("JDBC saving is not supported at this time.");
} }
} }
+1 -1
View File
@@ -1,7 +1,7 @@
package org.apollo.net.codec.game; package org.apollo.net.codec.game;
/** /**
* Represents the order of bytes in a {@link DataType} when {@code {@link DataType#getBytes()} > 1}. * Represents the order of bytes in a {@link DataType} when {@link DataType#getBytes()} {@code > 1}.
* *
* @author Graham * @author Graham
*/ */
@@ -15,7 +15,7 @@ import org.apollo.net.release.Release;
import org.apollo.util.StatefulFrameDecoder; import org.apollo.util.StatefulFrameDecoder;
/** /**
* A {@link StatefulFrameDecoder} which decodes game packets. * A {@link StatefulFrameDecoder} that decodes {@link GamePacket}s.
* *
* @author Graham * @author Graham
*/ */
@@ -59,17 +59,16 @@ public final class GamePacketDecoder extends StatefulFrameDecoder<GameDecoderSta
} }
@Override @Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, GameDecoderState state) protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, GameDecoderState state) throws IOException {
throws IOException {
switch (state) { switch (state) {
case GAME_OPCODE: case GAME_OPCODE:
decodeOpcode(ctx, in, out); decodeOpcode(in, out);
break; break;
case GAME_LENGTH: case GAME_LENGTH:
decodeLength(ctx, in, out); decodeLength(in);
break; break;
case GAME_PAYLOAD: case GAME_PAYLOAD:
decodePayload(ctx, in, out); decodePayload(in, out);
break; break;
default: default:
throw new IllegalStateException("Invalid game decoder state."); throw new IllegalStateException("Invalid game decoder state.");
@@ -77,34 +76,27 @@ public final class GamePacketDecoder extends StatefulFrameDecoder<GameDecoderSta
} }
/** /**
* Decodes in the length state. * Decodes the length state.
* *
* @param ctx The channel handler context.
* @param channel The channel.
* @param buffer The buffer. * @param buffer The buffer.
* @return The frame, or {@code null}.
* @throws Exception If an error occurs.
*/ */
private Object decodeLength(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) { private void decodeLength(ByteBuf buffer) {
if (buffer.isReadable()) { if (buffer.isReadable()) {
length = buffer.readUnsignedByte(); length = buffer.readUnsignedByte();
if (length != 0) { if (length != 0) {
setState(GameDecoderState.GAME_PAYLOAD); setState(GameDecoderState.GAME_PAYLOAD);
} }
} }
return null;
} }
/** /**
* Decodes in the opcode state. * Decodes the opcode state.
* *
* @param ctx The channel handler context.
* @param channel The channel.
* @param buffer The buffer. * @param buffer The buffer.
* @return The frame, or {@code null}. * @param out The {@link List} of objects to be passed along the pipeline.
* @throws IOException If a received opcode or packet type is illegal. * @throws IOException If a received opcode or packet type is illegal.
*/ */
private void decodeOpcode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws IOException { private void decodeOpcode(ByteBuf buffer, List<Object> out) throws IOException {
if (buffer.isReadable()) { if (buffer.isReadable()) {
int encryptedOpcode = buffer.readUnsignedByte(); int encryptedOpcode = buffer.readUnsignedByte();
opcode = encryptedOpcode - random.nextInt() & 0xFF; opcode = encryptedOpcode - random.nextInt() & 0xFF;
@@ -135,15 +127,12 @@ public final class GamePacketDecoder extends StatefulFrameDecoder<GameDecoderSta
} }
/** /**
* Decodes in the payload state. * Decodes the payload state.
* *
* @param ctx The channel handler context.
* @param channel The channel.
* @param buffer The buffer. * @param buffer The buffer.
* @return The frame, or {@code null}. * @param out The {@link List} of objects to be passed along the pipeline.
* @throws Exception If an error occurs.
*/ */
private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) { private void decodePayload(ByteBuf buffer, List<Object> out) {
if (buffer.readableBytes() >= length) { if (buffer.readableBytes() >= length) {
ByteBuf payload = buffer.readBytes(length); ByteBuf payload = buffer.readBytes(length);
setState(GameDecoderState.GAME_OPCODE); setState(GameDecoderState.GAME_OPCODE);
@@ -58,8 +58,7 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
} }
@Override @Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, LoginDecoderState state) protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, LoginDecoderState state) throws Exception {
throws Exception {
switch (state) { switch (state) {
case LOGIN_HANDSHAKE: case LOGIN_HANDSHAKE:
decodeHandshake(ctx, in, out); decodeHandshake(ctx, in, out);
@@ -79,10 +78,8 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
* Decodes in the handshake state. * Decodes in the handshake state.
* *
* @param ctx The channel handler context. * @param ctx The channel handler context.
* @param channel The channel.
* @param buffer The buffer. * @param buffer The buffer.
* @return The frame, or {@code null}. * @param out The {@link List} of objects to pass forward through the pipeline.
* @throws Exception If an error occurs.
*/ */
private void decodeHandshake(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) { private void decodeHandshake(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) {
if (buffer.isReadable()) { if (buffer.isReadable()) {
@@ -103,9 +100,8 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
* Decodes in the header state. * Decodes in the header state.
* *
* @param ctx The channel handler context. * @param ctx The channel handler context.
* @param channel The channel.
* @param buffer The buffer. * @param buffer The buffer.
* @return The frame, or {@code null}. * @param out The {@link List} of objects to pass forward through the pipeline.
* @throws IOException If the login type sent by the client is invalid. * @throws IOException If the login type sent by the client is invalid.
*/ */
private void decodeHeader(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws IOException { private void decodeHeader(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws IOException {
@@ -127,9 +123,8 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
* Decodes in the payload state. * Decodes in the payload state.
* *
* @param ctx The channel handler context. * @param ctx The channel handler context.
* @param channel The channel.
* @param buffer The buffer. * @param buffer The buffer.
* @return The frame, or {@code null}. * @param out The {@link List} of objects to pass forward through the pipeline.
* @throws Exception If an error occurs. * @throws Exception If an error occurs.
*/ */
private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception { private void decodePayload(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
@@ -201,8 +196,8 @@ public final class LoginDecoder extends StatefulFrameDecoder<LoginDecoderState>
PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash, uid); PlayerCredentials credentials = new PlayerCredentials(username, password, usernameHash, uid);
IsaacRandomPair randomPair = new IsaacRandomPair(encodingRandom, decodingRandom); IsaacRandomPair randomPair = new IsaacRandomPair(encodingRandom, decodingRandom);
LoginRequest request = new LoginRequest(credentials, randomPair, reconnecting, lowMemory, releaseNumber, LoginRequest request = new LoginRequest(credentials, randomPair, reconnecting, lowMemory, releaseNumber, archiveCrcs,
archiveCrcs, clientVersion); clientVersion);
out.add(request); out.add(request);
if (buffer.isReadable()) { if (buffer.isReadable()) {
@@ -13,6 +13,9 @@ import java.util.List;
*/ */
public final class LoginEncoder extends MessageToMessageEncoder<LoginResponse> { public final class LoginEncoder extends MessageToMessageEncoder<LoginResponse> {
/**
* Creates the login encoder.
*/
public LoginEncoder() { public LoginEncoder() {
super(LoginResponse.class); super(LoginResponse.class);
} }
@@ -21,10 +24,12 @@ public final class LoginEncoder extends MessageToMessageEncoder<LoginResponse> {
protected void encode(ChannelHandlerContext ctx, LoginResponse response, List<Object> out) { protected void encode(ChannelHandlerContext ctx, LoginResponse response, List<Object> out) {
ByteBuf buffer = ctx.alloc().buffer(3); ByteBuf buffer = ctx.alloc().buffer(3);
buffer.writeByte(response.getStatus()); buffer.writeByte(response.getStatus());
if (response.getStatus() == LoginConstants.STATUS_OK) { if (response.getStatus() == LoginConstants.STATUS_OK) {
buffer.writeByte(response.getRights()); buffer.writeByte(response.getRights());
buffer.writeByte(response.isFlagged() ? 1 : 0); buffer.writeByte(response.isFlagged() ? 1 : 0);
} }
out.add(buffer); out.add(buffer);
} }
@@ -54,9 +54,10 @@ public final class LoginRequest {
* @param reconnecting The reconnecting flag. * @param reconnecting The reconnecting flag.
* @param releaseNumber The release number. * @param releaseNumber The release number.
* @param archiveCrcs The archive CRCs. * @param archiveCrcs The archive CRCs.
* @param clientVersion The client version.
*/ */
public LoginRequest(PlayerCredentials credentials, IsaacRandomPair randomPair, boolean lowMemory, public LoginRequest(PlayerCredentials credentials, IsaacRandomPair randomPair, boolean lowMemory, boolean reconnecting,
boolean reconnecting, int releaseNumber, int[] archiveCrcs, int clientVersion) { int releaseNumber, int[] archiveCrcs, int clientVersion) {
this.credentials = credentials; this.credentials = credentials;
this.randomPair = randomPair; this.randomPair = randomPair;
this.lowMemory = lowMemory; this.lowMemory = lowMemory;
@@ -333,7 +333,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
/** /**
* Puts a force movement block in the specified builder. * Puts a force movement block in the specified builder.
* *
* @param forceMovementBlock The block. * @param block The block.
* @param builder The builder. * @param builder The builder.
*/ */
private void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) { private void putForceMovementBlock(ForceMovementBlock block, GamePacketBuilder builder) {
@@ -388,8 +388,7 @@ public final class PlayerSynchronizationMessageEncoder extends MessageEncoder<Pl
* @param message The message. * @param message The message.
* @param builder The builder. * @param builder The builder.
*/ */
private void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, private void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) {
GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0; boolean updateRequired = seg.getBlockSet().size() > 0;
if (seg.getType() == SegmentType.TELEPORT) { if (seg.getType() == SegmentType.TELEPORT) {
Position position = ((TeleportSegment) seg).getDestination(); Position position = ((TeleportSegment) seg).getDestination();
@@ -7,7 +7,7 @@ import org.apollo.net.codec.game.GamePacketBuilder;
import org.apollo.net.release.MessageEncoder; import org.apollo.net.release.MessageEncoder;
/** /**
* A {@link MessageEncoder} for the {@link SetWidgetComponentEvent}. * A {@link MessageEncoder} for the {@link SetWidgetVisibilityMessage}.
* *
* @author Chris Fletcher * @author Chris Fletcher
*/ */
-1
View File
@@ -42,7 +42,6 @@ public abstract class Session {
* Processes a message received from the channel. * Processes a message received from the channel.
* *
* @param message The message. * @param message The message.
* @throws Exception If an error occurs.
*/ */
public abstract void messageReceived(Object message); public abstract void messageReceived(Object message);
@@ -1,7 +1,6 @@
package org.apollo.util; package org.apollo.util;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.ByteToMessageDecoder;
@@ -11,11 +10,10 @@ import java.util.List;
* A stateful implementation of a {@link ByteToMessageDecoder} which may be extended and used by other classes. The * A stateful implementation of a {@link ByteToMessageDecoder} which may be extended and used by other classes. The
* current state is tracked by this class and is a user-specified enumeration. * current state is tracked by this class and is a user-specified enumeration.
* *
* The state may be changed by calling the {@link StatefulFrameDecoder#setState(Enum)} method. * The state may be changed by calling the {@link StatefulFrameDecoder#setState} method.
* *
* The current state is supplied as a parameter in the * The current state is supplied as a parameter in the {@link StatefulFrameDecoder#decode} and
* {@link StatefulFrameDecoder#decode(ChannelHandlerContext, Channel, ByteBuf, Enum)} and * {@link StatefulFrameDecoder#decodeLast} methods.
* {@link StatefulFrameDecoder#decodeLast(ChannelHandlerContext, Channel, ByteBuf, Enum)} methods.
* *
* This class is not thread safe: it is recommended that the state is only set in the decode methods overriden. * This class is not thread safe: it is recommended that the state is only set in the decode methods overriden.
* *
@@ -61,8 +59,8 @@ public abstract class StatefulFrameDecoder<T extends Enum<T>> extends ByteToMess
* Decodes the received packets into a frame. * Decodes the received packets into a frame.
* *
* @param ctx The current context of this handler. * @param ctx The current context of this handler.
* @param channel The channel. * @param in The cumulative buffer, which may contain zero or more bytes.
* @param buffer 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(Enum)}.
*/ */
protected abstract void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, T state) throws Exception; protected abstract void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, T state) throws Exception;
@@ -77,8 +75,8 @@ public abstract class StatefulFrameDecoder<T extends Enum<T>> extends ByteToMess
* required. If you do not, remaining data will be discarded! * required. If you do not, remaining data will be discarded!
* *
* @param ctx The current context of this handler. * @param ctx The current context of this handler.
* @param channel The channel. * @param in The cumulative buffer, which may contain zero or more bytes.
* @param buffer 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(Enum)}.
*/ */
protected void decodeLast(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, T state) { protected void decodeLast(ChannelHandlerContext ctx, ByteBuf in, List<Object> out, T state) {
@@ -53,6 +53,7 @@ public final class PluginMetaData {
* Creates the plugin meta data. * Creates the plugin meta data.
* *
* @param id The plugin's id. * @param id The plugin's id.
* @param base The plugin's base folder.
* @param name The plugin's name. * @param name The plugin's name.
* @param description The plugin's description. * @param description The plugin's description.
* @param authors The plugin's authors. * @param authors The plugin's authors.