mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 08:40:03 +00:00
@@ -21,16 +21,21 @@ public final class MessageHandlerChainSet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies the appropriate {@link MessageHandlerChain} that a {@link Message} has been received.
|
* Notifies the appropriate {@link MessageHandlerChain} that a {@link Message} has been received.
|
||||||
*
|
*
|
||||||
* @param player The {@link Player} receiving the Message.
|
* @param player The {@link Player} receiving the Message.
|
||||||
* @param message The Message.
|
* @param message The Message.
|
||||||
* @return {@code true} if the Message propagated down the chain without being terminated or if the chain for the
|
* @return {@code true} if the Message propagated down the chain without being terminated or if the chain for the
|
||||||
* Message was not found, otherwise {@code false}.
|
* Message was not found, otherwise {@code false}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public <M extends Message> boolean notify(Player player, M message) {
|
public <M extends Message> boolean notify(Player player, M message) {
|
||||||
@SuppressWarnings("unchecked")
|
Class<M> clazz = (Class<M>) message.getClass();
|
||||||
MessageHandlerChain<M> chain = (MessageHandlerChain<M>) chains.get(message.getClass());
|
while (clazz.getSuperclass() != Message.class) {
|
||||||
return chain == null || chain.notify(player, message);
|
clazz = (Class<M>) clazz.getSuperclass();
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageHandlerChain<M> chain = (MessageHandlerChain<M>) chains.computeIfAbsent(clazz, MessageHandlerChain::new);
|
||||||
|
return chain.notify(player, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public final class MessageHandlerChainSetParser {
|
|||||||
* @throws SAXException If a SAX error occurs.
|
* @throws SAXException If a SAX error occurs.
|
||||||
* @throws ReflectiveOperationException If a reflection error occurs.
|
* @throws ReflectiveOperationException If a reflection error occurs.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public MessageHandlerChainSet parse(World world) throws IOException, SAXException, ReflectiveOperationException {
|
public MessageHandlerChainSet parse(World world) throws IOException, SAXException, ReflectiveOperationException {
|
||||||
XmlNode messages = parser.parse(is);
|
XmlNode messages = parser.parse(is);
|
||||||
if (!messages.getName().equals("messages")) {
|
if (!messages.getName().equals("messages")) {
|
||||||
@@ -75,7 +76,6 @@ public final class MessageHandlerChainSetParser {
|
|||||||
throw new IOException("Type node must have a value.");
|
throw new IOException("Type node must have a value.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Class<? extends Message> messageClass = (Class<? extends Message>) Class.forName(messageClassName);
|
Class<? extends Message> messageClass = (Class<? extends Message>) Class.forName(messageClassName);
|
||||||
|
|
||||||
for (XmlNode handlerNode : chainNode) {
|
for (XmlNode handlerNode : chainNode) {
|
||||||
@@ -88,7 +88,6 @@ public final class MessageHandlerChainSetParser {
|
|||||||
throw new IOException("Handler node must have a value.");
|
throw new IOException("Handler node must have a value.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
Class<? extends MessageHandler<? extends Message>> handlerClass = (Class<? extends MessageHandler<? extends Message>>) Class.forName(handlerClassName);
|
Class<? extends MessageHandler<? extends Message>> handlerClass = (Class<? extends MessageHandler<? extends Message>>) Class.forName(handlerClassName);
|
||||||
MessageHandler<? extends Message> handler = handlerClass.getConstructor(World.class).newInstance(world);
|
MessageHandler<? extends Message> handler = handlerClass.getConstructor(World.class).newInstance(world);
|
||||||
chainSet.putHandler(messageClass, handler);
|
chainSet.putHandler(messageClass, handler);
|
||||||
|
|||||||
Reference in New Issue
Block a user