MassiveCore - Object Titles and Mixed Messages

This commit is contained in:
Olof Larsson 2016-03-15 20:44:22 +01:00
parent e7a397668b
commit 0a297211bf

View File

@ -67,7 +67,6 @@ public class MessageMixinDefault extends MessageMixinAbstract
// One // One
// NOTE: The core implementation // NOTE: The core implementation
@SuppressWarnings("unchecked")
@Override @Override
public boolean messageOne(Object sendeeObject, Collection<?> messages) public boolean messageOne(Object sendeeObject, Collection<?> messages)
{ {
@ -79,41 +78,34 @@ public class MessageMixinDefault extends MessageMixinAbstract
if (messages == null) return false; if (messages == null) return false;
if (messages.isEmpty()) return false; if (messages.isEmpty()) return false;
// Type Switch // For each Message
Object first = messages.iterator().next(); for (Object message : messages)
if (first instanceof String)
{ {
// String if (message instanceof String)
Collection<String> strings = (Collection<String>) messages;
sendee.sendMessage(strings.toArray(new String[0]));
return true;
}
else if (first instanceof Mson)
{
// Mson
Collection<Mson> msons = (Collection<Mson>) messages;
if (sendee instanceof Player && NmsPacket.get().isAvailable())
{ {
Player player = (Player) sendee; String string = (String)message;
for (Mson mson : msons) 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()); NmsPacket.sendRaw(player, mson.toRaw());
} }
} else
else
{
for (Mson mson : msons)
{ {
sendee.sendMessage(mson.toPlain(true)); sendee.sendMessage(mson.toPlain(true));
} }
} }
return true; else
} {
else String desc = (message == null ? "null" : message.getClass().getSimpleName());
{ throw new IllegalArgumentException(desc + " is neither String nor Mson.");
String desc = first == null ? "null" : first.getClass().getSimpleName(); }
throw new IllegalArgumentException(desc + " is neither String nor Mson.");
} }
return true;
} }
} }