mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-04 08:39:27 +00:00
Move EventContext functionality into Event, remove EventContext, add LogoutEvent support.
This commit is contained in:
@@ -20,6 +20,7 @@ import org.apollo.game.model.Position;
|
||||
import org.apollo.game.model.World;
|
||||
import org.apollo.game.model.area.Sector;
|
||||
import org.apollo.game.model.event.impl.LoginEvent;
|
||||
import org.apollo.game.model.event.impl.LogoutEvent;
|
||||
import org.apollo.game.model.inter.InterfaceConstants;
|
||||
import org.apollo.game.model.inter.InterfaceListener;
|
||||
import org.apollo.game.model.inter.InterfaceSet;
|
||||
@@ -600,7 +601,9 @@ public final class Player extends Mob {
|
||||
* Logs the player out, if possible.
|
||||
*/
|
||||
public void logout() {
|
||||
send(new LogoutMessage());
|
||||
if (World.getWorld().submit(new LogoutEvent(this))) {
|
||||
send(new LogoutMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,5 +6,26 @@ package org.apollo.game.model.event;
|
||||
* @author Major
|
||||
*/
|
||||
public abstract class Event {
|
||||
|
||||
/**
|
||||
* Indicates whether or not the Event chain has been terminated.
|
||||
*/
|
||||
private boolean terminated;
|
||||
|
||||
/**
|
||||
* Terminates the Event chain.
|
||||
*/
|
||||
public final void terminate() {
|
||||
terminated = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the Event chain has been terminated.
|
||||
*
|
||||
* @return {@code true} if the Event chain has been terminated, otherwise {@code false}.
|
||||
*/
|
||||
public final boolean terminated() {
|
||||
return terminated;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package org.apollo.game.model.event;
|
||||
|
||||
/**
|
||||
* The context of an {@link Event}.
|
||||
*
|
||||
* @author Major
|
||||
*/
|
||||
final class EventContext {
|
||||
|
||||
/**
|
||||
* Indicates whether or not the Event chain has been terminated.
|
||||
*/
|
||||
private boolean terminated;
|
||||
|
||||
/**
|
||||
* Terminates the Event chain.
|
||||
*/
|
||||
public void terminateEvent() {
|
||||
terminated = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether or not the Event chain has been terminated.
|
||||
*
|
||||
* @return {@code true} if the Event chain has been terminated, otherwise {@code false}.
|
||||
*/
|
||||
public boolean terminated() {
|
||||
return terminated;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,8 +14,7 @@ public interface EventListener<E> {
|
||||
* Handles the {@link Event} that occurred.
|
||||
*
|
||||
* @param event The Event.
|
||||
* @param context The {@link EventContext}.
|
||||
*/
|
||||
public void handle(E event, EventContext context);
|
||||
public void handle(E event);
|
||||
|
||||
}
|
||||
@@ -48,16 +48,15 @@ final class EventListenerChain<E extends Event> {
|
||||
* @return {@code true} if the Event should continue on with its outcome, {@code false} if not.
|
||||
*/
|
||||
public boolean notify(E event) {
|
||||
EventContext context = new EventContext();
|
||||
for (EventListener<E> listener : listeners) {
|
||||
listener.handle(event, context);
|
||||
listener.handle(event);
|
||||
|
||||
if (context.terminated()) {
|
||||
if (event.terminated()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user