From 1d1b3453b35847997b6c6e6e3b06768552256945 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 22 Aug 2017 01:37:54 +0200 Subject: [PATCH] Added support for /ignore, improved unlols --- .../buttondevteam/chat/ChatProcessing.java | 24 +++++++----- .../java/buttondevteam/chat/PluginMain.java | 2 +- .../chat/commands/UnlolCommand.java | 39 +++++++++++++------ .../listener/PlayerJoinLeaveListener.java | 2 + 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index ef8bdae..199e533 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -19,11 +19,13 @@ import buttondevteam.chat.commands.UnlolCommand; import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.formatting.*; import buttondevteam.lib.TBMCChatEvent; +import buttondevteam.lib.TBMCChatEventBase; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.chat.Channel; import buttondevteam.lib.chat.TellrawSerializableEnum; import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerBase; +import lombok.val; import buttondevteam.chat.listener.PlayerListener; import buttondevteam.lib.chat.*; @@ -90,7 +92,7 @@ public class ChatProcessing { if (player != null && PluginMain.essentials.getUser(player).isMuted()) return true; - doFunStuff(sender, message); + doFunStuff(sender, e, message); ChatPlayer mp = null; if (player != null) @@ -132,6 +134,8 @@ public class ChatProcessing { Objective obj = PluginMain.SB.getObjective(channel.ID); int score = -1; for (Player p : Bukkit.getOnlinePlayers()) { + if (PluginMain.essentials.getUser(p).isIgnoredPlayer(PluginMain.essentials.getUser(player))) + continue; final int mcScore = VanillaUtils.getMCScoreIfChatOn(p, e); obj.getScore(p.getName()) .setScore(p.getUniqueId().equals(player == null ? null : player.getUniqueId()) // p.UniqueID==player?.UniqueID @@ -303,22 +307,24 @@ public class ChatProcessing { return formatters; } - static void doFunStuff(CommandSender sender, String message) { + static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) { if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F")) PlayerListener.Fs.add(sender); String msg = message.toLowerCase(); - if (msg.contains("lol")) { - UnlolCommand.Lastlolornot = true; - UnlolCommand.Lastlol = sender; - } else { + val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime()); + boolean add = false; + if (add = msg.contains("lol")) + lld.setLolornot(true); + else { for (int i = 0; i < PlayerListener.LaughStrings.length; i++) { - if (msg.contains(PlayerListener.LaughStrings[i])) { - UnlolCommand.Lastlol = sender; - UnlolCommand.Lastlolornot = false; + if (add = msg.contains(PlayerListener.LaughStrings[i])) { + lld.setLolornot(false); break; } } } + if (add) + UnlolCommand.Lastlol.put(event.getChannel(), lld); } } diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index 7780e2c..f54690c 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -337,7 +337,7 @@ public class PluginMain extends JavaPlugin { // Translated to Java: 2015.07.15. if (town == null) return new RecipientTestResult("You aren't in a town."); Nation nation = null; - int index = -1; + int index; if (nationchat) { if (town.hasNation()) nation = town.getNation(); diff --git a/src/main/java/buttondevteam/chat/commands/UnlolCommand.java b/src/main/java/buttondevteam/chat/commands/UnlolCommand.java index 9e7c187..c4eaa69 100644 --- a/src/main/java/buttondevteam/chat/commands/UnlolCommand.java +++ b/src/main/java/buttondevteam/chat/commands/UnlolCommand.java @@ -1,19 +1,24 @@ package buttondevteam.chat.commands; +import java.util.HashMap; +import java.util.Map; + import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import buttondevteam.lib.TBMCChatEventBase; +import buttondevteam.lib.chat.Channel; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCCommandBase; +import lombok.Data; @CommandClass(modOnly = false) public final class UnlolCommand extends TBMCCommandBase { - public static CommandSender Lastlol = null; - public static boolean Lastlolornot; + public static Map Lastlol = new HashMap<>(); @Override public String[] GetHelpText(String alias) { @@ -25,16 +30,26 @@ public final class UnlolCommand extends TBMCCommandBase { @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { - if (Lastlol != null) { - if (Lastlol instanceof Player) - ((Player) Lastlol) - .addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2 * 20, 5, false, false)); - String msg = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) - + (Lastlolornot ? " unlolled " : " unlaughed ") - + (Lastlol instanceof Player ? ((Player) Lastlol).getDisplayName() : Lastlol.getName()); - Bukkit.broadcastMessage(msg); - Lastlol = null; - } + LastlolData lol = Lastlol.values().stream().filter(lld -> lld.Chatevent.shouldSendTo(sender)) + .max((lld1, lld2) -> Long.compare(lld1.Loltime, lld2.Loltime)).orElse(null); + if (lol == null) + return true; + if (lol.Lolowner instanceof Player) + ((Player) lol.Lolowner) + .addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 2 * 20, 5, false, false)); + String msg = (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + + (lol.Lolornot ? " unlolled " : " unlaughed ") + + (lol.Lolowner instanceof Player ? ((Player) lol.Lolowner).getDisplayName() : lol.Lolowner.getName()); + Bukkit.broadcastMessage(msg); + Lastlol.remove(lol.Chatevent.getChannel()); return true; } + + @Data + public static class LastlolData { + private boolean Lolornot; + private final CommandSender Lolowner; + private final TBMCChatEventBase Chatevent; + private final long Loltime; + } } diff --git a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java index 5b61e94..5e05bee 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java @@ -16,6 +16,7 @@ import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.FlairStates; import buttondevteam.chat.PlayerJoinTimerTask; import buttondevteam.chat.PluginMain; +import buttondevteam.chat.commands.UnlolCommand; import buttondevteam.lib.player.TBMCPlayerJoinEvent; import buttondevteam.lib.player.TBMCPlayerLoadEvent; import buttondevteam.lib.player.TBMCPlayerSaveEvent; @@ -111,6 +112,7 @@ public class PlayerJoinLeaveListener implements Listener { } if (deletenick != null) PlayerListener.nicknames.remove(deletenick); + UnlolCommand.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer())); } }