mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-07 00:38:46 +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.World'
|
||||||
java_import 'org.apollo.game.model.entity.Player'
|
java_import 'org.apollo.game.model.entity.Player'
|
||||||
java_import 'org.apollo.game.model.event.EventListener'
|
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.model.setting.PrivilegeLevel'
|
||||||
java_import 'org.apollo.game.scheduling.ScheduledTask'
|
java_import 'org.apollo.game.scheduling.ScheduledTask'
|
||||||
java_import 'org.apollo.util.plugin.PluginContext'
|
java_import 'org.apollo.util.plugin.PluginContext'
|
||||||
@@ -66,8 +67,10 @@ class ProcEventListener
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Executes the block handling the Event.
|
# Executes the block handling the Event.
|
||||||
def handle(event, context)
|
def handle(event)
|
||||||
@block.call(event, context)
|
args = [ event ]
|
||||||
|
args << event.player if event.kind_of?(PlayerEvent)
|
||||||
|
@block.call(*args)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ on :message, :remove_friend do |ctx, player, message|
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Update the friend server status and send the friend/ignore lists of the player logging in.
|
# Update the friend server status and send the friend/ignore lists of the player logging in.
|
||||||
on :login do |event, context|
|
on :login do |event, player|
|
||||||
player = event.player
|
|
||||||
player.send(FriendServerStatusMessage.new(ServerStatus::CONNECTING))
|
player.send(FriendServerStatusMessage.new(ServerStatus::CONNECTING))
|
||||||
player.send(IgnoreListMessage.new(player.ignored_usernames)) if player.ignored_usernames.size > 0
|
player.send(IgnoreListMessage.new(player.ignored_usernames)) if player.ignored_usernames.size > 0
|
||||||
|
|
||||||
@@ -63,8 +62,8 @@ on :login do |event, context|
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Notifies the player's friends that the player has logged out.
|
# Notifies the player's friends that the player has logged out.
|
||||||
on :logout do |event, context|
|
on :logout do |event, player|
|
||||||
update_friends(event.player, 0)
|
update_friends(player, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -44,14 +44,14 @@ end
|
|||||||
|
|
||||||
# Appends a tiara to the list.
|
# Appends a tiara to the list.
|
||||||
def append_tiara(hash)
|
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]
|
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)
|
TIARAS_BY_TALISMAN[talisman] = TIARAS_BY_ID[tiara_id] = TIARAS_BY_ALTAR[altar] = Tiara.new(tiara_id, altar, talisman, bitshift, experience)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Sets the correct config upon login, if the player is wearing a tiara.
|
# 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
|
player = event.player
|
||||||
hat = player.equipment.get(EquipmentConstants::HAT)
|
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.World;
|
||||||
import org.apollo.game.model.area.Sector;
|
import org.apollo.game.model.area.Sector;
|
||||||
import org.apollo.game.model.event.impl.LoginEvent;
|
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.InterfaceConstants;
|
||||||
import org.apollo.game.model.inter.InterfaceListener;
|
import org.apollo.game.model.inter.InterfaceListener;
|
||||||
import org.apollo.game.model.inter.InterfaceSet;
|
import org.apollo.game.model.inter.InterfaceSet;
|
||||||
@@ -600,7 +601,9 @@ public final class Player extends Mob {
|
|||||||
* Logs the player out, if possible.
|
* Logs the player out, if possible.
|
||||||
*/
|
*/
|
||||||
public void logout() {
|
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
|
* @author Major
|
||||||
*/
|
*/
|
||||||
public abstract class Event {
|
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.
|
* Handles the {@link Event} that occurred.
|
||||||
*
|
*
|
||||||
* @param event The Event.
|
* @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.
|
* @return {@code true} if the Event should continue on with its outcome, {@code false} if not.
|
||||||
*/
|
*/
|
||||||
public boolean notify(E event) {
|
public boolean notify(E event) {
|
||||||
EventContext context = new EventContext();
|
|
||||||
for (EventListener<E> listener : listeners) {
|
for (EventListener<E> listener : listeners) {
|
||||||
listener.handle(event, context);
|
listener.handle(event);
|
||||||
|
|
||||||
if (context.terminated()) {
|
if (event.terminated()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user