mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 16:49:12 +00:00
Reformat with tabs instead of spaces.
This commit is contained in:
@@ -40,9 +40,11 @@ import org.apollo.util.NameUtil;
|
|||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The world class is a singleton which contains objects like the {@link MobRepository} for players and NPCs. It should
|
* The world class is a singleton which contains objects like the
|
||||||
* only contain things relevant to the in-game world and not classes which deal with I/O and such (these may be better
|
* {@link MobRepository} for players and NPCs. It should only contain things
|
||||||
* off inside some custom {@link Service} or other code, however, the circumstances are rare).
|
* relevant to the in-game world and not classes which deal with I/O and such
|
||||||
|
* (these may be better off inside some custom {@link Service} or other code,
|
||||||
|
* however, the circumstances are rare).
|
||||||
*
|
*
|
||||||
* @author Graham
|
* @author Graham
|
||||||
*/
|
*/
|
||||||
@@ -153,8 +155,8 @@ public final class World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link Player} with the specified username. Note that this will return {@code null} if the player is
|
* Gets the {@link Player} with the specified username. Note that this will
|
||||||
* offline.
|
* return {@code null} if the player is offline.
|
||||||
*
|
*
|
||||||
* @param username The username.
|
* @param username The username.
|
||||||
* @return The player.
|
* @return The player.
|
||||||
@@ -200,12 +202,14 @@ public final class World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialises the world by loading definitions from the specified file system.
|
* Initialises the world by loading definitions from the specified file
|
||||||
|
* system.
|
||||||
*
|
*
|
||||||
* @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 Exception If any definitions could not be loaded or there was a failure when loading plugins.
|
* @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 {
|
||||||
releaseNumber = release;
|
releaseNumber = release;
|
||||||
@@ -237,7 +241,9 @@ public final class World {
|
|||||||
placeEntities(objects);
|
placeEntities(objects);
|
||||||
logger.fine("Loaded " + objects.length + " static objects.");
|
logger.fine("Loaded " + objects.length + " static objects.");
|
||||||
|
|
||||||
npcMovement = new NpcMovementTask(regions); // Must be exactly here because of ordering issues.
|
npcMovement = new NpcMovementTask(regions); // Must be exactly here
|
||||||
|
// because of ordering
|
||||||
|
// issues.
|
||||||
scheduler.schedule(npcMovement);
|
scheduler.schedule(npcMovement);
|
||||||
|
|
||||||
manager.start();
|
manager.start();
|
||||||
@@ -256,7 +262,8 @@ public final class World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an {@link EventListener}, listening for an {@link Event} of the specified type.
|
* Adds an {@link EventListener}, listening for an {@link Event} of the
|
||||||
|
* specified type.
|
||||||
*
|
*
|
||||||
* @param type The type of the Event.
|
* @param type The type of the Event.
|
||||||
* @param listener The EventListener.
|
* @param listener The EventListener.
|
||||||
@@ -276,7 +283,8 @@ public final class World {
|
|||||||
* Registers the specified npc.
|
* Registers the specified npc.
|
||||||
*
|
*
|
||||||
* @param npc The npc.
|
* @param npc The npc.
|
||||||
* @return {@code true} if the npc registered successfully, otherwise {@code false}.
|
* @return {@code true} if the npc registered successfully, otherwise
|
||||||
|
* {@code false}.
|
||||||
*/
|
*/
|
||||||
public boolean register(Npc npc) {
|
public boolean register(Npc npc) {
|
||||||
boolean success = npcRepository.add(npc);
|
boolean success = npcRepository.add(npc);
|
||||||
@@ -319,8 +327,8 @@ public final class World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spawns the specified {@link Entity}, which must not be a {@link Player} or an {@link Npc}, which have their own
|
* Spawns the specified {@link Entity}, which must not be a {@link Player}
|
||||||
* register methods.
|
* or an {@link Npc}, which have their own register methods.
|
||||||
*
|
*
|
||||||
* @param entity The Entity.
|
* @param entity The Entity.
|
||||||
*/
|
*/
|
||||||
@@ -375,12 +383,12 @@ public final class World {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds entities to regions in the {@link RegionRepository}. By default, we do not notify listeners.
|
* Adds entities to regions in the {@link RegionRepository}. By default, we
|
||||||
|
* do not notify listeners.
|
||||||
*
|
*
|
||||||
* @param entities The entities.
|
* @param entities The entities.
|
||||||
*/
|
*/
|
||||||
private void placeEntities(Entity... entities) {
|
private void placeEntities(Entity... entities) {
|
||||||
Arrays.stream(entities).forEach(entity -> regions.fromPosition(entity.getPosition()).addEntity(entity, false));
|
Arrays.stream(entities).forEach(entity -> regions.fromPosition(entity.getPosition()).addEntity(entity, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -218,7 +218,8 @@ public final class Player extends Mob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a click, represented by a {@link Point}, to the {@link List} of clicks.
|
* Adds a click, represented by a {@link Point}, to the {@link List} of
|
||||||
|
* clicks.
|
||||||
*
|
*
|
||||||
* @param point The point.
|
* @param point The point.
|
||||||
* @return {@code true} if the point was added successfully.
|
* @return {@code true} if the point was added successfully.
|
||||||
@@ -246,7 +247,8 @@ public final class Player extends Mob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the specified {@link DynamicGameObject} to this Player's {@link Set} of visible objects.
|
* Adds the specified {@link DynamicGameObject} to this Player's {@link Set}
|
||||||
|
* of visible objects.
|
||||||
*
|
*
|
||||||
* @param object The DynamicGameObject.
|
* @param object The DynamicGameObject.
|
||||||
*/
|
*/
|
||||||
@@ -289,10 +291,12 @@ public final class Player extends Mob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether this player is friends with the player with the specified username or not.
|
* Indicates whether this player is friends with the player with the
|
||||||
|
* specified username or not.
|
||||||
*
|
*
|
||||||
* @param username The username of the other player.
|
* @param username The username of the other player.
|
||||||
* @return {@code true} if the specified username is on this player's friend list, otherwise {@code false}.
|
* @return {@code true} if the specified username is on this player's friend
|
||||||
|
* list, otherwise {@code false}.
|
||||||
*/
|
*/
|
||||||
public boolean friendsWith(String username) {
|
public boolean friendsWith(String username) {
|
||||||
return friends.contains(username.toLowerCase());
|
return friends.contains(username.toLowerCase());
|
||||||
@@ -410,7 +414,8 @@ public final class Player extends Mob {
|
|||||||
/**
|
/**
|
||||||
* Gets the last known region.
|
* Gets the last known region.
|
||||||
*
|
*
|
||||||
* @return The last known region, or {@code null} if the player has never known a region.
|
* @return The last known region, or {@code null} if the player has never
|
||||||
|
* known a region.
|
||||||
*/
|
*/
|
||||||
public Position getLastKnownRegion() {
|
public Position getLastKnownRegion() {
|
||||||
return lastKnownRegion;
|
return lastKnownRegion;
|
||||||
@@ -508,7 +513,8 @@ public final class Player extends Mob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether or not the player with the specified username is on this player's ignore list.
|
* Indicates whether or not the player with the specified username is on
|
||||||
|
* this player's ignore list.
|
||||||
*
|
*
|
||||||
* @param username The username of the player.
|
* @param username The username of the player.
|
||||||
* @return {@code true} if the player is ignored, {@code false} if not.
|
* @return {@code true} if the player is ignored, {@code false} if not.
|
||||||
@@ -541,7 +547,8 @@ public final class Player extends Mob {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments this player's viewing distance if it is less than the maximum viewing distance.
|
* Increments this player's viewing distance if it is less than the maximum
|
||||||
|
* viewing distance.
|
||||||
*/
|
*/
|
||||||
public void incrementViewingDistance() {
|
public void incrementViewingDistance() {
|
||||||
if (viewingDistance < Position.MAX_DISTANCE) {
|
if (viewingDistance < Position.MAX_DISTANCE) {
|
||||||
@@ -597,7 +604,8 @@ public final class Player extends Mob {
|
|||||||
/**
|
/**
|
||||||
* Checks if this player is withdrawing noted items.
|
* Checks if this player is withdrawing noted items.
|
||||||
*
|
*
|
||||||
* @return {@code true} if the player is currently withdrawing notes, otherwise {@code false}.
|
* @return {@code true} if the player is currently withdrawing notes,
|
||||||
|
* otherwise {@code false}.
|
||||||
*/
|
*/
|
||||||
public boolean isWithdrawingNotes() {
|
public boolean isWithdrawingNotes() {
|
||||||
return withdrawingNotes;
|
return withdrawingNotes;
|
||||||
@@ -661,7 +669,8 @@ 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.
|
* @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());
|
||||||
@@ -671,14 +680,16 @@ 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.
|
* @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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the specified {@link DynamicGameObject} from this Player's {@link Set} of visible objects.
|
* Removes the specified {@link DynamicGameObject} from this Player's
|
||||||
|
* {@link Set} of visible objects.
|
||||||
*
|
*
|
||||||
* @param object The DynamicGameObject.
|
* @param object The DynamicGameObject.
|
||||||
*/
|
*/
|
||||||
@@ -930,7 +941,8 @@ public final class Player extends Mob {
|
|||||||
/**
|
/**
|
||||||
* Sets whether or not the player is withdrawing notes from the bank.
|
* Sets whether or not the player is withdrawing notes from the bank.
|
||||||
*
|
*
|
||||||
* @param withdrawingNotes Whether or not the player is withdrawing noted items.
|
* @param withdrawingNotes Whether or not the player is withdrawing noted
|
||||||
|
* items.
|
||||||
*/
|
*/
|
||||||
public void setWithdrawingNotes(boolean withdrawingNotes) {
|
public void setWithdrawingNotes(boolean withdrawingNotes) {
|
||||||
this.withdrawingNotes = withdrawingNotes;
|
this.withdrawingNotes = withdrawingNotes;
|
||||||
@@ -951,8 +963,7 @@ public final class Player extends Mob {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return MoreObjects.toStringHelper(this).add("username", getUsername()).add("privilege", privilegeLevel)
|
return MoreObjects.toStringHelper(this).add("username", getUsername()).add("privilege", privilegeLevel).toString();
|
||||||
.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -985,16 +996,13 @@ 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);
|
||||||
|
|
||||||
InventoryListener syncInventoryListener = new SynchronizationInventoryListener(this,
|
InventoryListener syncInventoryListener = new SynchronizationInventoryListener(this, SynchronizationInventoryListener.INVENTORY_ID);
|
||||||
SynchronizationInventoryListener.INVENTORY_ID);
|
|
||||||
InventoryListener syncBankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID);
|
InventoryListener syncBankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID);
|
||||||
InventoryListener syncEquipmentListener = new SynchronizationInventoryListener(this,
|
InventoryListener syncEquipmentListener = new SynchronizationInventoryListener(this, SynchronizationInventoryListener.EQUIPMENT_ID);
|
||||||
SynchronizationInventoryListener.EQUIPMENT_ID);
|
|
||||||
|
|
||||||
inventory.addListener(syncInventoryListener);
|
inventory.addListener(syncInventoryListener);
|
||||||
inventory.addListener(fullInventoryListener);
|
inventory.addListener(fullInventoryListener);
|
||||||
|
|||||||
@@ -26,15 +26,17 @@ import org.apollo.util.xml.XmlParser;
|
|||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link GameService} class schedules and manages the execution of the {@link GamePulseHandler} class.
|
* The {@link GameService} class schedules and manages the execution of the
|
||||||
|
* {@link GamePulseHandler} class.
|
||||||
*
|
*
|
||||||
* @author Graham
|
* @author Graham
|
||||||
*/
|
*/
|
||||||
public final class GameService extends Service {
|
public final class GameService extends Service {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The number of times to unregister players per cycle. This is to ensure the saving threads don't get swamped with
|
* The number of times to unregister players per cycle. This is to ensure
|
||||||
* requests and slow everything down.
|
* the saving threads don't get swamped with requests and slow everything
|
||||||
|
* down.
|
||||||
*/
|
*/
|
||||||
private static final int UNREGISTERS_PER_CYCLE = 50;
|
private static final int UNREGISTERS_PER_CYCLE = 50;
|
||||||
|
|
||||||
@@ -61,8 +63,7 @@ public final class GameService extends Service {
|
|||||||
/**
|
/**
|
||||||
* The scheduled executor service.
|
* The scheduled executor service.
|
||||||
*/
|
*/
|
||||||
private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(ThreadUtil
|
private final ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(ThreadUtil.create("GameService"));
|
||||||
.create("GameService"));
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link MessageHandlerChainSet}.
|
* The {@link MessageHandlerChainSet}.
|
||||||
@@ -144,17 +145,19 @@ public final class GameService extends Service {
|
|||||||
*/
|
*/
|
||||||
public void shutdown(boolean natural) {
|
public void shutdown(boolean natural) {
|
||||||
scheduledExecutor.shutdownNow();
|
scheduledExecutor.shutdownNow();
|
||||||
// TODO: Other events that should happen upon natural or unexpected shutdown.
|
// TODO: Other events that should happen upon natural or unexpected
|
||||||
|
// shutdown.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
scheduledExecutor.scheduleAtFixedRate(new GamePulseHandler(this), GameConstants.PULSE_DELAY,
|
scheduledExecutor.scheduleAtFixedRate(new GamePulseHandler(this), GameConstants.PULSE_DELAY, GameConstants.PULSE_DELAY,
|
||||||
GameConstants.PULSE_DELAY, TimeUnit.MILLISECONDS);
|
TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unregisters a player. Returns immediately. The player is unregistered at the start of the next cycle.
|
* Unregisters a player. Returns immediately. The player is unregistered at
|
||||||
|
* the start of the next cycle.
|
||||||
*
|
*
|
||||||
* @param player The player.
|
* @param player The player.
|
||||||
*/
|
*/
|
||||||
@@ -163,7 +166,8 @@ public final class GameService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers a player. Returns immediately. The player is registered at the start of the next cycle.
|
* Registers a player. Returns immediately. The player is registered at the
|
||||||
|
* start of the next cycle.
|
||||||
*
|
*
|
||||||
* @param player The player.
|
* @param player The player.
|
||||||
*/
|
*/
|
||||||
@@ -206,7 +210,8 @@ public final class GameService extends Service {
|
|||||||
*
|
*
|
||||||
* @throws IOException If there is an error accessing the file.
|
* @throws IOException If there is an error accessing the file.
|
||||||
* @throws SAXException If there is an error parsing the file.
|
* @throws SAXException If there is an error parsing the file.
|
||||||
* @throws ReflectiveOperationException If a MessageHandler could not be created.
|
* @throws ReflectiveOperationException If a MessageHandler could not be
|
||||||
|
* created.
|
||||||
*/
|
*/
|
||||||
private void init() throws IOException, SAXException, ReflectiveOperationException {
|
private void init() throws IOException, SAXException, ReflectiveOperationException {
|
||||||
try (InputStream input = new FileInputStream("data/messages.xml")) {
|
try (InputStream input = new FileInputStream("data/messages.xml")) {
|
||||||
|
|||||||
@@ -86,7 +86,8 @@ public final class LoginSession extends Session {
|
|||||||
optional = Optional.empty();
|
optional = Optional.empty();
|
||||||
rights = 0;
|
rights = 0;
|
||||||
|
|
||||||
status = registration == RegistrationStatus.ALREADY_ONLINE ? LoginConstants.STATUS_ACCOUNT_ONLINE : LoginConstants.STATUS_SERVER_FULL;
|
status = registration == RegistrationStatus.ALREADY_ONLINE ? LoginConstants.STATUS_ACCOUNT_ONLINE
|
||||||
|
: LoginConstants.STATUS_SERVER_FULL;
|
||||||
} else {
|
} else {
|
||||||
GameSession session = new GameSession(channel, context, player, request.isReconnecting());
|
GameSession session = new GameSession(channel, context, player, request.isReconnecting());
|
||||||
channel.attr(ApolloHandler.SESSION_KEY).set(session);
|
channel.attr(ApolloHandler.SESSION_KEY).set(session);
|
||||||
@@ -105,7 +106,8 @@ public final class LoginSession extends Session {
|
|||||||
channel.pipeline().addFirst("messageEncoder", new GameMessageEncoder(release));
|
channel.pipeline().addFirst("messageEncoder", new GameMessageEncoder(release));
|
||||||
channel.pipeline().addBefore("messageEncoder", "gameEncoder", new GamePacketEncoder(randomPair.getEncodingRandom()));
|
channel.pipeline().addBefore("messageEncoder", "gameEncoder", new GamePacketEncoder(randomPair.getEncodingRandom()));
|
||||||
|
|
||||||
channel.pipeline().addBefore("handler", "gameDecoder", new GamePacketDecoder(randomPair.getDecodingRandom(), context.getRelease()));
|
channel.pipeline().addBefore("handler", "gameDecoder",
|
||||||
|
new GamePacketDecoder(randomPair.getDecodingRandom(), context.getRelease()));
|
||||||
channel.pipeline().addAfter("gameDecoder", "messageDecoder", new GameMessageDecoder(release));
|
channel.pipeline().addAfter("gameDecoder", "messageDecoder", new GameMessageDecoder(release));
|
||||||
|
|
||||||
channel.pipeline().remove("loginDecoder");
|
channel.pipeline().remove("loginDecoder");
|
||||||
|
|||||||
Reference in New Issue
Block a user