From 050fd885605c068b191308990859b1517d6d26aa Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 12 Jul 2018 23:27:17 +0200 Subject: [PATCH] Added API changes --- .../appendtext/AppendTextCommandBase.java | 20 ++++++++++--------- .../chat/listener/PlayerListener.java | 14 +++++-------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java b/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java index 50afc8f..01255df 100644 --- a/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java +++ b/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java @@ -2,14 +2,13 @@ package buttondevteam.chat.commands.appendtext; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.listener.PlayerListener; -import buttondevteam.lib.chat.Channel; -import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.chat.TBMCChatAPI; -import buttondevteam.lib.chat.TBMCCommandBase; +import buttondevteam.lib.chat.*; import buttondevteam.lib.player.TBMCPlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import java.util.UUID; + @CommandClass(modOnly = false, excludeFromPath = true) public abstract class AppendTextCommandBase extends TBMCCommandBase { @@ -22,14 +21,17 @@ public abstract class AppendTextCommandBase extends TBMCCommandBase { String msg = GetAppendedText(); for (int i = args.length - 1; i >= 0; i--) msg = args[i] + " " + msg; + ChatPlayer cp; if (sender instanceof Player) - TBMCChatAPI.SendChatMessage( - TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class).CurrentChannel, sender, - msg, true); + TBMCChatAPI.SendChatMessage(ChatMessage.builder( + (cp = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class)).CurrentChannel, sender, + cp, msg).fromCommand(true).build()); else if (sender.isOp()) - TBMCChatAPI.SendChatMessage(PlayerListener.ConsoleChannel, sender, msg); + TBMCChatAPI.SendChatMessage(ChatMessage.builder(PlayerListener.ConsoleChannel, sender, + (cp = TBMCPlayer.getPlayer(new UUID(0, 0), ChatPlayer.class)), msg).build()); else - TBMCChatAPI.SendChatMessage(Channel.GlobalChat, sender, msg); + TBMCChatAPI.SendChatMessage(ChatMessage.builder(Channel.GlobalChat, sender, + (cp = TBMCPlayer.getPlayer(new UUID(0, 0), ChatPlayer.class)), msg).build()); //TODO return true; } } diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index d4bd7a1..1c379a8 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -5,10 +5,7 @@ import buttondevteam.chat.ChatProcessing; import buttondevteam.chat.PluginMain; import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.TBMCCoreAPI; -import buttondevteam.lib.chat.Channel; -import buttondevteam.lib.chat.ChatChannelRegisterEvent; -import buttondevteam.lib.chat.ChatRoom; -import buttondevteam.lib.chat.TBMCChatAPI; +import buttondevteam.lib.chat.*; import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerGetInfoEvent; @@ -59,9 +56,8 @@ public class PlayerListener implements Listener { public void onPlayerChat(AsyncPlayerChatEvent event) { if (event.isCancelled()) return; - TBMCChatAPI.SendChatMessage( - TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class).CurrentChannel, - event.getPlayer(), event.getMessage()); + ChatPlayer cp = TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class); + TBMCChatAPI.SendChatMessage(ChatMessage.builder(cp.CurrentChannel, event.getPlayer(), cp, event.getMessage()).build()); event.setCancelled(true); // The custom event should only be cancelled when muted or similar } @@ -79,7 +75,7 @@ public class PlayerListener implements Listener { if (sender instanceof Player) mp = TBMCPlayer.getPlayer(((Player) sender).getUniqueId(), ChatPlayer.class); else - mp = null; + mp = TBMCPlayer.getPlayer(new UUID(0, 0), ChatPlayer.class); //Use 0, 0 for console and whatever - TODO: Refactor console stuff String cmd; final BiPredicate checkchid = (chan, cmd1) -> cmd1.equalsIgnoreCase(chan.ID) || (chan.IDs != null && Arrays.stream(chan.IDs).anyMatch(cmd1::equalsIgnoreCase)); if (index == -1) { // Only the command is run @@ -138,7 +134,7 @@ public class PlayerListener implements Listener { } else for (Channel channel : Channel.getChannels()) { if (checkchid.test(channel, cmd)) { //Apparently method references don't require final variables - TBMCChatAPI.SendChatMessage(channel, sender, message.substring(index + 1)); + TBMCChatAPI.SendChatMessage(ChatMessage.builder(channel, sender, mp, message.substring(index + 1)).build()); return true; } }