New features for the message mixin.

This commit is contained in:
Olof Larsson 2013-03-02 15:41:05 +01:00
parent b00eb28834
commit 8e071f2f6f
4 changed files with 259 additions and 77 deletions

View File

@ -4,21 +4,55 @@ import java.util.Collection;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore.Predictate;
public interface MessageMixin
{
public boolean message(CommandSender sender, String message);
public boolean message(CommandSender sender, Collection<String> messages);
public boolean message(CommandSender sender, String... messages);
// -------------------------------------------- //
// RAW MESSAGE
// -------------------------------------------- //
public boolean message(String senderId, String message);
public boolean message(String senderId, Collection<String> messages);
public boolean message(String senderId, String... messages);
// All
public boolean message(String message);
public boolean message(String... messages);
public boolean message(Collection<String> messages);
public boolean msg(CommandSender sender, String msg);
public boolean msg(CommandSender sender, String msg, Object... args);
public boolean msg(CommandSender sender, Collection<String> msgs);
// Predictate
public boolean message(Predictate<CommandSender> predictate, String message);
public boolean message(Predictate<CommandSender> predictate, String... messages);
public boolean message(Predictate<CommandSender> predictate, Collection<String> messages);
public boolean msg(String senderId, String msg);
public boolean msg(String senderId, String msg, Object... args);
public boolean msg(String senderId, Collection<String> msgs);
// One
public boolean message(CommandSender sendee, String message);
public boolean message(CommandSender sendee, String... messages);
public boolean message(CommandSender sendee, Collection<String> messages);
// One by id
public boolean message(String sendeeId, String message);
public boolean message(String sendeeId, String... messages);
public boolean message(String sendeeId, Collection<String> messages);
// -------------------------------------------- //
// PARSE MESSAGE
// -------------------------------------------- //
// All
public boolean msg(String msg);
public boolean msg(String msg, Object... args);
public boolean msg(Collection<String> msgs);
// Predictate
public boolean msg(Predictate<CommandSender> predictate, String msg);
public boolean msg(Predictate<CommandSender> predictate, String msg, Object... args);
public boolean msg(Predictate<CommandSender> predictate, Collection<String> msgs);
// One
public boolean msg(CommandSender sendee, String msg);
public boolean msg(CommandSender sendee, String msg, Object... args);
public boolean msg(CommandSender sendee, Collection<String> msgs);
// One by id
public boolean msg(String sendeeId, String msg);
public boolean msg(String sendeeId, String msg, Object... args);
public boolean msg(String sendeeId, Collection<String> msgs);
}

View File

@ -1,76 +1,151 @@
package com.massivecraft.mcore.mixin;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore.Predictate;
import com.massivecraft.mcore.util.MUtil;
import com.massivecraft.mcore.util.Txt;
public abstract class MessageMixinAbstract implements MessageMixin
{
// -------------------------------------------- //
// RAW MESSAGE
// -------------------------------------------- //
// All
@Override
public boolean message(CommandSender sender, String... messages)
public boolean message(String message)
{
Collection<String> coll = new ArrayList<String>(Arrays.asList(messages));
return this.message(sender, coll);
return this.message(MUtil.list(message));
}
@Override
public boolean message(String... messages)
{
return this.message(Arrays.asList(messages));
}
// Predictate
@Override
public boolean message(Predictate<CommandSender> predictate, String message)
{
return this.message(predictate, MUtil.list(message));
}
@Override
public boolean message(Predictate<CommandSender> predictate, String... messages)
{
return this.message(predictate, Arrays.asList(messages));
}
// One
@Override
public boolean message(CommandSender sendee, String message)
{
return this.message(sendee, MUtil.list(message));
}
@Override
public boolean message(CommandSender sendee, String... messages)
{
return this.message(sendee, Arrays.asList(messages));
}
// One by id
@Override
public boolean message(String sendeeId, String message)
{
return this.message(sendeeId, MUtil.list(message));
}
@Override
public boolean message(String sendeeId, String... messages)
{
return this.message(sendeeId, Arrays.asList(messages));
}
// -------------------------------------------- //
// PARSE MESSAGE
// -------------------------------------------- //
// They are all in abstract!
// All
@Override
public boolean message(String senderId, String... messages)
public boolean msg(String msg)
{
Collection<String> coll = new ArrayList<String>(Arrays.asList(messages));
return this.message(senderId, coll);
return this.message(Txt.parse(msg));
}
@Override
public boolean msg(CommandSender sender, String msg)
public boolean msg(String msg, Object... args)
{
return this.message(sender, Txt.parse(msg));
return this.message(Txt.parse(msg, args));
}
@Override
public boolean msg(CommandSender sender, String msg, Object... args)
public boolean msg(Collection<String> msgs)
{
return this.message(sender, Txt.parse(msg, args));
return this.message(Txt.parse(msgs));
}
// Predictate
@Override
public boolean msg(CommandSender sender, Collection<String> msgs)
public boolean msg(Predictate<CommandSender> predictate, String msg)
{
List<String> messages = new ArrayList<String>();
for (String msg : msgs)
{
String message = Txt.parse(msg);
messages.add(message);
}
return this.message(sender, messages);
return this.message(predictate, Txt.parse(msg));
}
@Override
public boolean msg(String senderId, String msg)
public boolean msg(Predictate<CommandSender> predictate, String msg, Object... args)
{
return this.message(senderId, Txt.parse(msg));
return this.message(predictate, Txt.parse(msg, args));
}
@Override
public boolean msg(String senderId, String msg, Object... args)
public boolean msg(Predictate<CommandSender> predictate, Collection<String> msgs)
{
return this.message(senderId, Txt.parse(msg, args));
return this.message(predictate, Txt.parse(msgs));
}
// One
@Override
public boolean msg(String senderId, Collection<String> msgs)
public boolean msg(CommandSender sendee, String msg)
{
List<String> messages = new ArrayList<String>();
for (String msg : msgs)
{
String message = Txt.parse(msg);
messages.add(message);
}
return this.message(senderId, messages);
return this.message(sendee, Txt.parse(msg));
}
@Override
public boolean msg(CommandSender sendee, String msg, Object... args)
{
return this.message(sendee, Txt.parse(msg, args));
}
@Override
public boolean msg(CommandSender sendee, Collection<String> msgs)
{
return this.message(sendee, Txt.parse(msgs));
}
// One by id
@Override
public boolean msg(String sendeeId, String msg)
{
return this.message(sendeeId, Txt.parse(msg));
}
@Override
public boolean msg(String sendeeId, String msg, Object... args)
{
return this.message(sendeeId, Txt.parse(msg, args));
}
@Override
public boolean msg(String sendeeId, Collection<String> msgs)
{
return this.message(sendeeId, Txt.parse(msgs));
}
}

View File

@ -4,6 +4,7 @@ import java.util.Collection;
import org.bukkit.command.CommandSender;
import com.massivecraft.mcore.Predictate;
import com.massivecraft.mcore.util.SenderUtil;
public class MessageMixinDefault extends MessageMixinAbstract
@ -20,36 +21,47 @@ public class MessageMixinDefault extends MessageMixinAbstract
// -------------------------------------------- //
@Override
public boolean message(CommandSender sender, String message)
public boolean message(Collection<String> messages)
{
if (sender == null) return false;
if (message == null) return false;
sender.sendMessage(message);
return true;
}
@Override
public boolean message(CommandSender sender, Collection<String> messages)
{
if (sender == null) return false;
if (messages == null) return false;
for (String message : messages)
for (CommandSender sender : SenderUtil.getOnlineSenders())
{
sender.sendMessage(message);
this.message(sender, messages);
}
return true;
}
@Override
public boolean message(String senderId, String message)
public boolean message(Predictate<CommandSender> predictate, Collection<String> messages)
{
return this.message(SenderUtil.getSender(senderId), message);
if (predictate == null) return false;
if (messages == null) return false;
for (CommandSender sender : SenderUtil.getOnlineSenders())
{
if (!predictate.apply(sender)) continue;
this.message(sender, messages);
}
return true;
}
@Override
public boolean message(String senderId, Collection<String> messages)
public boolean message(CommandSender sendee, Collection<String> messages)
{
return this.message(SenderUtil.getSender(senderId), messages);
if (sendee == null) return false;
if (messages == null) return false;
for (String message : messages)
{
sendee.sendMessage(message);
}
return true;
}
@Override
public boolean message(String sendeeId, Collection<String> messages)
{
if (sendeeId == null) return false;
if (messages == null) return false;
return this.message(SenderUtil.getSender(sendeeId), messages);
}
}

View File

@ -10,6 +10,7 @@ import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;
import com.massivecraft.mcore.PS;
import com.massivecraft.mcore.Predictate;
public class Mixin
{
@ -345,32 +346,91 @@ public class Mixin
// STATIC EXPOSE: MESSAGE
// -------------------------------------------- //
// All
public static boolean message(String message)
{
return getMessageMixin().message(message);
}
public static boolean message(String... messages)
{
return getMessageMixin().message(messages);
}
public static boolean message(Collection<String> messages)
{
return getMessageMixin().message(messages);
}
// Predictate
public static boolean message(Predictate<CommandSender> predictate, String message)
{
return getMessageMixin().message(predictate, message);
}
public static boolean message(Predictate<CommandSender> predictate, String... messages)
{
return getMessageMixin().message(predictate, messages);
}
public static boolean message(Predictate<CommandSender> predictate, Collection<String> messages)
{
return getMessageMixin().message(predictate, messages);
}
// One
public static boolean message(CommandSender sender, String message)
{
return getMessageMixin().message(sender, message);
}
public static boolean message(CommandSender sender, Collection<String> messages)
{
return getMessageMixin().message(sender, messages);
}
public static boolean message(CommandSender sender, String... messages)
{
return getMessageMixin().message(sender, messages);
}
public static boolean message(CommandSender sender, Collection<String> messages)
{
return getMessageMixin().message(sender, messages);
}
// One by id
public static boolean message(String senderId, String message)
{
return getMessageMixin().message(senderId, message);
}
public static boolean message(String senderId, Collection<String> messages)
{
return getMessageMixin().message(senderId, messages);
}
public static boolean message(String senderId, String... messages)
{
return getMessageMixin().message(senderId, messages);
}
public static boolean message(String senderId, Collection<String> messages)
{
return getMessageMixin().message(senderId, messages);
}
// All
public static boolean msg(String msg)
{
return getMessageMixin().msg(msg);
}
public static boolean msg(String msg, Object... args)
{
return getMessageMixin().msg(msg, args);
}
public static boolean msg(Collection<String> msgs)
{
return getMessageMixin().msg(msgs);
}
// Predictate
public static boolean msg(Predictate<CommandSender> predictate, String msg)
{
return getMessageMixin().msg(predictate, msg);
}
public static boolean msg(Predictate<CommandSender> predictate, String msg, Object... args)
{
return getMessageMixin().msg(predictate, msg, args);
}
public static boolean msg(Predictate<CommandSender> predictate, Collection<String> msgs)
{
return getMessageMixin().msg(predictate, msgs);
}
// One
public static boolean msg(CommandSender sender, String msg)
{
return getMessageMixin().msg(sender, msg);
@ -384,6 +444,7 @@ public class Mixin
return getMessageMixin().msg(sender, msgs);
}
// One by id
public static boolean msg(String senderId, String msg)
{
return getMessageMixin().msg(senderId, msg);