Implement Chat Formatting per platform

This commit is contained in:
Aikar
2017-06-27 00:24:05 -04:00
parent 2e493fcb49
commit cd109eb266
17 changed files with 250 additions and 45 deletions
@@ -28,9 +28,11 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class BukkitCommandIssuer implements CommandIssuer {
private final BukkitCommandManager manager;
private final CommandSender sender;
BukkitCommandIssuer(CommandSender sender) {
BukkitCommandIssuer(BukkitCommandManager manager, CommandSender sender) {
this.manager = manager;
this.sender = sender;
}
@@ -47,14 +49,7 @@ public class BukkitCommandIssuer implements CommandIssuer {
@Override
public void sendMessage(MessageType type, String message) {
switch (type) {
case ERROR:
case SYNTAX:
sender.sendMessage(ChatColor.RED + ACFBukkitUtil.color(message));
break;
default:
sender.sendMessage(ChatColor.YELLOW + ACFBukkitUtil.color(message));
}
sender.sendMessage(ACFBukkitUtil.color(format(manager, type, message)));
}
@Override
@@ -27,6 +27,7 @@ import co.aikar.commands.apachecommonslang.ApacheCommonsExceptionUtil;
import co.aikar.timings.lib.MCTiming;
import co.aikar.timings.lib.TimingManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException;
@@ -89,6 +90,9 @@ public class BukkitCommandManager extends CommandManager {
ACFUtil.sneaky(e);
}
this.commandMap = commandMap;
this.formatters.put(MessageType.ERROR, new BukkitMessageFormatter(ChatColor.RED, ChatColor.YELLOW, ChatColor.RED));
this.formatters.put(MessageType.SYNTAX, new BukkitMessageFormatter(ChatColor.YELLOW, ChatColor.GREEN, ChatColor.WHITE));
this.formatters.put(MessageType.INFO, new BukkitMessageFormatter(ChatColor.BLUE, ChatColor.DARK_GREEN, ChatColor.GREEN));
Bukkit.getPluginManager().registerEvents(new ACFBukkitListener(plugin), plugin);
}
@@ -184,7 +188,7 @@ public class BukkitCommandManager extends CommandManager {
if (!(issuer instanceof CommandSender)) {
throw new IllegalArgumentException(issuer.getClass().getName() + " is not a Command Issuer.");
}
return new BukkitCommandIssuer((CommandSender) issuer);
return new BukkitCommandIssuer(this, (CommandSender) issuer);
}
@Override
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2016-2017 Daniel Ennis (Aikar) - MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package co.aikar.commands;
import org.bukkit.ChatColor;
public class BukkitMessageFormatter implements MessageFormatter {
private final ChatColor color1;
private final ChatColor color2;
private final ChatColor color3;
public BukkitMessageFormatter(ChatColor color1) {
this(color1, color1);
}
public BukkitMessageFormatter(ChatColor color1, ChatColor color2) {
this(color1, color2, color2);
}
public BukkitMessageFormatter(ChatColor color1, ChatColor color2, ChatColor color3) {
this.color1 = color1;
this.color2 = color2;
this.color3 = color3;
}
@Override
public String c1(String message) {
return color1 + message;
}
@Override
public String c2(String message) {
return color2 + message;
}
@Override
public String c3(String message) {
return color3 + message;
}
}
@@ -51,12 +51,12 @@ public class BukkitRootCommand extends Command implements RootCommand {
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException {
return tabComplete(new BukkitCommandIssuer(sender), alias, args);
return tabComplete(new BukkitCommandIssuer(manager, sender), alias, args);
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
return execute(new BukkitCommandIssuer(sender), commandLabel, args);
return execute(new BukkitCommandIssuer(manager, sender), commandLabel, args);
}
private List<String> tabComplete(CommandIssuer sender, String alias, String[] args) throws IllegalArgumentException {