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