From 39d932bf777bda394f1a08e9b081e284ebb04e7f Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 25 Nov 2016 19:46:23 +0100 Subject: [PATCH] Added support for the chat event --- .../java/buttondevteam/chat/ChatProcessing.java | 4 ++-- .../appendtext/AppendTextCommandBase.java | 15 +++++++++++++-- .../chat/listener/PlayerListener.java | 13 +++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index e72e40a..885306b 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -46,7 +46,7 @@ public class ChatProcessing { private static boolean pingedconsole = false; // Returns e.setCancelled - public static boolean ProcessChat(CommandSender sender, String message) { + public static boolean ProcessChat(Channel channel, CommandSender sender, String message) { long processstart = System.nanoTime(); if (PluginMain.essentials == null) PluginMain.essentials = (Essentials) (Bukkit.getPluginManager().getPlugin("Essentials")); @@ -81,7 +81,7 @@ public class ChatProcessing { } } } - Channel currentchannel = (mp == null ? PlayerListener.ConsoleChannel : mp.CurrentChannel); + Channel currentchannel = channel; ArrayList formatters = new ArrayList(); diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java b/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java index 497058c..a81d352 100644 --- a/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java +++ b/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java @@ -1,8 +1,13 @@ package buttondevteam.chat.commands.appendtext; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; -import buttondevteam.chat.ChatProcessing; +import buttondevteam.chat.ChatPlayer; +import buttondevteam.chat.listener.PlayerListener; +import buttondevteam.lib.TBMCPlayer; +import buttondevteam.lib.chat.Channel; +import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCCommandBase; public abstract class AppendTextCommandBase extends TBMCCommandBase { @@ -16,7 +21,13 @@ public abstract class AppendTextCommandBase extends TBMCCommandBase { String msg = GetAppendedText(); for (int i = args.length - 1; i >= 0; i--) msg = args[i] + " " + msg; - ChatProcessing.ProcessChat(sender, msg); + if (sender instanceof Player) + TBMCChatAPI.SendChatMessage( + TBMCPlayer.getPlayer((Player) sender).asPluginPlayer(ChatPlayer.class).CurrentChannel, sender, msg); + else if (sender.isOp()) + TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, sender, msg); + else + TBMCChatAPI.SendChatMessage(Channel.GlobalChat, sender, msg); return true; } diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 89b8b1d..b63f06e 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -27,9 +27,11 @@ import org.bukkit.potion.PotionEffectType; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.ChatProcessing; import buttondevteam.chat.PluginMain; +import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.TBMCPlayer; import buttondevteam.lib.TBMCPlayer.InfoTarget; import buttondevteam.lib.chat.Channel; +import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.TBMCPlayerGetInfoEvent; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -64,7 +66,9 @@ public class PlayerListener implements Listener { public void onPlayerChat(AsyncPlayerChatEvent event) { if (event.isCancelled()) return; - event.setCancelled(ChatProcessing.ProcessChat(event.getPlayer(), event.getMessage())); + TBMCChatAPI.SendChatMessage( + TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class).CurrentChannel, + event.getPlayer(), event.getMessage()); } @EventHandler(priority = EventPriority.HIGHEST) @@ -288,7 +292,7 @@ public class PlayerListener implements Listener { if (cmd.equalsIgnoreCase(channel.Command)) { Channel c = ConsoleChannel; ConsoleChannel = channel; - ChatProcessing.ProcessChat(Bukkit.getServer().getConsoleSender(), + TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, Bukkit.getConsoleSender(), event.getCommand().substring(index + 1)); ConsoleChannel = c; event.setCommand("dontrunthiscmd"); @@ -329,4 +333,9 @@ public class PlayerListener implements Listener { e.addInfo("/r/TheButton flair: " + flair); e.addInfo("Respect: " + (double) cp.getFCount() / (double) cp.getFDeaths()); } + + @EventHandler + public void onPlayerTBMCChat(TBMCChatEvent e) { + ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage()); + } }