1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-06 07:32:46 +00:00

Event dispatcher changes and packet implementations

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-19 13:08:32 -03:00
parent 2c4af6d91d
commit 2d1181483a
77 changed files with 796 additions and 519 deletions

View File

@@ -25,10 +25,10 @@ import com.l2jserver.service.ServiceManager;
import com.l2jserver.service.cache.CacheService;
import com.l2jserver.service.configuration.ConfigurationService;
import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.game.SpawnService;
import com.l2jserver.service.game.chat.ChatService;
import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.game.template.TemplateService;
import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.id.WorldIDService;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.service.network.keygen.BlowfishKeygenService;
@@ -75,7 +75,7 @@ public class L2JGameServerMain {
.getInstance(NPCTemplateIDProvider.class);
final NPCIDProvider provider = injector
.getInstance(NPCIDProvider.class);
final WorldService world = injector.getInstance(WorldService.class);
final SpawnService spawnService = injector.getInstance(SpawnService.class);
final NPCTemplateID id = templateProvider.createID(12077);
final NPC npc = id.getTemplate().create();
@@ -84,6 +84,6 @@ public class L2JGameServerMain {
// close to char spawn
npc.setPoint(Point.fromXYZ(-71301, 258259, -3134));
world.add(npc);
spawnService.spawn(npc, null);
}
}

View File

@@ -256,7 +256,7 @@ public class Lineage2Connection {
* @return an {@link Set} containing all {@link ChannelFuture} instances.
*/
public Set<ChannelFuture> broadcast(ServerPacket packet) {
final Set<ChannelFuture> futures = CollectionFactory.newSet(null);
final Set<ChannelFuture> futures = CollectionFactory.newSet();
for (final L2Character character : worldService
.iterable(new CharacterBroadcastFilter(characterID.getObject()))) {
final Lineage2Connection conn = networkService.discover(character

View File

@@ -0,0 +1,129 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.game.net.packet.client;
import org.jboss.netty.buffer.ChannelBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.game.net.packet.server.ActionFailedPacket;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.id.object.ActorID;
import com.l2jserver.model.id.object.provider.ObjectIDResolver;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Completes the creation of an character. Creates the object, inserts into the
* database and notifies the client about the status of the operation.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterAttackRequestPacket extends AbstractClientPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x01;
/**
* The Logger
*/
private final Logger log = LoggerFactory.getLogger(this.getClass());
/**
* The {@link CharacterService}
*/
private final CharacterService charService;
/**
* The {@link ObjectID} resolver
*/
private final ObjectIDResolver idResolver;
/**
* The {@link ObjectID} being attacked
*/
private int objectId;
/**
* The position of the target
*/
@SuppressWarnings("unused")
private Coordinate origin;
/**
* The attack action type
*/
@SuppressWarnings("unused")
private CharacterAttackAction action;
public enum CharacterAttackAction {
/**
* Normal click
*/
CLICK(0),
/**
* Clicked with shift-click
*/
SHIFT_CLICK(1);
public final int id;
CharacterAttackAction(int id) {
this.id = id;
}
public static CharacterAttackAction fromID(int id) {
for (final CharacterAttackAction action : values())
if (action.id == id)
return action;
return null;
}
}
@Inject
public CharacterAttackRequestPacket(CharacterService charService,
ObjectIDResolver idResolver) {
this.charService = charService;
this.idResolver = idResolver;
}
@Override
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
this.objectId = buffer.readInt();
this.origin = Coordinate.fromXYZ(buffer.readInt(), buffer.readInt(),
buffer.readInt());
this.action = CharacterAttackAction.fromID(buffer.readByte());
}
@Override
public void process(final Lineage2Connection conn) {
final L2Character character = conn.getCharacter();
// since this is an erasure type, this is safe.
final ObjectID<Actor> id = idResolver.resolve(objectId);
if (!(id instanceof ActorID)) {
conn.write(ActionFailedPacket.SHARED_INSTANCE);
log.warn("Player {} is trying to attack {} which is not an actor",
character, id);
return;
}
final Actor actor = id.getObject();
charService.attack(character, actor);
}
}

View File

@@ -0,0 +1,50 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.game.net.packet.server;
import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
/**
* This packet responds to the Restart request
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ActionFailedPacket extends AbstractServerPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x1f;
/**
* The {@link ActionFailedPacket} shared instance
*/
public static final ActionFailedPacket SHARED_INSTANCE = new ActionFailedPacket();
/**
* Creates a new instance
*/
public ActionFailedPacket() {
super(OPCODE);
}
@Override
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
}
}

View File

@@ -21,7 +21,7 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.game.net.packet.server.CharacterCreateFailPacket.Reason;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.util.dimensional.Coordinate;
/**
@@ -40,22 +40,25 @@ public class ActorMovementPacket extends AbstractServerPacket {
/**
* The selected character
*/
private final L2Character character;
private final Actor actor;
/**
* The source coordinate
*/
private Coordinate source;
public ActorMovementPacket(L2Character character, Coordinate source) {
public ActorMovementPacket(Actor actor, Coordinate source) {
super(OPCODE);
this.character = character;
this.actor = actor;
this.source = source;
}
@Override
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
buffer.writeInt(character.getID().getID());
buffer.writeInt(actor.getID().getID());
buffer.writeInt(character.getPoint().getX());
buffer.writeInt(character.getPoint().getY());
buffer.writeInt(character.getPoint().getZ());
buffer.writeInt(actor.getPoint().getX());
buffer.writeInt(actor.getPoint().getY());
buffer.writeInt(actor.getPoint().getZ());
buffer.writeInt(source.getX());
buffer.writeInt(source.getY());

View File

@@ -29,7 +29,7 @@ import com.l2jserver.model.world.character.CharacterInventory.InventoryLocation;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class InventoryPacket extends AbstractServerPacket {
public class CharacterInventoryPacket extends AbstractServerPacket {
/**
* The packet OPCODE
*/
@@ -44,7 +44,7 @@ public class InventoryPacket extends AbstractServerPacket {
*/
private boolean showWindow = false;
public InventoryPacket(CharacterInventory inventory) {
public CharacterInventoryPacket(CharacterInventory inventory) {
super(OPCODE);
this.inventory = inventory;
}

View File

@@ -68,7 +68,7 @@ public class NPCInformationPacket extends AbstractServerPacket {
buffer.writeDouble(template.getMovementSpeedMultiplier());
buffer.writeDouble(template.getAttackSpeedMultiplier());
buffer.writeDouble(template.getCollisionRadius());
buffer.writeDouble(template.getCollisionHeigth());
buffer.writeDouble(template.getCollisionHeight());
buffer.writeInt(0x00); // right hand weapon
buffer.writeInt(0x00); // chest
buffer.writeInt(0x00); // left hand weapon
@@ -92,7 +92,7 @@ public class NPCInformationPacket extends AbstractServerPacket {
buffer.writeByte(0x00); // title color 0=client
buffer.writeDouble(template.getCollisionRadius());
buffer.writeDouble(template.getCollisionHeigth());
buffer.writeDouble(template.getCollisionHeight());
buffer.writeInt(0x00); // C4 - enchant effect
buffer.writeInt(0x00); // C6 -- is flying
buffer.writeInt(0x00); // unk

View File

@@ -58,7 +58,7 @@ public class ServerObjectPacket extends AbstractServerPacket {
buffer.writeDouble(template.getMovementSpeedMultiplier());
buffer.writeDouble(template.getAttackSpeedMultiplier());
buffer.writeDouble(template.getCollisionRadius()); // coll radius
buffer.writeDouble(template.getCollisionHeigth()); // coll height
buffer.writeDouble(template.getCollisionHeight()); // coll height
buffer.writeInt((template.isAttackable() ? npc.getHP() : 0x00));
buffer.writeInt((template.isAttackable() ? template.getMaxHP() : 0x00));
buffer.writeInt(0x01); // object type

View File

@@ -19,13 +19,16 @@ package com.l2jserver.model.template;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterAction;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.id.template.provider.ItemTemplateIDProvider;
import com.l2jserver.model.world.AbstractActor.Race;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.service.game.CharacterService;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.util.calculator.Calculator;
/**
* Template for {@link NPC}
@@ -33,22 +36,52 @@ import com.l2jserver.service.network.NetworkService;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class NPCTemplate extends ActorTemplate<NPC> {
/**
* The {@link NetworkService}
*/
@Inject
protected NetworkService networkService;
/**
* The {@link CharacterService}
*/
@Inject
protected CharacterService charService;
/**
* The {@link ItemTemplateID} provider
*/
@Inject
protected ItemTemplateIDProvider itemTemplateIdProvider;
/**
* The NPC name
*/
protected String name = null;
/**
* The NPC title
*/
protected String title = null;
/**
* The attackable state of the NPC
*/
protected boolean attackable = false;
/**
* The movement speed multiplier
*/
protected double movementSpeedMultiplier = 1.0;
/**
* The attack speed multiplier
*/
protected double attackSpeedMultiplier = 1.0;
/**
* The collision radius
*/
protected double collisionRadius = 0;
protected double collisionHeigth = 0;
/**
* The collision height
*/
protected double collisionHeight = 0;
protected int maxHp;
@@ -70,10 +103,23 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> {
.getID());
if (conn == null)
return;
System.out.println(action);
charService.target(character, npc);
}
/**
* Receives an attack from an {@link Actor}
*
* @param npc
* the {@link NPC} being attacked
* @param calculator
* the calculator
* @param attacker
* the attacker actor
*/
public void receiveAttack(NPC npc, Calculator calculator, Actor attacker) {
// TODO add attributes to calculator!
}
@Override
public NPC createInstance() {
return new NPC(this.getID());
@@ -122,10 +168,10 @@ public abstract class NPCTemplate extends ActorTemplate<NPC> {
}
/**
* @return the collisionHeigth
* @return the collisionHeight
*/
public double getCollisionHeigth() {
return collisionHeigth;
public double getCollisionHeight() {
return collisionHeight;
}
/**

View File

@@ -26,8 +26,8 @@ import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
import com.l2jserver.util.calculator.Calculator;
import com.l2jserver.util.calculator.DivisionFunction;
import com.l2jserver.util.calculator.MultiplicationFunction;
import com.l2jserver.util.calculator.Function;
import com.l2jserver.util.calculator.MultiplicationFunction;
import com.l2jserver.util.calculator.SetFunction;
import com.l2jserver.util.calculator.SubtractFunction;
import com.l2jserver.util.calculator.SumFunction;
@@ -152,7 +152,7 @@ public abstract class WeaponTemplate extends ItemTemplate implements Attackable
*/
public class WeaponAttribute {
private final Map<WeaponAttributeType, Map<Integer, Function<Double>>> operations = CollectionFactory
.newMap(null, null);
.newMap();
/**
* Sets the result of an calculator
@@ -248,7 +248,7 @@ public abstract class WeaponTemplate extends ItemTemplate implements Attackable
private Map<Integer, Function<Double>> getMap(WeaponAttributeType type) {
Map<Integer, Function<Double>> map = operations.get(type);
if (map == null) {
map = CollectionFactory.newMap(null, null);
map = CollectionFactory.newMap();
operations.put(type, map);
}
return map;

View File

@@ -22,9 +22,6 @@ import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.ClanID;
import com.l2jserver.model.id.object.iterator.WorldObjectIterator;
import com.l2jserver.model.world.capability.Joinable;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.model.world.clan.ClanEvent;
import com.l2jserver.model.world.clan.ClanListener;
import com.l2jserver.model.world.clan.ClanMembers;
/**
@@ -32,8 +29,7 @@ import com.l2jserver.model.world.clan.ClanMembers;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Clan extends AbstractObject implements
Listenable<ClanListener, ClanEvent>, Joinable<L2Character> {
public class Clan extends AbstractObject implements Joinable<L2Character> {
/**
* Clan leader
*/

View File

@@ -20,14 +20,12 @@ import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.template.ItemTemplateID;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.capability.Dropable;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.model.world.capability.Playable;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.character.CharacterInventory.InventoryLocation;
import com.l2jserver.model.world.character.CharacterInventory.InventoryPaperdoll;
import com.l2jserver.model.world.item.ItemEvent;
import com.l2jserver.model.world.item.ItemListener;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
/**
* This class represents an {@link Item} in the Lineage II World. The item can
@@ -50,7 +48,7 @@ import com.l2jserver.util.dimensional.Coordinate;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Item extends AbstractObject implements Playable, Spawnable,
Listenable<ItemListener, ItemEvent>, Dropable {
Dropable {
/**
* The {@link ItemTemplate} ID
*/
@@ -177,4 +175,19 @@ public class Item extends AbstractObject implements Playable, Spawnable,
public void setOwnerID(CharacterID ownerID) {
this.ownerID = ownerID;
}
/*
* (non-Javadoc)
*
* @see com.l2jserver.model.world.capability.Pointable#getPoint()
*/
@Override
public Point getPoint() {
return null;
}
@Override
public void setPoint(Point point) {
}
}

View File

@@ -20,6 +20,8 @@ import com.l2jserver.game.net.packet.client.CharacterActionPacket.CharacterActio
import com.l2jserver.model.id.object.NPCID;
import com.l2jserver.model.id.template.NPCTemplateID;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.util.calculator.Calculator;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -47,6 +49,11 @@ public class NPC extends AbstractActor {
getTemplate().action(this, character, action);
}
public void receiveAttack(Calculator calculator, Actor attacker) {
// TODO add buffs to calculator!
getTemplate().receiveAttack(this, calculator, attacker);
}
/**
* @return the NPC template ID
*/

View File

@@ -23,9 +23,6 @@ import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.id.object.ClanID;
import com.l2jserver.model.id.object.iterator.WorldObjectIterator;
import com.l2jserver.model.world.capability.Joinable;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.model.world.party.PartyEvent;
import com.l2jserver.model.world.party.PartyListener;
import com.l2jserver.util.factory.CollectionFactory;
/**
@@ -33,13 +30,11 @@ import com.l2jserver.util.factory.CollectionFactory;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Party extends AbstractObject implements
Listenable<PartyListener, PartyEvent>, Joinable<L2Character> {
public class Party extends AbstractObject implements Joinable<L2Character> {
/**
* Active party members
*/
private final List<CharacterID> members = CollectionFactory
.newList(CharacterID.class);
private final List<CharacterID> members = CollectionFactory.newList();
@Override
public void join(L2Character member) {

View File

@@ -40,7 +40,7 @@ public class ActorSkillContainer implements Iterable<Skill> {
/**
* The learned skill list
*/
private List<Skill> skills = CollectionFactory.newList(Skill.class);
private List<Skill> skills = CollectionFactory.newList();
/**
* Creates a new instance

View File

@@ -16,14 +16,14 @@
*/
package com.l2jserver.model.world.actor.event;
import com.l2jserver.service.game.world.event.FilteredWorldListener;
import com.l2jserver.service.game.world.event.TypedWorldListener;
/**
* This listener will filter to only dispatch {@link ActorEvent} events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class ActorListener extends FilteredWorldListener<ActorEvent> {
public abstract class ActorListener extends TypedWorldListener<ActorEvent> {
public ActorListener() {
super(ActorEvent.class);
}

View File

@@ -0,0 +1,72 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.model.world.actor.event;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.util.dimensional.Point;
/**
* Event dispatcher once an actor has spawned in the world
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ActorSpawnEvent implements ActorEvent, SpawnEvent {
/**
* The spawned player
*/
private final Actor actor;
/**
* The spawning point
*/
private final Point point;
/**
* Creates a new instance
*
* @param actor
* the spawned actor
* @param point
* the spawn point
*/
public ActorSpawnEvent(Actor actor, Point point) {
this.actor = actor;
this.point = point;
}
@Override
public Spawnable getObject() {
return actor;
}
@Override
public Actor getActor() {
return actor;
}
@Override
public Point getPoint() {
return point;
}
@Override
public ObjectID<?>[] getDispatchableObjects() {
return new ObjectID<?>[] { actor.getID() };
}
}

View File

@@ -20,8 +20,6 @@ import com.l2jserver.model.id.object.ActorID;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.model.world.actor.ActorEffects;
import com.l2jserver.model.world.actor.ActorSkillContainer;
import com.l2jserver.model.world.actor.event.ActorEvent;
import com.l2jserver.model.world.actor.event.ActorListener;
/**
* Defines an {@link AbstractObject} that defines an Actor (NPC, player, pet,
@@ -29,9 +27,8 @@ import com.l2jserver.model.world.actor.event.ActorListener;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Actor extends Listenable<ActorListener, ActorEvent>,
Spawnable, Pointable, Damagable, Attackable, Attacker, Castable,
Caster, Levelable, Killable, Equiper, Equipable {
public interface Actor extends Spawnable, Pointable, Damagable, Attackable,
Attacker, Castable, Caster, Levelable, Killable, Equiper, Equipable {
/**
* @return the actor effects
*/

View File

@@ -24,7 +24,7 @@ import com.l2jserver.util.dimensional.Coordinate;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Spawnable extends ObjectCapability, Positionable {
public interface Spawnable extends ObjectCapability, Positionable, Pointable {
void spawn(Coordinate coordinate);
boolean isSpawned();

View File

@@ -40,7 +40,7 @@ public class CharacterFriendList implements Iterable<L2Character> {
* The list of friends of this character
*/
private final Set<CharacterID> friends = CollectionFactory
.newSet(CharacterID.class);
.newSet();
/**
* Creates a new instance

View File

@@ -38,7 +38,7 @@ public class CharacterInventory implements Iterable<Item> {
/**
* The items in this character inventory
*/
private final Set<Item> items = CollectionFactory.newSet(Item.class);
private final Set<Item> items = CollectionFactory.newSet();
/**
* Creates a new instance

View File

@@ -37,8 +37,7 @@ public class CharacterShortcutContainer implements Iterable<Shortcut> {
/**
* The shortcut list
*/
private List<Shortcut> shortcuts = CollectionFactory
.newList(Shortcut.class);
private List<Shortcut> shortcuts = CollectionFactory.newList();
/**
* Creates a new instance

View File

@@ -18,11 +18,11 @@ package com.l2jserver.model.world.character.event;
import java.util.Date;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Listenable;
/**
* Event triggered once a character logs-in.
@@ -90,7 +90,7 @@ public class CharacterEnterWorldEvent implements CharacterEvent {
}
@Override
public Listenable<?, ?>[] getDispatchableObjects() {
return new Listenable<?, ?>[] { character };
public ObjectID<?>[] getDispatchableObjects() {
return new ObjectID<?>[] { character.getID() };
}
}

View File

@@ -18,11 +18,11 @@ package com.l2jserver.model.world.character.event;
import java.util.Date;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Listenable;
/**
* Event triggered once a character logs-out.
@@ -90,7 +90,7 @@ public class CharacterLeaveWorldEvent implements CharacterEvent {
}
@Override
public Listenable<?, ?>[] getDispatchableObjects() {
return new Listenable<?, ?>[] { character };
public ObjectID<?>[] getDispatchableObjects() {
return new ObjectID<?>[] { character.getID() };
}
}

View File

@@ -16,7 +16,7 @@
*/
package com.l2jserver.model.world.character.event;
import com.l2jserver.service.game.world.event.FilteredWorldListener;
import com.l2jserver.service.game.world.event.TypedWorldListener;
/**
* This listener will filter to only dispatch {@link CharacterEvent} events.
@@ -24,7 +24,7 @@ import com.l2jserver.service.game.world.event.FilteredWorldListener;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class CharacterListener extends
FilteredWorldListener<CharacterEvent> {
TypedWorldListener<CharacterEvent> {
public CharacterListener() {
super(CharacterEvent.class);
}

View File

@@ -16,11 +16,11 @@
*/
package com.l2jserver.model.world.character.event;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.util.dimensional.Point;
/**
@@ -79,7 +79,7 @@ public class CharacterMoveEvent implements CharacterEvent {
}
@Override
public Listenable<?, ?>[] getDispatchableObjects() {
return new Listenable<?, ?>[] { character };
public ObjectID<?>[] getDispatchableObjects() {
return new ObjectID<?>[] { character.getID() };
}
}

View File

@@ -16,11 +16,11 @@
*/
package com.l2jserver.model.world.character.event;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.util.dimensional.Point;
/**
@@ -79,7 +79,7 @@ public class CharacterStopMoveEvent implements CharacterEvent {
}
@Override
public Listenable<?, ?>[] getDispatchableObjects() {
return new Listenable<?, ?>[] { character };
public ObjectID<?>[] getDispatchableObjects() {
return new ObjectID<?>[] { character.getID() };
}
}

View File

@@ -16,11 +16,11 @@
*/
package com.l2jserver.model.world.character.event;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Listenable;
/**
* Event triggered once a character moves
@@ -78,7 +78,7 @@ public class CharacterTargetDeselectedEvent implements CharacterEvent {
}
@Override
public Listenable<?, ?>[] getDispatchableObjects() {
return new Listenable<?, ?>[] { character };
public ObjectID<?>[] getDispatchableObjects() {
return new ObjectID<?>[] { character.getID() };
}
}

View File

@@ -16,11 +16,11 @@
*/
package com.l2jserver.model.world.character.event;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Listenable;
/**
* Event triggered once a character moves
@@ -79,7 +79,7 @@ public class CharacterTargetSelectedEvent implements CharacterEvent {
}
@Override
public Listenable<?, ?>[] getDispatchableObjects() {
return new Listenable<?, ?>[] { character };
public ObjectID<?>[] getDispatchableObjects() {
return new ObjectID<?>[] { character.getID() };
}
}

View File

@@ -16,14 +16,14 @@
*/
package com.l2jserver.model.world.clan;
import com.l2jserver.service.game.world.event.FilteredWorldListener;
import com.l2jserver.service.game.world.event.TypedWorldListener;
/**
* This listener will filter to only dispatch {@link ClanEvent} events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class ClanListener extends FilteredWorldListener<ClanEvent> {
public abstract class ClanListener extends TypedWorldListener<ClanEvent> {
public ClanListener() {
super(ClanEvent.class);
}

View File

@@ -39,8 +39,7 @@ public class ClanMembers implements Iterable<CharacterID> {
/**
* The list of active members
*/
private final Set<CharacterID> members = CollectionFactory
.newSet(CharacterID.class);
private final Set<CharacterID> members = CollectionFactory.newSet();
/**
* Creates a new instance

View File

@@ -18,7 +18,7 @@ package com.l2jserver.model.world.event;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.service.game.world.event.WorldEvent;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
/**
* Event for objects spawning
@@ -30,7 +30,7 @@ public interface SpawnEvent extends WorldEvent {
Spawnable getObject();
/**
* @return the spawning coordinate
* @return the spawning point
*/
Coordinate getCoordinate();
Point getPoint();
}

View File

@@ -16,11 +16,11 @@
*/
package com.l2jserver.model.world.item;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.Item;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.model.world.player.event.PlayerEvent;
/**
@@ -72,7 +72,7 @@ public class ItemDropEvent implements ItemEvent, PlayerEvent {
}
@Override
public Listenable<?, ?>[] getDispatchableObjects() {
return new Listenable<?, ?>[] { player, item };
public ObjectID<?>[] getDispatchableObjects() {
return new ObjectID<?>[] { item.getID() };
}
}

View File

@@ -16,14 +16,14 @@
*/
package com.l2jserver.model.world.item;
import com.l2jserver.service.game.world.event.FilteredWorldListener;
import com.l2jserver.service.game.world.event.TypedWorldListener;
/**
* This listener will filter to only dispatch {@link ItemEvent} events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class ItemListener extends FilteredWorldListener<ItemEvent> {
public abstract class ItemListener extends TypedWorldListener<ItemEvent> {
public ItemListener() {
super(ItemEvent.class);
}

View File

@@ -14,17 +14,16 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator.operation;
package com.l2jserver.model.world.npc.event;
public class SubtractOperation implements CalculatorOperation<Integer> {
private Integer value;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.game.world.event.WorldEvent;
public SubtractOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return value - this.value;
}
/**
* Base event for {@link NPC} instances
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface NPCEvent extends WorldEvent {
NPC getNPC();
}

View File

@@ -14,17 +14,17 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator.operation;
package com.l2jserver.model.world.npc.event;
public class SetOperation implements CalculatorOperation<Integer> {
private Integer value;
import com.l2jserver.service.game.world.event.TypedWorldListener;
public SetOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return this.value;
/**
* This listener will filter to only dispatch {@link NPCEvent} events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class NPCListener extends TypedWorldListener<NPCEvent> {
public NPCListener() {
super(NPCEvent.class);
}
}

View File

@@ -14,17 +14,30 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator.operation;
package com.l2jserver.model.world.npc.event;
public class MultiplyOperation implements CalculatorOperation<Integer> {
private Integer value;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.actor.event.ActorSpawnEvent;
import com.l2jserver.util.dimensional.Point;
public MultiplyOperation(Integer value) {
this.value = value;
/**
* Event dispatched once a {@link NPC} has spawned in the world.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class NPCSpawnEvent extends ActorSpawnEvent implements NPCEvent {
/**
* @param npc
* the npc
* @param point
* the spawn point
*/
public NPCSpawnEvent(NPC npc, Point point) {
super(npc, point);
}
@Override
public Integer calculate(Integer value) {
return value * this.value;
public NPC getNPC() {
return (NPC) super.getActor();
}
}

View File

@@ -16,14 +16,14 @@
*/
package com.l2jserver.model.world.player.event;
import com.l2jserver.service.game.world.event.FilteredWorldListener;
import com.l2jserver.service.game.world.event.TypedWorldListener;
/**
* This listener will filter to only dispatch {@link PlayerEvent} events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class PlayerListener extends FilteredWorldListener<PlayerEvent> {
public abstract class PlayerListener extends TypedWorldListener<PlayerEvent> {
public PlayerListener() {
super(PlayerEvent.class);
}

View File

@@ -17,62 +17,27 @@
package com.l2jserver.model.world.player.event;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.model.world.actor.event.ActorSpawnEvent;
import com.l2jserver.util.dimensional.Point;
/**
* Event dispatcher once an player has spawned in the world
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class PlayerSpawnEvent implements PlayerEvent, SpawnEvent {
public class PlayerSpawnEvent extends ActorSpawnEvent implements PlayerEvent {
/**
* The spawned player
* @param actor
* the player
* @param point
* the spawn point
*/
private final Player player;
/**
* The spawning coordinate
*/
private final Coordinate coordinate;
/**
* Creates a new instance
*
* @param player
* the spawned player
* @param coordinate
* the spawn coordinate
*/
public PlayerSpawnEvent(Player player, Coordinate coordinate) {
this.player = player;
this.coordinate = coordinate;
}
@Override
public Spawnable getObject() {
return player;
public PlayerSpawnEvent(Player player, Point point) {
super(player, point);
}
@Override
public Player getPlayer() {
return player;
}
@Override
public Coordinate getCoordinate() {
return coordinate;
}
@Override
public Actor getActor() {
return player;
}
@Override
public Listenable<?, ?>[] getDispatchableObjects() {
return new Listenable<?, ?>[] { player };
return (Player) getActor();
}
}

View File

@@ -17,7 +17,7 @@
package com.l2jserver.model.world.player.event;
import com.l2jserver.model.world.Player;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
/**
* Event dispatched once an player is teleported to another location
@@ -30,10 +30,10 @@ public class PlayerTeleportEvent extends PlayerSpawnEvent {
*
* @param player
* the teleported player
* @param coordinate
* the coordinate
* @param point
* the teleport point
*/
public PlayerTeleportEvent(Player player, Coordinate coordinate) {
super(player, coordinate);
public PlayerTeleportEvent(Player player, Point point) {
super(player, point);
}
}

View File

@@ -42,7 +42,7 @@ public class ServiceManager {
*/
private final Injector injector;
private final Set<Service> knownServices = CollectionFactory.newSet(null);
private final Set<Service> knownServices = CollectionFactory.newSet();
@Inject
public ServiceManager(Injector injector) {
@@ -124,7 +124,7 @@ public class ServiceManager {
private Set<Class<? extends Service>> createStopDependencies(
Set<Class<? extends Service>> depends, Service serviceClass) {
if (depends == null)
depends = CollectionFactory.newSet(null);
depends = CollectionFactory.newSet();
for (final Service service : knownServices) {
if (service.getDependencies() == null
|| service.getDependencies().length == 0)

View File

@@ -20,7 +20,6 @@ import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.WeakHashMap;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
@@ -33,7 +32,7 @@ import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.ServiceStopException;
/**
* Simple cache that stores invocation results in a {@link WeakHashMap}.
* Simple cache that stores invocation results in a EhCache {@link Cache}.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/

View File

@@ -39,6 +39,7 @@ import com.l2jserver.service.configuration.Configuration.ConfigurationName;
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertyGetter;
import com.l2jserver.service.configuration.Configuration.ConfigurationPropertySetter;
import com.l2jserver.service.logging.LoggingService;
import com.l2jserver.util.factory.CollectionFactory;
import com.l2jserver.util.transformer.Transformer;
import com.l2jserver.util.transformer.TransformerFactory;
@@ -64,7 +65,7 @@ public class ProxyConfigurationService extends AbstractService implements
/**
* The cache of configuration objects
*/
private Map<Class<?>, Object> cache = new WeakHashMap<Class<?>, Object>();
private Map<Class<?>, Object> cache = CollectionFactory.newWeakMap();
@Override
protected void doStart() throws ServiceStartException {
@@ -102,7 +103,7 @@ public class ProxyConfigurationService extends AbstractService implements
*/
private class ConfigInvocationHandler implements InvocationHandler {
private final Properties properties;
private Map<String, Object> cache = new WeakHashMap<String, Object>();
private Map<String, Object> cache = CollectionFactory.newWeakMap();
public ConfigInvocationHandler(Properties properties) {
this.properties = properties;

View File

@@ -318,7 +318,7 @@ public class MySQLDatabaseService extends AbstractService implements
final PreparedStatement st = conn.prepareStatement(query());
parametize(st);
st.execute();
final List<T> list = CollectionFactory.newList(null);
final List<T> list = CollectionFactory.newList();
final ResultSet rs = st.getResultSet();
while (rs.next()) {
list.add(mapper().map(rs));

View File

@@ -53,6 +53,16 @@ public interface CharacterService extends Service {
*/
void target(L2Character character, Actor actor);
/**
* Attacks with the given <tt>character</tt> the <tt>target</tt>
*
* @param character
* the character
* @param target
* the target
*/
void attack(L2Character character, Actor target);
/**
* Moves the given <tt>character</tt> to <tt>coordinate</tt>
*

View File

@@ -19,13 +19,14 @@ package com.l2jserver.service.game;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.client.CharacterChatMessagePacket.MessageDestination;
import com.l2jserver.game.net.packet.server.ActionFailedPacket;
import com.l2jserver.game.net.packet.server.ActorChatMessagePacket;
import com.l2jserver.game.net.packet.server.ActorMovementPacket;
import com.l2jserver.game.net.packet.server.CharacterInformationPacket;
import com.l2jserver.game.net.packet.server.CharacterInventoryPacket;
import com.l2jserver.game.net.packet.server.CharacterMovementTypePacket;
import com.l2jserver.game.net.packet.server.CharacterTargetSelectedPacket;
import com.l2jserver.game.net.packet.server.GameGuardQueryPacket;
import com.l2jserver.game.net.packet.server.InventoryPacket;
import com.l2jserver.game.net.packet.server.NPCInformationPacket;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.world.L2Character;
@@ -33,12 +34,15 @@ import com.l2jserver.model.world.L2Character.CharacterMoveType;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Positionable;
import com.l2jserver.model.world.character.event.CharacterEnterWorldEvent;
import com.l2jserver.model.world.character.event.CharacterEvent;
import com.l2jserver.model.world.character.event.CharacterLeaveWorldEvent;
import com.l2jserver.model.world.character.event.CharacterListener;
import com.l2jserver.model.world.character.event.CharacterMoveEvent;
import com.l2jserver.model.world.character.event.CharacterTargetDeselectedEvent;
import com.l2jserver.model.world.character.event.CharacterTargetSelectedEvent;
import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.game.ai.AIService;
@@ -46,7 +50,10 @@ import com.l2jserver.service.game.chat.ChatService;
import com.l2jserver.service.game.chat.channel.ChatChannel;
import com.l2jserver.service.game.chat.channel.ChatChannelListener;
import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.FilteredWorldListener;
import com.l2jserver.service.game.world.event.WorldEvent;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.game.world.event.WorldListener;
import com.l2jserver.service.game.world.filter.impl.KnownListFilter;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.util.dimensional.Coordinate;
@@ -117,6 +124,30 @@ public class CharacterServiceImpl extends AbstractService implements
}
};
// event broadcast listener
// this listener will be filtered so that only interesting events are
// dispatched, once a event arrives will be possible to check check if
// the given event will be broadcasted or not
final WorldListener broadcastListener = new FilteredWorldListener<Positionable>(
new KnownListFilter(character)) {
@Override
protected boolean dispatch(WorldEvent e, Positionable object) {
if (e instanceof NPCSpawnEvent) {
conn.write(new NPCInformationPacket((NPC) object));
} else if (e instanceof CharacterEnterWorldEvent) {
// conn.write(packet)
// TODO char broadcast
} else if (e instanceof CharacterMoveEvent) {
final CharacterMoveEvent evt = (CharacterMoveEvent) e;
conn.write(new ActorMovementPacket((L2Character) object,
evt.getPoint().getCoordinate()));
}
// keep listener alive
return true;
}
};
eventDispatcher.addListener(broadcastListener);
// leave world event
eventDispatcher.addListener(id, new CharacterListener() {
@Override
@@ -127,7 +158,11 @@ public class CharacterServiceImpl extends AbstractService implements
// remove chat listeners
chatService.getGlobalChannel().removeChatChannelListener(
globalChatListener);
// remove broadcast listener
eventDispatcher.removeListener(broadcastListener);
// we can kill this listener now
return false;
}
});
@@ -140,7 +175,7 @@ public class CharacterServiceImpl extends AbstractService implements
conn.write(new CharacterInformationPacket(character));
// TODO game guard enforcing
conn.write(new GameGuardQueryPacket());
conn.write(new InventoryPacket(character.getInventory()));
conn.write(new CharacterInventoryPacket(character.getInventory()));
// characters start in run mode
run(character);
@@ -159,7 +194,7 @@ public class CharacterServiceImpl extends AbstractService implements
eventDispatcher.dispatch(new CharacterEnterWorldEvent(character));
// spawn the player -- this will also dispatch a spawn event
spawnService.spawn(character);
spawnService.spawn(character, null);
}
@Override
@@ -205,6 +240,21 @@ public class CharacterServiceImpl extends AbstractService implements
}
}
@Override
public void attack(L2Character character, Actor target) {
final CharacterID id = character.getID();
final Lineage2Connection conn = networkService.discover(id);
// check if this Actor can be attacked
if (target instanceof NPC) {
final NPC npc = (NPC) target;
if (!npc.getTemplate().isAttackable()) {
conn.write(ActionFailedPacket.SHARED_INSTANCE);
return;
}
}
}
@Override
public void walk(L2Character character) {
final CharacterID id = character.getID();

View File

@@ -22,6 +22,7 @@ import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportEvent;
import com.l2jserver.service.Service;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
/**
* This service is responsible for spawning monsters, npcs and players.
@@ -37,8 +38,11 @@ public interface SpawnService extends Service {
*
* @param spawnable
* the spawnable object
* @param point
* the spawning point. If null, will try to use
* {@link Spawnable#getPoint()}.
*/
void spawn(Spawnable spawnable);
void spawn(Spawnable spawnable, Point point);
/**
* Teleports the object to the given <tt>point</tt>.

View File

@@ -16,13 +16,19 @@
*/
package com.l2jserver.service.game;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.server.CharacterTeleportPacket;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.NPC;
import com.l2jserver.model.world.Player;
import com.l2jserver.model.world.capability.Spawnable;
import com.l2jserver.model.world.event.SpawnEvent;
import com.l2jserver.model.world.npc.event.NPCSpawnEvent;
import com.l2jserver.model.world.player.event.PlayerTeleportEvent;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
@@ -30,6 +36,7 @@ import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.util.dimensional.Coordinate;
import com.l2jserver.util.dimensional.Point;
/**
* Default implementation for {@link SpawnService}
@@ -38,6 +45,15 @@ import com.l2jserver.util.dimensional.Coordinate;
*/
@Depends({ WorldService.class })
public class SpawnServiceImpl extends AbstractService implements SpawnService {
/**
* The logger
*/
private final Logger log = LoggerFactory.getLogger(this.getClass());
/**
* The {@link WorldService}
*/
private final WorldService worldService;
/**
* The {@link WorldService} event dispatcher
*/
@@ -48,15 +64,46 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
private final NetworkService networkService;
@Inject
public SpawnServiceImpl(WorldEventDispatcher eventDispatcher,
NetworkService networkService) {
public SpawnServiceImpl(WorldService worldService,
WorldEventDispatcher eventDispatcher, NetworkService networkService) {
this.worldService = worldService;
this.eventDispatcher = eventDispatcher;
this.networkService = networkService;
}
@Override
public void spawn(Spawnable spawnable) {
// TODO Auto-generated method stub
public void spawn(Spawnable spawnable, Point point) {
// sanitize
if (point == null)
// retrieving stored point
point = spawnable.getPoint();
if (point == null) {
// not point send and no point stored, aborting
log.warn("Trying to spawn {} to a null point", spawnable);
return;
}
// set the spawning point
spawnable.setPoint(point);
// register object in the world
if (!worldService.add(spawnable))
// object was already in world
return;
// create the SpawnEvent
SpawnEvent event = null;
if (spawnable instanceof NPC) {
final NPC npc = (NPC) spawnable;
event = new NPCSpawnEvent(npc, point);
} else if (spawnable instanceof L2Character) {
event = null;
}
if (event != null)
// dispatch spawn event
eventDispatcher.dispatch(event);
// TODO broadcast this object to players nearby
}
@Override
@@ -69,8 +116,9 @@ public class SpawnServiceImpl extends AbstractService implements SpawnService {
return;
conn.write(new CharacterTeleportPacket(conn.getCharacter()));
}
// dispatch events
eventDispatcher.dispatch(new PlayerTeleportEvent(player, coordinate));
// dispatch teleport event
eventDispatcher.dispatch(new PlayerTeleportEvent(player, coordinate
.toPoint()));
// TODO broadcast this player new position
}

View File

@@ -78,9 +78,9 @@ public class SimpleChatService extends AbstractService implements ChatService {
@Override
protected void doStart() throws ServiceStartException {
this.global = new GlobalChatChannelImpl();
this.privateChannels = CollectionFactory.newMap(null, null);
this.clanChannels = CollectionFactory.newMap(null, null);
this.regionChannels = CollectionFactory.newMap(null, null);
this.privateChannels = CollectionFactory.newMap();
this.clanChannels = CollectionFactory.newMap();
this.regionChannels = CollectionFactory.newMap();
}
@Override
@@ -137,7 +137,7 @@ public class SimpleChatService extends AbstractService implements ChatService {
* The list of all listeners on this channel
*/
protected final Set<ChatChannelListener> listeners = CollectionFactory
.newSet(null);
.newSet();
@Override
public void send(CharacterID sender, String message) {

View File

@@ -19,7 +19,6 @@ package com.l2jserver.service.game.scripting;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -60,7 +59,7 @@ public class ScriptingServiceImpl extends AbstractService implements
/**
* Collection of script contexts
*/
private final Set<ScriptContext> contexts = new HashSet<ScriptContext>();
private final Set<ScriptContext> contexts = CollectionFactory.newSet();
@Inject
public ScriptingServiceImpl(Injector injector) {
@@ -90,8 +89,7 @@ public class ScriptingServiceImpl extends AbstractService implements
final Unmarshaller u = c.createUnmarshaller();
final ScriptList list = (ScriptList) u.unmarshal(scriptDescriptor);
final List<ScriptContext> contexts = CollectionFactory
.newList(ScriptContext.class);
final List<ScriptContext> contexts = CollectionFactory.newList();
for (ScriptInfo si : list.getScriptInfos()) {
final ScriptContext context = createContext(si, null);

View File

@@ -18,7 +18,6 @@ package com.l2jserver.service.game.scripting.impl;
import java.io.File;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.io.FileUtils;
@@ -32,6 +31,7 @@ import com.l2jserver.service.game.scripting.ScriptCompiler;
import com.l2jserver.service.game.scripting.ScriptContext;
import com.l2jserver.service.game.scripting.classlistener.ClassListener;
import com.l2jserver.service.game.scripting.classlistener.DefaultClassListener;
import com.l2jserver.util.factory.CollectionFactory;
/**
* This class is actual implementation of {@link ScriptContext}
@@ -222,7 +222,7 @@ public class ScriptContextImpl implements ScriptContext {
public synchronized void addChildScriptContext(ScriptContext context) {
synchronized (this) {
if (childScriptContexts == null) {
childScriptContexts = new HashSet<ScriptContext>();
childScriptContexts = CollectionFactory.newSet();
}
if (childScriptContexts.contains(context)) {

View File

@@ -20,7 +20,6 @@ import java.io.File;
import java.io.IOException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -51,7 +50,7 @@ public class ClassFileManager extends
* This map contains classes compiled for this classloader
*/
private final Map<String, BinaryClass> compiledClasses = CollectionFactory
.newMap(String.class, BinaryClass.class);
.newMap();
/**
* Classloader that will be used to load compiled classes
@@ -204,7 +203,7 @@ public class ClassFileManager extends
if (StandardLocation.CLASS_PATH.equals(location)
&& kinds.contains(Kind.CLASS)) {
List<JavaFileObject> temp = new ArrayList<JavaFileObject>();
List<JavaFileObject> temp = CollectionFactory.newList();
for (JavaFileObject object : objects) {
temp.add(object);
}

View File

@@ -24,7 +24,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@@ -37,6 +36,7 @@ import org.slf4j.LoggerFactory;
import com.l2jserver.service.game.scripting.ScriptClassLoader;
import com.l2jserver.util.ClassUtils;
import com.l2jserver.util.factory.CollectionFactory;
/**
* This classloader is used to load script classes. <br>
@@ -71,7 +71,7 @@ public class ScriptClassLoaderImpl extends ScriptClassLoader {
* annotations, but they are needed by JavaCompiler to perform valid
* compilation
*/
private Set<String> libraryClasses = new HashSet<String>();
private Set<String> libraryClasses = CollectionFactory.newSet();
/**
* Creates new ScriptClassLoader with given ClassFileManger
@@ -215,7 +215,7 @@ public class ScriptClassLoaderImpl extends ScriptClassLoader {
*/
public Set<JavaFileObject> getClassesForPackage(String packageName)
throws IOException {
Set<JavaFileObject> result = new HashSet<JavaFileObject>();
Set<JavaFileObject> result = CollectionFactory.newSet();
// load parent
ClassLoader parent = getParent();

View File

@@ -18,7 +18,6 @@ package com.l2jserver.service.game.scripting.impl.javacc;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
@@ -34,6 +33,7 @@ import org.slf4j.LoggerFactory;
import com.l2jserver.service.game.scripting.CompilationResult;
import com.l2jserver.service.game.scripting.ScriptClassLoader;
import com.l2jserver.service.game.scripting.ScriptCompiler;
import com.l2jserver.util.factory.CollectionFactory;
/**
* Wrapper for JavaCompiler api
@@ -142,7 +142,7 @@ public class ScriptCompilerImpl implements ScriptCompiler {
"Amount of classes is not equal to amount of sources");
}
List<JavaFileObject> compilationUnits = new ArrayList<JavaFileObject>();
List<JavaFileObject> compilationUnits = CollectionFactory.newList();
for (int i = 0; i < classNames.length; i++) {
JavaFileObject compilationUnit = new JavaSourceFromString(
@@ -164,7 +164,7 @@ public class ScriptCompilerImpl implements ScriptCompiler {
*/
@Override
public CompilationResult compile(Iterable<File> compilationUnits) {
List<JavaFileObject> list = new ArrayList<JavaFileObject>();
List<JavaFileObject> list = CollectionFactory.newList();
for (File f : compilationUnits) {
list.add(new JavaSourceFromFile(f, JavaFileObject.Kind.SOURCE));

View File

@@ -43,8 +43,7 @@ public class ScriptTemplateService extends AbstractService implements
private ScriptContext context;
@SuppressWarnings("rawtypes")
private Map<TemplateID, Template> templates = CollectionFactory.newMap(
TemplateID.class, Template.class);
private Map<TemplateID, Template> templates = CollectionFactory.newMap();
@Inject
public ScriptTemplateService(ScriptingService scriptingService,

View File

@@ -21,6 +21,7 @@ import java.util.List;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Positionable;
import com.l2jserver.service.Service;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
@@ -69,6 +70,32 @@ public interface WorldService extends Service, Iterable<WorldObject> {
*/
<T extends WorldObject> T find(ObjectID<T> id) throws ClassCastException;
/**
* Executes an action inside the callback for each object in <tt>object</tt>
* known list.
*
* @param object
* the object
* @param callback
* the callback
*/
void knownlist(Positionable object, KnownListCallback callback);
/**
* The KnownList callback is used to execute an action for each object know
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface KnownListCallback {
/**
* Performs an action on the given known <tt>object</tt>
*
* @param object
* the object known by the other object
*/
void knownObject(WorldObject object);
}
/**
* Get the event dispatcher
*

View File

@@ -26,6 +26,7 @@ import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Positionable;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.AbstractService.Depends;
import com.l2jserver.service.ServiceStartException;
@@ -34,10 +35,12 @@ import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.game.scripting.ScriptingService;
import com.l2jserver.service.game.template.TemplateService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.game.world.event.WorldEventDispatcherImpl;
import com.l2jserver.service.game.world.filter.FilterIterator;
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
import com.l2jserver.service.game.world.filter.impl.IDFilter;
import com.l2jserver.service.game.world.filter.impl.InstanceFilter;
import com.l2jserver.service.game.world.filter.impl.KnownListFilter;
import com.l2jserver.service.logging.LoggingService;
import com.l2jserver.util.factory.CollectionFactory;
@@ -58,16 +61,15 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
/**
* The set of all objects registered in the world
*/
private final Set<WorldObject> objects = CollectionFactory
.newSet(WorldObject.class);
private final Set<WorldObject> objects = CollectionFactory.newSet();
/**
* The world event dispatcher
*/
private final WorldEventDispatcher dispatcher;
private final WorldEventDispatcherImpl dispatcher;
@Inject
public WorldServiceImpl(WorldEventDispatcher dispatcher) {
this.dispatcher = dispatcher;
this.dispatcher = (WorldEventDispatcherImpl) dispatcher;
}
@Override
@@ -84,6 +86,8 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
@Override
public boolean remove(WorldObject object) {
log.debug("Removing object {} from world", object);
// we also need to remove all listeners for this object
dispatcher.clear(object.getID());
return objects.remove(object);
}
@@ -103,6 +107,17 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
return null;
}
@Override
public void knownlist(Positionable object, KnownListCallback callback) {
if (object == null)
return;
if (callback == null)
return;
for (Positionable known : iterable(new KnownListFilter(object))) {
callback.knownObject(known);
}
}
@Override
public WorldEventDispatcher getEventDispatcher() {
return dispatcher;
@@ -111,7 +126,7 @@ public class WorldServiceImpl extends AbstractService implements WorldService {
@Override
public <T extends WorldObject> List<T> list(WorldObjectFilter<T> filter) {
log.debug("Listing objects with filter {}", filter);
final List<T> list = CollectionFactory.newList(null);
final List<T> list = CollectionFactory.newList();
for (final T object : this.iterable(filter)) {
list.add(object);
}

View File

@@ -16,28 +16,33 @@
*/
package com.l2jserver.service.game.world.event;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
/**
* This listener will filter to only dispatch an certain type events.
* This listener will filter to only dispatch events on which the object matches
* an given {@link WorldObjectFilter}.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class FilteredWorldListener<T> implements WorldListener {
private final Class<T> type;
public abstract class FilteredWorldListener<T extends WorldObject> implements
WorldListener {
private final WorldObjectFilter<T> filter;
public FilteredWorldListener(Class<T> type) {
this.type = type;
public FilteredWorldListener(WorldObjectFilter<T> filter) {
this.filter = filter;
}
@Override
@SuppressWarnings("unchecked")
public boolean dispatch(WorldEvent e) {
if (!type.isInstance(e))
if (!filter.accept((T) e.getObject()))
return false;
return dispatch((T) e);
return dispatch(e, (T) e.getObject());
}
/**
* @see WorldListener#dispatch(WorldEvent)
*/
protected abstract boolean dispatch(T e);
protected abstract boolean dispatch(WorldEvent e, T object);
}

View File

@@ -14,23 +14,30 @@
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.service.game.world.event.WorldEvent;
import com.l2jserver.service.game.world.event.WorldListener;
package com.l2jserver.service.game.world.event;
/**
* Defines an {@link AbstractObject} that can attach {@link WorldListener} that
* notifies of events on that object.
* This listener will filter to only dispatch an certain type events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
* @param <L>
* the listener type
* @param <E>
* the event type
*/
public interface Listenable<L extends WorldListener, E extends WorldEvent>
extends ObjectCapability {
public abstract class TypedWorldListener<T> implements WorldListener {
private final Class<T> type;
public TypedWorldListener(Class<T> type) {
this.type = type;
}
@Override
@SuppressWarnings("unchecked")
public boolean dispatch(WorldEvent e) {
if (!type.isInstance(e))
return false;
return dispatch((T) e);
}
/**
* @see WorldListener#dispatch(WorldEvent)
*/
protected abstract boolean dispatch(T e);
}

View File

@@ -16,8 +16,8 @@
*/
package com.l2jserver.service.game.world.event;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Listenable;
public interface WorldEvent {
/**
@@ -28,5 +28,5 @@ public interface WorldEvent {
/**
* @return the list of objects that will be notified of this event
*/
Listenable<?, ?>[] getDispatchableObjects();
ObjectID<?>[] getDispatchableObjects();
}

View File

@@ -17,7 +17,7 @@
package com.l2jserver.service.game.world.event;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.model.world.WorldObject;
/**
* This event dispatcher notify listeners that an certain event occured in their
@@ -39,73 +39,56 @@ public interface WorldEventDispatcher {
/**
* Adds a new global <tt>listener</tt>
*
* @param <E>
* the event type
* @param <L>
* the listener type
* @param listener
* the listener
*/
<E extends WorldEvent, L extends WorldListener> void addListener(
WorldListener listener);
void addListener(WorldListener listener);
/**
* Adds a new <tt>listener</tt> to <tt>object</tt>
*
* @param <E>
* the event type
* @param <L>
* the listener type
* @param object
* the object to listen to
* @param listener
* the listener
*/
<E extends WorldEvent, L extends WorldListener> void addListener(
Listenable<L, E> object, WorldListener listener);
void addListener(WorldObject object, WorldListener listener);
/**
* Adds a new <tt>listener</tt> to object with id <tt>id</tt>
*
* @param <E>
* the event type
* @param <L>
* the listener type
* @param id
* the object id to listen to
* @param listener
* the listener
*/
<E extends WorldEvent, L extends WorldListener> void addListener(
ObjectID<? extends Listenable<L, E>> id, WorldListener listener);
void addListener(ObjectID<?> id, WorldListener listener);
/**
* Removes an existing global <tt>listener</tt>
*
* @param listener
* the listener
*/
void removeListener(WorldListener listener);
/**
* Removes an existing <tt>listener</tt> from <tt>object</tt>
*
* @param <E>
* the event type
* @param <L>
* the listener type
* @param object
* the object to listen to
* @param listener
* the listener
*/
<E extends WorldEvent, L extends WorldListener> void removeListener(
Listenable<L, E> object, WorldListener listener);
void removeListener(WorldObject object, WorldListener listener);
/**
* Removes an existing <tt>listener</tt> from the object with id <tt>id</tt>
*
* @param <E>
* the event type
* @param <L>
* the listener type
* @param id
* the object id to listen to
* @param listener
* the listener
*/
<E extends WorldEvent, L extends WorldListener> void removeListener(
ObjectID<? extends Listenable<L, E>> id, WorldListener listener);
void removeListener(ObjectID<?> id, WorldListener listener);
}

View File

@@ -16,7 +16,9 @@
*/
package com.l2jserver.service.game.world.event;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
@@ -24,7 +26,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.world.capability.Listenable;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.util.factory.CollectionFactory;
/**
@@ -38,10 +40,12 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
private final Timer timer = new Timer();
private Queue<ListenerIDPair> listeners = CollectionFactory
.newConcurrentQueue(ListenerIDPair.class);
private Queue<WorldEvent> events = CollectionFactory
.newConcurrentQueue(WorldEvent.class);
private Set<WorldListener> globalListeners = CollectionFactory.newSet();
private Map<ObjectID<?>, Set<WorldListener>> listeners = CollectionFactory
.newMap();
// private Queue<ListenerIDPair> listeners = CollectionFactory
// .newConcurrentQueue(ListenerIDPair.class);
private Queue<WorldEvent> events = CollectionFactory.newConcurrentQueue();
public WorldEventDispatcherImpl() {
timer.scheduleAtFixedRate(new TimerTask() {
@@ -53,6 +57,7 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
try {
doDispatch(event);
} catch (Throwable t) {
log.warn("Exception in WorldEventDispatcher thread", t);
}
}
}, 0, 50);
@@ -66,22 +71,22 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
public void doDispatch(WorldEvent event) {
log.debug("Dispatching event {}", event);
final Listenable<?, ?>[] objects = event.getDispatchableObjects();
for (final ListenerIDPair pair : listeners) {
for (Listenable<?, ?> obj : objects) {
if (obj == null)
continue;
if (!pair.testDispatch(obj.getID()))
continue;
final ObjectID<?>[] objects = event.getDispatchableObjects();
for (ObjectID<?> obj : objects) {
if (obj == null)
continue;
final Set<WorldListener> listeners = getListeners(obj);
for (final WorldListener listener : listeners) {
try {
if (pair.dispatch(event))
continue;
if (!listener.dispatch(event))
// remove listener if return value is false
listeners.remove(listener);
} catch (ClassCastException e) {
log.debug(
"Exception in Listener. This might indicate an implementation issue in {}",
pair.listener.getClass());
listener.getClass());
listeners.remove(listener);
}
listeners.remove(pair);
}
}
}
@@ -89,96 +94,52 @@ public class WorldEventDispatcherImpl implements WorldEventDispatcher {
@Override
public void addListener(WorldListener listener) {
log.debug("Adding new listener global {}", listener);
listeners.add(new ListenerIDPair(null, listener));
globalListeners.add(listener);
}
@Override
public <E extends WorldEvent, L extends WorldListener> void addListener(
Listenable<L, E> object, WorldListener listener) {
log.debug("Adding new listener {} to {}", listener,
(object != null ? object.getID() : null));
listeners.add(new ListenerIDPair((object != null ? object.getID()
: null), listener));
public void addListener(WorldObject object, WorldListener listener) {
addListener(object.getID(), listener);
}
@Override
public <E extends WorldEvent, L extends WorldListener> void addListener(
ObjectID<? extends Listenable<L, E>> id, WorldListener listener) {
public void addListener(ObjectID<?> id, WorldListener listener) {
log.debug("Adding new listener {} to {}", listener, id);
listeners.add(new ListenerIDPair(id, listener));
getListeners(id).add(listener);
}
@Override
public <E extends WorldEvent, L extends WorldListener> void removeListener(
Listenable<L, E> object, WorldListener listener) {
log.debug("Removing new listener {} from {}", listener, object.getID());
listeners.remove(new ListenerIDPair(object.getID(), listener));
public void removeListener(WorldListener listener) {
globalListeners.remove(listener);
}
@Override
public <E extends WorldEvent, L extends WorldListener> void removeListener(
ObjectID<? extends Listenable<L, E>> id, WorldListener listener) {
public void removeListener(WorldObject object, WorldListener listener) {
removeListener(object.getID(), listener);
}
@Override
public void removeListener(ObjectID<?> id, WorldListener listener) {
log.debug("Removing new listener {} from {}", listener, id);
listeners.remove(new ListenerIDPair(id, listener));
getListeners(id).remove(listener);
}
private class ListenerIDPair {
private ObjectID<?> ID;
private WorldListener listener;
/**
* Removes all listeners from a given object
*
* @param id
* the object id
*/
public void clear(ObjectID<?> id) {
listeners.remove(id);
}
public ListenerIDPair(ObjectID<?> ID, WorldListener listener) {
super();
this.ID = ID;
this.listener = listener;
}
public boolean testDispatch(ObjectID<?> id) {
if (this.ID == null) // global listeners
return true;
return id.equals(this.ID);
}
public boolean dispatch(WorldEvent e) {
return listener.dispatch(e);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + getOuterType().hashCode();
result = prime * result + ((ID == null) ? 0 : ID.hashCode());
result = prime * result
+ ((listener == null) ? 0 : listener.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ListenerIDPair other = (ListenerIDPair) obj;
if (!getOuterType().equals(other.getOuterType()))
return false;
if (ID == null) {
if (other.ID != null)
return false;
} else if (!ID.equals(other.ID))
return false;
if (listener == null) {
if (other.listener != null)
return false;
} else if (!listener.equals(other.listener))
return false;
return true;
}
private WorldEventDispatcherImpl getOuterType() {
return WorldEventDispatcherImpl.this;
private Set<WorldListener> getListeners(ObjectID<?> id) {
Set<WorldListener> set = listeners.get(id);
if (set == null) {
set = CollectionFactory.newSet();
listeners.put(id, set);
}
return set;
}
}

View File

@@ -16,20 +16,22 @@
*/
package com.l2jserver.service.game.world.filter.impl;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.WorldObject;
import com.l2jserver.model.world.capability.Positionable;
import com.l2jserver.service.game.world.filter.AndFilter;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
* This filter will only accept {@link WorldObject} which are in vision of
* another object.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class KnownListFilter extends AndFilter<Positionable> {
public static final int KNOWNLIST_RANGE = 200;
@SuppressWarnings("unchecked")
public KnownListFilter(L2Character character) {
public KnownListFilter(Positionable object) {
super(new InstanceFilter<Positionable>(Positionable.class),
new RangeFilter(character.getPosition(), KNOWNLIST_RANGE));
new RangeFilter(object, KNOWNLIST_RANGE));
}
}

View File

@@ -18,7 +18,6 @@ package com.l2jserver.service.game.world.filter.impl;
import com.l2jserver.model.world.capability.Positionable;
import com.l2jserver.service.game.world.filter.WorldObjectFilter;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Filter objects that are in the <tt>range</tt> of <tt>coordinate</tt>
@@ -29,7 +28,7 @@ public class RangeFilter implements WorldObjectFilter<Positionable> {
/**
* The coordinate point
*/
private final Coordinate coordinate;
private final Positionable object;
/**
* The desired maximum distance of the object
*/
@@ -38,32 +37,20 @@ public class RangeFilter implements WorldObjectFilter<Positionable> {
/**
* Creates a new instance
*
* @param coordinate
* the coordinate as base for range search
* @param objcect
* the positionable object as center point for range search
* @param range
* the desired maximum distance of the object
*/
public RangeFilter(final Coordinate coordinate, final int range) {
this.coordinate = coordinate;
public RangeFilter(final Positionable object, final int range) {
this.object = object;
this.range = range;
}
/**
* Creates a new instance
*
* @param positionable
* the base object
* @param range
* the desired maximum distance of the object
*/
public RangeFilter(final Positionable positionable, final int range) {
this(positionable.getPosition(), range);
}
@Override
public boolean accept(Positionable other) {
if (other == null)
return false;
return other.getPosition().getDistance(coordinate) <= range;
return other.getPosition().getDistance(object.getPosition()) <= range;
}
}

View File

@@ -111,6 +111,8 @@ public class CachedWorldIDService extends AbstractService implements
@Override
public <I extends ObjectID<?>> void add(I id) {
if(id == null)
return;
cache.put(new Element(id.getID(), id));
}

View File

@@ -74,8 +74,7 @@ public class NettyNetworkService extends AbstractService implements
/**
* The client list. This list all active clients in the server
*/
private Set<Lineage2Connection> clients = CollectionFactory
.newSet(Lineage2Connection.class);
private Set<Lineage2Connection> clients = CollectionFactory.newSet();
@Inject
public NettyNetworkService(ConfigurationService configService,

View File

@@ -33,7 +33,7 @@ public class Calculator implements Function<Double> {
* List of operations in this calculator
*/
private final List<FunctionContainer> functions = CollectionFactory
.newList(null);
.newList();
/**
* Creates a new empty calculator. Functions can be add using

View File

@@ -16,10 +16,7 @@
*/
package com.l2jserver.util.factory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
@@ -27,6 +24,10 @@ import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import javolution.util.FastList;
import javolution.util.FastMap;
import javolution.util.FastSet;
/**
* Factory class to create {@link Collection} instances.
*
@@ -38,12 +39,10 @@ public class CollectionFactory {
*
* @param <T>
* the type
* @param type
* the type
* @return the created list
*/
public static final <T> List<T> newList(Class<T> type) {
return new ArrayList<T>();
public static final <T> List<T> newList() {
return new FastList<T>();
}
/**
@@ -55,8 +54,8 @@ public class CollectionFactory {
* the type
* @return the created set
*/
public static final <T> Set<T> newSet(Class<T> type) {
return new HashSet<T>();
public static final <T> Set<T> newSet() {
return new FastSet<T>();
}
/**
@@ -64,11 +63,9 @@ public class CollectionFactory {
*
* @param <T>
* the type
* @param type
* the type
* @return the created queue
*/
public static final <T> Queue<T> newConcurrentQueue(Class<T> type) {
public static final <T> Queue<T> newConcurrentQueue() {
return new ConcurrentLinkedQueue<T>();
}
@@ -79,14 +76,10 @@ public class CollectionFactory {
* the key type
* @param <V>
* the value type
* @param key
* the key type class
* @param value
* the value type class
* @return the new map
*/
public static final <K, V> Map<K, V> newMap(Class<K> key, Class<V> value) {
return new HashMap<K, V>();
public static final <K, V> Map<K, V> newMap() {
return new FastMap<K, V>();
}
/**
@@ -96,13 +89,9 @@ public class CollectionFactory {
* the key type
* @param <V>
* the value type
* @param key
* the key type class
* @param value
* the value type class
* @return the new map
*/
public static final <K, V> Map<K, V> newWeakMap(Class<K> key, Class<V> value) {
public static final <K, V> Map<K, V> newWeakMap() {
return new WeakHashMap<K, V>();
}
}

View File

@@ -1,59 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator;
import java.util.List;
import com.l2jserver.util.factory.CollectionFactory;
import com.l2jserver.util.oldcalculator.operation.AddOperation;
import com.l2jserver.util.oldcalculator.operation.CalculatorOperation;
import com.l2jserver.util.oldcalculator.operation.SetOperation;
import com.l2jserver.util.oldcalculator.operation.SubtractOperation;
/**
* The formula object does an sequence of steps into calculating something.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class Formula {
private List<CalculatorOperation<Integer>> operations = CollectionFactory
.newList(null);
public void addOperation(int order, CalculatorOperation<Integer> operation) {
operations.set(order, operation);
}
public void add(int order, int value) {
addOperation(order, new AddOperation(value));
}
public void subtract(int order, int value) {
addOperation(order, new SubtractOperation(value));
}
public void set(int order, int value) {
addOperation(order, new SetOperation(value));
}
public int calculate() {
int value = 0;
for (CalculatorOperation<Integer> operation : operations) {
value = operation.calculate(value);
}
return value;
}
}

View File

@@ -1,30 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator.operation;
public class AddOperation implements CalculatorOperation<Integer> {
private Integer value;
public AddOperation(Integer value) {
this.value = value;
}
@Override
public Integer calculate(Integer value) {
return value + this.value;
}
}

View File

@@ -1,21 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.util.oldcalculator.operation;
public interface CalculatorOperation<T extends Number> {
T calculate(T value);
}

View File

@@ -25,6 +25,7 @@ import org.junit.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
import com.l2jserver.GameServerModule;
import com.l2jserver.model.id.object.provider.CharacterIDProvider;
import com.l2jserver.model.id.object.provider.ItemIDProvider;
@@ -36,9 +37,11 @@ import com.l2jserver.model.world.item.ItemListener;
import com.l2jserver.model.world.player.event.PlayerEvent;
import com.l2jserver.model.world.player.event.PlayerListener;
import com.l2jserver.model.world.player.event.PlayerSpawnEvent;
import com.l2jserver.service.ServiceManager;
import com.l2jserver.service.ServiceStartException;
import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.event.WorldEventDispatcher;
import com.l2jserver.service.game.world.id.WorldIDService;
public class WorldEventDispatcherImplTest {
private WorldService world;
@@ -49,7 +52,10 @@ public class WorldEventDispatcherImplTest {
@Before
public void tearUp() throws ServiceStartException {
Injector injector = Guice.createInjector(new GameServerModule());
Injector injector = Guice.createInjector(Stage.PRODUCTION,
new GameServerModule());
injector.getInstance(ServiceManager.class).start(WorldIDService.class);
cidFactory = injector.getInstance(CharacterIDProvider.class);
iidFactory = injector.getInstance(ItemIDProvider.class);
@@ -139,9 +145,9 @@ public class WorldEventDispatcherImplTest {
});
dispatcher.dispatch(new ItemDropEvent(character1, item1));
Thread.sleep(100); // wait a bit for dispatching to happen
Thread.sleep(1000); // wait a bit for dispatching to happen
Assert.assertTrue(bool1.get());
Assert.assertFalse(bool1.get());
Assert.assertTrue(bool2.get());
}
}

View File

@@ -41,7 +41,7 @@ public class CharacterTemplateConverter {
private static String template;
private static Map<CharacterClass, String> parents = CollectionFactory
.newMap(CharacterClass.class, String.class);
.newMap();
public static void main(String[] args) throws SQLException, IOException,
ClassNotFoundException {