From 26b44fbfe1a4fb71dfe6d341fdc347083a8afbf8 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 20 Feb 2019 15:23:07 +0100 Subject: [PATCH] Moved all /unlol and F stuff #85 --- .idea/ButtonChat.iml | 29 ++++++++ .../buttondevteam/chat/ChatProcessing.java | 46 +++++------- .../java/buttondevteam/chat/PluginMain.java | 4 +- .../chat/components/fun/FunComponent.java | 71 ++++++++++++++++++- .../chat/components/fun/UnlolCommand.java | 26 +++---- .../chat/listener/PlayerListener.java | 37 +--------- 6 files changed, 129 insertions(+), 84 deletions(-) diff --git a/.idea/ButtonChat.iml b/.idea/ButtonChat.iml index d0664f8..051580a 100644 --- a/.idea/ButtonChat.iml +++ b/.idea/ButtonChat.iml @@ -40,5 +40,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 21fe575..eab698b 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -1,5 +1,6 @@ package buttondevteam.chat; +import buttondevteam.chat.components.fun.FunComponent; import buttondevteam.chat.components.fun.UnlolCommand; import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.formatting.ChatFormatter; @@ -7,6 +8,7 @@ import buttondevteam.chat.formatting.TellrawEvent; import buttondevteam.chat.formatting.TellrawPart; import buttondevteam.chat.formatting.TellrawSerializer; import buttondevteam.chat.listener.PlayerListener; +import buttondevteam.core.ComponentManager; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.TBMCChatEventBase; @@ -296,12 +298,8 @@ public class ChatProcessing { } ChatPlayer mpp = TBMCPlayer.getPlayer(nottest ? p.getUniqueId() : new UUID(0, 0), ChatPlayer.class); if (nottest) { - if (PluginMain.Instance.notificationSound().get().length() == 0) - p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn - else - p.playSound(p.getLocation(), PluginMain.Instance.notificationSound().get(), 1.0f, - PluginMain.Instance.notificationPitch().get()); - } + playPingSound(p); + } String color = String.format("§%x", (mpp.GetFlairColor() == 0x00 ? 0xb : mpp.GetFlairColor())); return color + (nottest ? p.getName() : pn.get()) + "§r"; //Fix name casing, except when testing }).priority(Priority.High).type(ChatFormatter.Type.Excluder).build()); @@ -316,12 +314,8 @@ public class ChatProcessing { + match.toLowerCase() + " but was reported as online."); return "§c" + match + "§r"; } - if (PluginMain.Instance.notificationSound().get().length() == 0) - p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn - else - p.playSound(p.getLocation(), PluginMain.Instance.notificationSound().get(), 1.0f, - PluginMain.Instance.notificationPitch().get()); - return PluginMain.essentials.getUser(p).getNickname(); + playPingSound(p); + return PluginMain.essentials.getUser(p).getNickname(); } error.accept("Player nicknamed " + match.toLowerCase() + " not found in nickname map but was reported as online."); @@ -331,24 +325,16 @@ public class ChatProcessing { return formatters; } - static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) { - if (PlayerListener.ActiveF && !PlayerListener.Fs.contains(sender) && message.equalsIgnoreCase("F")) - PlayerListener.Fs.add(sender); + private static void playPingSound(Player p) { + if (PluginMain.Instance.notificationSound().get().length() == 0) + p.playSound(p.getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0f, 0.5f); // TODO: Airhorn + else + p.playSound(p.getLocation(), PluginMain.Instance.notificationSound().get(), 1.0f, + PluginMain.Instance.notificationPitch().get()); + } - String msg = message.toLowerCase(); - val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime()); - boolean add; - if (add = msg.contains("lol")) - lld.setLolornot(true); - else { - for (int i = 0; i < PlayerListener.LaughStrings.length; i++) { - if (add = msg.contains(PlayerListener.LaughStrings[i])) { - lld.setLolornot(false); - break; - } - } - } - if (add) - UnlolCommand.Lastlol.put(event.getChannel(), lld); + static void doFunStuff(CommandSender sender, TBMCChatEventBase event, String message) { + val fc=ComponentManager.getIfEnabled(FunComponent.class); + if(fc!=null) fc.onChat(sender, event, message); } } diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index e1c8b14..7a57a49 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -84,7 +84,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 private boolean setupPermissions() { RegisteredServiceProvider permissionProvider = getServer().getServicesManager() - .getRegistration(net.milkbowl.vault.permission.Permission.class); + .getRegistration(net.milkbowl.vault.permission.Permission.class); if (permissionProvider != null) { permission = permissionProvider.getProvider(); } @@ -93,7 +93,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 private boolean setupEconomy() { RegisteredServiceProvider economyProvider = getServer().getServicesManager() - .getRegistration(net.milkbowl.vault.economy.Economy.class); + .getRegistration(net.milkbowl.vault.economy.Economy.class); if (economyProvider != null) { economy = economyProvider.getProvider(); } diff --git a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java index 068fa0a..93ab4f6 100644 --- a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java +++ b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java @@ -1,18 +1,87 @@ package buttondevteam.chat.components.fun; +import buttondevteam.chat.ChatPlayer; +import buttondevteam.chat.PluginMain; +import buttondevteam.lib.TBMCChatEventBase; import buttondevteam.lib.architecture.Component; +import buttondevteam.lib.player.TBMCPlayer; import lombok.val; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.scheduler.BukkitTask; -public class FunComponent extends Component { +import java.util.ArrayList; +import java.util.Random; + +public class FunComponent extends Component implements Listener { + private final static String[] LaughStrings = new String[]{"xd", "lel", "lawl", "kek", "lmao", "hue", "hah", "rofl"}; + private boolean ActiveF = false; + private ChatPlayer FPlayer = null; + private BukkitTask Ftask = null; + private ArrayList Fs = new ArrayList<>(); + private UnlolCommand command; @Override protected void enable() { val pc = new PressCommand(); registerCommand(pc); registerListener(pc); + registerCommand(command=new UnlolCommand()); + registerListener(this); } @Override protected void disable() { } + + public void onChat(CommandSender sender, TBMCChatEventBase event, String message) { + if (ActiveF && !Fs.contains(sender) && message.equalsIgnoreCase("F")) + Fs.add(sender); + + String msg = message.toLowerCase(); + val lld = new UnlolCommand.LastlolData(sender, event, System.nanoTime()); + boolean add; + if (add = msg.contains("lol")) + lld.setLolornot(true); + else { + for (int i = 0; i < LaughStrings.length; i++) { + if (add = msg.contains(LaughStrings[i])) { + lld.setLolornot(false); + break; + } + } + } + if (add) + command.Lastlol.put(event.getChannel(), lld); + } + + @EventHandler + public void onPlayerDeath(PlayerDeathEvent e) { + // MinigamePlayer mgp = Minigames.plugin.pdata.getMinigamePlayer(e.getEntity()); + if (/* (mgp != null && !mgp.isInMinigame()) && */ new Random().nextBoolean()) { // Don't store Fs for NPCs + Runnable tt = () -> { + if (ActiveF) { + ActiveF = false; + if (FPlayer != null && FPlayer.FCount().get() < Integer.MAX_VALUE - 1) + FPlayer.FCount().set(FPlayer.FCount().get() + Fs.size()); + Bukkit.broadcastMessage("§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people") + + " paid their respects.§r"); + Fs.clear(); + } + }; + if (Ftask != null) { + Ftask.cancel(); + tt.run(); //Finish previous one + } + ActiveF = true; + Fs.clear(); + FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId(), ChatPlayer.class); + FPlayer.FDeaths().set(FPlayer.FDeaths().get() + 1); + Bukkit.broadcastMessage("§bPress F to pay respects.§r"); + Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20); + } + } } diff --git a/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java b/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java index 2ad8e6b..683be84 100644 --- a/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java @@ -2,8 +2,7 @@ package buttondevteam.chat.components.fun; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCChatEventBase; -import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.chat.TBMCCommandBase; +import buttondevteam.lib.chat.*; import lombok.Data; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -15,21 +14,18 @@ import java.util.Comparator; import java.util.HashMap; import java.util.Map; -@CommandClass(modOnly = false) -public final class UnlolCommand extends TBMCCommandBase { +@CommandClass(modOnly = false, helpText = { + "§6---- Unlol/unlaugh ----", + "This command is based on a joke between NorbiPeti and Ghostise", + "It will make the last person saying one of the recognized laugh strings blind for a few seconds", + "Note that you can only unlaugh laughs that weren't unlaughed before" +}) +public final class UnlolCommand extends ICommand2MC { - public static Map Lastlol = new HashMap<>(); + public Map Lastlol = new HashMap<>(); - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Unlol/unlaugh ----", - "This command is based on a joke between NorbiPeti and Ghostise", - "It will make the last person saying one of the recognized laugh strings blind for a few seconds", - "Note that you can only unlaugh laughs that weren't unlaughed before" }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { + @Command2.Subcommand + public boolean def(CommandSender sender) { LastlolData lol = Lastlol.values().stream().filter(lld -> lld.Chatevent.shouldSendTo(sender)) .max(Comparator.comparingLong(lld -> lld.Loltime)).orElse(null); if (lol == null) diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 86feab5..d20ded5 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -5,6 +5,7 @@ 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; @@ -38,9 +39,7 @@ import org.bukkit.event.server.ServerCommandEvent; import org.bukkit.help.HelpTopic; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; -import org.bukkit.scheduler.BukkitTask; -import java.util.ArrayList; import java.util.Arrays; import java.util.Map.Entry; import java.util.Random; @@ -53,8 +52,6 @@ public class PlayerListener implements Listener { */ public static BiMap nicknames = HashBiMap.create(); - public final static String[] LaughStrings = new String[]{"xd", "lel", "lawl", "kek", "lmao", "hue", "hah", "rofl"}; - @EventHandler(priority = EventPriority.HIGHEST) public void onPlayerChat(AsyncPlayerChatEvent event) { if (event.isCancelled()) @@ -164,38 +161,6 @@ public class PlayerListener implements Listener { } } - public static boolean ActiveF = false; - public static ChatPlayer FPlayer = null; - public static BukkitTask Ftask = null; - public static ArrayList Fs = new ArrayList<>(); - - @EventHandler - public void onPlayerDeath(PlayerDeathEvent e) { - // MinigamePlayer mgp = Minigames.plugin.pdata.getMinigamePlayer(e.getEntity()); - if (/* (mgp != null && !mgp.isInMinigame()) && */ new Random().nextBoolean()) { // Don't store Fs for NPCs - Runnable tt = () -> { - if (ActiveF) { - ActiveF = false; - if (FPlayer != null && FPlayer.FCount().get() < Integer.MAX_VALUE - 1) - FPlayer.FCount().set(FPlayer.FCount().get() + Fs.size()); - Bukkit.broadcastMessage("§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people") - + " paid their respects.§r"); - Fs.clear(); - } - }; - if (Ftask != null) { - Ftask.cancel(); - tt.run(); //Finish previous one - } - ActiveF = true; - Fs.clear(); - FPlayer = TBMCPlayer.getPlayer(e.getEntity().getUniqueId(), ChatPlayer.class); - FPlayer.FDeaths().set(FPlayer.FDeaths().get() + 1); - Bukkit.broadcastMessage("§bPress F to pay respects.§r"); - Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20); - } - } - @EventHandler @SuppressWarnings("deprecation") public void onVotifierEvent(VotifierEvent event) { //TODO: Move to teh Core eh