mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 08:39:17 +00:00
Move Entity.EntityType to a separate file, remove WeakReferencing in DynamicGameObject.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
require 'java'
|
require 'java'
|
||||||
|
|
||||||
java_import 'org.apollo.game.model.Position'
|
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'
|
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.World;
|
||||||
import org.apollo.game.model.area.Region;
|
import org.apollo.game.model.area.Region;
|
||||||
import org.apollo.game.model.def.ObjectDefinition;
|
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.Player;
|
||||||
import org.apollo.game.model.entity.obj.GameObject;
|
import org.apollo.game.model.entity.obj.GameObject;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package org.apollo.game.message.impl;
|
package org.apollo.game.message.impl;
|
||||||
|
|
||||||
import org.apollo.game.message.Message;
|
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.
|
* 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.
|
* The type of the Mob.
|
||||||
*/
|
*/
|
||||||
private final Entity.EntityType type;
|
private final EntityType type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The index of the Mob.
|
* The index of the Mob.
|
||||||
@@ -32,7 +32,7 @@ public abstract class MagicOnMobMessage extends Message {
|
|||||||
* @param index The Mob index.
|
* @param index The Mob index.
|
||||||
* @param spellId The spell id.
|
* @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.type = type;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.spellId = spellId;
|
this.spellId = spellId;
|
||||||
@@ -43,7 +43,7 @@ public abstract class MagicOnMobMessage extends Message {
|
|||||||
*
|
*
|
||||||
* @return The Mob type.
|
* @return The Mob type.
|
||||||
*/
|
*/
|
||||||
public Entity.EntityType getType() {
|
public EntityType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.apollo.game.message.impl;
|
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}
|
* The magic on npc {@link MagicOnNpcMessage}
|
||||||
@@ -16,7 +16,7 @@ public final class MagicOnNpcMessage extends MagicOnMobMessage {
|
|||||||
* @param spellId The spell id used.
|
* @param spellId The spell id used.
|
||||||
*/
|
*/
|
||||||
public MagicOnNpcMessage(int index, int spellId) {
|
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;
|
package org.apollo.game.message.impl;
|
||||||
|
|
||||||
import org.apollo.game.model.entity.Entity;
|
import org.apollo.game.model.entity.EntityType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Player {@link MagicOnMobMessage}.
|
* The Player {@link MagicOnMobMessage}.
|
||||||
@@ -16,7 +16,7 @@ public final class MagicOnPlayerMessage extends MagicOnMobMessage {
|
|||||||
* @param spellId The spell id used.
|
* @param spellId The spell id used.
|
||||||
*/
|
*/
|
||||||
public MagicOnPlayerMessage(int index, int spellId) {
|
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.NpcDefinition;
|
||||||
import org.apollo.game.model.def.ObjectDefinition;
|
import org.apollo.game.model.def.ObjectDefinition;
|
||||||
import org.apollo.game.model.entity.Entity;
|
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.Npc;
|
||||||
import org.apollo.game.model.entity.Player;
|
import org.apollo.game.model.entity.Player;
|
||||||
import org.apollo.game.model.entity.obj.GameObject;
|
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.collision.CollisionMatrix;
|
||||||
import org.apollo.game.model.area.update.UpdateOperation;
|
import org.apollo.game.model.area.update.UpdateOperation;
|
||||||
import org.apollo.game.model.entity.Entity;
|
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 org.apollo.game.model.entity.obj.GameObject;
|
||||||
|
|
||||||
import com.google.common.base.MoreObjects;
|
import com.google.common.base.MoreObjects;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.apollo.game.model.area.collision;
|
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}.
|
* A type of flag in a {@link CollisionMatrix}.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.apollo.game.model.area.collision;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apollo.game.model.Direction;
|
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.MoreObjects;
|
||||||
import com.google.common.base.Preconditions;
|
import com.google.common.base.Preconditions;
|
||||||
|
|||||||
@@ -13,52 +13,6 @@ import org.apollo.game.model.area.update.UpdateOperation;
|
|||||||
*/
|
*/
|
||||||
public abstract class Entity {
|
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.
|
* The Position of this Entity.
|
||||||
*/
|
*/
|
||||||
@@ -84,16 +38,9 @@ public abstract class Entity {
|
|||||||
public abstract boolean equals(Object obj);
|
public abstract boolean equals(Object obj);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link EntityType} of this entity.
|
* Gets the {@link Position} of this Entity.
|
||||||
*
|
*
|
||||||
* @return The entity type.
|
* @return The Position.
|
||||||
*/
|
|
||||||
public abstract EntityType getEntityType();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the {@link Position} of this entity.
|
|
||||||
*
|
|
||||||
* @return The position.
|
|
||||||
*/
|
*/
|
||||||
public final Position getPosition() {
|
public final Position getPosition() {
|
||||||
return position;
|
return position;
|
||||||
@@ -108,6 +55,13 @@ public abstract class Entity {
|
|||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the {@link EntityType} of this Entity.
|
||||||
|
*
|
||||||
|
* @return The EntityType.
|
||||||
|
*/
|
||||||
|
public abstract EntityType getEntityType();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract int hashCode();
|
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.ArrayDeque;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apollo.game.message.Message;
|
import org.apollo.game.message.Message;
|
||||||
import org.apollo.game.message.impl.ConfigMessage;
|
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.AttributeMap;
|
||||||
import org.apollo.game.model.entity.attr.AttributePersistence;
|
import org.apollo.game.model.entity.attr.AttributePersistence;
|
||||||
import org.apollo.game.model.entity.attr.NumericalAttribute;
|
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.MembershipStatus;
|
||||||
import org.apollo.game.model.entity.setting.PrivacyState;
|
import org.apollo.game.model.entity.setting.PrivacyState;
|
||||||
import org.apollo.game.model.entity.setting.PrivilegeLevel;
|
import org.apollo.game.model.entity.setting.PrivilegeLevel;
|
||||||
@@ -62,7 +65,6 @@ public final class Player extends Mob {
|
|||||||
|
|
||||||
static {
|
static {
|
||||||
AttributeMap.define("run_energy", AttributeDefinition.forInt(100, AttributePersistence.PERSISTENT));
|
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.
|
* 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.
|
* 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.
|
* 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.
|
* 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.
|
* Indicates whether this player has the message filter enabled.
|
||||||
@@ -123,7 +125,7 @@ public final class Player extends Mob {
|
|||||||
/**
|
/**
|
||||||
* This player's interface set.
|
* 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.
|
* 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.
|
* 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.
|
* The MembershipStatus of this Player.
|
||||||
*/
|
*/
|
||||||
private transient MembershipStatus members = MembershipStatus.FREE;
|
private MembershipStatus members = MembershipStatus.FREE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This player's prayer icon.
|
* 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.
|
* 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.
|
* 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.
|
* 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}.
|
* 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.
|
* 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.
|
* The id of the world this player is in.
|
||||||
*/
|
*/
|
||||||
private transient int worldId = 1;
|
private int worldId = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the Player.
|
* Creates the Player.
|
||||||
@@ -237,6 +244,16 @@ public final class Player extends Mob {
|
|||||||
ignores.add(username.toLowerCase());
|
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.
|
* Decrements this player's viewing distance if it is greater than 1.
|
||||||
*/
|
*/
|
||||||
@@ -316,16 +333,6 @@ public final class Player extends Mob {
|
|||||||
return clicks;
|
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.
|
* Gets the player's credentials.
|
||||||
*
|
*
|
||||||
@@ -602,6 +609,8 @@ public final class Player extends Mob {
|
|||||||
if (world.submit(new LogoutEvent(this))) {
|
if (world.submit(new LogoutEvent(this))) {
|
||||||
send(new LogoutMessage());
|
send(new LogoutMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
localObjects.forEach(object -> object.removeFrom(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -649,6 +658,16 @@ public final class Player extends Mob {
|
|||||||
return ignores.remove(username.toLowerCase());
|
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.
|
* 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.
|
* @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 (getClientVersion() > 0) {
|
if (!filterable || !filteringMessages) {
|
||||||
send(new ServerChatMessage(message, filterable));
|
|
||||||
} else if (!filterable || !filteringMessages) {
|
|
||||||
send(new ServerChatMessage(message));
|
send(new ServerChatMessage(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -942,7 +959,8 @@ public final class Player extends Mob {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
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.
|
* Initialises the player's inventories.
|
||||||
*/
|
*/
|
||||||
private void initInventories() {
|
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 fullBankListener = new FullInventoryListener(this, FullInventoryListener.FULL_BANK_MESSAGE);
|
||||||
InventoryListener appearanceListener = new AppearanceInventoryListener(this);
|
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 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(syncInventoryListener);
|
||||||
inventory.addListener(fullInventoryListener);
|
inventory.addListener(fullInventoryListener);
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
package org.apollo.game.model.entity.obj;
|
package org.apollo.game.model.entity.obj;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apollo.game.model.Position;
|
import org.apollo.game.model.Position;
|
||||||
import org.apollo.game.model.World;
|
import org.apollo.game.model.World;
|
||||||
|
import org.apollo.game.model.entity.EntityType;
|
||||||
import org.apollo.game.model.entity.Player;
|
import org.apollo.game.model.entity.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,40 +15,6 @@ import org.apollo.game.model.entity.Player;
|
|||||||
*/
|
*/
|
||||||
public final class DynamicGameObject extends GameObject {
|
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.
|
* 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.
|
* 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.
|
* 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.
|
* @return {@code true} if this GameObject was not already visible to the specified Player.
|
||||||
*/
|
*/
|
||||||
public boolean addTo(Player player) {
|
public boolean addTo(Player player) {
|
||||||
WeakPlayerReference reference = new WeakPlayerReference(player);
|
return players.add(player);
|
||||||
return players.add(reference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -125,13 +90,12 @@ public final class DynamicGameObject extends GameObject {
|
|||||||
* @return {@code true} if this GameObject was visible to the specified Player.
|
* @return {@code true} if this GameObject was visible to the specified Player.
|
||||||
*/
|
*/
|
||||||
public boolean removeFrom(Player player) {
|
public boolean removeFrom(Player player) {
|
||||||
WeakPlayerReference reference = new WeakPlayerReference(player);
|
return players.remove(player);
|
||||||
return players.remove(reference);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean viewableBy(Player player, World world) {
|
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.World;
|
||||||
import org.apollo.game.model.area.RegionCoordinates;
|
import org.apollo.game.model.area.RegionCoordinates;
|
||||||
import org.apollo.game.model.area.RegionRepository;
|
import org.apollo.game.model.area.RegionRepository;
|
||||||
|
import org.apollo.game.model.entity.EntityType;
|
||||||
import org.apollo.game.model.entity.Player;
|
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.Position;
|
||||||
import org.apollo.game.model.area.Region;
|
import org.apollo.game.model.area.Region;
|
||||||
import org.apollo.game.model.area.RegionRepository;
|
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;
|
import com.google.common.base.Preconditions;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user