mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Move Entity.EntityType to a separate file, remove WeakReferencing in DynamicGameObject.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.game.model.Position'
|
||||
java_import 'org.apollo.game.model.entity.Entity$EntityType'
|
||||
java_import 'org.apollo.game.model.entity.EntityType'
|
||||
java_import 'org.apollo.game.model.entity.Player'
|
||||
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.area.Region;
|
||||
import org.apollo.game.model.def.ObjectDefinition;
|
||||
import org.apollo.game.model.entity.Entity.EntityType;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
import org.apollo.game.model.entity.Player;
|
||||
import org.apollo.game.model.entity.obj.GameObject;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.apollo.game.message.impl;
|
||||
|
||||
import org.apollo.game.message.Message;
|
||||
import org.apollo.game.model.entity.Entity;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
|
||||
/**
|
||||
* A {@link Message} sent by the client when a Player uses a magic spell on a Mob.
|
||||
@@ -13,7 +13,7 @@ public abstract class MagicOnMobMessage extends Message {
|
||||
/**
|
||||
* The type of the Mob.
|
||||
*/
|
||||
private final Entity.EntityType type;
|
||||
private final EntityType type;
|
||||
|
||||
/**
|
||||
* The index of the Mob.
|
||||
@@ -32,7 +32,7 @@ public abstract class MagicOnMobMessage extends Message {
|
||||
* @param index The Mob index.
|
||||
* @param spellId The spell id.
|
||||
*/
|
||||
public MagicOnMobMessage(Entity.EntityType type, int index, int spellId) {
|
||||
public MagicOnMobMessage(EntityType type, int index, int spellId) {
|
||||
this.type = type;
|
||||
this.index = index;
|
||||
this.spellId = spellId;
|
||||
@@ -43,7 +43,7 @@ public abstract class MagicOnMobMessage extends Message {
|
||||
*
|
||||
* @return The Mob type.
|
||||
*/
|
||||
public Entity.EntityType getType() {
|
||||
public EntityType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.apollo.game.message.impl;
|
||||
|
||||
import org.apollo.game.model.entity.Entity;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
|
||||
/**
|
||||
* The magic on npc {@link MagicOnNpcMessage}
|
||||
@@ -16,7 +16,7 @@ public final class MagicOnNpcMessage extends MagicOnMobMessage {
|
||||
* @param spellId The spell id used.
|
||||
*/
|
||||
public MagicOnNpcMessage(int index, int spellId) {
|
||||
super(Entity.EntityType.NPC, index, spellId);
|
||||
super(EntityType.NPC, index, spellId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.apollo.game.message.impl;
|
||||
|
||||
import org.apollo.game.model.entity.Entity;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
|
||||
/**
|
||||
* The Player {@link MagicOnMobMessage}.
|
||||
@@ -16,7 +16,7 @@ public final class MagicOnPlayerMessage extends MagicOnMobMessage {
|
||||
* @param spellId The spell id used.
|
||||
*/
|
||||
public MagicOnPlayerMessage(int index, int spellId) {
|
||||
super(Entity.EntityType.PLAYER, index, spellId);
|
||||
super(EntityType.PLAYER, index, spellId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import org.apollo.game.model.def.ItemDefinition;
|
||||
import org.apollo.game.model.def.NpcDefinition;
|
||||
import org.apollo.game.model.def.ObjectDefinition;
|
||||
import org.apollo.game.model.entity.Entity;
|
||||
import org.apollo.game.model.entity.Entity.EntityType;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
import org.apollo.game.model.entity.Npc;
|
||||
import org.apollo.game.model.entity.Player;
|
||||
import org.apollo.game.model.entity.obj.GameObject;
|
||||
|
||||
@@ -16,7 +16,7 @@ import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.area.collision.CollisionMatrix;
|
||||
import org.apollo.game.model.area.update.UpdateOperation;
|
||||
import org.apollo.game.model.entity.Entity;
|
||||
import org.apollo.game.model.entity.Entity.EntityType;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
import org.apollo.game.model.entity.obj.GameObject;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.apollo.game.model.area.collision;
|
||||
|
||||
import org.apollo.game.model.entity.Entity.EntityType;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
|
||||
/**
|
||||
* A type of flag in a {@link CollisionMatrix}.
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.apollo.game.model.area.collision;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apollo.game.model.Direction;
|
||||
import org.apollo.game.model.entity.Entity.EntityType;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
@@ -13,52 +13,6 @@ import org.apollo.game.model.area.update.UpdateOperation;
|
||||
*/
|
||||
public abstract class Entity {
|
||||
|
||||
/**
|
||||
* Represents a type of {@link Entity}.
|
||||
*/
|
||||
public enum EntityType {
|
||||
|
||||
/**
|
||||
* A GameObject that is loaded dynamically, usually for specific Players.
|
||||
*/
|
||||
DYNAMIC_OBJECT,
|
||||
|
||||
/**
|
||||
* An Item that is positioned on the ground.
|
||||
*/
|
||||
GROUND_ITEM,
|
||||
|
||||
/**
|
||||
* An Npc.
|
||||
*/
|
||||
NPC,
|
||||
|
||||
/**
|
||||
* A Player.
|
||||
*/
|
||||
PLAYER,
|
||||
|
||||
/**
|
||||
* A projectile (e.g. an arrow).
|
||||
*/
|
||||
PROJECTILE,
|
||||
|
||||
/**
|
||||
* A GameObject that is loaded statically (i.e. from the game resources) at start-up.
|
||||
*/
|
||||
STATIC_OBJECT;
|
||||
|
||||
/**
|
||||
* Returns whether or not this EntityType is for a Mob.
|
||||
*
|
||||
* @return {@code true} if this EntityType is for a Mob, otherwise {@code false}.
|
||||
*/
|
||||
public boolean isMob() {
|
||||
return this == PLAYER || this == NPC;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The Position of this Entity.
|
||||
*/
|
||||
@@ -84,16 +38,9 @@ public abstract class Entity {
|
||||
public abstract boolean equals(Object obj);
|
||||
|
||||
/**
|
||||
* Gets the {@link EntityType} of this entity.
|
||||
* Gets the {@link Position} of this Entity.
|
||||
*
|
||||
* @return The entity type.
|
||||
*/
|
||||
public abstract EntityType getEntityType();
|
||||
|
||||
/**
|
||||
* Gets the {@link Position} of this entity.
|
||||
*
|
||||
* @return The position.
|
||||
* @return The Position.
|
||||
*/
|
||||
public final Position getPosition() {
|
||||
return position;
|
||||
@@ -108,6 +55,13 @@ public abstract class Entity {
|
||||
return world;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link EntityType} of this Entity.
|
||||
*
|
||||
* @return The EntityType.
|
||||
*/
|
||||
public abstract EntityType getEntityType();
|
||||
|
||||
@Override
|
||||
public abstract int hashCode();
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.apollo.game.model.entity;
|
||||
|
||||
/**
|
||||
* Represents a type of {@link Entity}.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
public enum EntityType {
|
||||
|
||||
/**
|
||||
* A GameObject that is loaded dynamically, usually for specific Players.
|
||||
*/
|
||||
DYNAMIC_OBJECT,
|
||||
|
||||
/**
|
||||
* An Item that is positioned on the ground.
|
||||
*/
|
||||
GROUND_ITEM,
|
||||
|
||||
/**
|
||||
* An Npc.
|
||||
*/
|
||||
NPC,
|
||||
|
||||
/**
|
||||
* A Player.
|
||||
*/
|
||||
PLAYER,
|
||||
|
||||
/**
|
||||
* A projectile (e.g. an arrow).
|
||||
*/
|
||||
PROJECTILE,
|
||||
|
||||
/**
|
||||
* A GameObject that is loaded statically (i.e. from the game resources) at start-up.
|
||||
*/
|
||||
STATIC_OBJECT;
|
||||
|
||||
/**
|
||||
* Returns whether or not this EntityType is for a Mob.
|
||||
*
|
||||
* @return {@code true} if this EntityType is for a Mob, otherwise {@code false}.
|
||||
*/
|
||||
public boolean isMob() {
|
||||
return this == PLAYER || this == NPC;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,9 @@ package org.apollo.game.model.entity;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apollo.game.message.Message;
|
||||
import org.apollo.game.message.impl.ConfigMessage;
|
||||
@@ -23,6 +25,7 @@ import org.apollo.game.model.entity.attr.AttributeDefinition;
|
||||
import org.apollo.game.model.entity.attr.AttributeMap;
|
||||
import org.apollo.game.model.entity.attr.AttributePersistence;
|
||||
import org.apollo.game.model.entity.attr.NumericalAttribute;
|
||||
import org.apollo.game.model.entity.obj.DynamicGameObject;
|
||||
import org.apollo.game.model.entity.setting.MembershipStatus;
|
||||
import org.apollo.game.model.entity.setting.PrivacyState;
|
||||
import org.apollo.game.model.entity.setting.PrivilegeLevel;
|
||||
@@ -62,7 +65,6 @@ public final class Player extends Mob {
|
||||
|
||||
static {
|
||||
AttributeMap.define("run_energy", AttributeDefinition.forInt(100, AttributePersistence.PERSISTENT));
|
||||
AttributeMap.define("client_version", AttributeDefinition.forInt(0, AttributePersistence.TRANSIENT));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +85,7 @@ public final class Player extends Mob {
|
||||
/**
|
||||
* A deque of this player's mouse clicks.
|
||||
*/
|
||||
private transient Deque<Point> clicks = new ArrayDeque<>();
|
||||
private Deque<Point> clicks = new ArrayDeque<>();
|
||||
|
||||
/**
|
||||
* This player's credentials.
|
||||
@@ -93,12 +95,12 @@ public final class Player extends Mob {
|
||||
/**
|
||||
* A flag which indicates there are npcs that couldn't be added.
|
||||
*/
|
||||
private transient boolean excessiveNpcs = false;
|
||||
private boolean excessiveNpcs = false;
|
||||
|
||||
/**
|
||||
* A flag which indicates there are players that couldn't be added.
|
||||
*/
|
||||
private transient boolean excessivePlayers = false;
|
||||
private boolean excessivePlayers = false;
|
||||
|
||||
/**
|
||||
* Indicates whether this player has the message filter enabled.
|
||||
@@ -123,7 +125,7 @@ public final class Player extends Mob {
|
||||
/**
|
||||
* This player's interface set.
|
||||
*/
|
||||
private final transient InterfaceSet interfaceSet = new InterfaceSet(this);
|
||||
private final InterfaceSet interfaceSet = new InterfaceSet(this);
|
||||
|
||||
/**
|
||||
* Whether or not the player is skulled.
|
||||
@@ -133,12 +135,17 @@ public final class Player extends Mob {
|
||||
/**
|
||||
* The centre of the last region the client has loaded.
|
||||
*/
|
||||
private transient Position lastKnownRegion;
|
||||
private Position lastKnownRegion;
|
||||
|
||||
/**
|
||||
* The Set of DynamicGameObjects that are visible to this Player.
|
||||
*/
|
||||
private final Set<DynamicGameObject> localObjects = new HashSet<>();
|
||||
|
||||
/**
|
||||
* The MembershipStatus of this Player.
|
||||
*/
|
||||
private transient MembershipStatus members = MembershipStatus.FREE;
|
||||
private MembershipStatus members = MembershipStatus.FREE;
|
||||
|
||||
/**
|
||||
* This player's prayer icon.
|
||||
@@ -153,12 +160,12 @@ public final class Player extends Mob {
|
||||
/**
|
||||
* A temporary queue of messages sent during the login process.
|
||||
*/
|
||||
private final transient Deque<Message> queuedMessages = new ArrayDeque<>();
|
||||
private final Deque<Message> queuedMessages = new ArrayDeque<>();
|
||||
|
||||
/**
|
||||
* A flag indicating if the region changed in the last cycle.
|
||||
*/
|
||||
private transient boolean regionChanged = false;
|
||||
private boolean regionChanged = false;
|
||||
|
||||
/**
|
||||
* A flag indicating if this player is running.
|
||||
@@ -173,7 +180,7 @@ public final class Player extends Mob {
|
||||
/**
|
||||
* The {@link GameSession} currently attached to this {@link Player}.
|
||||
*/
|
||||
private transient GameSession session;
|
||||
private GameSession session;
|
||||
|
||||
/**
|
||||
* The privacy state of this player's trade chat.
|
||||
@@ -193,7 +200,7 @@ public final class Player extends Mob {
|
||||
/**
|
||||
* The id of the world this player is in.
|
||||
*/
|
||||
private transient int worldId = 1;
|
||||
private int worldId = 1;
|
||||
|
||||
/**
|
||||
* Creates the Player.
|
||||
@@ -237,6 +244,16 @@ public final class Player extends Mob {
|
||||
ignores.add(username.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified {@link DynamicGameObject} to this Player's {@link Set} of visible objects.
|
||||
*
|
||||
* @param object The DynamicGameObject.
|
||||
*/
|
||||
public void addObject(DynamicGameObject object) {
|
||||
localObjects.add(object);
|
||||
object.addTo(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrements this player's viewing distance if it is greater than 1.
|
||||
*/
|
||||
@@ -316,16 +333,6 @@ public final class Player extends Mob {
|
||||
return clicks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value denoting the clients modified version (0 if it is an unmodified jagex client).
|
||||
*
|
||||
* @return The version.
|
||||
*/
|
||||
public int getClientVersion() {
|
||||
Attribute<Integer> version = attributes.get("client_version");
|
||||
return version.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player's credentials.
|
||||
*
|
||||
@@ -602,6 +609,8 @@ public final class Player extends Mob {
|
||||
if (world.submit(new LogoutEvent(this))) {
|
||||
send(new LogoutMessage());
|
||||
}
|
||||
|
||||
localObjects.forEach(object -> object.removeFrom(this));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -649,6 +658,16 @@ public final class Player extends Mob {
|
||||
return ignores.remove(username.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the specified {@link DynamicGameObject} from this Player's {@link Set} of visible objects.
|
||||
*
|
||||
* @param object The DynamicGameObject.
|
||||
*/
|
||||
public void removeObject(DynamicGameObject object) {
|
||||
localObjects.remove(object);
|
||||
object.removeFrom(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the excessive players flag.
|
||||
*/
|
||||
@@ -718,9 +737,7 @@ public final class Player extends Mob {
|
||||
* @param filterable Whether or not the message can be filtered.
|
||||
*/
|
||||
public void sendMessage(String message, boolean filterable) {
|
||||
if (getClientVersion() > 0) {
|
||||
send(new ServerChatMessage(message, filterable));
|
||||
} else if (!filterable || !filteringMessages) {
|
||||
if (!filterable || !filteringMessages) {
|
||||
send(new ServerChatMessage(message));
|
||||
}
|
||||
}
|
||||
@@ -942,7 +959,8 @@ public final class Player extends Mob {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return MoreObjects.toStringHelper(this).add("username", getUsername()).add("privilege", privilegeLevel).add("client version", getClientVersion()).toString();
|
||||
return MoreObjects.toStringHelper(this).add("username", getUsername()).add("privilege", privilegeLevel)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -957,13 +975,16 @@ public final class Player extends Mob {
|
||||
* Initialises the player's inventories.
|
||||
*/
|
||||
private void initInventories() {
|
||||
InventoryListener fullInventoryListener = new FullInventoryListener(this, FullInventoryListener.FULL_INVENTORY_MESSAGE);
|
||||
InventoryListener fullInventoryListener = new FullInventoryListener(this,
|
||||
FullInventoryListener.FULL_INVENTORY_MESSAGE);
|
||||
InventoryListener fullBankListener = new FullInventoryListener(this, FullInventoryListener.FULL_BANK_MESSAGE);
|
||||
InventoryListener appearanceListener = new AppearanceInventoryListener(this);
|
||||
|
||||
InventoryListener syncInventoryListener = new SynchronizationInventoryListener(this, SynchronizationInventoryListener.INVENTORY_ID);
|
||||
InventoryListener syncInventoryListener = new SynchronizationInventoryListener(this,
|
||||
SynchronizationInventoryListener.INVENTORY_ID);
|
||||
InventoryListener syncBankListener = new SynchronizationInventoryListener(this, BankConstants.BANK_INVENTORY_ID);
|
||||
InventoryListener syncEquipmentListener = new SynchronizationInventoryListener(this, SynchronizationInventoryListener.EQUIPMENT_ID);
|
||||
InventoryListener syncEquipmentListener = new SynchronizationInventoryListener(this,
|
||||
SynchronizationInventoryListener.EQUIPMENT_ID);
|
||||
|
||||
inventory.addListener(syncInventoryListener);
|
||||
inventory.addListener(fullInventoryListener);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.apollo.game.model.entity.obj;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
import org.apollo.game.model.entity.Player;
|
||||
|
||||
/**
|
||||
@@ -15,40 +15,6 @@ import org.apollo.game.model.entity.Player;
|
||||
*/
|
||||
public final class DynamicGameObject extends GameObject {
|
||||
|
||||
/**
|
||||
* A {@link WeakReference} for {@link Player}s.
|
||||
*/
|
||||
private static final class WeakPlayerReference extends WeakReference<Player> {
|
||||
|
||||
/**
|
||||
* Creates the WeakPlayerReference.
|
||||
*
|
||||
* @param player The Player wrapped in this {@link WeakReference}.
|
||||
*/
|
||||
public WeakPlayerReference(Player player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof WeakPlayerReference) {
|
||||
WeakPlayerReference other = (WeakPlayerReference) obj; // TODO need to have a reference queue
|
||||
|
||||
Player player = get();
|
||||
return player != null && player.equals(other.get());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
Player player = get();
|
||||
return player == null ? 0 : player.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a DynamicGameObject that is visible only to {@link Player}s specified later.
|
||||
*
|
||||
@@ -85,7 +51,7 @@ public final class DynamicGameObject extends GameObject {
|
||||
/**
|
||||
* The Set of Players that can view this DynamicGameObject.
|
||||
*/
|
||||
private final Set<WeakPlayerReference> players = new HashSet<>();
|
||||
private final Set<Player> players = new HashSet<>();
|
||||
|
||||
/**
|
||||
* Creates the DynamicGameObject.
|
||||
@@ -109,8 +75,7 @@ public final class DynamicGameObject extends GameObject {
|
||||
* @return {@code true} if this GameObject was not already visible to the specified Player.
|
||||
*/
|
||||
public boolean addTo(Player player) {
|
||||
WeakPlayerReference reference = new WeakPlayerReference(player);
|
||||
return players.add(reference);
|
||||
return players.add(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,13 +90,12 @@ public final class DynamicGameObject extends GameObject {
|
||||
* @return {@code true} if this GameObject was visible to the specified Player.
|
||||
*/
|
||||
public boolean removeFrom(Player player) {
|
||||
WeakPlayerReference reference = new WeakPlayerReference(player);
|
||||
return players.remove(reference);
|
||||
return players.remove(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean viewableBy(Player player, World world) {
|
||||
return alwaysVisible || players.contains(new WeakPlayerReference(player));
|
||||
return alwaysVisible || players.contains(player);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.area.RegionCoordinates;
|
||||
import org.apollo.game.model.area.RegionRepository;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
import org.apollo.game.model.entity.Player;
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.apollo.game.model.Direction;
|
||||
import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.area.Region;
|
||||
import org.apollo.game.model.area.RegionRepository;
|
||||
import org.apollo.game.model.entity.Entity.EntityType;
|
||||
import org.apollo.game.model.entity.EntityType;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user