From 0a297211bf4bec2730adf190f3cc16c1022ed145 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 15 Mar 2016 20:44:22 +0100 Subject: [PATCH] MassiveCore - Object Titles and Mixed Messages --- .../mixin/MessageMixinDefault.java | 44 ++++++++----------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/src/com/massivecraft/massivecore/mixin/MessageMixinDefault.java b/src/com/massivecraft/massivecore/mixin/MessageMixinDefault.java index e22db854..6c7c37b2 100644 --- a/src/com/massivecraft/massivecore/mixin/MessageMixinDefault.java +++ b/src/com/massivecraft/massivecore/mixin/MessageMixinDefault.java @@ -67,7 +67,6 @@ public class MessageMixinDefault extends MessageMixinAbstract // One // NOTE: The core implementation - @SuppressWarnings("unchecked") @Override public boolean messageOne(Object sendeeObject, Collection messages) { @@ -79,41 +78,34 @@ public class MessageMixinDefault extends MessageMixinAbstract if (messages == null) return false; if (messages.isEmpty()) return false; - // Type Switch - Object first = messages.iterator().next(); - if (first instanceof String) + // For each Message + for (Object message : messages) { - // String - Collection strings = (Collection) messages; - sendee.sendMessage(strings.toArray(new String[0])); - return true; - } - else if (first instanceof Mson) - { - // Mson - Collection msons = (Collection) messages; - if (sendee instanceof Player && NmsPacket.get().isAvailable()) + if (message instanceof String) { - Player player = (Player) sendee; - for (Mson mson : msons) + String string = (String)message; + sendee.sendMessage(string); + } + else if (message instanceof Mson) + { + Mson mson = (Mson)message; + if (sendee instanceof Player && NmsPacket.get().isAvailable()) { + Player player = (Player) sendee; NmsPacket.sendRaw(player, mson.toRaw()); } - } - else - { - for (Mson mson : msons) + else { sendee.sendMessage(mson.toPlain(true)); } } - return true; - } - else - { - String desc = first == null ? "null" : first.getClass().getSimpleName(); - throw new IllegalArgumentException(desc + " is neither String nor Mson."); + else + { + String desc = (message == null ? "null" : message.getClass().getSimpleName()); + throw new IllegalArgumentException(desc + " is neither String nor Mson."); + } } + return true; } }