Refactor Messenger to allow for custom prefixes.
- Messenger no longer has a static nature and must be instantiated to be used. The prefix is provided in the constructor. - MobArena instantiates a global Messenger in onEnable() with a prefix string from global-settings. This instance is used by anything that isn't arena-specific, as well as for arenas with no prefix. - ArenaImpl instantiates a local Messenger in its constructor if, and only if, its arena-specific prefix setting is non-empty. Otherwise it uses the plugin's global instance.
This commit is contained in:
@@ -11,28 +11,35 @@ import com.garbagemule.MobArena.framework.Arena;
|
||||
|
||||
public class Messenger
|
||||
{
|
||||
private Messenger() {}
|
||||
private final String prefix;
|
||||
|
||||
public static boolean tell(CommandSender p, String msg) {
|
||||
public Messenger(String prefix) {
|
||||
if (prefix.contains("&")) {
|
||||
prefix = ChatColor.translateAlternateColorCodes('&', prefix);
|
||||
}
|
||||
this.prefix = prefix;
|
||||
}
|
||||
|
||||
public boolean tell(CommandSender p, String msg) {
|
||||
// If the input sender is null or the string is empty, return.
|
||||
if (p == null || msg.equals("")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Otherwise, send the message with the [MobArena] tag.
|
||||
p.sendMessage(ChatColor.GREEN + "[MobArena] " + ChatColor.RESET + msg);
|
||||
p.sendMessage(prefix + ChatColor.RESET + msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean tell(CommandSender p, Msg msg, String s) {
|
||||
public boolean tell(CommandSender p, Msg msg, String s) {
|
||||
return tell(p, msg.format(s));
|
||||
}
|
||||
|
||||
public static boolean tell(CommandSender p, Msg msg) {
|
||||
public boolean tell(CommandSender p, Msg msg) {
|
||||
return tell(p, msg.toString());
|
||||
}
|
||||
|
||||
public static void announce(Arena arena, String msg) {
|
||||
public void announce(Arena arena, String msg) {
|
||||
List<Player> players = new ArrayList<Player>();
|
||||
players.addAll(arena.getPlayersInArena());
|
||||
players.addAll(arena.getPlayersInLobby());
|
||||
@@ -42,11 +49,11 @@ public class Messenger
|
||||
}
|
||||
}
|
||||
|
||||
public static void announce(Arena arena, Msg msg, String s) {
|
||||
public void announce(Arena arena, Msg msg, String s) {
|
||||
announce(arena, msg.format(s));
|
||||
}
|
||||
|
||||
public static void announce(Arena arena, Msg msg) {
|
||||
public void announce(Arena arena, Msg msg) {
|
||||
announce(arena, msg.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user