From 40a17399510af25f0399251529032ef27ff1a79e Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 27 Feb 2019 13:48:36 +0100 Subject: [PATCH] Moved /un... to its component --- .idea/ButtonChat.iml | 29 +----------- .../chat/components/fun/FunComponent.java | 45 ++++++++++++++++++- .../chat/listener/PlayerListener.java | 36 +++------------ 3 files changed, 52 insertions(+), 58 deletions(-) diff --git a/.idea/ButtonChat.iml b/.idea/ButtonChat.iml index 051580a..9b778e4 100644 --- a/.idea/ButtonChat.iml +++ b/.idea/ButtonChat.iml @@ -11,35 +11,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java index b0f18e2..53bfb23 100644 --- a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java +++ b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java @@ -2,17 +2,26 @@ package buttondevteam.chat.components.fun; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.PluginMain; -import buttondevteam.chat.listener.PlayerListener; import buttondevteam.lib.TBMCChatEventBase; +import buttondevteam.lib.TBMCCommandPreprocessEvent; +import buttondevteam.lib.TBMCSystemChatEvent; +import buttondevteam.lib.ThorpeUtils; import buttondevteam.lib.architecture.Component; +import buttondevteam.lib.chat.TBMCChatAPI; +import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.TBMCPlayer; import lombok.val; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.help.HelpTopic; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitTask; import java.util.ArrayList; @@ -25,8 +34,10 @@ public class FunComponent extends Component implements Listener { private BukkitTask Ftask = null; private ArrayList Fs = new ArrayList<>(); private UnlolCommand command; + private TBMCSystemChatEvent.BroadcastTarget unlolTarget; @Override protected void enable() { + unlolTarget = TBMCSystemChatEvent.BroadcastTarget.add("unlol"); val pc = new PressCommand(); registerCommand(pc); registerListener(pc); @@ -91,4 +102,36 @@ public class FunComponent extends Component implements Listener { public void onPlayerLeave(PlayerQuitEvent event) { command.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer())); } + + @EventHandler(priority = EventPriority.LOWEST) + public void onCommandPreprocess(TBMCCommandPreprocessEvent event) { + if (event.isCancelled()) return; + final String cmd = event.getMessage(); + // We don't care if we have arguments + if (cmd.toLowerCase().startsWith("/un")) { + for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap().getHelpTopics()) { + if (ht.getName().equalsIgnoreCase(cmd)) + return; + } + if (PluginMain.permission.has(event.getSender(), "thorpe.unanything")) { + event.setCancelled(true); + String s = cmd.substring(3); + int index = event.getMessage().indexOf(' '); + if (index == -1) { + event.getSender().sendMessage("§cUsage: /un" + s + " "); + return; + } + Player target = Bukkit.getPlayer(event.getMessage().substring(index + 1)); + if (target == null) { + event.getSender().sendMessage("§cError: Player not found. (/un" + s + " )"); + return; + } + val user = ChromaGamerBase.getFromSender(event.getSender()); + target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false)); + val chan = user.channel().get(); + TBMCChatAPI.SendSystemMessage(chan, chan.getRTR(event.getSender()), ThorpeUtils.getDisplayName(event.getSender()) + " un" + s + + "'d " + target.getDisplayName(), unlolTarget); + } + } + } } diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 1b50b8c..28fb592 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -5,7 +5,6 @@ import buttondevteam.chat.ChatProcessing; import buttondevteam.chat.PluginMain; import buttondevteam.chat.commands.ucmds.HistoryCommand; import buttondevteam.chat.components.flair.FlairComponent; -import buttondevteam.chat.components.fun.FunComponent; import buttondevteam.chat.components.towncolors.TownColorComponent; import buttondevteam.core.ComponentManager; import buttondevteam.core.component.channel.Channel; @@ -13,6 +12,8 @@ import buttondevteam.core.component.channel.ChatChannelRegisterEvent; import buttondevteam.core.component.channel.ChatRoom; import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.TBMCSystemChatEvent; +import buttondevteam.lib.ThorpeUtils; import buttondevteam.lib.chat.ChatMessage; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.player.ChromaGamerBase; @@ -33,16 +34,13 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.*; +import org.bukkit.event.player.AsyncPlayerChatEvent; +import org.bukkit.event.player.PlayerChatTabCompleteEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.server.ServerCommandEvent; -import org.bukkit.help.HelpTopic; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; import java.util.Arrays; import java.util.Map.Entry; -import java.util.Random; import java.util.UUID; import java.util.function.BiPredicate; @@ -100,12 +98,12 @@ public class PlayerListener implements Listener { if (cmd.equalsIgnoreCase("tpahere")) { Player player = Bukkit.getPlayer(message.substring(index + 1)); if (player != null && sender instanceof Player) - player.sendMessage("§b" + ((Player) sender).getDisplayName() + " §bis in this world: " + player.sendMessage("§b" + ((Player) sender).getDisplayName() + " §bis in this world: " //TODO: Move to the Core + ((Player) sender).getWorld().getName()); } else if (cmd.equalsIgnoreCase("minecraft:me")) { if (!(sender instanceof Player) || !PluginMain.essentials.getUser((Player) sender).isMuted()) { String msg = message.substring(index + 1); - Bukkit.broadcastMessage(String.format("* %s %s", sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName(), msg)); + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, String.format("* %s %s", ThorpeUtils.getDisplayName(sender), msg), TBMCSystemChatEvent.BroadcastTarget.ALL); //TODO: Don't send to all return true; } else { sender.sendMessage("§cCan't use /minecraft:me while muted."); @@ -129,26 +127,6 @@ public class PlayerListener implements Listener { } // TODO: Target selectors } - // We don't care if we have arguments - if (cmd.toLowerCase().startsWith("un")) { - for (HelpTopic ht : PluginMain.Instance.getServer().getHelpMap().getHelpTopics()) { - if (ht.getName().equalsIgnoreCase("/" + cmd)) - return false; - } - if (PluginMain.permission.has(sender, "tbmc.admin")) { - String s = cmd.substring(2); - Player target = Bukkit.getPlayer(message.substring(index + 1)); - if (target == null) { - sender.sendMessage("§cError: Player not found. (/un" + s + " )"); - return true; - } - target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 10 * 20, 5, false, false)); - Bukkit.broadcastMessage( - (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + " un" + s - + "'d " + target.getDisplayName()); - return true; - } - } return false; }