diff --git a/data/plugin/plugin/PluginLoader.java b/data/plugin/plugin/PluginLoader.java index 1036fe4db..c42babdae 100644 --- a/data/plugin/plugin/PluginLoader.java +++ b/data/plugin/plugin/PluginLoader.java @@ -60,7 +60,7 @@ public class PluginLoader implements Loader, Unloader { private static Set>> getSuitableClasses( Class[] classes) { final Set>> suitable = CollectionFactory - .newSet(null); + .newSet(); for (Class clazz : classes) { if (!ClassUtils.isSubclass(clazz, Template.class)) continue; diff --git a/data/script/template/script/template/TemplateLoader.java b/data/script/template/script/template/TemplateLoader.java index 68fcf3d14..a854c4e7b 100644 --- a/data/script/template/script/template/TemplateLoader.java +++ b/data/script/template/script/template/TemplateLoader.java @@ -76,7 +76,7 @@ public class TemplateLoader implements Loader, Unloader { private static Set>> getSuitableClasses( Class[] classes) { final Set>> suitable = CollectionFactory - .newSet(null); + .newSet(); for (Class clazz : classes) { if (!ClassUtils.isSubclass(clazz, Template.class)) continue; diff --git a/data/script/template/script/template/actor/monster/WolfMonsterTemplate.java b/data/script/template/script/template/actor/monster/WolfMonsterTemplate.java index 806e9cdfc..6046e36b9 100644 --- a/data/script/template/script/template/actor/monster/WolfMonsterTemplate.java +++ b/data/script/template/script/template/actor/monster/WolfMonsterTemplate.java @@ -34,6 +34,6 @@ public class WolfMonsterTemplate extends MonsterNPCTemplate { this.attackable = true; this.maxHp = 200; this.collisionRadius = 13.00; - this.collisionHeigth = 9.00; + this.collisionHeight = 9.00; } } diff --git a/pom.xml b/pom.xml index 762675f01..44adbcc1c 100644 --- a/pom.xml +++ b/pom.xml @@ -106,6 +106,13 @@ jar runtime + + javolution + javolution + 5.5.1 + jar + runtime + @@ -185,5 +192,11 @@ false + + maven2-repository.java.net + Java.net Repository for Maven + http://download.java.net/maven/2/ + default + \ No newline at end of file diff --git a/src/main/java/com/l2jserver/L2JGameServerMain.java b/src/main/java/com/l2jserver/L2JGameServerMain.java index dae1a3319..1b4c5405a 100644 --- a/src/main/java/com/l2jserver/L2JGameServerMain.java +++ b/src/main/java/com/l2jserver/L2JGameServerMain.java @@ -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); } } diff --git a/src/main/java/com/l2jserver/game/net/Lineage2Connection.java b/src/main/java/com/l2jserver/game/net/Lineage2Connection.java index f1ef471d9..490d3afe5 100644 --- a/src/main/java/com/l2jserver/game/net/Lineage2Connection.java +++ b/src/main/java/com/l2jserver/game/net/Lineage2Connection.java @@ -256,7 +256,7 @@ public class Lineage2Connection { * @return an {@link Set} containing all {@link ChannelFuture} instances. */ public Set broadcast(ServerPacket packet) { - final Set futures = CollectionFactory.newSet(null); + final Set futures = CollectionFactory.newSet(); for (final L2Character character : worldService .iterable(new CharacterBroadcastFilter(characterID.getObject()))) { final Lineage2Connection conn = networkService.discover(character diff --git a/src/main/java/com/l2jserver/game/net/packet/client/CharacterAttackRequestPacket.java b/src/main/java/com/l2jserver/game/net/packet/client/CharacterAttackRequestPacket.java new file mode 100644 index 000000000..1c0c6b07f --- /dev/null +++ b/src/main/java/com/l2jserver/game/net/packet/client/CharacterAttackRequestPacket.java @@ -0,0 +1,129 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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 Rogiel + */ +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 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); + } +} diff --git a/src/main/java/com/l2jserver/game/net/packet/server/ActionFailedPacket.java b/src/main/java/com/l2jserver/game/net/packet/server/ActionFailedPacket.java new file mode 100644 index 000000000..3cae21060 --- /dev/null +++ b/src/main/java/com/l2jserver/game/net/packet/server/ActionFailedPacket.java @@ -0,0 +1,50 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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 Rogiel + */ +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) { + } +} diff --git a/src/main/java/com/l2jserver/game/net/packet/server/ActorMovementPacket.java b/src/main/java/com/l2jserver/game/net/packet/server/ActorMovementPacket.java index 3fd09136c..c9a51ee1f 100644 --- a/src/main/java/com/l2jserver/game/net/packet/server/ActorMovementPacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/server/ActorMovementPacket.java @@ -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()); diff --git a/src/main/java/com/l2jserver/game/net/packet/server/InventoryPacket.java b/src/main/java/com/l2jserver/game/net/packet/server/CharacterInventoryPacket.java similarity index 95% rename from src/main/java/com/l2jserver/game/net/packet/server/InventoryPacket.java rename to src/main/java/com/l2jserver/game/net/packet/server/CharacterInventoryPacket.java index 48b61b558..367e3b26f 100644 --- a/src/main/java/com/l2jserver/game/net/packet/server/InventoryPacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/server/CharacterInventoryPacket.java @@ -29,7 +29,7 @@ import com.l2jserver.model.world.character.CharacterInventory.InventoryLocation; * * @author Rogiel */ -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; } diff --git a/src/main/java/com/l2jserver/game/net/packet/server/NPCInformationPacket.java b/src/main/java/com/l2jserver/game/net/packet/server/NPCInformationPacket.java index 3eb6ff9f0..cbb1f6bd9 100644 --- a/src/main/java/com/l2jserver/game/net/packet/server/NPCInformationPacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/server/NPCInformationPacket.java @@ -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 diff --git a/src/main/java/com/l2jserver/game/net/packet/server/ServerObjectPacket.java b/src/main/java/com/l2jserver/game/net/packet/server/ServerObjectPacket.java index 48187359d..e8083e802 100644 --- a/src/main/java/com/l2jserver/game/net/packet/server/ServerObjectPacket.java +++ b/src/main/java/com/l2jserver/game/net/packet/server/ServerObjectPacket.java @@ -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 diff --git a/src/main/java/com/l2jserver/model/template/NPCTemplate.java b/src/main/java/com/l2jserver/model/template/NPCTemplate.java index 3b6f45230..5c84739c5 100644 --- a/src/main/java/com/l2jserver/model/template/NPCTemplate.java +++ b/src/main/java/com/l2jserver/model/template/NPCTemplate.java @@ -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 Rogiel */ public abstract class NPCTemplate extends ActorTemplate { + /** + * 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 { .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 { } /** - * @return the collisionHeigth + * @return the collisionHeight */ - public double getCollisionHeigth() { - return collisionHeigth; + public double getCollisionHeight() { + return collisionHeight; } /** diff --git a/src/main/java/com/l2jserver/model/template/item/WeaponTemplate.java b/src/main/java/com/l2jserver/model/template/item/WeaponTemplate.java index 40b5a7e6c..00cee8a58 100644 --- a/src/main/java/com/l2jserver/model/template/item/WeaponTemplate.java +++ b/src/main/java/com/l2jserver/model/template/item/WeaponTemplate.java @@ -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>> 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> getMap(WeaponAttributeType type) { Map> map = operations.get(type); if (map == null) { - map = CollectionFactory.newMap(null, null); + map = CollectionFactory.newMap(); operations.put(type, map); } return map; diff --git a/src/main/java/com/l2jserver/model/world/Clan.java b/src/main/java/com/l2jserver/model/world/Clan.java index 648c14567..624a01844 100644 --- a/src/main/java/com/l2jserver/model/world/Clan.java +++ b/src/main/java/com/l2jserver/model/world/Clan.java @@ -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 Rogiel */ -public class Clan extends AbstractObject implements - Listenable, Joinable { +public class Clan extends AbstractObject implements Joinable { /** * Clan leader */ diff --git a/src/main/java/com/l2jserver/model/world/Item.java b/src/main/java/com/l2jserver/model/world/Item.java index 7a2cdc8d2..e7b1296e2 100644 --- a/src/main/java/com/l2jserver/model/world/Item.java +++ b/src/main/java/com/l2jserver/model/world/Item.java @@ -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 Rogiel */ public class Item extends AbstractObject implements Playable, Spawnable, - Listenable, 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) { + + } } diff --git a/src/main/java/com/l2jserver/model/world/NPC.java b/src/main/java/com/l2jserver/model/world/NPC.java index 1e37e9208..1350bce62 100644 --- a/src/main/java/com/l2jserver/model/world/NPC.java +++ b/src/main/java/com/l2jserver/model/world/NPC.java @@ -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 Rogiel @@ -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 */ diff --git a/src/main/java/com/l2jserver/model/world/Party.java b/src/main/java/com/l2jserver/model/world/Party.java index b0575631a..b43c55764 100644 --- a/src/main/java/com/l2jserver/model/world/Party.java +++ b/src/main/java/com/l2jserver/model/world/Party.java @@ -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 Rogiel */ -public class Party extends AbstractObject implements - Listenable, Joinable { +public class Party extends AbstractObject implements Joinable { /** * Active party members */ - private final List members = CollectionFactory - .newList(CharacterID.class); + private final List members = CollectionFactory.newList(); @Override public void join(L2Character member) { diff --git a/src/main/java/com/l2jserver/model/world/actor/ActorSkillContainer.java b/src/main/java/com/l2jserver/model/world/actor/ActorSkillContainer.java index ff76672ad..b0863bbc7 100644 --- a/src/main/java/com/l2jserver/model/world/actor/ActorSkillContainer.java +++ b/src/main/java/com/l2jserver/model/world/actor/ActorSkillContainer.java @@ -40,7 +40,7 @@ public class ActorSkillContainer implements Iterable { /** * The learned skill list */ - private List skills = CollectionFactory.newList(Skill.class); + private List skills = CollectionFactory.newList(); /** * Creates a new instance diff --git a/src/main/java/com/l2jserver/model/world/actor/event/ActorListener.java b/src/main/java/com/l2jserver/model/world/actor/event/ActorListener.java index a7caf31fd..5f3bd3b71 100644 --- a/src/main/java/com/l2jserver/model/world/actor/event/ActorListener.java +++ b/src/main/java/com/l2jserver/model/world/actor/event/ActorListener.java @@ -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 Rogiel */ -public abstract class ActorListener extends FilteredWorldListener { +public abstract class ActorListener extends TypedWorldListener { public ActorListener() { super(ActorEvent.class); } diff --git a/src/main/java/com/l2jserver/model/world/actor/event/ActorSpawnEvent.java b/src/main/java/com/l2jserver/model/world/actor/event/ActorSpawnEvent.java new file mode 100644 index 000000000..4ce7f2783 --- /dev/null +++ b/src/main/java/com/l2jserver/model/world/actor/event/ActorSpawnEvent.java @@ -0,0 +1,72 @@ +/* + * This file is part of l2jserver . + * + * 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 . + */ +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 Rogiel + */ +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() }; + } +} diff --git a/src/main/java/com/l2jserver/model/world/capability/Actor.java b/src/main/java/com/l2jserver/model/world/capability/Actor.java index 1704c3e82..bdda7fe15 100644 --- a/src/main/java/com/l2jserver/model/world/capability/Actor.java +++ b/src/main/java/com/l2jserver/model/world/capability/Actor.java @@ -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 Rogiel */ -public interface Actor extends Listenable, - 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 */ diff --git a/src/main/java/com/l2jserver/model/world/capability/Spawnable.java b/src/main/java/com/l2jserver/model/world/capability/Spawnable.java index 5204c0e01..d39672eba 100644 --- a/src/main/java/com/l2jserver/model/world/capability/Spawnable.java +++ b/src/main/java/com/l2jserver/model/world/capability/Spawnable.java @@ -24,7 +24,7 @@ import com.l2jserver.util.dimensional.Coordinate; * * @author Rogiel */ -public interface Spawnable extends ObjectCapability, Positionable { +public interface Spawnable extends ObjectCapability, Positionable, Pointable { void spawn(Coordinate coordinate); boolean isSpawned(); diff --git a/src/main/java/com/l2jserver/model/world/character/CharacterFriendList.java b/src/main/java/com/l2jserver/model/world/character/CharacterFriendList.java index 0c6e25ecd..ed2c0ba34 100644 --- a/src/main/java/com/l2jserver/model/world/character/CharacterFriendList.java +++ b/src/main/java/com/l2jserver/model/world/character/CharacterFriendList.java @@ -40,7 +40,7 @@ public class CharacterFriendList implements Iterable { * The list of friends of this character */ private final Set friends = CollectionFactory - .newSet(CharacterID.class); + .newSet(); /** * Creates a new instance diff --git a/src/main/java/com/l2jserver/model/world/character/CharacterInventory.java b/src/main/java/com/l2jserver/model/world/character/CharacterInventory.java index 4e9f2322f..11fae622e 100644 --- a/src/main/java/com/l2jserver/model/world/character/CharacterInventory.java +++ b/src/main/java/com/l2jserver/model/world/character/CharacterInventory.java @@ -38,7 +38,7 @@ public class CharacterInventory implements Iterable { /** * The items in this character inventory */ - private final Set items = CollectionFactory.newSet(Item.class); + private final Set items = CollectionFactory.newSet(); /** * Creates a new instance diff --git a/src/main/java/com/l2jserver/model/world/character/CharacterShortcutContainer.java b/src/main/java/com/l2jserver/model/world/character/CharacterShortcutContainer.java index 17b29fa85..31cfc9d7b 100644 --- a/src/main/java/com/l2jserver/model/world/character/CharacterShortcutContainer.java +++ b/src/main/java/com/l2jserver/model/world/character/CharacterShortcutContainer.java @@ -37,8 +37,7 @@ public class CharacterShortcutContainer implements Iterable { /** * The shortcut list */ - private List shortcuts = CollectionFactory - .newList(Shortcut.class); + private List shortcuts = CollectionFactory.newList(); /** * Creates a new instance diff --git a/src/main/java/com/l2jserver/model/world/character/event/CharacterEnterWorldEvent.java b/src/main/java/com/l2jserver/model/world/character/event/CharacterEnterWorldEvent.java index f615c51f4..a13e4e6ed 100644 --- a/src/main/java/com/l2jserver/model/world/character/event/CharacterEnterWorldEvent.java +++ b/src/main/java/com/l2jserver/model/world/character/event/CharacterEnterWorldEvent.java @@ -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() }; } } diff --git a/src/main/java/com/l2jserver/model/world/character/event/CharacterLeaveWorldEvent.java b/src/main/java/com/l2jserver/model/world/character/event/CharacterLeaveWorldEvent.java index da153e1d9..d31a61fb4 100644 --- a/src/main/java/com/l2jserver/model/world/character/event/CharacterLeaveWorldEvent.java +++ b/src/main/java/com/l2jserver/model/world/character/event/CharacterLeaveWorldEvent.java @@ -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() }; } } diff --git a/src/main/java/com/l2jserver/model/world/character/event/CharacterListener.java b/src/main/java/com/l2jserver/model/world/character/event/CharacterListener.java index 65c584aa9..46a97041c 100644 --- a/src/main/java/com/l2jserver/model/world/character/event/CharacterListener.java +++ b/src/main/java/com/l2jserver/model/world/character/event/CharacterListener.java @@ -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 Rogiel */ public abstract class CharacterListener extends - FilteredWorldListener { + TypedWorldListener { public CharacterListener() { super(CharacterEvent.class); } diff --git a/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java b/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java index b60444f16..3cabe6788 100644 --- a/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java +++ b/src/main/java/com/l2jserver/model/world/character/event/CharacterMoveEvent.java @@ -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() }; } } diff --git a/src/main/java/com/l2jserver/model/world/character/event/CharacterStopMoveEvent.java b/src/main/java/com/l2jserver/model/world/character/event/CharacterStopMoveEvent.java index 350bb84d7..87195794c 100644 --- a/src/main/java/com/l2jserver/model/world/character/event/CharacterStopMoveEvent.java +++ b/src/main/java/com/l2jserver/model/world/character/event/CharacterStopMoveEvent.java @@ -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() }; } } diff --git a/src/main/java/com/l2jserver/model/world/character/event/CharacterTargetDeselectedEvent.java b/src/main/java/com/l2jserver/model/world/character/event/CharacterTargetDeselectedEvent.java index e60bf085f..1260911fa 100644 --- a/src/main/java/com/l2jserver/model/world/character/event/CharacterTargetDeselectedEvent.java +++ b/src/main/java/com/l2jserver/model/world/character/event/CharacterTargetDeselectedEvent.java @@ -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() }; } } diff --git a/src/main/java/com/l2jserver/model/world/character/event/CharacterTargetSelectedEvent.java b/src/main/java/com/l2jserver/model/world/character/event/CharacterTargetSelectedEvent.java index cb7f8f813..62bb55a3d 100644 --- a/src/main/java/com/l2jserver/model/world/character/event/CharacterTargetSelectedEvent.java +++ b/src/main/java/com/l2jserver/model/world/character/event/CharacterTargetSelectedEvent.java @@ -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() }; } } diff --git a/src/main/java/com/l2jserver/model/world/clan/ClanListener.java b/src/main/java/com/l2jserver/model/world/clan/ClanListener.java index 45e1edcbe..bb2872e95 100644 --- a/src/main/java/com/l2jserver/model/world/clan/ClanListener.java +++ b/src/main/java/com/l2jserver/model/world/clan/ClanListener.java @@ -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 Rogiel */ -public abstract class ClanListener extends FilteredWorldListener { +public abstract class ClanListener extends TypedWorldListener { public ClanListener() { super(ClanEvent.class); } diff --git a/src/main/java/com/l2jserver/model/world/clan/ClanMembers.java b/src/main/java/com/l2jserver/model/world/clan/ClanMembers.java index 114591fcd..a4e8a0e32 100644 --- a/src/main/java/com/l2jserver/model/world/clan/ClanMembers.java +++ b/src/main/java/com/l2jserver/model/world/clan/ClanMembers.java @@ -39,8 +39,7 @@ public class ClanMembers implements Iterable { /** * The list of active members */ - private final Set members = CollectionFactory - .newSet(CharacterID.class); + private final Set members = CollectionFactory.newSet(); /** * Creates a new instance diff --git a/src/main/java/com/l2jserver/model/world/event/SpawnEvent.java b/src/main/java/com/l2jserver/model/world/event/SpawnEvent.java index 746e02fd6..fb16a5805 100644 --- a/src/main/java/com/l2jserver/model/world/event/SpawnEvent.java +++ b/src/main/java/com/l2jserver/model/world/event/SpawnEvent.java @@ -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(); } \ No newline at end of file diff --git a/src/main/java/com/l2jserver/model/world/item/ItemDropEvent.java b/src/main/java/com/l2jserver/model/world/item/ItemDropEvent.java index 2f0a376d7..96db7c187 100644 --- a/src/main/java/com/l2jserver/model/world/item/ItemDropEvent.java +++ b/src/main/java/com/l2jserver/model/world/item/ItemDropEvent.java @@ -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() }; } } diff --git a/src/main/java/com/l2jserver/model/world/item/ItemListener.java b/src/main/java/com/l2jserver/model/world/item/ItemListener.java index c5ab92751..902737d37 100644 --- a/src/main/java/com/l2jserver/model/world/item/ItemListener.java +++ b/src/main/java/com/l2jserver/model/world/item/ItemListener.java @@ -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 Rogiel */ -public abstract class ItemListener extends FilteredWorldListener { +public abstract class ItemListener extends TypedWorldListener { public ItemListener() { super(ItemEvent.class); } diff --git a/src/main/java/com/l2jserver/util/oldcalculator/operation/SubtractOperation.java b/src/main/java/com/l2jserver/model/world/npc/event/NPCEvent.java similarity index 69% rename from src/main/java/com/l2jserver/util/oldcalculator/operation/SubtractOperation.java rename to src/main/java/com/l2jserver/model/world/npc/event/NPCEvent.java index 73ad144df..81921eba0 100644 --- a/src/main/java/com/l2jserver/util/oldcalculator/operation/SubtractOperation.java +++ b/src/main/java/com/l2jserver/model/world/npc/event/NPCEvent.java @@ -14,17 +14,16 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.util.oldcalculator.operation; +package com.l2jserver.model.world.npc.event; -public class SubtractOperation implements CalculatorOperation { - 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 Rogiel + */ +public interface NPCEvent extends WorldEvent { + NPC getNPC(); } diff --git a/src/main/java/com/l2jserver/util/oldcalculator/operation/SetOperation.java b/src/main/java/com/l2jserver/model/world/npc/event/NPCListener.java similarity index 65% rename from src/main/java/com/l2jserver/util/oldcalculator/operation/SetOperation.java rename to src/main/java/com/l2jserver/model/world/npc/event/NPCListener.java index 05aeca1ad..bc6bcaa8c 100644 --- a/src/main/java/com/l2jserver/util/oldcalculator/operation/SetOperation.java +++ b/src/main/java/com/l2jserver/model/world/npc/event/NPCListener.java @@ -14,17 +14,17 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.util.oldcalculator.operation; +package com.l2jserver.model.world.npc.event; -public class SetOperation implements CalculatorOperation { - 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 Rogiel + */ +public abstract class NPCListener extends TypedWorldListener { + public NPCListener() { + super(NPCEvent.class); } } diff --git a/src/main/java/com/l2jserver/util/oldcalculator/operation/MultiplyOperation.java b/src/main/java/com/l2jserver/model/world/npc/event/NPCSpawnEvent.java similarity index 54% rename from src/main/java/com/l2jserver/util/oldcalculator/operation/MultiplyOperation.java rename to src/main/java/com/l2jserver/model/world/npc/event/NPCSpawnEvent.java index a43d051c3..6529a933a 100644 --- a/src/main/java/com/l2jserver/util/oldcalculator/operation/MultiplyOperation.java +++ b/src/main/java/com/l2jserver/model/world/npc/event/NPCSpawnEvent.java @@ -14,17 +14,30 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -package com.l2jserver.util.oldcalculator.operation; +package com.l2jserver.model.world.npc.event; -public class MultiplyOperation implements CalculatorOperation { - 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 Rogiel + */ +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(); } } diff --git a/src/main/java/com/l2jserver/model/world/player/event/PlayerListener.java b/src/main/java/com/l2jserver/model/world/player/event/PlayerListener.java index 5cd405a3a..96a04b45e 100644 --- a/src/main/java/com/l2jserver/model/world/player/event/PlayerListener.java +++ b/src/main/java/com/l2jserver/model/world/player/event/PlayerListener.java @@ -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 Rogiel */ -public abstract class PlayerListener extends FilteredWorldListener { +public abstract class PlayerListener extends TypedWorldListener { public PlayerListener() { super(PlayerEvent.class); } diff --git a/src/main/java/com/l2jserver/model/world/player/event/PlayerSpawnEvent.java b/src/main/java/com/l2jserver/model/world/player/event/PlayerSpawnEvent.java index fc56409f7..8f7866e32 100644 --- a/src/main/java/com/l2jserver/model/world/player/event/PlayerSpawnEvent.java +++ b/src/main/java/com/l2jserver/model/world/player/event/PlayerSpawnEvent.java @@ -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 Rogiel */ -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(); } } diff --git a/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportEvent.java b/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportEvent.java index e29033aa7..e21bdd7b2 100644 --- a/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportEvent.java +++ b/src/main/java/com/l2jserver/model/world/player/event/PlayerTeleportEvent.java @@ -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); } } diff --git a/src/main/java/com/l2jserver/service/ServiceManager.java b/src/main/java/com/l2jserver/service/ServiceManager.java index a39950fe5..afa1344ee 100644 --- a/src/main/java/com/l2jserver/service/ServiceManager.java +++ b/src/main/java/com/l2jserver/service/ServiceManager.java @@ -42,7 +42,7 @@ public class ServiceManager { */ private final Injector injector; - private final Set knownServices = CollectionFactory.newSet(null); + private final Set knownServices = CollectionFactory.newSet(); @Inject public ServiceManager(Injector injector) { @@ -124,7 +124,7 @@ public class ServiceManager { private Set> createStopDependencies( Set> 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) diff --git a/src/main/java/com/l2jserver/service/cache/EhCacheService.java b/src/main/java/com/l2jserver/service/cache/EhCacheService.java index 0fe6ed490..73dabf7fc 100644 --- a/src/main/java/com/l2jserver/service/cache/EhCacheService.java +++ b/src/main/java/com/l2jserver/service/cache/EhCacheService.java @@ -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 Rogiel */ diff --git a/src/main/java/com/l2jserver/service/configuration/ProxyConfigurationService.java b/src/main/java/com/l2jserver/service/configuration/ProxyConfigurationService.java index facf0a925..de0e1865c 100644 --- a/src/main/java/com/l2jserver/service/configuration/ProxyConfigurationService.java +++ b/src/main/java/com/l2jserver/service/configuration/ProxyConfigurationService.java @@ -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, Object> cache = new WeakHashMap, Object>(); + private Map, 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 cache = new WeakHashMap(); + private Map cache = CollectionFactory.newWeakMap(); public ConfigInvocationHandler(Properties properties) { this.properties = properties; diff --git a/src/main/java/com/l2jserver/service/database/MySQLDatabaseService.java b/src/main/java/com/l2jserver/service/database/MySQLDatabaseService.java index a8e244bd4..519eba010 100644 --- a/src/main/java/com/l2jserver/service/database/MySQLDatabaseService.java +++ b/src/main/java/com/l2jserver/service/database/MySQLDatabaseService.java @@ -318,7 +318,7 @@ public class MySQLDatabaseService extends AbstractService implements final PreparedStatement st = conn.prepareStatement(query()); parametize(st); st.execute(); - final List list = CollectionFactory.newList(null); + final List list = CollectionFactory.newList(); final ResultSet rs = st.getResultSet(); while (rs.next()) { list.add(mapper().map(rs)); diff --git a/src/main/java/com/l2jserver/service/game/CharacterService.java b/src/main/java/com/l2jserver/service/game/CharacterService.java index dd73b5e38..b69805ef7 100644 --- a/src/main/java/com/l2jserver/service/game/CharacterService.java +++ b/src/main/java/com/l2jserver/service/game/CharacterService.java @@ -53,6 +53,16 @@ public interface CharacterService extends Service { */ void target(L2Character character, Actor actor); + /** + * Attacks with the given character the target + * + * @param character + * the character + * @param target + * the target + */ + void attack(L2Character character, Actor target); + /** * Moves the given character to coordinate * diff --git a/src/main/java/com/l2jserver/service/game/CharacterServiceImpl.java b/src/main/java/com/l2jserver/service/game/CharacterServiceImpl.java index e9638400f..6467e7b7d 100644 --- a/src/main/java/com/l2jserver/service/game/CharacterServiceImpl.java +++ b/src/main/java/com/l2jserver/service/game/CharacterServiceImpl.java @@ -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( + 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(); diff --git a/src/main/java/com/l2jserver/service/game/SpawnService.java b/src/main/java/com/l2jserver/service/game/SpawnService.java index 401788ddd..e80a938c4 100644 --- a/src/main/java/com/l2jserver/service/game/SpawnService.java +++ b/src/main/java/com/l2jserver/service/game/SpawnService.java @@ -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 point. diff --git a/src/main/java/com/l2jserver/service/game/SpawnServiceImpl.java b/src/main/java/com/l2jserver/service/game/SpawnServiceImpl.java index 1114a9138..048f1a1de 100644 --- a/src/main/java/com/l2jserver/service/game/SpawnServiceImpl.java +++ b/src/main/java/com/l2jserver/service/game/SpawnServiceImpl.java @@ -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 } diff --git a/src/main/java/com/l2jserver/service/game/chat/SimpleChatService.java b/src/main/java/com/l2jserver/service/game/chat/SimpleChatService.java index 186ebb45f..89ed048c4 100644 --- a/src/main/java/com/l2jserver/service/game/chat/SimpleChatService.java +++ b/src/main/java/com/l2jserver/service/game/chat/SimpleChatService.java @@ -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 listeners = CollectionFactory - .newSet(null); + .newSet(); @Override public void send(CharacterID sender, String message) { diff --git a/src/main/java/com/l2jserver/service/game/scripting/ScriptingServiceImpl.java b/src/main/java/com/l2jserver/service/game/scripting/ScriptingServiceImpl.java index 4be9aab93..02de91ba4 100644 --- a/src/main/java/com/l2jserver/service/game/scripting/ScriptingServiceImpl.java +++ b/src/main/java/com/l2jserver/service/game/scripting/ScriptingServiceImpl.java @@ -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 contexts = new HashSet(); + private final Set 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 contexts = CollectionFactory - .newList(ScriptContext.class); + final List contexts = CollectionFactory.newList(); for (ScriptInfo si : list.getScriptInfos()) { final ScriptContext context = createContext(si, null); diff --git a/src/main/java/com/l2jserver/service/game/scripting/impl/ScriptContextImpl.java b/src/main/java/com/l2jserver/service/game/scripting/impl/ScriptContextImpl.java index af1f8bef7..24053f3df 100644 --- a/src/main/java/com/l2jserver/service/game/scripting/impl/ScriptContextImpl.java +++ b/src/main/java/com/l2jserver/service/game/scripting/impl/ScriptContextImpl.java @@ -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(); + childScriptContexts = CollectionFactory.newSet(); } if (childScriptContexts.contains(context)) { diff --git a/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ClassFileManager.java b/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ClassFileManager.java index 31bef3f29..eb3f69d3c 100644 --- a/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ClassFileManager.java +++ b/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ClassFileManager.java @@ -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 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 temp = new ArrayList(); + List temp = CollectionFactory.newList(); for (JavaFileObject object : objects) { temp.add(object); } diff --git a/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ScriptClassLoaderImpl.java b/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ScriptClassLoaderImpl.java index f1a95df1c..baaee9090 100644 --- a/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ScriptClassLoaderImpl.java +++ b/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ScriptClassLoaderImpl.java @@ -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.
@@ -71,7 +71,7 @@ public class ScriptClassLoaderImpl extends ScriptClassLoader { * annotations, but they are needed by JavaCompiler to perform valid * compilation */ - private Set libraryClasses = new HashSet(); + private Set libraryClasses = CollectionFactory.newSet(); /** * Creates new ScriptClassLoader with given ClassFileManger @@ -215,7 +215,7 @@ public class ScriptClassLoaderImpl extends ScriptClassLoader { */ public Set getClassesForPackage(String packageName) throws IOException { - Set result = new HashSet(); + Set result = CollectionFactory.newSet(); // load parent ClassLoader parent = getParent(); diff --git a/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ScriptCompilerImpl.java b/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ScriptCompilerImpl.java index b2ba42668..30092bf07 100644 --- a/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ScriptCompilerImpl.java +++ b/src/main/java/com/l2jserver/service/game/scripting/impl/javacc/ScriptCompilerImpl.java @@ -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 compilationUnits = new ArrayList(); + List 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 compilationUnits) { - List list = new ArrayList(); + List list = CollectionFactory.newList(); for (File f : compilationUnits) { list.add(new JavaSourceFromFile(f, JavaFileObject.Kind.SOURCE)); diff --git a/src/main/java/com/l2jserver/service/game/template/ScriptTemplateService.java b/src/main/java/com/l2jserver/service/game/template/ScriptTemplateService.java index 027184c5b..acbd36fbb 100644 --- a/src/main/java/com/l2jserver/service/game/template/ScriptTemplateService.java +++ b/src/main/java/com/l2jserver/service/game/template/ScriptTemplateService.java @@ -43,8 +43,7 @@ public class ScriptTemplateService extends AbstractService implements private ScriptContext context; @SuppressWarnings("rawtypes") - private Map templates = CollectionFactory.newMap( - TemplateID.class, Template.class); + private Map templates = CollectionFactory.newMap(); @Inject public ScriptTemplateService(ScriptingService scriptingService, diff --git a/src/main/java/com/l2jserver/service/game/world/WorldService.java b/src/main/java/com/l2jserver/service/game/world/WorldService.java index 94f6a7458..5f6de6627 100644 --- a/src/main/java/com/l2jserver/service/game/world/WorldService.java +++ b/src/main/java/com/l2jserver/service/game/world/WorldService.java @@ -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 { */ T find(ObjectID id) throws ClassCastException; + /** + * Executes an action inside the callback for each object in object + * 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 Rogiel + */ + public interface KnownListCallback { + /** + * Performs an action on the given known object + * + * @param object + * the object known by the other object + */ + void knownObject(WorldObject object); + } + /** * Get the event dispatcher * diff --git a/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java b/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java index e4208ae47..e72275a9d 100644 --- a/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java +++ b/src/main/java/com/l2jserver/service/game/world/WorldServiceImpl.java @@ -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 objects = CollectionFactory - .newSet(WorldObject.class); + private final Set 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 List list(WorldObjectFilter filter) { log.debug("Listing objects with filter {}", filter); - final List list = CollectionFactory.newList(null); + final List list = CollectionFactory.newList(); for (final T object : this.iterable(filter)) { list.add(object); } diff --git a/src/main/java/com/l2jserver/service/game/world/event/FilteredWorldListener.java b/src/main/java/com/l2jserver/service/game/world/event/FilteredWorldListener.java index 4486fd2da..63ed3a6cc 100644 --- a/src/main/java/com/l2jserver/service/game/world/event/FilteredWorldListener.java +++ b/src/main/java/com/l2jserver/service/game/world/event/FilteredWorldListener.java @@ -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 Rogiel */ -public abstract class FilteredWorldListener implements WorldListener { - private final Class type; +public abstract class FilteredWorldListener implements + WorldListener { + private final WorldObjectFilter filter; - public FilteredWorldListener(Class type) { - this.type = type; + public FilteredWorldListener(WorldObjectFilter 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); } diff --git a/src/main/java/com/l2jserver/model/world/capability/Listenable.java b/src/main/java/com/l2jserver/service/game/world/event/TypedWorldListener.java similarity index 58% rename from src/main/java/com/l2jserver/model/world/capability/Listenable.java rename to src/main/java/com/l2jserver/service/game/world/event/TypedWorldListener.java index 7c7a1e626..bf848f9c7 100644 --- a/src/main/java/com/l2jserver/model/world/capability/Listenable.java +++ b/src/main/java/com/l2jserver/service/game/world/event/TypedWorldListener.java @@ -14,23 +14,30 @@ * You should have received a copy of the GNU General Public License * along with l2jserver. If not, see . */ -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 Rogiel - * - * @param - * the listener type - * @param - * the event type */ -public interface Listenable - extends ObjectCapability { +public abstract class TypedWorldListener implements WorldListener { + private final Class type; + + public TypedWorldListener(Class 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); } diff --git a/src/main/java/com/l2jserver/service/game/world/event/WorldEvent.java b/src/main/java/com/l2jserver/service/game/world/event/WorldEvent.java index 41bf1ca5d..1b76d253e 100644 --- a/src/main/java/com/l2jserver/service/game/world/event/WorldEvent.java +++ b/src/main/java/com/l2jserver/service/game/world/event/WorldEvent.java @@ -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(); } diff --git a/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcher.java b/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcher.java index aa45ec07c..0322c6cb8 100644 --- a/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcher.java +++ b/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcher.java @@ -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 listener * - * @param - * the event type - * @param - * the listener type * @param listener * the listener */ - void addListener( - WorldListener listener); + void addListener(WorldListener listener); /** * Adds a new listener to object * - * @param - * the event type - * @param - * the listener type * @param object * the object to listen to * @param listener * the listener */ - void addListener( - Listenable object, WorldListener listener); + void addListener(WorldObject object, WorldListener listener); /** * Adds a new listener to object with id id * - * @param - * the event type - * @param - * the listener type * @param id * the object id to listen to * @param listener * the listener */ - void addListener( - ObjectID> id, WorldListener listener); + void addListener(ObjectID id, WorldListener listener); + + /** + * Removes an existing global listener + * + * @param listener + * the listener + */ + void removeListener(WorldListener listener); /** * Removes an existing listener from object * - * @param - * the event type - * @param - * the listener type * @param object * the object to listen to * @param listener * the listener */ - void removeListener( - Listenable object, WorldListener listener); + void removeListener(WorldObject object, WorldListener listener); /** * Removes an existing listener from the object with id id * - * @param - * the event type - * @param - * the listener type * @param id * the object id to listen to * @param listener * the listener */ - void removeListener( - ObjectID> id, WorldListener listener); + void removeListener(ObjectID id, WorldListener listener); } diff --git a/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherImpl.java b/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherImpl.java index 161984e5b..620bcd5b6 100644 --- a/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherImpl.java +++ b/src/main/java/com/l2jserver/service/game/world/event/WorldEventDispatcherImpl.java @@ -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 listeners = CollectionFactory - .newConcurrentQueue(ListenerIDPair.class); - private Queue events = CollectionFactory - .newConcurrentQueue(WorldEvent.class); + private Set globalListeners = CollectionFactory.newSet(); + private Map, Set> listeners = CollectionFactory + .newMap(); + // private Queue listeners = CollectionFactory + // .newConcurrentQueue(ListenerIDPair.class); + private Queue 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 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 void addListener( - Listenable 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 void addListener( - ObjectID> 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 void removeListener( - Listenable 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 void removeListener( - ObjectID> 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 getListeners(ObjectID id) { + Set set = listeners.get(id); + if (set == null) { + set = CollectionFactory.newSet(); + listeners.put(id, set); } + return set; } } diff --git a/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListFilter.java b/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListFilter.java index 7263eb011..a6e55b0e2 100644 --- a/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListFilter.java +++ b/src/main/java/com/l2jserver/service/game/world/filter/impl/KnownListFilter.java @@ -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 Rogiel + * This filter will only accept {@link WorldObject} which are in vision of + * another object. * + * @author Rogiel */ public class KnownListFilter extends AndFilter { public static final int KNOWNLIST_RANGE = 200; @SuppressWarnings("unchecked") - public KnownListFilter(L2Character character) { + public KnownListFilter(Positionable object) { super(new InstanceFilter(Positionable.class), - new RangeFilter(character.getPosition(), KNOWNLIST_RANGE)); + new RangeFilter(object, KNOWNLIST_RANGE)); } } diff --git a/src/main/java/com/l2jserver/service/game/world/filter/impl/RangeFilter.java b/src/main/java/com/l2jserver/service/game/world/filter/impl/RangeFilter.java index 2d0353c28..415e7b358 100644 --- a/src/main/java/com/l2jserver/service/game/world/filter/impl/RangeFilter.java +++ b/src/main/java/com/l2jserver/service/game/world/filter/impl/RangeFilter.java @@ -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 range of coordinate @@ -29,7 +28,7 @@ public class RangeFilter implements WorldObjectFilter { /** * 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 { /** * 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; } } diff --git a/src/main/java/com/l2jserver/service/game/world/id/CachedWorldIDService.java b/src/main/java/com/l2jserver/service/game/world/id/CachedWorldIDService.java index 7aa15cce0..c32c9c95a 100644 --- a/src/main/java/com/l2jserver/service/game/world/id/CachedWorldIDService.java +++ b/src/main/java/com/l2jserver/service/game/world/id/CachedWorldIDService.java @@ -111,6 +111,8 @@ public class CachedWorldIDService extends AbstractService implements @Override public > void add(I id) { + if(id == null) + return; cache.put(new Element(id.getID(), id)); } diff --git a/src/main/java/com/l2jserver/service/network/NettyNetworkService.java b/src/main/java/com/l2jserver/service/network/NettyNetworkService.java index ffbfc4e1e..da1d1806a 100644 --- a/src/main/java/com/l2jserver/service/network/NettyNetworkService.java +++ b/src/main/java/com/l2jserver/service/network/NettyNetworkService.java @@ -74,8 +74,7 @@ public class NettyNetworkService extends AbstractService implements /** * The client list. This list all active clients in the server */ - private Set clients = CollectionFactory - .newSet(Lineage2Connection.class); + private Set clients = CollectionFactory.newSet(); @Inject public NettyNetworkService(ConfigurationService configService, diff --git a/src/main/java/com/l2jserver/util/calculator/Calculator.java b/src/main/java/com/l2jserver/util/calculator/Calculator.java index 900fdf92c..357cad207 100644 --- a/src/main/java/com/l2jserver/util/calculator/Calculator.java +++ b/src/main/java/com/l2jserver/util/calculator/Calculator.java @@ -33,7 +33,7 @@ public class Calculator implements Function { * List of operations in this calculator */ private final List functions = CollectionFactory - .newList(null); + .newList(); /** * Creates a new empty calculator. Functions can be add using diff --git a/src/main/java/com/l2jserver/util/factory/CollectionFactory.java b/src/main/java/com/l2jserver/util/factory/CollectionFactory.java index 614a605c3..3d563fb03 100644 --- a/src/main/java/com/l2jserver/util/factory/CollectionFactory.java +++ b/src/main/java/com/l2jserver/util/factory/CollectionFactory.java @@ -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 * the type - * @param type - * the type * @return the created list */ - public static final List newList(Class type) { - return new ArrayList(); + public static final List newList() { + return new FastList(); } /** @@ -55,8 +54,8 @@ public class CollectionFactory { * the type * @return the created set */ - public static final Set newSet(Class type) { - return new HashSet(); + public static final Set newSet() { + return new FastSet(); } /** @@ -64,11 +63,9 @@ public class CollectionFactory { * * @param * the type - * @param type - * the type * @return the created queue */ - public static final Queue newConcurrentQueue(Class type) { + public static final Queue newConcurrentQueue() { return new ConcurrentLinkedQueue(); } @@ -79,14 +76,10 @@ public class CollectionFactory { * the key type * @param * the value type - * @param key - * the key type class - * @param value - * the value type class * @return the new map */ - public static final Map newMap(Class key, Class value) { - return new HashMap(); + public static final Map newMap() { + return new FastMap(); } /** @@ -96,13 +89,9 @@ public class CollectionFactory { * the key type * @param * the value type - * @param key - * the key type class - * @param value - * the value type class * @return the new map */ - public static final Map newWeakMap(Class key, Class value) { + public static final Map newWeakMap() { return new WeakHashMap(); } } diff --git a/src/main/java/com/l2jserver/util/oldcalculator/Formula.java b/src/main/java/com/l2jserver/util/oldcalculator/Formula.java deleted file mode 100644 index c6766aff7..000000000 --- a/src/main/java/com/l2jserver/util/oldcalculator/Formula.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * This file is part of l2jserver . - * - * 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 . - */ -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 Rogiel - */ -public class Formula { - private List> operations = CollectionFactory - .newList(null); - - public void addOperation(int order, CalculatorOperation 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 operation : operations) { - value = operation.calculate(value); - } - return value; - } -} diff --git a/src/main/java/com/l2jserver/util/oldcalculator/operation/AddOperation.java b/src/main/java/com/l2jserver/util/oldcalculator/operation/AddOperation.java deleted file mode 100644 index 7648b3208..000000000 --- a/src/main/java/com/l2jserver/util/oldcalculator/operation/AddOperation.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is part of l2jserver . - * - * 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 . - */ -package com.l2jserver.util.oldcalculator.operation; - -public class AddOperation implements CalculatorOperation { - private Integer value; - - public AddOperation(Integer value) { - this.value = value; - } - - @Override - public Integer calculate(Integer value) { - return value + this.value; - } -} diff --git a/src/main/java/com/l2jserver/util/oldcalculator/operation/CalculatorOperation.java b/src/main/java/com/l2jserver/util/oldcalculator/operation/CalculatorOperation.java deleted file mode 100644 index e2eda0e45..000000000 --- a/src/main/java/com/l2jserver/util/oldcalculator/operation/CalculatorOperation.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * This file is part of l2jserver . - * - * 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 . - */ -package com.l2jserver.util.oldcalculator.operation; - -public interface CalculatorOperation { - T calculate(T value); -} diff --git a/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java b/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java index b62c13a93..f27d40e74 100644 --- a/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java +++ b/src/test/java/com/l2jserver/service/world/WorldEventDispatcherImplTest.java @@ -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()); } } diff --git a/src/tool/java/com/l2jserver/tool/conversor/chartemplate/CharacterTemplateConverter.java b/src/tool/java/com/l2jserver/tool/conversor/chartemplate/CharacterTemplateConverter.java index e563d5c22..057ba63d5 100644 --- a/src/tool/java/com/l2jserver/tool/conversor/chartemplate/CharacterTemplateConverter.java +++ b/src/tool/java/com/l2jserver/tool/conversor/chartemplate/CharacterTemplateConverter.java @@ -41,7 +41,7 @@ public class CharacterTemplateConverter { private static String template; private static Map parents = CollectionFactory - .newMap(CharacterClass.class, String.class); + .newMap(); public static void main(String[] args) throws SQLException, IOException, ClassNotFoundException {