From f875985aa966b472fbdee93d9eab28748199978f Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 2 Mar 2019 18:56:01 +0100 Subject: [PATCH] Moved the MC chat handler here And gitignore is moved as well The chat handler doesn't interfere with displaying the chat, that's still handled by the chat plugin --- ButtonCore/.gitignore => .gitignore | 0 .../java/buttondevteam/core/PlayerListener.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+) rename ButtonCore/.gitignore => .gitignore (100%) diff --git a/ButtonCore/.gitignore b/.gitignore similarity index 100% rename from ButtonCore/.gitignore rename to .gitignore diff --git a/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java b/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java index d151e51..0ea7ac4 100755 --- a/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java +++ b/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java @@ -4,7 +4,10 @@ import buttondevteam.lib.TBMCCommandPreprocessEvent; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.architecture.ButtonPlugin; +import buttondevteam.lib.chat.ChatMessage; import buttondevteam.lib.chat.Command2MCSender; +import buttondevteam.lib.chat.TBMCChatAPI; +import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerBase; import lombok.val; import org.bukkit.Bukkit; @@ -13,6 +16,7 @@ import org.bukkit.event.Cancellable; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; +import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; @@ -70,4 +74,14 @@ public class PlayerListener implements Listener { TBMCCoreAPI.SendException("Command processing failed for sender '" + event.getSender() + "' and message '" + event.getMessage() + "'", e); } } + + @EventHandler(priority = EventPriority.HIGH) //The one in the chat plugin is set to highest + public void onPlayerChat(AsyncPlayerChatEvent event) { + if (event.isCancelled()) + return; //The chat plugin should cancel it after this handler + val cp = TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), TBMCPlayer.class); + TBMCChatAPI.SendChatMessage(ChatMessage.builder(event.getPlayer(), cp, event.getMessage()).build()); + //Not cancelling the original event here, it's cancelled in the chat plugin + //This way other plugins can deal with the MC formatting if the chat plugin isn't present, but other platforms still get the message + } } \ No newline at end of file