mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Move EventContext functionality into Event, remove EventContext, add LogoutEvent support.
This commit is contained in:
@@ -19,6 +19,7 @@ java_import 'org.apollo.game.message.handler.MessageHandler'
|
||||
java_import 'org.apollo.game.model.World'
|
||||
java_import 'org.apollo.game.model.entity.Player'
|
||||
java_import 'org.apollo.game.model.event.EventListener'
|
||||
java_import 'org.apollo.game.model.event.PlayerEvent'
|
||||
java_import 'org.apollo.game.model.setting.PrivilegeLevel'
|
||||
java_import 'org.apollo.game.scheduling.ScheduledTask'
|
||||
java_import 'org.apollo.util.plugin.PluginContext'
|
||||
@@ -66,8 +67,10 @@ class ProcEventListener
|
||||
end
|
||||
|
||||
# Executes the block handling the Event.
|
||||
def handle(event, context)
|
||||
@block.call(event, context)
|
||||
def handle(event)
|
||||
args = [ event ]
|
||||
args << event.player if event.kind_of?(PlayerEvent)
|
||||
@block.call(*args)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -42,8 +42,7 @@ on :message, :remove_friend do |ctx, player, message|
|
||||
end
|
||||
|
||||
# Update the friend server status and send the friend/ignore lists of the player logging in.
|
||||
on :login do |event, context|
|
||||
player = event.player
|
||||
on :login do |event, player|
|
||||
player.send(FriendServerStatusMessage.new(ServerStatus::CONNECTING))
|
||||
player.send(IgnoreListMessage.new(player.ignored_usernames)) if player.ignored_usernames.size > 0
|
||||
|
||||
@@ -63,8 +62,8 @@ on :login do |event, context|
|
||||
end
|
||||
|
||||
# Notifies the player's friends that the player has logged out.
|
||||
on :logout do |event, context|
|
||||
update_friends(event.player, 0)
|
||||
on :logout do |event, player|
|
||||
update_friends(player, 0)
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -44,14 +44,14 @@ end
|
||||
|
||||
# Appends a tiara to the list.
|
||||
def append_tiara(hash)
|
||||
raise 'Hash must contain a tiara id, altar id, talisman id, a bitshift number, and experience.' unless hash.has_key?(:tiara_id) && hash.has_key?(:altar) && hash.has_key?(:talisman) && hash.has_key?(:bitshift) && hash.has_key?(:experience)
|
||||
raise 'Hash must contain a tiara id, altar id, talisman id, a bitshift number, and experience.' unless hash.has_keys?(:altar, :bitshift, :experience, :talisman, :tiara_id)
|
||||
tiara_id = hash[:tiara_id]; altar = hash[:altar]; talisman = hash[:talisman]; bitshift = hash[:bitshift]; experience = hash[:experience]
|
||||
|
||||
TIARAS_BY_TALISMAN[talisman] = TIARAS_BY_ID[tiara_id] = TIARAS_BY_ALTAR[altar] = Tiara.new(tiara_id, altar, talisman, bitshift, experience)
|
||||
end
|
||||
|
||||
# Sets the correct config upon login, if the player is wearing a tiara.
|
||||
on :login do |event, context|
|
||||
on :login do |event, player|
|
||||
player = event.player
|
||||
hat = player.equipment.get(EquipmentConstants::HAT)
|
||||
|
||||
|
||||
@@ -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