1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-09 08:52:51 +00:00

Better event system

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-18 02:09:14 -03:00
parent be329a50e9
commit cd41122035
34 changed files with 660 additions and 186 deletions

View File

@@ -36,12 +36,6 @@ public class Pet extends Player implements Summonable {
*/
private ItemID itemID;
@Override
public void teleport(Coordinate coordinate) {
// TODO Auto-generated method stub
}
@Override
public void summon(Coordinate coordinate) {
// TODO Auto-generated method stub

View File

@@ -18,8 +18,6 @@ package com.l2jserver.model.world;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.model.world.capability.Playable;
import com.l2jserver.model.world.capability.Teleportable;
import com.l2jserver.util.dimensional.Coordinate;
/**
* {@link Player} is any object that can be controlled by the player. The most
@@ -27,13 +25,6 @@ import com.l2jserver.util.dimensional.Coordinate;
*
* @author Rogiel
*/
public abstract class Player extends AbstractActor implements Playable, Actor,
Teleportable {
@Override
public void teleport(Coordinate coordinate) {
// final PlayerTeleportEvent event = new PlayerTeleportEvent(this,
// coordinate);
// this.setPosition(coordinate);
// event.dispatch();
}
public abstract class Player extends AbstractActor implements Playable, Actor {
}

View File

@@ -16,13 +16,24 @@
*/
package com.l2jserver.model.world.actor.event;
import com.l2jserver.model.world.capability.Actor;
import com.l2jserver.service.game.world.event.WorldEvent;
import com.l2jserver.service.game.world.event.WorldListener;
/**
* Base listener for {@link Actor} instances
* This listener will filter to only dispatch {@link ActorEvent} events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface ActorListener extends WorldListener<ActorEvent> {
public abstract class ActorListener implements WorldListener {
@Override
public boolean dispatch(WorldEvent e) {
if (!(e instanceof ActorEvent))
return false;
return dispatch((ActorEvent) e);
}
/**
* @see WorldListener#dispatch(WorldEvent)
*/
protected abstract boolean dispatch(ActorEvent e);
}

View File

@@ -31,6 +31,6 @@ import com.l2jserver.service.game.world.event.WorldListener;
* @param <E>
* the event type
*/
public interface Listenable<L extends WorldListener<E>, E extends WorldEvent>
public interface Listenable<L extends WorldListener, E extends WorldEvent>
extends ObjectCapability {
}

View File

@@ -1,31 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Defines an {@link AbstractObject} that can be teleported by
* {@link Teleporter} objects. Note that it is also possible to teleport
* <b>without</b> a teleporter!
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Teleportable extends ObjectCapability, Positionable, Spawnable {
void teleport(Coordinate coordinate);
}

View File

@@ -1,30 +0,0 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.model.world.capability;
import com.l2jserver.model.world.AbstractObject;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Defines an {@link AbstractObject} that can teleport {@link Teleportable}
* objects.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface Teleporter extends ObjectCapability {
void teleport(Coordinate coord, Teleportable target);
}

View File

@@ -29,7 +29,7 @@ import com.l2jserver.model.world.capability.Listenable;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterLoggedInEvent implements CharacterEvent {
public class CharacterEnterWorldEvent implements CharacterEvent {
/**
* The character that is logging in
*/
@@ -47,7 +47,7 @@ public class CharacterLoggedInEvent implements CharacterEvent {
* @param date
* the login date
*/
public CharacterLoggedInEvent(L2Character character, Date date) {
public CharacterEnterWorldEvent(L2Character character, Date date) {
this.character = character;
this.date = date;
}
@@ -58,7 +58,7 @@ public class CharacterLoggedInEvent implements CharacterEvent {
* @param character
* the character
*/
public CharacterLoggedInEvent(L2Character character) {
public CharacterEnterWorldEvent(L2Character character) {
this(character, new Date());
}

View File

@@ -0,0 +1,96 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* l2jserver is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.model.world.character.event;
import java.util.Date;
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.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterLeaveWorldEvent implements CharacterEvent {
/**
* The character that is logging in
*/
private final L2Character character;
/**
* The time that this character has logged off
*/
private final Date date;
/**
* Creates a new instance
*
* @param character
* the character
* @param date
* the logout date
*/
public CharacterLeaveWorldEvent(L2Character character, Date date) {
this.character = character;
this.date = date;
}
/**
* Creates a new instance. Login date is set to now.
*
* @param character
* the character
*/
public CharacterLeaveWorldEvent(L2Character character) {
this(character, new Date());
}
/**
* @return the logout date
*/
public Date getDate() {
return date;
}
@Override
public Player getPlayer() {
return character;
}
@Override
public Actor getActor() {
return character;
}
@Override
public WorldObject getObject() {
return character;
}
@Override
public L2Character getCharacter() {
return character;
}
@Override
public Listenable<?, ?>[] getDispatchableObjects() {
return new Listenable<?, ?>[] { character };
}
}

View File

@@ -16,18 +16,17 @@
*/
package com.l2jserver.model.world.character.event;
import com.l2jserver.model.world.player.event.PlayerEvent;
import com.l2jserver.model.world.player.event.PlayerListener;
import com.l2jserver.service.game.world.event.WorldEvent;
import com.l2jserver.service.game.world.event.WorldListener;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
* This listener will filter to only dispatch {@link CharacterEvent} events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class CharacterListener extends PlayerListener {
public abstract class CharacterListener implements WorldListener {
@Override
protected boolean dispatch(PlayerEvent e) {
public boolean dispatch(WorldEvent e) {
if (!(e instanceof CharacterEvent))
return false;
return dispatch((CharacterEvent) e);

View File

@@ -16,12 +16,24 @@
*/
package com.l2jserver.model.world.clan;
import com.l2jserver.service.game.world.event.WorldEvent;
import com.l2jserver.service.game.world.event.WorldListener;
/**
* Base listener for {@link ClanEvent}
* This listener will filter to only dispatch {@link ClanEvent} events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface ClanListener extends WorldListener<ClanEvent> {
public abstract class ClanListener implements WorldListener {
@Override
public boolean dispatch(WorldEvent e) {
if (!(e instanceof ClanEvent))
return false;
return dispatch((ClanEvent) e);
}
/**
* @see WorldListener#dispatch(WorldEvent)
*/
protected abstract boolean dispatch(ClanEvent e);
}

View File

@@ -16,12 +16,24 @@
*/
package com.l2jserver.model.world.item;
import com.l2jserver.service.game.world.event.WorldEvent;
import com.l2jserver.service.game.world.event.WorldListener;
/**
* Listener for {@link ItemEvent}
* This listener will filter to only dispatch {@link ItemEvent} events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface ItemListener extends WorldListener<ItemEvent> {
public abstract class ItemListener implements WorldListener {
@Override
public boolean dispatch(WorldEvent e) {
if (!(e instanceof ItemEvent))
return false;
return dispatch((ItemEvent) e);
}
/**
* @see WorldListener#dispatch(WorldEvent)
*/
protected abstract boolean dispatch(ItemEvent e);
}

View File

@@ -16,12 +16,24 @@
*/
package com.l2jserver.model.world.party;
import com.l2jserver.service.game.world.event.WorldEvent;
import com.l2jserver.service.game.world.event.WorldListener;
/**
* Listener for {@link PartyEvent}
* This listener will filter to only dispatch {@link PartyEvent} events.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public interface PartyListener extends WorldListener<PartyEvent> {
public abstract class PartyListener implements WorldListener {
@Override
public boolean dispatch(WorldEvent e) {
if (!(e instanceof PartyEvent))
return false;
return dispatch((PartyEvent) e);
}
/**
* @see WorldListener#dispatch(WorldEvent)
*/
protected abstract boolean dispatch(PartyEvent e);
}

View File

@@ -16,8 +16,6 @@
*/
package com.l2jserver.model.world.player.event;
import com.l2jserver.model.world.actor.event.ActorEvent;
import com.l2jserver.model.world.actor.event.ActorListener;
import com.l2jserver.service.game.world.event.WorldEvent;
import com.l2jserver.service.game.world.event.WorldListener;
@@ -26,9 +24,9 @@ import com.l2jserver.service.game.world.event.WorldListener;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class PlayerListener implements ActorListener {
public abstract class PlayerListener implements WorldListener {
@Override
public boolean dispatch(ActorEvent e) {
public boolean dispatch(WorldEvent e) {
if (!(e instanceof PlayerEvent))
return false;
return dispatch((PlayerEvent) e);

View File

@@ -20,7 +20,7 @@ import com.l2jserver.model.world.Player;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Event dispatched once an player is teleported.
* Event dispatched once an player is teleported to another location
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/