From df7f8bca5ee0bd5860fe51c3e7ee49096f960d36 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Tue, 12 Feb 2019 22:28:42 +0100 Subject: [PATCH 01/13] Town color error fix, applying changes --- src/main/java/buttondevteam/chat/ChatProcessing.java | 5 +++-- .../chat/components/fun/PressCommand.java | 7 ++++--- .../components/towncolors/TownColorComponent.java | 6 ++++-- .../chat/components/towny/TownyAnnouncer.java | 12 +++++++++--- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index cb593df..86a9526 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -52,7 +52,8 @@ public class ChatProcessing { private static final Pattern SPOILER_PATTERN = Pattern.compile("\\|\\|"); private static final Color[] RainbowPresserColors = new Color[]{Color.Red, Color.Gold, Color.Yellow, Color.Green, Color.Blue, Color.DarkPurple}; - private static boolean pingedconsole = false; + private static final Pattern WORD_PATTERN = Pattern.compile("\\S+"); + private static boolean pingedconsole = false; public static final ChatFormatter ESCAPE_FORMATTER = ChatFormatter.builder().regex(ESCAPE_PATTERN).build(); @@ -134,7 +135,7 @@ public class ChatProcessing { ArrayList formatters = addFormatters(colormode); if (colormode == channel.Color().get() && mp != null && mp.RainbowPresserColorMode) { // Only overwrite channel color final AtomicInteger rpc = new AtomicInteger(0); - formatters.add(ChatFormatter.builder().color(colormode).onmatch((match, cf, s) -> { + formatters.add(ChatFormatter.builder().regex(WORD_PATTERN).color(colormode).onmatch((match, cf, s) -> { cf.setColor(RainbowPresserColors[rpc.getAndUpdate(i -> ++i < RainbowPresserColors.length ? i : 0)]); return match; }).build()); diff --git a/src/main/java/buttondevteam/chat/components/fun/PressCommand.java b/src/main/java/buttondevteam/chat/components/fun/PressCommand.java index 7923d21..b9ddc7d 100644 --- a/src/main/java/buttondevteam/chat/components/fun/PressCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/PressCommand.java @@ -3,8 +3,9 @@ package buttondevteam.chat.components.fun; import buttondevteam.core.component.restart.ScheduledRestartCommand; import buttondevteam.lib.ScheduledServerRestartEvent; import buttondevteam.lib.ThorpeUtils; -import buttondevteam.lib.chat.Command2MC; +import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.ICommand2MC; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.event.EventHandler; @@ -13,12 +14,12 @@ import org.bukkit.event.Listener; import java.util.HashSet; @CommandClass -public class PressCommand extends Command2MC implements Listener { +public class PressCommand extends ICommand2MC implements Listener { private HashSet pressers; //Will be cleared with this class on shutdown/disable private ScheduledRestartCommand command; private int startTicks; - @Subcommand + @Command2.Subcommand public void def(CommandSender sender) { if (command == null) { sender.sendMessage("§cThe timer isn't ticking... yet."); diff --git a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java index 02c8b42..b94d993 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java @@ -12,6 +12,7 @@ import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.chat.Color; import com.earth2me.essentials.User; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; +import com.palmergames.bukkit.towny.object.Nation; import lombok.experimental.var; import lombok.val; import org.bukkit.Bukkit; @@ -79,9 +80,10 @@ public class TownColorComponent extends Component { return; for (val entry : TownColors.entrySet()) { try { - val nation = TownyComponent.TU.getTownsMap().get(entry.getKey()).getNation(); + val town = TownyComponent.TU.getTownsMap().get(entry.getKey()); + Nation nation; Color nc; - if (nation == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null) + if (!town.hasNation() || (nation = town.getNation()) == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null) nc = Color.White; setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue(), nc); } catch (Exception e) { diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java index f6788e8..dc69adf 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java @@ -3,6 +3,7 @@ package buttondevteam.chat.components.towny; import buttondevteam.chat.ChatProcessing; import buttondevteam.chat.PluginMain; import buttondevteam.core.component.channel.Channel; +import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.chat.TBMCChatAPI; import com.palmergames.bukkit.towny.TownyLogger; import lombok.val; @@ -24,17 +25,17 @@ public class TownyAnnouncer { case "Town": TBMCChatAPI.SendSystemMessage(PluginMain.TownChat, new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID), - logRecord.getMessage(), ChatProcessing.MCORIGIN); + logRecord.getMessage(), target, ChatProcessing.MCORIGIN); break; case "Nation": TBMCChatAPI.SendSystemMessage(PluginMain.NationChat, new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID), - logRecord.getMessage(), ChatProcessing.MCORIGIN); + logRecord.getMessage(), target, ChatProcessing.MCORIGIN); break; case "Global": TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, - logRecord.getMessage(), ChatProcessing.MCORIGIN); + logRecord.getMessage(), target, ChatProcessing.MCORIGIN); break; } } @@ -50,11 +51,16 @@ public class TownyAnnouncer { } }; + private static TBMCSystemChatEvent.BroadcastTarget target; + public static void setup() { + target = TBMCSystemChatEvent.BroadcastTarget.add("towny"); TownyLogger.log.addHandler(HANDLER); } public static void setdown() { + TBMCSystemChatEvent.BroadcastTarget.remove(target); + target = null; TownyLogger.log.removeHandler(HANDLER); } } From 36655dfd849e9dfd3fff91294f617dbfeb356060 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 20 Feb 2019 13:41:53 +0100 Subject: [PATCH 02/13] Adding project file and moving /unlol Also fixed Vault dep --- .gitignore | 2 +- .idea/ButtonChat.iml | 44 +++++++++++++++++++ pom.xml | 8 ++-- .../buttondevteam/chat/ChatProcessing.java | 2 +- .../fun}/UnlolCommand.java | 2 +- .../listener/PlayerJoinLeaveListener.java | 2 +- 6 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 .idea/ButtonChat.iml rename src/main/java/buttondevteam/chat/{commands => components/fun}/UnlolCommand.java (97%) diff --git a/.gitignore b/.gitignore index deefcdf..456756d 100644 --- a/.gitignore +++ b/.gitignore @@ -217,7 +217,7 @@ pip-log.txt .mr.developer.cfg .metadata/* TheButtonAutoFlair/out/artifacts/Autoflair/Autoflair.jar -*.iml +#*.iml *.name .idea/compiler.xml *.xml diff --git a/.idea/ButtonChat.iml b/.idea/ButtonChat.iml new file mode 100644 index 0000000..d0664f8 --- /dev/null +++ b/.idea/ButtonChat.iml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index b8cbcb0..aaac3ac 100644 --- a/pom.xml +++ b/pom.xml @@ -163,10 +163,10 @@ Minigames http://maven.addstar.com.au/artifactory/release - + @@ -215,9 +215,9 @@ - net.milkbowl.vault + com.github.milkbowl VaultAPI - 1.6 + master-SNAPSHOT provided diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 86a9526..21fe575 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -1,6 +1,6 @@ package buttondevteam.chat; -import buttondevteam.chat.commands.UnlolCommand; +import buttondevteam.chat.components.fun.UnlolCommand; import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.formatting.ChatFormatter; import buttondevteam.chat.formatting.TellrawEvent; diff --git a/src/main/java/buttondevteam/chat/commands/UnlolCommand.java b/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java similarity index 97% rename from src/main/java/buttondevteam/chat/commands/UnlolCommand.java rename to src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java index 7ab2311..2ad8e6b 100644 --- a/src/main/java/buttondevteam/chat/commands/UnlolCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java @@ -1,4 +1,4 @@ -package buttondevteam.chat.commands; +package buttondevteam.chat.components.fun; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCChatEventBase; diff --git a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java index 4dfb371..915596f 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java @@ -3,7 +3,7 @@ package buttondevteam.chat.listener; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.PlayerJoinTimerTask; import buttondevteam.chat.PluginMain; -import buttondevteam.chat.commands.UnlolCommand; +import buttondevteam.chat.components.fun.UnlolCommand; import buttondevteam.chat.commands.ucmds.HistoryCommand; import buttondevteam.chat.components.flair.FlairComponent; import buttondevteam.chat.components.flair.FlairStates; From 26b44fbfe1a4fb71dfe6d341fdc347083a8afbf8 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 20 Feb 2019 15:23:07 +0100 Subject: [PATCH 03/13] 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 From c5e33a93ba0e830989e791f72f03848d1d62c01f Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 20 Feb 2019 16:48:08 +0100 Subject: [PATCH 04/13] Moved chat-only stuff, F top, append text start #85 --- .../buttondevteam/chat/ChatProcessing.java | 6 +- .../chat/commands/ChatonlyCommand.java | 32 ---------- .../appendext/AppendTextComponent.java | 27 ++++++++ .../chatonly/ChatOnlyComponent.java | 62 +++++++++++++++++++ .../components/chatonly/ChatonlyCommand.java | 28 +++++++++ .../fun}/FTopCommand.java | 36 +++++------ .../chat/components/fun/FunComponent.java | 7 +++ .../listener/PlayerJoinLeaveListener.java | 7 +-- .../chat/listener/PlayerListener.java | 15 ----- 9 files changed, 143 insertions(+), 77 deletions(-) delete mode 100644 src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java create mode 100644 src/main/java/buttondevteam/chat/components/appendext/AppendTextComponent.java create mode 100644 src/main/java/buttondevteam/chat/components/chatonly/ChatOnlyComponent.java create mode 100644 src/main/java/buttondevteam/chat/components/chatonly/ChatonlyCommand.java rename src/main/java/buttondevteam/chat/{commands => components/fun}/FTopCommand.java (73%) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index eab698b..5486a2a 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.chatonly.ChatOnlyComponent; import buttondevteam.chat.components.fun.FunComponent; import buttondevteam.chat.components.fun.UnlolCommand; import buttondevteam.chat.commands.ucmds.admin.DebugCommand; @@ -212,10 +213,7 @@ public class ChatProcessing { @Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier, String origin) { TellrawPart json = new TellrawPart(""); - if (mp != null && mp.ChatOnly) { - json.addExtra(new TellrawPart("[C]") - .setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Chat only"))); - } + ChatOnlyComponent.tellrawCreate(mp, json); //TODO: Make nice API json.addExtra( new TellrawPart(channelidentifier) .setHoverEvent( diff --git a/src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java b/src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java deleted file mode 100644 index e85c7d3..0000000 --- a/src/main/java/buttondevteam/chat/commands/ChatonlyCommand.java +++ /dev/null @@ -1,32 +0,0 @@ -package buttondevteam.chat.commands; - -import org.bukkit.GameMode; -import org.bukkit.entity.Player; - -import buttondevteam.chat.ChatPlayer; -import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.chat.PlayerCommandBase; -import buttondevteam.lib.player.TBMCPlayer; - -@CommandClass(modOnly = false) -public final class ChatonlyCommand extends PlayerCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Chat-only mode ----", // - "This mode makes you invincible but unable to move, teleport or interact with the world in any way", // - "It was designed for chat clients", // - "Once enabled, the only way of disabling it is by relogging to the server" // - }; - } - - @Override - public boolean OnCommand(Player player, String alias, String[] args) { - ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); - p.ChatOnly = true; - player.setGameMode(GameMode.SPECTATOR); - player.sendMessage("§bChat-only mode enabled. You are now invincible."); - return true; - } - -} diff --git a/src/main/java/buttondevteam/chat/components/appendext/AppendTextComponent.java b/src/main/java/buttondevteam/chat/components/appendext/AppendTextComponent.java new file mode 100644 index 0000000..42637c1 --- /dev/null +++ b/src/main/java/buttondevteam/chat/components/appendext/AppendTextComponent.java @@ -0,0 +1,27 @@ +package buttondevteam.chat.components.appendext; + +import buttondevteam.lib.architecture.Component; +import buttondevteam.lib.architecture.ConfigData; +import buttondevteam.lib.architecture.IHaveConfig; +import lombok.val; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.function.Supplier; + +public class AppendTextComponent extends Component { + private HashMap appendTexts=new HashMap<>(); + private ConfigData helpText(IHaveConfig config) { + return config.getData("helpText", ()->new String[0]); + } + + @Override + protected void enable() { + val cs=getConfig().getConfig(); //TODO + } + + @Override + protected void disable() { + + } +} diff --git a/src/main/java/buttondevteam/chat/components/chatonly/ChatOnlyComponent.java b/src/main/java/buttondevteam/chat/components/chatonly/ChatOnlyComponent.java new file mode 100644 index 0000000..dce2089 --- /dev/null +++ b/src/main/java/buttondevteam/chat/components/chatonly/ChatOnlyComponent.java @@ -0,0 +1,62 @@ +package buttondevteam.chat.components.chatonly; + +import buttondevteam.chat.ChatPlayer; +import buttondevteam.chat.formatting.TellrawEvent; +import buttondevteam.chat.formatting.TellrawPart; +import buttondevteam.core.ComponentManager; +import buttondevteam.lib.architecture.Component; +import buttondevteam.lib.player.TBMCPlayer; +import buttondevteam.lib.player.TBMCPlayerJoinEvent; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerTeleportEvent; + +public class ChatOnlyComponent extends Component implements Listener { + @Override + protected void enable() { + registerListener(this); + registerCommand(new ChatonlyCommand()); + } + + @Override + protected void disable() { + + } + + public static void playerJoin(ChatPlayer cp, Player p) { + if(!ComponentManager.isEnabled(ChatOnlyComponent.class)) + return; + if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) { + cp.ChatOnly = false; + p.setGameMode(GameMode.SURVIVAL); + } + } + + public static void tellrawCreate(ChatPlayer mp, TellrawPart json) { + if(!ComponentManager.isEnabled(ChatOnlyComponent.class)) + return; + if (mp != null && mp.ChatOnly) { + json.addExtra(new TellrawPart("[C]") + .setHoverEvent(TellrawEvent.create(TellrawEvent.HoverAction.SHOW_TEXT, "Chat only"))); + } + } + + @EventHandler + public void onPlayerMove(PlayerMoveEvent e) { + ChatPlayer mp = TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class); + if (mp.ChatOnly) + e.setCancelled(true); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerTeleport(PlayerTeleportEvent e) { + if (TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class).ChatOnly) { + e.setCancelled(true); + e.getPlayer().sendMessage("§cYou are not allowed to teleport while in chat-only mode."); + } + } +} diff --git a/src/main/java/buttondevteam/chat/components/chatonly/ChatonlyCommand.java b/src/main/java/buttondevteam/chat/components/chatonly/ChatonlyCommand.java new file mode 100644 index 0000000..9af57be --- /dev/null +++ b/src/main/java/buttondevteam/chat/components/chatonly/ChatonlyCommand.java @@ -0,0 +1,28 @@ +package buttondevteam.chat.components.chatonly; + +import buttondevteam.lib.chat.ICommand2MC; +import org.bukkit.GameMode; +import org.bukkit.entity.Player; + +import buttondevteam.chat.ChatPlayer; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.PlayerCommandBase; +import buttondevteam.lib.player.TBMCPlayer; + +@CommandClass(modOnly = false, helpText = { + "§6---- Chat-only mode ----", // + "This mode makes you invincible but unable to move, teleport or interact with the world in any way", // + "It was designed for chat clients", // + "Once enabled, the only way of disabling it is by relogging to the server" // +}) +public final class ChatonlyCommand extends ICommand2MC { + + public boolean def(Player player) { + ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); + p.ChatOnly = true; + player.setGameMode(GameMode.SPECTATOR); + player.sendMessage("§bChat-only mode enabled. You are now invincible."); + return true; + } + +} diff --git a/src/main/java/buttondevteam/chat/commands/FTopCommand.java b/src/main/java/buttondevteam/chat/components/fun/FTopCommand.java similarity index 73% rename from src/main/java/buttondevteam/chat/commands/FTopCommand.java rename to src/main/java/buttondevteam/chat/components/fun/FTopCommand.java index 8c10178..037811e 100644 --- a/src/main/java/buttondevteam/chat/commands/FTopCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/FTopCommand.java @@ -1,8 +1,10 @@ -package buttondevteam.chat.commands; +package buttondevteam.chat.components.fun; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.PluginMain; +import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.ICommand2MC; import buttondevteam.lib.chat.TBMCCommandBase; import buttondevteam.lib.player.TBMCPlayerBase; import lombok.val; @@ -16,23 +18,17 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; -@CommandClass -public class FTopCommand extends TBMCCommandBase { - - @Override - public String[] GetHelpText(String arg0) { - return new String[]{ // - "§6---- F Top ----", // - "Shows the respect leaderboard" // - }; - } +@CommandClass(helpText = { + "§6---- F Top ----", // + "Shows the respect leaderboard" // +}) +public class FTopCommand extends ICommand2MC { private final File playerdir = new File(TBMCPlayerBase.TBMC_PLAYERS_DIR); private ChatPlayer[] cached; private long lastcache = 0; - @Override - public boolean OnCommand(CommandSender arg0, String arg1, String[] arg2) { + public boolean def(CommandSender sender, @Command2.OptionalArg int page) { Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> { if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too) cached = Arrays.stream(Objects.requireNonNull(playerdir.listFiles())).sequential() @@ -52,15 +48,13 @@ public class FTopCommand extends TBMCCommandBase { } int i; try { - i = arg2.length > 0 ? Integer.parseInt(arg2[0]) : 1; - if (i < 1) - i = 1; //i=1 - } catch (Exception e) { - i = 1; - } + i = page<1?1:page; + } catch (Exception e) { + i = 1; + } val ai = new AtomicInteger(); - arg0.sendMessage("§6---- Top Fs ----"); - arg0.sendMessage(Arrays.stream(cached).skip((i - 1) * 10).limit(i * 10) + sender.sendMessage("§6---- Top Fs ----"); + sender.sendMessage(Arrays.stream(cached).skip((i - 1) * 10).limit(i * 10) .map(cp -> String.format("%d. %s - %f.2", ai.incrementAndGet(), cp.PlayerName().get(), cp.getF())) .collect(Collectors.joining("\n"))); }); diff --git a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java index 93ab4f6..b0f18e2 100644 --- a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java +++ b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java @@ -2,6 +2,7 @@ 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.architecture.Component; import buttondevteam.lib.player.TBMCPlayer; @@ -11,6 +12,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.scheduler.BukkitTask; import java.util.ArrayList; @@ -30,6 +32,7 @@ public class FunComponent extends Component implements Listener { registerListener(pc); registerCommand(command=new UnlolCommand()); registerListener(this); + registerCommand(new FTopCommand()); } @Override @@ -84,4 +87,8 @@ public class FunComponent extends Component implements Listener { Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20); } } + @EventHandler + public void onPlayerLeave(PlayerQuitEvent event) { + command.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer())); + } } diff --git a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java index 915596f..7f726bd 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java @@ -3,6 +3,7 @@ package buttondevteam.chat.listener; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.PlayerJoinTimerTask; import buttondevteam.chat.PluginMain; +import buttondevteam.chat.components.chatonly.ChatOnlyComponent; import buttondevteam.chat.components.fun.UnlolCommand; import buttondevteam.chat.commands.ucmds.HistoryCommand; import buttondevteam.chat.components.flair.FlairComponent; @@ -62,10 +63,7 @@ public class PlayerJoinLeaveListener implements Listener { TownColorComponent.updatePlayerColors(p, cp); //TO!DO: Doesn't have effect - It can help to register the listener - if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) { - cp.ChatOnly = false; - p.setGameMode(GameMode.SURVIVAL); - } + ChatOnlyComponent.playerJoin(cp, p); HistoryCommand.showHistory(e.getPlayer(), "u history", new String[0], null); } @@ -77,7 +75,6 @@ public class PlayerJoinLeaveListener implements Listener { @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { PlayerListener.nicknames.inverse().remove(event.getPlayer().getUniqueId()); - UnlolCommand.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer())); } } diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index d20ded5..1b50b8c 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -176,21 +176,6 @@ public class PlayerListener implements Listener { } } - @EventHandler - public void onPlayerMove(PlayerMoveEvent e) { - ChatPlayer mp = TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class); - if (mp.ChatOnly) - e.setCancelled(true); - } - - @EventHandler(priority = EventPriority.LOWEST) - public void onPlayerTeleport(PlayerTeleportEvent e) { - if (TBMCPlayer.getPlayer(e.getPlayer().getUniqueId(), ChatPlayer.class).ChatOnly) { - e.setCancelled(true); - e.getPlayer().sendMessage("§cYou are not allowed to teleport while in chat-only mode."); - } - } - @EventHandler(priority = EventPriority.HIGHEST) public void onConsoleCommand(ServerCommandEvent event) { if (onCommandPreprocess(event.getSender(), event.getCommand())) From 40a17399510af25f0399251529032ef27ff1a79e Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 27 Feb 2019 13:48:36 +0100 Subject: [PATCH 05/13] 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; } From f7c1106d1c8bf8b21c6bedda26149eec70c63ff0 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Wed, 27 Feb 2019 16:41:49 +0100 Subject: [PATCH 06/13] Replaced (almost) all broadcasts --- .idea/ButtonChat.iml | 29 +++++++++++++++++++ .../announce/AnnouncerComponent.java | 9 +++++- .../chat/components/fun/FunComponent.java | 14 ++++++--- .../chat/components/fun/PressCommand.java | 5 +++- .../chat/components/fun/UnlolCommand.java | 12 ++++++-- 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/.idea/ButtonChat.iml b/.idea/ButtonChat.iml index 9b778e4..aba73b5 100644 --- a/.idea/ButtonChat.iml +++ b/.idea/ButtonChat.iml @@ -42,5 +42,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java b/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java index fce4422..f841a2b 100644 --- a/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java +++ b/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java @@ -1,7 +1,10 @@ package buttondevteam.chat.components.announce; +import buttondevteam.core.component.channel.Channel; +import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.ConfigData; +import buttondevteam.lib.chat.TBMCChatAPI; import org.bukkit.Bukkit; import java.util.ArrayList; @@ -14,6 +17,9 @@ public class AnnouncerComponent extends Component implements Runnable { public ConfigData AnnounceTime() { return getConfig().getData("announceTime", 15 * 60 * 1000); } + + private TBMCSystemChatEvent.BroadcastTarget target; + private static int AnnounceMessageIndex = 0; @Override @@ -26,7 +32,7 @@ public class AnnouncerComponent extends Component implements Runnable { } if (Bukkit.getOnlinePlayers().size() == 0) continue; //Don't post to Discord if nobody is on if (AnnounceMessages().get().size() > AnnounceMessageIndex) { - Bukkit.broadcastMessage(AnnounceMessages().get().get(AnnounceMessageIndex)); + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, AnnounceMessages().get().get(AnnounceMessageIndex), target); AnnounceMessageIndex++; if (AnnounceMessageIndex == AnnounceMessages().get().size()) AnnounceMessageIndex = 0; @@ -36,6 +42,7 @@ public class AnnouncerComponent extends Component implements Runnable { @Override protected void enable() { + target= TBMCSystemChatEvent.BroadcastTarget.add("announcements"); registerCommand(new AddCommand()); registerCommand(new EditCommand()); registerCommand(new ListCommand()); diff --git a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java index 53bfb23..9053635 100644 --- a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java +++ b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java @@ -2,6 +2,7 @@ package buttondevteam.chat.components.fun; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.PluginMain; +import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCChatEventBase; import buttondevteam.lib.TBMCCommandPreprocessEvent; import buttondevteam.lib.TBMCSystemChatEvent; @@ -10,6 +11,7 @@ import buttondevteam.lib.architecture.Component; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.TBMCPlayer; +import lombok.Getter; import lombok.val; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -35,13 +37,15 @@ public class FunComponent extends Component implements Listener { private ArrayList Fs = new ArrayList<>(); private UnlolCommand command; private TBMCSystemChatEvent.BroadcastTarget unlolTarget; + private TBMCSystemChatEvent.BroadcastTarget fTarget; @Override protected void enable() { unlolTarget = TBMCSystemChatEvent.BroadcastTarget.add("unlol"); + fTarget = TBMCSystemChatEvent.BroadcastTarget.add("respect"); val pc = new PressCommand(); registerCommand(pc); registerListener(pc); - registerCommand(command=new UnlolCommand()); + registerCommand(command=new UnlolCommand(unlolTarget)); registerListener(this); registerCommand(new FTopCommand()); } @@ -81,8 +85,9 @@ public class FunComponent extends Component implements Listener { 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"); + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, + "§b" + Fs.size() + " " + (Fs.size() == 1 ? "person" : "people") + + " paid their respects.§r", fTarget); Fs.clear(); } }; @@ -94,7 +99,8 @@ public class FunComponent extends Component implements Listener { 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"); + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, + "§bPress F to pay respects.§r", fTarget); Bukkit.getScheduler().runTaskLaterAsynchronously(PluginMain.Instance, tt, 15 * 20); } } diff --git a/src/main/java/buttondevteam/chat/components/fun/PressCommand.java b/src/main/java/buttondevteam/chat/components/fun/PressCommand.java index b9ddc7d..123aab5 100644 --- a/src/main/java/buttondevteam/chat/components/fun/PressCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/PressCommand.java @@ -1,11 +1,14 @@ package buttondevteam.chat.components.fun; +import buttondevteam.core.component.channel.Channel; +import buttondevteam.core.component.restart.RestartComponent; import buttondevteam.core.component.restart.ScheduledRestartCommand; import buttondevteam.lib.ScheduledServerRestartEvent; import buttondevteam.lib.ThorpeUtils; import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.ICommand2MC; +import buttondevteam.lib.chat.TBMCChatAPI; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.event.EventHandler; @@ -30,7 +33,7 @@ public class PressCommand extends ICommand2MC implements Listener { return; } pressers.add(sender); - Bukkit.broadcastMessage(String.format("§b-- %s §bpressed at %.0fs", ThorpeUtils.getDisplayName(sender), command.getRestartCounter() / 20f)); + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, String.format("§b-- %s §bpressed at %.0fs", ThorpeUtils.getDisplayName(sender), command.getRestartCounter() / 20f), command.getComponent().getRestartBroadcast()); command.setRestartCounter(startTicks); } diff --git a/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java b/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java index 683be84..8de6c9e 100644 --- a/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/UnlolCommand.java @@ -2,8 +2,11 @@ package buttondevteam.chat.components.fun; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCChatEventBase; +import buttondevteam.lib.TBMCSystemChatEvent; +import buttondevteam.lib.ThorpeUtils; import buttondevteam.lib.chat.*; import lombok.Data; +import lombok.RequiredArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -20,10 +23,13 @@ import java.util.Map; "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" }) +@RequiredArgsConstructor public final class UnlolCommand extends ICommand2MC { public Map Lastlol = new HashMap<>(); + private final TBMCSystemChatEvent.BroadcastTarget target; + @Command2.Subcommand public boolean def(CommandSender sender) { LastlolData lol = Lastlol.values().stream().filter(lld -> lld.Chatevent.shouldSendTo(sender)) @@ -33,10 +39,10 @@ public final class UnlolCommand extends ICommand2MC { 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()) + String msg = ThorpeUtils.getDisplayName(sender) + (lol.Lolornot ? " unlolled " : " unlaughed ") - + (lol.Lolowner instanceof Player ? ((Player) lol.Lolowner).getDisplayName() : lol.Lolowner.getName()); - Bukkit.broadcastMessage(msg); + + ThorpeUtils.getDisplayName(lol.Lolowner); + TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, msg, target); Lastlol.remove(lol.Chatevent.getChannel()); return true; } From 4744f2edf97e18f26847b802cc6c3fdf29bd03f1 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 1 Mar 2019 17:58:40 +0100 Subject: [PATCH 07/13] Supporting clean installs And other fixes Also moved the Votifier reward to the core Checking if Towny is present (only a soft-depend now) --- .idea/ButtonChat.iml | 32 ------------------- pom.xml | 9 ------ .../buttondevteam/chat/ChatProcessing.java | 19 ++++------- .../java/buttondevteam/chat/PluginMain.java | 11 +++---- .../towncolors/TownColorComponent.java | 1 + .../chat/components/towny/TownyAnnouncer.java | 15 ++++++--- .../chat/components/towny/TownyComponent.java | 24 +++++++++++--- .../chat/listener/PlayerListener.java | 17 ---------- src/main/resources/plugin.yml | 3 +- 9 files changed, 43 insertions(+), 88 deletions(-) diff --git a/.idea/ButtonChat.iml b/.idea/ButtonChat.iml index aba73b5..3d32cdf 100644 --- a/.idea/ButtonChat.iml +++ b/.idea/ButtonChat.iml @@ -11,8 +11,6 @@ - - @@ -28,36 +26,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/pom.xml b/pom.xml index aaac3ac..5626ea8 100644 --- a/pom.xml +++ b/pom.xml @@ -155,10 +155,6 @@ Essentials http://repo.ess3.net/content/repositories/essrel/ - - Votifier - https://dl.bintray.com/nuvotifier/maven/ - Minigames http://maven.addstar.com.au/artifactory/release @@ -207,11 +203,6 @@ Towny 8d3b6b6 - - com.vexsoftware - nuvotifier-universal - 2.3.4 - diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index 5486a2a..b9afa17 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -1,9 +1,9 @@ package buttondevteam.chat; +import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.components.chatonly.ChatOnlyComponent; import buttondevteam.chat.components.fun.FunComponent; -import buttondevteam.chat.components.fun.UnlolCommand; -import buttondevteam.chat.commands.ucmds.admin.DebugCommand; +import buttondevteam.chat.components.towny.TownyComponent; import buttondevteam.chat.formatting.ChatFormatter; import buttondevteam.chat.formatting.TellrawEvent; import buttondevteam.chat.formatting.TellrawPart; @@ -178,16 +178,11 @@ public class ChatProcessing { if (score < 0) // Never send messages to score below 0 sender.sendMessage("§cYou don't have permission to send this message or something went wrong"); else { - PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, - String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID, - score, jsonstr)); - if (e.getChannel().ID.equals(PluginMain.TownChat.ID) - || e.getChannel().ID.equals(PluginMain.NationChat.ID)) { - ((List) json.getExtra()).add(0, new TellrawPart("[SPY]")); - jsonstr = toJson(json); - Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format( - "tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr)); - } + PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, + String.format("tellraw @a[score_%s=%d,score_%s_min=%d] %s", channel.ID, score, channel.ID, + score, jsonstr)); + val tc = ComponentManager.getIfEnabled(TownyComponent.class); + if (tc != null) tc.handleSpies(channel, json, ChatProcessing::toJson); } } else PluginMain.Instance.getServer().dispatchCommand(PluginMain.Console, diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index 7a57a49..2361d37 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -5,7 +5,6 @@ import buttondevteam.chat.components.announce.AnnouncerComponent; import buttondevteam.chat.components.flair.FlairComponent; import buttondevteam.chat.components.fun.FunComponent; import buttondevteam.chat.components.towncolors.TownColorComponent; -import buttondevteam.chat.components.towncolors.TownyListener; import buttondevteam.chat.components.towny.TownyComponent; import buttondevteam.chat.listener.PlayerJoinLeaveListener; import buttondevteam.chat.listener.PlayerListener; @@ -33,9 +32,6 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 public static Scoreboard SB; - public static Channel TownChat; - public static Channel NationChat; - public ConfigData notificationSound() { return getIConfig().getData("notificationSound", ""); } @@ -52,20 +48,21 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); TBMCCoreAPI.RegisterEventsForExceptions(new PlayerJoinLeaveListener(), this); - TBMCCoreAPI.RegisterEventsForExceptions(new TownyListener(), this); TBMCChatAPI.AddCommands(this, YeehawCommand.class); Console = this.getServer().getConsoleSender(); SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...] - Component.registerComponent(this, new TownyComponent()); + if (Bukkit.getPluginManager().isPluginEnabled("Towny")) + Component.registerComponent(this, new TownyComponent()); TBMCChatAPI.RegisterChatChannel(new Channel("§7RP§f", Color.Gray, "rp", null)); //Since it's null, it's recognised as global if (!setupEconomy() || !setupPermissions()) TBMCCoreAPI.SendException("We're in trouble", new Exception("Failed to set up economy or permissions!")); - Component.registerComponent(this, new TownColorComponent()); + if (Bukkit.getPluginManager().isPluginEnabled("Towny")) + Component.registerComponent(this, new TownColorComponent()); Component.registerComponent(this, new FlairComponent()); //The original purpose of this plugin Component.registerComponent(this, new AnnouncerComponent()); Component.registerComponent(this, new FunComponent()); diff --git a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java index b94d993..c7917fa 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java @@ -97,6 +97,7 @@ public class TownColorComponent extends Component { registerCommand(new buttondevteam.chat.components.towncolors.admin.TownColorCommand()); registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand()); registerCommand(new TCCount()); + registerListener(new TownyListener()); } @Override diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java index dc69adf..55702c7 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyAnnouncer.java @@ -1,7 +1,6 @@ package buttondevteam.chat.components.towny; import buttondevteam.chat.ChatProcessing; -import buttondevteam.chat.PluginMain; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.chat.TBMCChatAPI; @@ -23,12 +22,14 @@ public class TownyAnnouncer { String groupID = m.group(2); //The group ID is correctly cased switch (String.valueOf(m.group(1))) { //valueOf: Handles null case "Town": - TBMCChatAPI.SendSystemMessage(PluginMain.TownChat, + if (townChannel == null) return; + TBMCChatAPI.SendSystemMessage(townChannel, new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, false), groupID), logRecord.getMessage(), target, ChatProcessing.MCORIGIN); break; case "Nation": - TBMCChatAPI.SendSystemMessage(PluginMain.NationChat, + if (nationChannel == null) return; + TBMCChatAPI.SendSystemMessage(nationChannel, new Channel.RecipientTestResult(TownyComponent.getTownNationIndex(groupID, true), groupID), logRecord.getMessage(), target, ChatProcessing.MCORIGIN); break; @@ -52,15 +53,21 @@ public class TownyAnnouncer { }; private static TBMCSystemChatEvent.BroadcastTarget target; + private static Channel townChannel; + private static Channel nationChannel; - public static void setup() { + public static void setup(Channel townChannel, Channel nationChannel) { target = TBMCSystemChatEvent.BroadcastTarget.add("towny"); + TownyAnnouncer.townChannel = townChannel; + TownyAnnouncer.nationChannel = nationChannel; TownyLogger.log.addHandler(HANDLER); } public static void setdown() { TBMCSystemChatEvent.BroadcastTarget.remove(target); target = null; + TownyAnnouncer.townChannel = null; + TownyAnnouncer.nationChannel = null; TownyLogger.log.removeHandler(HANDLER); } } diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java b/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java index 298ece8..6f3d283 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java @@ -1,6 +1,7 @@ package buttondevteam.chat.components.towny; import buttondevteam.chat.PluginMain; +import buttondevteam.chat.formatting.TellrawPart; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.architecture.Component; import buttondevteam.lib.chat.Color; @@ -17,6 +18,8 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; import java.util.stream.Collectors; public class TownyComponent extends Component { @@ -24,16 +27,19 @@ public class TownyComponent extends Component { private static ArrayList Towns; private static ArrayList Nations; + private Channel TownChat; + private Channel NationChat; + @Override protected void enable() { TU = ((Towny) Bukkit.getPluginManager().getPlugin("Towny")).getTownyUniverse(); Towns = TU.getTownsMap().values().stream().map(Town::getName).collect(Collectors.toCollection(ArrayList::new)); // Creates a snapshot of towns, new towns will be added when needed Nations = TU.getNationsMap().values().stream().map(Nation::getName).collect(Collectors.toCollection(ArrayList::new)); // Same here but with nations TBMCChatAPI.RegisterChatChannel( - PluginMain.TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false))); + TownChat = new Channel("§3TC§f", Color.DarkAqua, "tc", s -> checkTownNationChat(s, false))); TBMCChatAPI.RegisterChatChannel( - PluginMain.NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true))); - TownyAnnouncer.setup(); + NationChat = new Channel("§6NC§f", Color.Gold, "nc", s -> checkTownNationChat(s, true))); + TownyAnnouncer.setup(TownChat, NationChat); } @Override @@ -41,6 +47,14 @@ public class TownyComponent extends Component { TownyAnnouncer.setdown(); } + public void handleSpies(Channel channel, TellrawPart json, Function toJson) { + if (channel.ID.equals(TownChat.ID) || channel.ID.equals(NationChat.ID)) { + ((List) json.getExtra()).add(0, new TellrawPart("[SPY]")); + String jsonstr = toJson.apply(json); + Bukkit.getServer().dispatchCommand(PluginMain.Console, String.format( + "tellraw @a[score_%s=1000,score_%s_min=1000] %s", channel.ID, channel.ID, jsonstr)); + } + } /** * Return the error message for the message sender if they can't send it and the score @@ -49,13 +63,13 @@ public class TownyComponent extends Component { if (!(sender instanceof Player)) return new Channel.RecipientTestResult("§cYou are not a player!"); Resident resident = TU.getResidentMap().get(sender.getName().toLowerCase()); - Channel.RecipientTestResult result = checkTownNationChatInternal(sender, nationchat, resident); + Channel.RecipientTestResult result = checkTownNationChatInternal(nationchat, resident); if (result.errormessage != null && resident != null && resident.getModes().contains("spy")) // Only use spy if they wouldn't see it result = new Channel.RecipientTestResult(1000, "allspies"); // There won't be more than a thousand towns/nations probably return result; } - private static Channel.RecipientTestResult checkTownNationChatInternal(CommandSender sender, boolean nationchat, + private static Channel.RecipientTestResult checkTownNationChatInternal(boolean nationchat, Resident resident) { try { /* diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 28fb592..8dee232 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -22,8 +22,6 @@ import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerGetInfoEvent; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -import com.vexsoftware.votifier.model.Vote; -import com.vexsoftware.votifier.model.VotifierEvent; import lombok.val; import net.ess3.api.events.NickChangeEvent; import org.bukkit.Bukkit; @@ -139,21 +137,6 @@ public class PlayerListener implements Listener { } } - @EventHandler - @SuppressWarnings("deprecation") - public void onVotifierEvent(VotifierEvent event) { //TODO: Move to teh Core eh - Vote vote = event.getVote(); - PluginMain.Instance.getLogger().info("Vote: " + vote); - org.bukkit.OfflinePlayer op = Bukkit.getOfflinePlayer(vote.getUsername()); - Player p = Bukkit.getPlayer(vote.getUsername()); - if (op != null) { - PluginMain.economy.depositPlayer(op, 50.0); - } - if (p != null) { - p.sendMessage("§bThanks for voting! $50 was added to your account."); - } - } - @EventHandler(priority = EventPriority.HIGHEST) public void onConsoleCommand(ServerCommandEvent event) { if (onCommandPreprocess(event.getSender(), event.getCommand())) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 05cbe74..25ff051 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -33,13 +33,12 @@ commands: author: NorbiPeti depend: - Essentials -- Towny -- Votifier - Vault - ThorpeCore soft-depend: - Minigames - Dynmap-Towny +- Towny permissions: tbmc.admin: description: Gives access to /un- commands and /u admin commands From 8ff45ad676d1d0d1330603f19df25afde88115e5 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 2 Mar 2019 19:02:01 +0100 Subject: [PATCH 08/13] Some fixes Crash on player join without Towny fixed --- .../java/buttondevteam/chat/ChatProcessing.java | 4 ++-- .../chat/components/chatonly/ChatOnlyComponent.java | 9 +++++---- .../components/towncolors/TownColorComponent.java | 13 +++++++++++-- .../chat/listener/PlayerJoinLeaveListener.java | 10 +--------- .../buttondevteam/chat/listener/PlayerListener.java | 12 +++++------- src/test/java/buttondevteam/chat/ChatFormatIT.java | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/main/java/buttondevteam/chat/ChatProcessing.java b/src/main/java/buttondevteam/chat/ChatProcessing.java index b9afa17..6028b8a 100644 --- a/src/main/java/buttondevteam/chat/ChatProcessing.java +++ b/src/main/java/buttondevteam/chat/ChatProcessing.java @@ -144,7 +144,7 @@ public class ChatProcessing { }).build()); } pingedconsole = false; // Will set it to true onmatch (static constructor) - final String channelidentifier = getChannelID(channel, sender, e.getOrigin()); + final String channelidentifier = getChannelID(channel, e.getOrigin()); TellrawPart json = createTellraw(sender, message, player, mp, e.getUser(), channelidentifier, e.getOrigin()); long combinetime = System.nanoTime(); @@ -238,7 +238,7 @@ public class ChatProcessing { return player.getDisplayName(); } - static String getChannelID(Channel channel, CommandSender sender, String origin) { + static String getChannelID(Channel channel, String origin) { return ("[" + (MCORIGIN.equals(origin) ? "" : "§8" + origin.substring(0, 1) + "§r|") + channel.DisplayName().get()) + "]"; } diff --git a/src/main/java/buttondevteam/chat/components/chatonly/ChatOnlyComponent.java b/src/main/java/buttondevteam/chat/components/chatonly/ChatOnlyComponent.java index dce2089..7f17848 100644 --- a/src/main/java/buttondevteam/chat/components/chatonly/ChatOnlyComponent.java +++ b/src/main/java/buttondevteam/chat/components/chatonly/ChatOnlyComponent.java @@ -7,8 +7,8 @@ import buttondevteam.core.ComponentManager; import buttondevteam.lib.architecture.Component; import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerJoinEvent; +import lombok.val; import org.bukkit.GameMode; -import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -27,9 +27,10 @@ public class ChatOnlyComponent extends Component implements Listener { } - public static void playerJoin(ChatPlayer cp, Player p) { - if(!ComponentManager.isEnabled(ChatOnlyComponent.class)) - return; + @EventHandler + public void playerJoin(TBMCPlayerJoinEvent event) { + val p = event.getPlayer(); + val cp = event.GetPlayer().asPluginPlayer(ChatPlayer.class); if (cp.ChatOnly || p.getGameMode().equals(GameMode.SPECTATOR)) { cp.ChatOnly = false; p.setGameMode(GameMode.SURVIVAL); diff --git a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java index c7917fa..663768c 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java @@ -10,6 +10,7 @@ import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.ComponentMetadata; import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.chat.Color; +import buttondevteam.lib.player.TBMCPlayerJoinEvent; import com.earth2me.essentials.User; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.object.Nation; @@ -20,6 +21,8 @@ import org.bukkit.ChatColor; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; import org.dynmap.towny.DTBridge; import org.dynmap.towny.DynmapTownyPlugin; @@ -32,7 +35,7 @@ import java.util.function.Function; import java.util.stream.Collectors; @ComponentMetadata(depends = TownyComponent.class) -public class TownColorComponent extends Component { +public class TownColorComponent extends Component implements Listener { /** * Names lowercased */ @@ -98,6 +101,7 @@ public class TownColorComponent extends Component { registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand()); registerCommand(new TCCount()); registerListener(new TownyListener()); + registerListener(this); } @Override @@ -181,7 +185,7 @@ public class TownColorComponent extends Component { /** * Checks if the component is enabled */ - public static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join - nop, nicknames + private static void updatePlayerColors(Player player, ChatPlayer cp) { //Probably at join - nop, nicknames if (!ComponentManager.isEnabled(TownColorComponent.class)) return; User user = PluginMain.essentials.getUser(player); @@ -190,6 +194,11 @@ public class TownColorComponent extends Component { cp.FlairUpdate(); //Update in list } + @EventHandler + public void onPlayerJoin(TBMCPlayerJoinEvent event) { + updatePlayerColors(event.getPlayer(), event.GetPlayer().asPluginPlayer(ChatPlayer.class)); + } + private static void load_old(Consumer loadTC, Consumer loadNC) { PluginMain.Instance.getLogger().info("Loading files..."); diff --git a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java index 7f726bd..b8390b1 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java @@ -3,17 +3,13 @@ package buttondevteam.chat.listener; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.PlayerJoinTimerTask; import buttondevteam.chat.PluginMain; -import buttondevteam.chat.components.chatonly.ChatOnlyComponent; -import buttondevteam.chat.components.fun.UnlolCommand; import buttondevteam.chat.commands.ucmds.HistoryCommand; import buttondevteam.chat.components.flair.FlairComponent; import buttondevteam.chat.components.flair.FlairStates; -import buttondevteam.chat.components.towncolors.TownColorComponent; import buttondevteam.core.ComponentManager; import buttondevteam.lib.player.TBMCPlayerJoinEvent; import buttondevteam.lib.player.TBMCPlayerLoadEvent; import buttondevteam.lib.player.TBMCPlayerSaveEvent; -import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -59,11 +55,7 @@ public class PlayerJoinLeaveListener implements Listener { nwithoutformatting = nwithoutformatting.replace("§" + nwithoutformatting.charAt(index + 1), ""); } else nwithoutformatting = p.getName(); - PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId()); - - TownColorComponent.updatePlayerColors(p, cp); //TO!DO: Doesn't have effect - It can help to register the listener - - ChatOnlyComponent.playerJoin(cp, p); + PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId()); //TODO: FormatterComponent HistoryCommand.showHistory(e.getPlayer(), "u history", new String[0], null); } diff --git a/src/main/java/buttondevteam/chat/listener/PlayerListener.java b/src/main/java/buttondevteam/chat/listener/PlayerListener.java index 8dee232..84f7fc1 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerListener.java @@ -18,7 +18,6 @@ import buttondevteam.lib.chat.ChatMessage; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; -import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayerGetInfoEvent; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -52,8 +51,7 @@ public class PlayerListener implements Listener { public void onPlayerChat(AsyncPlayerChatEvent event) { if (event.isCancelled()) return; - ChatPlayer cp = TBMCPlayer.getPlayer(event.getPlayer().getUniqueId(), ChatPlayer.class); - TBMCChatAPI.SendChatMessage(ChatMessage.builder(event.getPlayer(), cp, event.getMessage()).build()); + //The custom event is called in the core, but doesn't cancel the MC event event.setCancelled(true); // The custom event should only be cancelled when muted or similar } @@ -170,12 +168,12 @@ public class PlayerListener implements Listener { HistoryCommand.addChatMessage(e.getCm(), e.getChannel()); e.setCancelled(ChatProcessing.ProcessChat(e)); } catch (NoClassDefFoundError | Exception ex) { // Weird things can happen + val str = "§c!§r[" + e.getChannel().DisplayName().get() + "] <" + + ThorpeUtils.getDisplayName(e.getSender()) + "> " + e.getMessage(); for (Player p : Bukkit.getOnlinePlayers()) if (e.shouldSendTo(p)) - p.sendMessage("§c!§r[" - + e.getChannel().DisplayName().get() + "] <" + (e.getSender() instanceof Player - ? ((Player) e.getSender()).getDisplayName() : e.getSender().getName()) - + "> " + e.getMessage()); + p.sendMessage(str); + Bukkit.getConsoleSender().sendMessage(str); TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex); } } diff --git a/src/test/java/buttondevteam/chat/ChatFormatIT.java b/src/test/java/buttondevteam/chat/ChatFormatIT.java index 4531c16..839942f 100644 --- a/src/test/java/buttondevteam/chat/ChatFormatIT.java +++ b/src/test/java/buttondevteam/chat/ChatFormatIT.java @@ -92,7 +92,7 @@ public class ChatFormatIT { @Test public void testMessage() { ArrayList cfs = ChatProcessing.addFormatters(Color.White); - final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, sender, ChatProcessing.MCORIGIN); + final String chid = ChatProcessing.getChannelID(Channel.GlobalChat, ChatProcessing.MCORIGIN); final TellrawPart tp = ChatProcessing.createTellraw(sender, message, null, null, null, chid, ChatProcessing.MCORIGIN); ChatFormatter.Combine(cfs, message, tp); System.out.println("Testing: " + message); From ae49777007a408ea9c387193678b5df6e1761997 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 8 Mar 2019 22:22:12 +0100 Subject: [PATCH 09/13] Made appendtext commands fully configurable --- .../java/buttondevteam/chat/PluginMain.java | 2 + .../appendtext/AppendTextCommandBase.java | 27 ----- .../commands/appendtext/LennyCommand.java | 18 ---- .../commands/appendtext/ShrugCommand.java | 18 ---- .../commands/appendtext/TableflipCommand.java | 17 --- .../commands/appendtext/UnflipCommand.java | 18 ---- .../commands/appendtext/WaitWhatCommand.java | 19 ---- .../appendext/AppendTextComponent.java | 100 ++++++++++++++++-- 8 files changed, 96 insertions(+), 123 deletions(-) delete mode 100644 src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java delete mode 100644 src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java delete mode 100644 src/main/java/buttondevteam/chat/commands/appendtext/ShrugCommand.java delete mode 100644 src/main/java/buttondevteam/chat/commands/appendtext/TableflipCommand.java delete mode 100644 src/main/java/buttondevteam/chat/commands/appendtext/UnflipCommand.java delete mode 100644 src/main/java/buttondevteam/chat/commands/appendtext/WaitWhatCommand.java diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index 2361d37..7a8bec7 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -2,6 +2,7 @@ package buttondevteam.chat; import buttondevteam.chat.commands.YeehawCommand; import buttondevteam.chat.components.announce.AnnouncerComponent; +import buttondevteam.chat.components.appendext.AppendTextComponent; import buttondevteam.chat.components.flair.FlairComponent; import buttondevteam.chat.components.fun.FunComponent; import buttondevteam.chat.components.towncolors.TownColorComponent; @@ -66,6 +67,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 Component.registerComponent(this, new FlairComponent()); //The original purpose of this plugin Component.registerComponent(this, new AnnouncerComponent()); Component.registerComponent(this, new FunComponent()); + Component.registerComponent(this, new AppendTextComponent()); } public static Essentials essentials = null; diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java b/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java deleted file mode 100644 index 5e36f88..0000000 --- a/src/main/java/buttondevteam/chat/commands/appendtext/AppendTextCommandBase.java +++ /dev/null @@ -1,27 +0,0 @@ -package buttondevteam.chat.commands.appendtext; - -import buttondevteam.lib.chat.ChatMessage; -import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.chat.TBMCChatAPI; -import buttondevteam.lib.chat.TBMCCommandBase; -import buttondevteam.lib.player.ChromaGamerBase; -import org.bukkit.command.CommandSender; - -@CommandClass(modOnly = false, excludeFromPath = true) -public abstract class AppendTextCommandBase extends TBMCCommandBase { - - public abstract String[] GetHelpText(String alias); - - public abstract String GetAppendedText(); - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - StringBuilder msg = new StringBuilder(); - for (String arg : args) msg.append(arg).append(" "); - msg.append(GetAppendedText()); - TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender, - ChromaGamerBase.getFromSender(sender), msg.toString()) - .fromCommand(true).build()); - return true; - } -} diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java b/src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java deleted file mode 100644 index 8d04cf2..0000000 --- a/src/main/java/buttondevteam/chat/commands/appendtext/LennyCommand.java +++ /dev/null @@ -1,18 +0,0 @@ -package buttondevteam.chat.commands.appendtext; - -public final class LennyCommand extends AppendTextCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Lenny ----", // - "This command appends a Lenny face after your message", // - "Or just sends one", // - "Use either /" + alias + " or just /" + alias }; // - } - - @Override - public String GetAppendedText() { - return "( ͡° ͜ʖ ͡°)"; - } - -} diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/ShrugCommand.java b/src/main/java/buttondevteam/chat/commands/appendtext/ShrugCommand.java deleted file mode 100644 index 56d30dc..0000000 --- a/src/main/java/buttondevteam/chat/commands/appendtext/ShrugCommand.java +++ /dev/null @@ -1,18 +0,0 @@ -package buttondevteam.chat.commands.appendtext; - -public final class ShrugCommand extends AppendTextCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Shrug ----", // - "This command appends a shrug after your message", // - "Or just makes you shrug", // - "Use either /" + alias + " or just /" + alias }; // - } - - @Override - public String GetAppendedText() { - return "¯\\\\\\_(ツ)\\_/¯"; - } - -} diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/TableflipCommand.java b/src/main/java/buttondevteam/chat/commands/appendtext/TableflipCommand.java deleted file mode 100644 index 6a98cc9..0000000 --- a/src/main/java/buttondevteam/chat/commands/appendtext/TableflipCommand.java +++ /dev/null @@ -1,17 +0,0 @@ -package buttondevteam.chat.commands.appendtext; - -public final class TableflipCommand extends AppendTextCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Tableflip ----", // - "This command appends a tableflip after your message", // - "Or just makes you tableflip", // - "Use either /" + alias + " or just /" + alias }; - } - - @Override - public String GetAppendedText() { - return "(╯°□°)╯︵ ┻━┻"; - } -} diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/UnflipCommand.java b/src/main/java/buttondevteam/chat/commands/appendtext/UnflipCommand.java deleted file mode 100644 index 498e077..0000000 --- a/src/main/java/buttondevteam/chat/commands/appendtext/UnflipCommand.java +++ /dev/null @@ -1,18 +0,0 @@ -package buttondevteam.chat.commands.appendtext; - -public final class UnflipCommand extends AppendTextCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Unflip ----", // - "This command appends an unflip after your message", // - "Or just unflips as you", // - "Use either /" + alias + " or just /" + alias }; - } - - @Override - public String GetAppendedText() { - return "┬─┬ ノ( ゜-゜ノ)"; - } - -} diff --git a/src/main/java/buttondevteam/chat/commands/appendtext/WaitWhatCommand.java b/src/main/java/buttondevteam/chat/commands/appendtext/WaitWhatCommand.java deleted file mode 100644 index 08b7799..0000000 --- a/src/main/java/buttondevteam/chat/commands/appendtext/WaitWhatCommand.java +++ /dev/null @@ -1,19 +0,0 @@ -package buttondevteam.chat.commands.appendtext; - -import buttondevteam.lib.chat.CommandClass; - -@CommandClass(modOnly = false) -public class WaitWhatCommand extends AppendTextCommandBase { - @Override - public String[] GetHelpText(String alias) { - return new String[] { // - "§6--- Wait what ----", // - "Wait what" // - }; - } - - @Override - public String GetAppendedText() { - return "wait what"; - } -} diff --git a/src/main/java/buttondevteam/chat/components/appendext/AppendTextComponent.java b/src/main/java/buttondevteam/chat/components/appendext/AppendTextComponent.java index 42637c1..7bd9778 100644 --- a/src/main/java/buttondevteam/chat/components/appendext/AppendTextComponent.java +++ b/src/main/java/buttondevteam/chat/components/appendext/AppendTextComponent.java @@ -1,27 +1,115 @@ package buttondevteam.chat.components.appendext; +import buttondevteam.chat.PluginMain; import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.architecture.IHaveConfig; +import buttondevteam.lib.chat.*; +import buttondevteam.lib.player.ChromaGamerBase; import lombok.val; +import org.bukkit.command.CommandSender; -import java.util.ArrayList; +import java.lang.reflect.Method; import java.util.HashMap; -import java.util.function.Supplier; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.function.Consumer; -public class AppendTextComponent extends Component { - private HashMap appendTexts=new HashMap<>(); +public class AppendTextComponent extends Component { + private Map appendTexts; private ConfigData helpText(IHaveConfig config) { - return config.getData("helpText", ()->new String[0]); + return config.getData("helpText", () -> new String[]{ + "Tableflip", // + "This command appends a tableflip after your message", // + "Or just makes you tableflip", // + }); + } + + private ConfigData appendedText(IHaveConfig config) { + return config.getData("appendedText", () -> "tableflip"); } @Override protected void enable() { - val cs=getConfig().getConfig(); //TODO + val map = new HashMap>(); + map.put("tableflip", conf -> { + helpText(conf).set(new String[]{ + "Tableflip", // + "This command appends a tableflip after your message", // + "Or just makes you tableflip", // + }); + appendedText(conf).set("(╯°□°)╯︵ ┻━┻"); + }); + map.put("unflip", conf -> { + helpText(conf).set(new String[]{ + "Unflip", // + "This command appends an unflip after your message", // + "Or just unflips as you", // + }); + appendedText(conf).set("┬─┬ ノ( ゜-゜ノ)"); + }); + map.put("shrug", conf -> { + helpText(conf).set(new String[]{ + "Shrug", // + "This command appends a shrug after your message", // + "Or just makes you shrug", // + }); + appendedText(conf).set("¯\\\\\\_(ツ)\\_/¯"); + }); + map.put("lenny", conf -> { + helpText(conf).set(new String[]{ + "Lenny", // + "This command appends a Lenny face after your message", // + "Or just sends one", // + }); + appendedText(conf).set("( ͡° ͜ʖ ͡°)"); + }); + map.put("ww", conf -> { + helpText(conf).set(new String[]{ + "Wait what", // + "Wait what" // + }); + appendedText(conf).set("wait what"); + }); + appendTexts = getConfigMap("texts", map); + for (String cmd : appendTexts.keySet()) + registerCommand(new CommandHandler(cmd)); } @Override protected void disable() { } + + @CommandClass + public class CommandHandler extends ICommand2MC { + private final String path; + private final String[] helpText; + private final String appendedText; + + CommandHandler(String command) { + val conf = appendTexts.get(command); + if (conf == null) throw new NoSuchElementException("AppendText command not found: " + command); + path = command; + helpText = helpText(conf).get(); + appendedText = appendedText(conf).get(); + + } + + @Command2.Subcommand + public void def(CommandSender sender, @Command2.OptionalArg @Command2.TextArg String message) { + TBMCChatAPI.SendChatMessage(ChatMessage.builder(sender, ChromaGamerBase.getFromSender(sender), + (message == null ? "" : message + " ") + appendedText).fromCommand(true).build()); + } + + @Override + public String getCommandPath() { + return path; + } + + @Override + public String[] getHelpText(Method method, Command2.Subcommand ann) { + return helpText; + } + } } From e510667215ff915fc6629ba810cd5c519853e6f0 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 9 Mar 2019 23:02:46 +0100 Subject: [PATCH 10/13] Rename, fix, nc toggle Renamed plugin Fixed duplicate chat handling (DC->MC) Implemented nation color toggle --- .../java/buttondevteam/chat/PluginMain.java | 4 +- .../announce/AnnouncerComponent.java | 3 +- .../chat/components/flair/FlairComponent.java | 3 +- .../chat/components/fun/FunComponent.java | 3 +- .../towncolors/TownColorComponent.java | 56 ++++++++++++------- .../components/towncolors/TownyListener.java | 5 ++ .../towncolors/admin/TownColorCommand.java | 31 +++++----- .../chat/components/towny/TownyComponent.java | 2 +- src/main/resources/plugin.yml | 2 +- 9 files changed, 68 insertions(+), 41 deletions(-) diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index 7a8bec7..b623489 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -9,6 +9,7 @@ import buttondevteam.chat.components.towncolors.TownColorComponent; import buttondevteam.chat.components.towny.TownyComponent; import buttondevteam.chat.listener.PlayerJoinLeaveListener; import buttondevteam.chat.listener.PlayerListener; +import buttondevteam.core.MainPlugin; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.architecture.ButtonPlugin; @@ -17,7 +18,6 @@ import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.TBMCChatAPI; import com.earth2me.essentials.Essentials; -import net.milkbowl.vault.chat.Chat; import net.milkbowl.vault.economy.Economy; import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; @@ -50,6 +50,7 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); TBMCCoreAPI.RegisterEventsForExceptions(new PlayerJoinLeaveListener(), this); TBMCChatAPI.AddCommands(this, YeehawCommand.class); + MainPlugin.Instance.setChatHandlerEnabled(false); //Disable Core chat handler Console = this.getServer().getConsoleSender(); SB = getServer().getScoreboardManager().getMainScoreboard(); // Main can be detected with @a[score_...] @@ -79,7 +80,6 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 public static Permission permission = null; public static Economy economy = null; - public static Chat chat = null; private boolean setupPermissions() { RegisteredServiceProvider permissionProvider = getServer().getServicesManager() diff --git a/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java b/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java index f841a2b..123b2c4 100644 --- a/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java +++ b/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java @@ -1,5 +1,6 @@ package buttondevteam.chat.components.announce; +import buttondevteam.chat.PluginMain; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.architecture.Component; @@ -9,7 +10,7 @@ import org.bukkit.Bukkit; import java.util.ArrayList; -public class AnnouncerComponent extends Component implements Runnable { +public class AnnouncerComponent extends Component implements Runnable { public ConfigData> AnnounceMessages() { return getConfig().getData("announceMessages", new ArrayList<>(0)); } diff --git a/src/main/java/buttondevteam/chat/components/flair/FlairComponent.java b/src/main/java/buttondevteam/chat/components/flair/FlairComponent.java index 3243205..89b4598 100644 --- a/src/main/java/buttondevteam/chat/components/flair/FlairComponent.java +++ b/src/main/java/buttondevteam/chat/components/flair/FlairComponent.java @@ -1,6 +1,7 @@ package buttondevteam.chat.components.flair; import buttondevteam.chat.ChatPlayer; +import buttondevteam.chat.PluginMain; import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.ConfigData; @@ -21,7 +22,7 @@ import java.net.UnknownHostException; import java.text.SimpleDateFormat; import java.util.*; -public class FlairComponent extends Component { +public class FlairComponent extends Component { private ConfigData FlairThreadURL() { return getConfig().getData("flairThreadURL", "https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/"); } diff --git a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java index 9053635..c11a84a 100644 --- a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java +++ b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java @@ -11,7 +11,6 @@ import buttondevteam.lib.architecture.Component; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.TBMCPlayer; -import lombok.Getter; import lombok.val; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; @@ -29,7 +28,7 @@ import org.bukkit.scheduler.BukkitTask; import java.util.ArrayList; import java.util.Random; -public class FunComponent extends Component implements Listener { +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; diff --git a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java index 663768c..8b6314f 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java @@ -14,6 +14,7 @@ import buttondevteam.lib.player.TBMCPlayerJoinEvent; import com.earth2me.essentials.User; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.object.Nation; +import lombok.Getter; import lombok.experimental.var; import lombok.val; import org.bukkit.Bukkit; @@ -35,7 +36,7 @@ import java.util.function.Function; import java.util.stream.Collectors; @ComponentMetadata(depends = TownyComponent.class) -public class TownColorComponent extends Component implements Listener { +public class TownColorComponent extends Component implements Listener { /** * Names lowercased */ @@ -49,17 +50,22 @@ public class TownColorComponent extends Component implements Listener { return getConfig().getData("colorCount", (byte) 1, cc -> ((Integer) cc).byteValue(), Byte::intValue); } - public ConfigData useNationColors() { //TODO + public ConfigData useNationColors() { return getConfig().getData("useNationColors", true); } + @Getter + private static TownColorComponent component; + @SuppressWarnings("unchecked") @Override protected void enable() { + component = this; //TODO: Don't register all commands automatically (welp) Consumer loadTC = cs -> TownColorComponent.TownColors.putAll(cs.getValues(true).entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, v -> ((List) v.getValue()).stream() .map(Color::valueOf).toArray(Color[]::new)))); + boolean usenc = useNationColors().get(); Consumer loadNC = ncs -> TownColorComponent.NationColor.putAll(ncs.getValues(true).entrySet().stream() .collect(Collectors.toMap(Map.Entry::getKey, v -> Color.valueOf((String) v.getValue())))); @@ -68,14 +74,17 @@ public class TownColorComponent extends Component implements Listener { loadTC.accept(cs); else load_old(loadTC, null); //Load old data - var ncs = getConfig().getConfig().getConfigurationSection("nationcolors"); - if (ncs != null) - loadNC.accept(ncs); - else - load_old(null, loadNC); //Why not choose by making different args null + if (usenc) { + var ncs = getConfig().getConfig().getConfigurationSection("nationcolors"); + if (ncs != null) + loadNC.accept(ncs); + else + load_old(null, loadNC); //Why not choose by making different args null + } TownColors.keySet().removeIf(t -> !TownyComponent.TU.getTownsMap().containsKey(t)); // Removes town colors for deleted/renamed towns - NationColor.keySet().removeIf(n -> !TownyComponent.TU.getNationsMap().containsKey(n)); // Removes nation colors for deleted/renamed nations + if (usenc) + NationColor.keySet().removeIf(n -> !TownyComponent.TU.getNationsMap().containsKey(n)); // Removes nation colors for deleted/renamed nations Bukkit.getScheduler().runTask(getPlugin(), () -> { val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny"); @@ -86,7 +95,9 @@ public class TownColorComponent extends Component implements Listener { val town = TownyComponent.TU.getTownsMap().get(entry.getKey()); Nation nation; Color nc; - if (!town.hasNation() || (nation = town.getNation()) == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null) + if (!useNationColors().get()) + nc = null; + else if (!town.hasNation() || (nation = town.getNation()) == null || (nc = NationColor.get(nation.getName().toLowerCase())) == null) nc = Color.White; setTownColor(dtp, buttondevteam.chat.components.towncolors.admin.TownColorCommand.getTownNameCased(entry.getKey()), entry.getValue(), nc); } catch (Exception e) { @@ -96,9 +107,11 @@ public class TownColorComponent extends Component implements Listener { }); registerCommand(new TownColorCommand()); - registerCommand(new NationColorCommand()); + if (useNationColors().get()) + registerCommand(new NationColorCommand()); registerCommand(new buttondevteam.chat.components.towncolors.admin.TownColorCommand()); - registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand()); + if (useNationColors().get()) + registerCommand(new buttondevteam.chat.components.towncolors.admin.NationColorCommand()); registerCommand(new TCCount()); registerListener(new TownyListener()); registerListener(this); @@ -108,8 +121,9 @@ public class TownColorComponent extends Component implements Listener { protected void disable() { getConfig().getConfig().createSection("towncolors", TownColors.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> Arrays.stream(v.getValue()).map(Enum::toString).toArray(String[]::new)))); - getConfig().getConfig().createSection("nationcolors", NationColor.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, - v -> v.getValue().toString()))); + if (useNationColors().get()) + getConfig().getConfig().createSection("nationcolors", NationColor.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, + v -> v.getValue().toString()))); } /** @@ -157,18 +171,20 @@ public class TownColorComponent extends Component implements Listener { len = name.length() / (clrs.length+1); else len = name.length() / clrs.length;*/ + boolean usenc = component.useNationColors().get(); val nclar = cp.NameColorLocations().get(); int[] ncl = nclar == null ? null : nclar.stream().mapToInt(Integer::intValue).toArray(); - if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length + 1)) //+1: Nation color + if (ncl != null && (Arrays.stream(ncl).sum() != name.length() || ncl.length != clrs.length + (usenc ? 1 : 0))) //+1: Nation color ncl = null; // Reset if name length changed //System.out.println("ncl: "+Arrays.toString(ncl)+" - sum: "+Arrays.stream(ncl).sum()+" - name len: "+name.length()); - if (!res.getTown().hasNation() - || (nc = NationColor.get(res.getTown().getNation().getName().toLowerCase())) == null) - nc = Color.White; - ret.append(anyColoredNamePart.apply(nc, ncl == null ? len : ncl[0])); //Make first color the nation color + if (usenc) { + if (!res.getTown().hasNation() + || (nc = NationColor.get(res.getTown().getNation().getName().toLowerCase())) == null) + nc = Color.White; + ret.append(anyColoredNamePart.apply(nc, ncl == null ? len : ncl[0])); //Make first color the nation color + } for (int i = 0; i < clrs.length; i++) - //ret.append(coloredNamePart.apply(ncl == null ? len : (nc==null?ncl[i]:ncl[i+1]), i)); - ret.append(coloredNamePart.apply(ncl == null ? len : ncl[i + 1], i)); + ret.append(coloredNamePart.apply(ncl == null ? len : (usenc ? ncl[i + 1] : ncl[i]), i)); return ret.toString(); } catch (NotRegisteredException e) { return nickname; diff --git a/src/main/java/buttondevteam/chat/components/towncolors/TownyListener.java b/src/main/java/buttondevteam/chat/components/towncolors/TownyListener.java index 6a9c28b..28501d9 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/TownyListener.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/TownyListener.java @@ -61,6 +61,7 @@ public class TownyListener implements Listener { @EventHandler public void onNationRename(RenameNationEvent event) { + if (!TownColorComponent.getComponent().useNationColors().get()) return; val clrs = TownColorComponent.NationColor.remove(event.getOldName().toLowerCase()); if (clrs != null) TownColorComponent.NationColor.put(event.getNation().getName().toLowerCase(), clrs); @@ -68,21 +69,25 @@ public class TownyListener implements Listener { @EventHandler //Gets called on town load as well public void onNationJoin(NationAddTownEvent event) { + if (!TownColorComponent.getComponent().useNationColors().get()) return; updateTownMembers(event.getTown()); } @EventHandler public void onNationLeave(NationRemoveTownEvent event) { + if (!TownColorComponent.getComponent().useNationColors().get()) return; updateTownMembers(event.getTown()); //The town still has it's colours } @EventHandler public void onNationDelete(DeleteNationEvent event) { + if (!TownColorComponent.getComponent().useNationColors().get()) return; TownColorComponent.NationColor.remove(event.getNationName().toLowerCase()); } @EventHandler public void onNationCreate(NewNationEvent event) { + if (!TownColorComponent.getComponent().useNationColors().get()) return; Player p = Bukkit.getPlayer(event.getNation().getCapital().getMayor().getName()); if (p != null) p.sendMessage("§6Use /u nationcolor to set a color for the nation."); diff --git a/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java b/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java index b4d5391..7993b49 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java @@ -51,21 +51,26 @@ public class TownColorCommand extends AdminCommandBase { clrs[i - 1] = c.get(); } Color tnc; - try { - tnc = TownColorComponent.NationColor.get(targetTown.getNation().getName().toLowerCase()); - } catch (Exception e) { - tnc = null; - } - if (tnc == null) tnc = Color.White; //Default nation color - TODO: Make configurable + boolean usenc = TownColorComponent.getComponent().useNationColors().get(); + if (usenc) { + try { + tnc = TownColorComponent.NationColor.get(targetTown.getNation().getName().toLowerCase()); + } catch (Exception e) { + tnc = null; + } + if (tnc == null) tnc = Color.White; //Default nation color - TODO: Make configurable + } else tnc = null; for (Map.Entry other : TownColorComponent.TownColors.entrySet()) { Color nc; - try { - nc = TownColorComponent.NationColor.get(TownyComponent.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase()); - } catch (Exception e) { //Too lazy for lots of null-checks and it may throw exceptions anyways - nc = null; - } - if (nc == null) nc = Color.White; //Default nation color - if (nc.getName().equals(tnc.getName())) { + if (usenc) { + try { + nc = TownColorComponent.NationColor.get(TownyComponent.TU.getTownsMap().get(other.getKey()).getNation().getName().toLowerCase()); + } catch (Exception e) { //Too lazy for lots of null-checks and it may throw exceptions anyways + nc = null; + } + if (nc == null) nc = Color.White; //Default nation color + } else nc = null; + if (!usenc || nc.getName().equals(tnc.getName())) { int C = 0; if (clrs.length == other.getValue().length) for (int i = 0; i < clrs.length; i++) diff --git a/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java b/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java index 6f3d283..dbfe93c 100644 --- a/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java +++ b/src/main/java/buttondevteam/chat/components/towny/TownyComponent.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.function.Function; import java.util.stream.Collectors; -public class TownyComponent extends Component { +public class TownyComponent extends Component { public static TownyUniverse TU; private static ArrayList Towns; private static ArrayList Nations; diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 25ff051..d618f6b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,4 +1,4 @@ -name: ButtonChat +name: Thorpe-Chat main: buttondevteam.chat.PluginMain version: 4.0 commands: From 5b5252382e8730f4cd3536528b15abd8c06261d7 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Mon, 11 Mar 2019 12:36:19 +0100 Subject: [PATCH 11/13] Converted, moved and deleted some commands Converted & noved: /u opme /yeehaw /u c Deleted: /u admin playerinfo /u admin updateplugin Also made the FunComponent more configurable Also removed old command registration, so some commands will stop working #85 --- .idea/ButtonChat.iml | 28 +++ .../java/buttondevteam/chat/PluginMain.java | 2 - .../chat/commands/ucmds/HelpCommand.java | 167 +++++++++--------- .../chat/commands/ucmds/OpmeCommand.java | 21 --- .../ucmds/admin/PlayerInfoCommand.java | 43 ----- .../commands/ucmds/admin/UpdatePlugin.java | 40 ----- .../ucmds => components/fun}/CCommand.java | 112 ++++++------ .../chat/components/fun/FunComponent.java | 51 ++++-- .../chat/components/fun/OpmeCommand.java | 18 ++ .../fun}/YeehawCommand.java | 58 +++--- 10 files changed, 246 insertions(+), 294 deletions(-) delete mode 100644 src/main/java/buttondevteam/chat/commands/ucmds/OpmeCommand.java delete mode 100644 src/main/java/buttondevteam/chat/commands/ucmds/admin/PlayerInfoCommand.java delete mode 100644 src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java rename src/main/java/buttondevteam/chat/{commands/ucmds => components/fun}/CCommand.java (61%) create mode 100644 src/main/java/buttondevteam/chat/components/fun/OpmeCommand.java rename src/main/java/buttondevteam/chat/{commands => components/fun}/YeehawCommand.java (61%) diff --git a/.idea/ButtonChat.iml b/.idea/ButtonChat.iml index 3d32cdf..73ae0d4 100644 --- a/.idea/ButtonChat.iml +++ b/.idea/ButtonChat.iml @@ -39,5 +39,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index b623489..ebb699b 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -1,6 +1,5 @@ package buttondevteam.chat; -import buttondevteam.chat.commands.YeehawCommand; import buttondevteam.chat.components.announce.AnnouncerComponent; import buttondevteam.chat.components.appendext.AppendTextComponent; import buttondevteam.chat.components.flair.FlairComponent; @@ -49,7 +48,6 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 TBMCCoreAPI.RegisterEventsForExceptions(new PlayerListener(), this); TBMCCoreAPI.RegisterEventsForExceptions(new PlayerJoinLeaveListener(), this); - TBMCChatAPI.AddCommands(this, YeehawCommand.class); MainPlugin.Instance.setChatHandlerEnabled(false); //Disable Core chat handler Console = this.getServer().getConsoleSender(); diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java index 8be549e..a009485 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java @@ -1,84 +1,83 @@ -package buttondevteam.chat.commands.ucmds; - -import java.util.ArrayList; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import buttondevteam.chat.PluginMain; -import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.chat.TBMCChatAPI; -import buttondevteam.lib.chat.TBMCCommandBase; - -@CommandClass(modOnly = false) -public final class HelpCommand extends UCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Help ----", "Prints out help messages for the TBMC plugins" }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - if (args.length == 0) { - sender.sendMessage(new String[] { "§6---- TBMC Help ----", "Do /u help for more info", - "Do /u help [subcommands] for more info about a command", "Topics:", - "commands: See all the commands from this plugin", - "chat: Shows some info about custom chat features", "colors: Shows Minecraft color codes" }); - return true; - } - if (args[0].equalsIgnoreCase("chat")) - sender.sendMessage(new String[] { "§6---- Chat features ----", - "- [g] Channel identifier: Click it to copy message", "-- [g]: Global chat (/g)", - "-- [TC] Town chat (/tc)", "-- [NC] Nation chat (/nc)", - "- Playernames: Hover over them to get some player info", - "-- Respect: This is the number of paid respects divided by eliglble deaths. This is a reference to CoD:AW's \"Press F to pay respects\"" }); - else if (args[0].equalsIgnoreCase("commands")) { - ArrayList text = new ArrayList(); - text.add("§6---- Command list ----"); - for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) - if (!cmd.getClass().getAnnotation(CommandClass.class).modOnly() || PluginMain.permission.has(sender, "tbmc.admin")) - if (!cmd.isPlayerOnly() || sender instanceof Player) - if (!cmd.GetCommandPath().contains(" ")) - text.add("/" + cmd.GetCommandPath()); - else { - final String topcmd = cmd.GetCommandPath().substring(0, cmd.GetCommandPath().indexOf(' ')); - if (!text.contains("/" + topcmd)) - text.add("/" + topcmd); - } - sender.sendMessage(text.toArray(new String[text.size()])); - } else if (args[0].equalsIgnoreCase("colors")) { - sender.sendMessage(new String[] { "§6---- Chat colors/formats ----", // - "Tellraw name - Code | Tellraw name - Code", // - "§0black - &0 | §1dark_blue - &1", // - "§2dark_green - &2 | §3dark_aqua - &3", // - "§4dark_red - &4 | §5dark_purple - &5", // - "§6gold - &6 | §7gray - &7", // - "§8dark_gray - &8 | §9blue - &9", // - "§agreen - &a | §baqua - &b", // - "§cred - &c | §dlight_purple - &d", // - "§eyellow - &e | §fwhite - &f", // - "§rreset - &r | §kk§robfuscated - &k", // - "§lbold - &l | §mstrikethrough - &m", // - "§nunderline - &n | §oitalic - &o", // - "The format codes in tellraw should be used like \"italic\":\"true\"" }); // - } else { - String path = args[0]; - for (int i = 1; i < args.length; i++) - path += " " + args[i]; - TBMCCommandBase cmd = TBMCChatAPI.GetCommands().get(path); - if (cmd == null) { - String[] subcmds = TBMCChatAPI.GetSubCommands(path, sender); - if (subcmds.length > 0) - sender.sendMessage(subcmds); - else - sender.sendMessage( - new String[] { "§cError: Command not found or you don't have permission for it: " + path, - "Usage example: /u accept --> /u help u accept" }); - } else - sender.sendMessage(cmd.GetHelpText(args[0])); - } - return true; - - } -} +package buttondevteam.chat.commands.ucmds; + +import buttondevteam.chat.PluginMain; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.TBMCChatAPI; +import buttondevteam.lib.chat.TBMCCommandBase; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.ArrayList; + +@CommandClass(modOnly = false) +public final class HelpCommand extends UCommandBase { + + @Override + public String[] GetHelpText(String alias) { + return new String[] { "§6---- Help ----", "Prints out help messages for the TBMC plugins" }; + } + + @Override + public boolean OnCommand(CommandSender sender, String alias, String[] args) { + if (args.length == 0) { + sender.sendMessage(new String[] { "§6---- TBMC Help ----", "Do /u help for more info", + "Do /u help [subcommands] for more info about a command", "Topics:", + "commands: See all the commands from this plugin", + "chat: Shows some info about custom chat features", "colors: Shows Minecraft color codes" }); + return true; + } + if (args[0].equalsIgnoreCase("chat")) + sender.sendMessage(new String[] { "§6---- Chat features ----", + "- [g] Channel identifier: Click it to copy message", "-- [g]: Global chat (/g)", + "-- [TC] Town chat (/tc)", "-- [NC] Nation chat (/nc)", + "- Playernames: Hover over them to get some player info", + "-- Respect: This is the number of paid respects divided by eliglble deaths. This is a reference to CoD:AW's \"Press F to pay respects\"" }); + else if (args[0].equalsIgnoreCase("commands")) { + ArrayList text = new ArrayList(); + text.add("§6---- Command list ----"); + for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) + if (!cmd.getClass().getAnnotation(CommandClass.class).modOnly() || PluginMain.permission.has(sender, "tbmc.admin")) + if (!cmd.isPlayerOnly() || sender instanceof Player) + if (!cmd.GetCommandPath().contains(" ")) + text.add("/" + cmd.GetCommandPath()); + else { + final String topcmd = cmd.GetCommandPath().substring(0, cmd.GetCommandPath().indexOf(' ')); + if (!text.contains("/" + topcmd)) + text.add("/" + topcmd); + } + sender.sendMessage(text.toArray(new String[0])); + } else if (args[0].equalsIgnoreCase("colors")) { + sender.sendMessage(new String[] { "§6---- Chat colors/formats ----", // + "Tellraw name - Code | Tellraw name - Code", // + "§0black - &0 | §1dark_blue - &1", // + "§2dark_green - &2 | §3dark_aqua - &3", // + "§4dark_red - &4 | §5dark_purple - &5", // + "§6gold - &6 | §7gray - &7", // + "§8dark_gray - &8 | §9blue - &9", // + "§agreen - &a | §baqua - &b", // + "§cred - &c | §dlight_purple - &d", // + "§eyellow - &e | §fwhite - &f", // + "§rreset - &r | §kk§robfuscated - &k", // + "§lbold - &l | §mstrikethrough - &m", // + "§nunderline - &n | §oitalic - &o", // + "The format codes in tellraw should be used like \"italic\":\"true\"" }); // + } else { + String path = args[0]; + for (int i = 1; i < args.length; i++) + path += " " + args[i]; + TBMCCommandBase cmd = TBMCChatAPI.GetCommands().get(path); + if (cmd == null) { + String[] subcmds = TBMCChatAPI.GetSubCommands(path, sender); + if (subcmds.length > 0) + sender.sendMessage(subcmds); + else + sender.sendMessage( + new String[] { "§cError: Command not found or you don't have permission for it: " + path, + "Usage example: /u accept --> /u help u accept" }); + } else + sender.sendMessage(cmd.GetHelpText(args[0])); + } + return true; + + } +} diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/OpmeCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/OpmeCommand.java deleted file mode 100644 index adc2096..0000000 --- a/src/main/java/buttondevteam/chat/commands/ucmds/OpmeCommand.java +++ /dev/null @@ -1,21 +0,0 @@ -package buttondevteam.chat.commands.ucmds; - -import org.bukkit.command.CommandSender; - -import buttondevteam.lib.chat.CommandClass; - -@CommandClass(modOnly = false) -public class OpmeCommand extends UCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- OP me ----", "Totally makes you OP" }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - sender.sendMessage("It would be nice, wouldn't it?"); - return true; - } - -} diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/PlayerInfoCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/PlayerInfoCommand.java deleted file mode 100644 index 241c0a1..0000000 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/PlayerInfoCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -package buttondevteam.chat.commands.ucmds.admin; - -import org.bukkit.command.CommandSender; - -import buttondevteam.chat.ChatPlayer; -import buttondevteam.lib.player.TBMCPlayerBase; - -public class PlayerInfoCommand extends AdminCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Player info ----", - "Shows some info about the player's flair, Reddit username(s) and other data known by the plugin", - "Usage: /u admin playerinfo " }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - if (args.length == 0) { - return false; - } - ChatPlayer p = TBMCPlayerBase.getFromName(args[0], ChatPlayer.class); - if (p == null) { - sender.sendMessage("§cPlayer not found: " + args[0] + "§r"); - return true; - } - StringBuilder sb = new StringBuilder(); - sb.append("§6Usernames:"); - for (String username : p.UserNames()) - sb.append(" ").append(username); - sender.sendMessage(new String[] { // - "Player name: " + p.PlayerName(), // - "User flair: " + p.GetFormattedFlair(), // - "Username: " + p.UserName(), // - "Flair state: " + p.FlairState(), // - sb.toString(), // - "FCount: " + p.FCount(), // - "FDeaths: " + p.FDeaths() // - }); - return true; - } - -} diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java deleted file mode 100644 index d78379d..0000000 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/UpdatePlugin.java +++ /dev/null @@ -1,40 +0,0 @@ -package buttondevteam.chat.commands.ucmds.admin; - -import buttondevteam.chat.PluginMain; -import buttondevteam.core.component.updater.PluginUpdater; -import buttondevteam.lib.TBMCCoreAPI; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; - -public class UpdatePlugin extends AdminCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { // - "§6---- Update plugin ----", // - "This command downloads the latest version of a TBMC plugin from GitHub", // - "To update a plugin: /" + alias + " ", // - "To list the plugin names: /" + alias // - }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> { - if (args.length == 0) { - sender.sendMessage("Downloading plugin names..."); - boolean first = true; - for (String plugin : PluginUpdater.GetPluginNames()) { - if (first) { - sender.sendMessage("§6---- Plugin names ----"); - first = false; - } - sender.sendMessage("- " + plugin); - } - } else - TBMCCoreAPI.UpdatePlugin(args[0], sender, args.length == 1 ? "master" : args[1]); - }); - return true; - } - -} diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java b/src/main/java/buttondevteam/chat/components/fun/CCommand.java similarity index 61% rename from src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java rename to src/main/java/buttondevteam/chat/components/fun/CCommand.java index 1a61844..0b8c55f 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/CCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/CCommand.java @@ -1,59 +1,53 @@ -package buttondevteam.chat.commands.ucmds; - -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import buttondevteam.chat.ChatPlayer; -import buttondevteam.chat.PluginMain; -import buttondevteam.lib.chat.*; -import buttondevteam.lib.player.TBMCPlayer; - -@CommandClass(modOnly = false) -@OptionallyPlayerCommandClass(playerOnly = true) -public class CCommand extends UCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Rainbow mode ----", "This command allows you to talk in rainbow colors", - "You need to be a donator or a mod to use this command" }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - Player player = (Player) sender; - ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); - if (args.length < 1) { - if (PluginMain.permission.has(player, "tbmc.rainbow")) { - p.RainbowPresserColorMode = !p.RainbowPresserColorMode; - p.OtherColorMode = null; - if (p.RainbowPresserColorMode) - player.sendMessage("§eRainbow colors §aenabled."); - else - player.sendMessage("§eRainbow colors §cdisabled."); - } else { - player.sendMessage("§cYou don't have permission for this command. Donate to get it!"); - return true; - } - } else { - if (PluginMain.permission.has(player, "tbmc.admin")) { - p.RainbowPresserColorMode = false; - p.OtherColorMode = null; - try { - p.OtherColorMode = Color.valueOf(args[0].toLowerCase()); - } catch (Exception e) { - player.sendMessage("§cUnknown message color: " + args[0]); - player.sendMessage("§cUse color names, like blue, or dark_aqua"); - } - if (p.OtherColorMode != null) - player.sendMessage(String.format("§eMessage color set to %s", p.OtherColorMode)); - else - player.sendMessage("§eMessage color reset."); - } else { - player.sendMessage("§cYou don't have permission for this command."); - return true; - } - } - return true; - } - -} +package buttondevteam.chat.components.fun; + +import buttondevteam.chat.ChatPlayer; +import buttondevteam.chat.PluginMain; +import buttondevteam.lib.chat.*; +import buttondevteam.lib.player.TBMCPlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandClass(path = "u c", helpText = { + "Rainbow mode", + "This command allows you to talk in rainbow colors" +}) +@OptionallyPlayerCommandClass(playerOnly = true) +public class CCommand extends ICommand2MC { + @Command2.Subcommand + public boolean def(CommandSender sender, @Command2.OptionalArg String color) { + Player player = (Player) sender; + ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); + if (color == null) { + if (PluginMain.permission.has(player, "thorpe.color.rainbow")) { + p.RainbowPresserColorMode = !p.RainbowPresserColorMode; + p.OtherColorMode = null; + if (p.RainbowPresserColorMode) + player.sendMessage("§eRainbow colors §aenabled."); + else + player.sendMessage("§eRainbow colors §cdisabled."); + } else { + player.sendMessage("§cYou don't have permission for this command."); + return true; + } + } else { + if (PluginMain.permission.has(player, "thorpe.color.custom")) { + p.RainbowPresserColorMode = false; + p.OtherColorMode = null; + try { + p.OtherColorMode = Color.valueOf(color.toLowerCase()); + } catch (Exception e) { + player.sendMessage("§cUnknown message color: " + color); + player.sendMessage("§cUse color names, like blue, or dark_aqua"); + } + if (p.OtherColorMode != null) + player.sendMessage(String.format("§eMessage color set to %s", p.OtherColorMode)); + else + player.sendMessage("§eMessage color reset."); + } else { + player.sendMessage("§cYou don't have permission for this command."); + return true; + } + } + return true; + } +} diff --git a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java index c11a84a..4b726b8 100644 --- a/src/main/java/buttondevteam/chat/components/fun/FunComponent.java +++ b/src/main/java/buttondevteam/chat/components/fun/FunComponent.java @@ -8,6 +8,7 @@ import buttondevteam.lib.TBMCCommandPreprocessEvent; import buttondevteam.lib.TBMCSystemChatEvent; import buttondevteam.lib.ThorpeUtils; import buttondevteam.lib.architecture.Component; +import buttondevteam.lib.architecture.ConfigData; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.player.ChromaGamerBase; import buttondevteam.lib.player.TBMCPlayer; @@ -29,7 +30,6 @@ 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; @@ -37,6 +37,19 @@ public class FunComponent extends Component implements Listener { private UnlolCommand command; private TBMCSystemChatEvent.BroadcastTarget unlolTarget; private TBMCSystemChatEvent.BroadcastTarget fTarget; + + private ConfigData laughStrings() { + return getConfig().getData("laughStrings", () -> new String[]{"xd", "lel", "lawl", "kek", "lmao", "hue", "hah", "rofl"}); + } + + private ConfigData respect() { + return getConfig().getData("respect", true); + } + + private ConfigData unlol() { + return getConfig().getData("unlol", true); + } + @Override protected void enable() { unlolTarget = TBMCSystemChatEvent.BroadcastTarget.add("unlol"); @@ -47,6 +60,9 @@ public class FunComponent extends Component implements Listener { registerCommand(command=new UnlolCommand(unlolTarget)); registerListener(this); registerCommand(new FTopCommand()); + registerCommand(new OpmeCommand()); + registerCommand(new YeehawCommand()); + registerCommand(new CCommand()); } @Override @@ -58,27 +74,30 @@ public class FunComponent extends Component implements Listener { 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 (unlol().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 { + String[] laughs = laughStrings().get(); + for (String laugh : laughs) { + if (add = msg.contains(laugh)) { + lld.setLolornot(false); + break; + } } } + if (add) + command.Lastlol.put(event.getChannel(), lld); } - 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 + if (e.getDeathMessage().length() > 0 && respect().get() && new Random().nextBoolean()) { // Don't store Fs for NPCs Runnable tt = () -> { if (ActiveF) { ActiveF = false; @@ -105,12 +124,14 @@ public class FunComponent extends Component implements Listener { } @EventHandler public void onPlayerLeave(PlayerQuitEvent event) { - command.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer())); + if (unlol().get()) + command.Lastlol.values().removeIf(lld -> lld.getLolowner().equals(event.getPlayer())); } @EventHandler(priority = EventPriority.LOWEST) public void onCommandPreprocess(TBMCCommandPreprocessEvent event) { if (event.isCancelled()) return; + if (!unlol().get()) return; final String cmd = event.getMessage(); // We don't care if we have arguments if (cmd.toLowerCase().startsWith("/un")) { diff --git a/src/main/java/buttondevteam/chat/components/fun/OpmeCommand.java b/src/main/java/buttondevteam/chat/components/fun/OpmeCommand.java new file mode 100644 index 0000000..bbae171 --- /dev/null +++ b/src/main/java/buttondevteam/chat/components/fun/OpmeCommand.java @@ -0,0 +1,18 @@ +package buttondevteam.chat.components.fun; + +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.ICommand2MC; +import org.bukkit.command.CommandSender; + +@CommandClass(modOnly = false, path = "u opme", helpText = { + "OP me", + "Totally makes you OP" +}) +public class OpmeCommand extends ICommand2MC { + @Command2.Subcommand + public boolean def(CommandSender sender) { + sender.sendMessage("It would be nice, wouldn't it?"); + return true; + } +} diff --git a/src/main/java/buttondevteam/chat/commands/YeehawCommand.java b/src/main/java/buttondevteam/chat/components/fun/YeehawCommand.java similarity index 61% rename from src/main/java/buttondevteam/chat/commands/YeehawCommand.java rename to src/main/java/buttondevteam/chat/components/fun/YeehawCommand.java index ba42373..56ac4e9 100644 --- a/src/main/java/buttondevteam/chat/commands/YeehawCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/YeehawCommand.java @@ -1,30 +1,28 @@ -package buttondevteam.chat.commands; - -import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.chat.TBMCCommandBase; -import buttondevteam.lib.player.TBMCYEEHAWEvent; -import org.bukkit.Bukkit; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandClass(modOnly = false) -public class YeehawCommand extends TBMCCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- YEEHAW command ----", "This command makes you YEEHAW." }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - final String message = "§b* " - + (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + " §bYEEHAWs."; - for (Player p : Bukkit.getOnlinePlayers()) { - p.playSound(p.getLocation(), "tbmc.yeehaw", 1f, 1f); - p.sendMessage(message); //Not broadcasting, so the Discord plugin can handle the event in a special way - } // Even a cmdblock could yeehaw in theory - // Or anyone from Discord - Bukkit.getPluginManager().callEvent(new TBMCYEEHAWEvent(sender)); - return true; - } -} +package buttondevteam.chat.components.fun; + +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.ICommand2MC; +import buttondevteam.lib.player.TBMCYEEHAWEvent; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +@CommandClass(modOnly = false, helpText = { + "YEEHAW command", + "This command makes you YEEHAW." +}) +public class YeehawCommand extends ICommand2MC { + @Command2.Subcommand + public boolean def(CommandSender sender) { + final String message = "§b* " + + (sender instanceof Player ? ((Player) sender).getDisplayName() : sender.getName()) + " §bYEEHAWs."; + for (Player p : Bukkit.getOnlinePlayers()) { + p.playSound(p.getLocation(), "tbmc.yeehaw", 1f, 1f); + p.sendMessage(message); //Not broadcasting, so the Discord plugin can handle the event in a special way + } // Even a cmdblock could yeehaw in theory + // Or anyone from Discord + Bukkit.getPluginManager().callEvent(new TBMCYEEHAWEvent(sender)); + return true; + } +} From 073346eb7fb1abe523cc541891d6e065a799b23a Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 14 Mar 2019 16:42:32 +0100 Subject: [PATCH 12/13] /u c sender changed to player --- src/main/java/buttondevteam/chat/components/fun/CCommand.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/buttondevteam/chat/components/fun/CCommand.java b/src/main/java/buttondevteam/chat/components/fun/CCommand.java index 0b8c55f..3cd8e27 100644 --- a/src/main/java/buttondevteam/chat/components/fun/CCommand.java +++ b/src/main/java/buttondevteam/chat/components/fun/CCommand.java @@ -4,7 +4,6 @@ import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.PluginMain; import buttondevteam.lib.chat.*; import buttondevteam.lib.player.TBMCPlayer; -import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandClass(path = "u c", helpText = { @@ -14,8 +13,7 @@ import org.bukkit.entity.Player; @OptionallyPlayerCommandClass(playerOnly = true) public class CCommand extends ICommand2MC { @Command2.Subcommand - public boolean def(CommandSender sender, @Command2.OptionalArg String color) { - Player player = (Player) sender; + public boolean def(Player player, @Command2.OptionalArg String color) { ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); if (color == null) { if (PluginMain.permission.has(player, "thorpe.color.rainbow")) { From c7f04b8731f764cff15749c94e2e61ea50fcca54 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 16 Mar 2019 03:07:33 +0100 Subject: [PATCH 13/13] Converted all of the commands Moved the announcer commands into one class --- .../java/buttondevteam/chat/PluginMain.java | 10 ++ .../chat/commands/MWikiCommand.java | 75 +++++++-------- .../chat/commands/ucmds/HelpCommand.java | 94 +++++++++---------- .../chat/commands/ucmds/HistoryCommand.java | 29 +++--- .../chat/commands/ucmds/InfoCommand.java | 79 +++++++--------- .../chat/commands/ucmds/UCommandBase.java | 23 ++--- .../ucmds/admin/AdminCommandBase.java | 20 ++-- .../commands/ucmds/admin/DebugCommand.java | 57 ++++++----- .../chat/components/announce/AddCommand.java | 36 ------- .../components/announce/AnnounceCommand.java | 80 ++++++++++++++++ .../announce/AnnounceCommandBase.java | 13 --- .../announce/AnnouncerComponent.java | 6 +- .../chat/components/announce/EditCommand.java | 44 --------- .../chat/components/announce/ListCommand.java | 27 ------ .../components/announce/RemoveCommand.java | 28 ------ .../components/announce/SetTimeCommand.java | 31 ------ .../chat/components/flair/AcceptCommand.java | 44 ++++----- .../chat/components/flair/FlairComponent.java | 6 +- .../chat/components/flair/IgnoreCommand.java | 18 ++-- .../components/flair/SetFlairCommand.java | 61 +++++------- .../components/towncolors/NColorCommand.java | 32 +++---- .../towncolors/NationColorCommand.java | 36 +++---- .../towncolors/TownColorCommand.java | 48 ++++++---- .../towncolors/TownColorComponent.java | 2 +- .../towncolors/admin/NationColorCommand.java | 43 ++++----- .../components/towncolors/admin/TCCount.java | 27 ++---- .../towncolors/admin/TownColorCommand.java | 65 ++++++------- .../listener/PlayerJoinLeaveListener.java | 2 +- 28 files changed, 428 insertions(+), 608 deletions(-) delete mode 100644 src/main/java/buttondevteam/chat/components/announce/AddCommand.java create mode 100644 src/main/java/buttondevteam/chat/components/announce/AnnounceCommand.java delete mode 100644 src/main/java/buttondevteam/chat/components/announce/AnnounceCommandBase.java delete mode 100644 src/main/java/buttondevteam/chat/components/announce/EditCommand.java delete mode 100644 src/main/java/buttondevteam/chat/components/announce/ListCommand.java delete mode 100644 src/main/java/buttondevteam/chat/components/announce/RemoveCommand.java delete mode 100644 src/main/java/buttondevteam/chat/components/announce/SetTimeCommand.java diff --git a/src/main/java/buttondevteam/chat/PluginMain.java b/src/main/java/buttondevteam/chat/PluginMain.java index ebb699b..ad7efb5 100644 --- a/src/main/java/buttondevteam/chat/PluginMain.java +++ b/src/main/java/buttondevteam/chat/PluginMain.java @@ -1,5 +1,10 @@ package buttondevteam.chat; +import buttondevteam.chat.commands.MWikiCommand; +import buttondevteam.chat.commands.ucmds.HelpCommand; +import buttondevteam.chat.commands.ucmds.HistoryCommand; +import buttondevteam.chat.commands.ucmds.InfoCommand; +import buttondevteam.chat.commands.ucmds.admin.DebugCommand; import buttondevteam.chat.components.announce.AnnouncerComponent; import buttondevteam.chat.components.appendext.AppendTextComponent; import buttondevteam.chat.components.flair.FlairComponent; @@ -67,6 +72,11 @@ public class PluginMain extends ButtonPlugin { // Translated to Java: 2015.07.15 Component.registerComponent(this, new AnnouncerComponent()); Component.registerComponent(this, new FunComponent()); Component.registerComponent(this, new AppendTextComponent()); + getCommand2MC().registerCommand(new DebugCommand()); + getCommand2MC().registerCommand(new HelpCommand()); + getCommand2MC().registerCommand(new HistoryCommand()); + getCommand2MC().registerCommand(new InfoCommand()); + getCommand2MC().registerCommand(new MWikiCommand()); } public static Essentials essentials = null; diff --git a/src/main/java/buttondevteam/chat/commands/MWikiCommand.java b/src/main/java/buttondevteam/chat/commands/MWikiCommand.java index 3a7e15a..2a7ad02 100644 --- a/src/main/java/buttondevteam/chat/commands/MWikiCommand.java +++ b/src/main/java/buttondevteam/chat/commands/MWikiCommand.java @@ -1,42 +1,33 @@ -package buttondevteam.chat.commands; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; - -import org.bukkit.command.CommandSender; - -import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.chat.TBMCCommandBase; - -@CommandClass(modOnly = false) -public class MWikiCommand extends TBMCCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Minecraft Wiki linker ----", // - "Use without parameters to get a link to the wiki", // - "You can also search the wiki, for example:", // - " /" + alias + " beacon - Provides a link that redirects to the beacon's wiki page" // - }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - String query = ""; - for (int i = 0; i < args.length; i++) - query += args[i] + " "; - query = query.trim(); - try { - if (query.length() == 0) - sender.sendMessage(new String[] { "§bMinecraft Wiki link: http://minecraft.gamepedia.com/", - "You can also search on it using /mwiki " }); - else - sender.sendMessage("§bMinecraft Wiki link: http://minecraft.gamepedia.com/index.php?search=" - + URLEncoder.encode(query, "UTF-8") + "&title=Special%3ASearch&go=Go"); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - } - return true; - } - -} +package buttondevteam.chat.commands; + +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.ICommand2MC; +import org.bukkit.command.CommandSender; + +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; + +@CommandClass(modOnly = false, helpText = { + "Minecraft Wiki linker", // + "Use without parameters to get a link to the wiki", // + "You can also search the wiki, for example:", // + " /mwiki beacon - Provides a link that redirects to the beacon's wiki page" // +}) +public class MWikiCommand extends ICommand2MC { + @Command2.Subcommand + public boolean def(CommandSender sender, @Command2.OptionalArg String query) { + try { + if (query == null) + sender.sendMessage(new String[] { "§bMinecraft Wiki link: http://minecraft.gamepedia.com/", + "You can also search on it using /mwiki " }); + else + sender.sendMessage("§bMinecraft Wiki link: http://minecraft.gamepedia.com/index.php?search=" + + URLEncoder.encode(query, "UTF-8") + "&title=Special%3ASearch&go=Go"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return true; + } + +} diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java index a009485..67d88c5 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/HelpCommand.java @@ -1,6 +1,7 @@ package buttondevteam.chat.commands.ucmds; import buttondevteam.chat.PluginMain; +import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCCommandBase; @@ -9,30 +10,32 @@ import org.bukkit.entity.Player; import java.util.ArrayList; -@CommandClass(modOnly = false) +@CommandClass(modOnly = false, helpText = { + "Help", + "Prints out help messages for the TBMC plugins" +}) public final class HelpCommand extends UCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Help ----", "Prints out help messages for the TBMC plugins" }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - if (args.length == 0) { - sender.sendMessage(new String[] { "§6---- TBMC Help ----", "Do /u help for more info", - "Do /u help [subcommands] for more info about a command", "Topics:", - "commands: See all the commands from this plugin", - "chat: Shows some info about custom chat features", "colors: Shows Minecraft color codes" }); + @Command2.Subcommand + public boolean def(CommandSender sender, @Command2.TextArg @Command2.OptionalArg String topicOrCommand) { + if (topicOrCommand == null) { + sender.sendMessage(new String[]{ + "§6---- Thorpe Help ----", + "Do /u help for more info", + "Do /u help [subcommands] for more info about a command", + "Topics:", + "commands: See all the commands from this plugin", + "chat: Shows some info about custom chat features", + "colors: Shows Minecraft color codes" + }); return true; } - if (args[0].equalsIgnoreCase("chat")) - sender.sendMessage(new String[] { "§6---- Chat features ----", - "- [g] Channel identifier: Click it to copy message", "-- [g]: Global chat (/g)", - "-- [TC] Town chat (/tc)", "-- [NC] Nation chat (/nc)", - "- Playernames: Hover over them to get some player info", - "-- Respect: This is the number of paid respects divided by eliglble deaths. This is a reference to CoD:AW's \"Press F to pay respects\"" }); - else if (args[0].equalsIgnoreCase("commands")) { + if (topicOrCommand.equalsIgnoreCase("chat")) + sender.sendMessage(new String[]{"§6---- Chat features ----", + "- [g] Channel identifier: Click it to copy message", "-- [g]: Global chat (/g)", + "-- [TC] Town chat (/tc)", "-- [NC] Nation chat (/nc)", + "- Playernames: Hover over them to get some player info", + "-- Respect: This is the number of paid respects divided by eliglble deaths. This is a reference to CoD:AW's \"Press F to pay respects\""}); + else if (topicOrCommand.equalsIgnoreCase("commands")) { ArrayList text = new ArrayList(); text.add("§6---- Command list ----"); for (TBMCCommandBase cmd : TBMCChatAPI.GetCommands().values()) @@ -46,36 +49,29 @@ public final class HelpCommand extends UCommandBase { text.add("/" + topcmd); } sender.sendMessage(text.toArray(new String[0])); - } else if (args[0].equalsIgnoreCase("colors")) { - sender.sendMessage(new String[] { "§6---- Chat colors/formats ----", // - "Tellraw name - Code | Tellraw name - Code", // - "§0black - &0 | §1dark_blue - &1", // - "§2dark_green - &2 | §3dark_aqua - &3", // - "§4dark_red - &4 | §5dark_purple - &5", // - "§6gold - &6 | §7gray - &7", // - "§8dark_gray - &8 | §9blue - &9", // - "§agreen - &a | §baqua - &b", // - "§cred - &c | §dlight_purple - &d", // - "§eyellow - &e | §fwhite - &f", // - "§rreset - &r | §kk§robfuscated - &k", // - "§lbold - &l | §mstrikethrough - &m", // - "§nunderline - &n | §oitalic - &o", // - "The format codes in tellraw should be used like \"italic\":\"true\"" }); // + } else if (topicOrCommand.equalsIgnoreCase("colors")) { + sender.sendMessage(new String[]{"§6---- Chat colors/formats ----", // + "Tellraw name - Code | Tellraw name - Code", // + "§0black - &0 | §1dark_blue - &1", // + "§2dark_green - &2 | §3dark_aqua - &3", // + "§4dark_red - &4 | §5dark_purple - &5", // + "§6gold - &6 | §7gray - &7", // + "§8dark_gray - &8 | §9blue - &9", // + "§agreen - &a | §baqua - &b", // + "§cred - &c | §dlight_purple - &d", // + "§eyellow - &e | §fwhite - &f", // + "§rreset - &r | §kk§robfuscated - &k", // + "§lbold - &l | §mstrikethrough - &m", // + "§nunderline - &n | §oitalic - &o", // + "The format codes in tellraw should be used like \"italic\":\"true\""}); // } else { - String path = args[0]; - for (int i = 1; i < args.length; i++) - path += " " + args[i]; - TBMCCommandBase cmd = TBMCChatAPI.GetCommands().get(path); - if (cmd == null) { - String[] subcmds = TBMCChatAPI.GetSubCommands(path, sender); - if (subcmds.length > 0) - sender.sendMessage(subcmds); - else + String[] text = getManager().getHelpText(topicOrCommand); + if (text == null) sender.sendMessage( - new String[] { "§cError: Command not found or you don't have permission for it: " + path, - "Usage example: /u accept --> /u help u accept" }); - } else - sender.sendMessage(cmd.GetHelpText(args[0])); + new String[]{"§cError: Command not found: " + topicOrCommand, + "Usage example: /u accept --> /u help u accept"}); + else + sender.sendMessage(text); } return true; diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java index 74a3628..fde4953 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/HistoryCommand.java @@ -2,48 +2,43 @@ package buttondevteam.chat.commands.ucmds; import buttondevteam.core.component.channel.Channel; import buttondevteam.lib.chat.ChatMessage; +import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; import lombok.RequiredArgsConstructor; import lombok.experimental.var; import lombok.val; import org.bukkit.command.CommandSender; -import javax.annotation.Nullable; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.stream.Stream; -@CommandClass +@CommandClass(helpText = { + "§6--- Chat History ----", // + "Returns the last 10 messages the player can see." // +}) public class HistoryCommand extends UCommandBase { /** * Key: ChannelID_groupID */ private static HashMap> messages = new HashMap<>(); - @Override - public String[] GetHelpText(String alias) { - return new String[]{ // - "§6--- Chat History ----", // - "Returns the last 10 messages the player can see." // - }; + @Command2.Subcommand + public boolean def(CommandSender sender, @Command2.OptionalArg String channel) { + return showHistory(sender, channel); } - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - return showHistory(sender, alias, args, this); - } - - public static boolean showHistory(CommandSender sender, String alias, String[] args, @Nullable HistoryCommand hc) { + public static boolean showHistory(CommandSender sender, String channel) { Function> getThem = ch -> messages.get(ch.ID + "_" + ch.getGroupID(sender)); //If can't see, groupID is null, and that shouldn't be in the map sender.sendMessage("§6---- Chat History ----"); Stream stream; - if (args.length == 0) { + if (channel == null) { stream = Channel.getChannels(); } else { - Optional och = Channel.getChannels().filter(chan -> chan.ID.equalsIgnoreCase(args[0])).findAny(); + Optional och = Channel.getChannels().filter(chan -> chan.ID.equalsIgnoreCase(channel)).findAny(); if (!och.isPresent()) { - sender.sendMessage("§cChannel not found. Use the ID, for example: /" + (hc == null ? "u history" : hc.GetCommandPath()) + " g"); + sender.sendMessage("§cChannel not found. Use the ID, for example: /u history g"); return true; } stream = Stream.of(och.get()); diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/InfoCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/InfoCommand.java index 4a61d4a..def4928 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/InfoCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/InfoCommand.java @@ -1,44 +1,35 @@ -package buttondevteam.chat.commands.ucmds; - -import org.bukkit.command.CommandSender; - -import buttondevteam.lib.TBMCCoreAPI; -import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.player.TBMCPlayer; -import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; -import buttondevteam.lib.player.TBMCPlayerBase; - -@CommandClass(modOnly = false) -public class InfoCommand extends UCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { // - "§6---- User information ----", // - "Get some information known about the user.", // - "Usage: /" + alias + " info " // - }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - if (args.length == 0) - return false; - if (args[0].equalsIgnoreCase("console") || args[0].equalsIgnoreCase("server") - || args[0].equalsIgnoreCase("@console")) { - sender.sendMessage("The server console."); - return true; - } - try (TBMCPlayer p = TBMCPlayerBase.getFromName(args[0], TBMCPlayer.class)) { - if (p == null) { - sender.sendMessage("§cThe specified player cannot be found"); - return true; - } - sender.sendMessage(p.getInfo(InfoTarget.MCCommand)); - } catch (Exception e) { - TBMCCoreAPI.SendException("Error while getting player information!", e); - sender.sendMessage("§cError while getting player information!"); - } - return true; - } -} +package buttondevteam.chat.commands.ucmds; + +import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.player.ChromaGamerBase.InfoTarget; +import buttondevteam.lib.player.TBMCPlayer; +import buttondevteam.lib.player.TBMCPlayerBase; +import org.bukkit.command.CommandSender; + +@CommandClass(modOnly = false, helpText = { + "User information", // + "Get some information known about the user.", // +}) +public class InfoCommand extends UCommandBase { + @Command2.Subcommand + public boolean def(CommandSender sender, String player) { + if (player.equalsIgnoreCase("console") || player.equalsIgnoreCase("server") + || player.equalsIgnoreCase("@console")) { + sender.sendMessage("The server console."); + return true; + } + try (TBMCPlayer p = TBMCPlayerBase.getFromName(player, TBMCPlayer.class)) { + if (p == null) { + sender.sendMessage("§cThe specified player cannot be found"); + return true; + } + sender.sendMessage(p.getInfo(InfoTarget.MCCommand)); + } catch (Exception e) { + TBMCCoreAPI.SendException("Error while getting player information!", e); + sender.sendMessage("§cError while getting player information!"); + } + return true; + } +} diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/UCommandBase.java b/src/main/java/buttondevteam/chat/commands/ucmds/UCommandBase.java index 2e10e17..d9be50a 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/UCommandBase.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/UCommandBase.java @@ -1,13 +1,10 @@ -package buttondevteam.chat.commands.ucmds; - -import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.chat.OptionallyPlayerCommandBase; -import buttondevteam.lib.chat.OptionallyPlayerCommandClass; - -@CommandClass(modOnly = false, path = "u") -@OptionallyPlayerCommandClass(playerOnly = false) -public abstract class UCommandBase extends OptionallyPlayerCommandBase { - - public abstract String[] GetHelpText(String alias); - -} +package buttondevteam.chat.commands.ucmds; + +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.ICommand2MC; +import buttondevteam.lib.chat.OptionallyPlayerCommandClass; + +@CommandClass(modOnly = false, path = "u") +@OptionallyPlayerCommandClass(playerOnly = false) +public abstract class UCommandBase extends ICommand2MC { +} diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/AdminCommandBase.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/AdminCommandBase.java index 9169762..167e58e 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/AdminCommandBase.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/AdminCommandBase.java @@ -1,11 +1,9 @@ -package buttondevteam.chat.commands.ucmds.admin; - -import buttondevteam.chat.commands.ucmds.UCommandBase; -import buttondevteam.lib.chat.CommandClass; - -@CommandClass(modOnly = true) -public abstract class AdminCommandBase extends UCommandBase { - - public abstract String[] GetHelpText(String alias); - -} +package buttondevteam.chat.commands.ucmds.admin; + +import buttondevteam.chat.commands.ucmds.UCommandBase; +import buttondevteam.lib.chat.CommandClass; + +@CommandClass(modOnly = true) +public abstract class AdminCommandBase extends UCommandBase { + +} diff --git a/src/main/java/buttondevteam/chat/commands/ucmds/admin/DebugCommand.java b/src/main/java/buttondevteam/chat/commands/ucmds/admin/DebugCommand.java index 0ae61e8..838236c 100644 --- a/src/main/java/buttondevteam/chat/commands/ucmds/admin/DebugCommand.java +++ b/src/main/java/buttondevteam/chat/commands/ucmds/admin/DebugCommand.java @@ -1,29 +1,28 @@ -package buttondevteam.chat.commands.ucmds.admin; - -import org.bukkit.command.CommandSender; - -import buttondevteam.chat.PluginMain; - -public class DebugCommand extends AdminCommandBase { - public static boolean DebugMode = false; - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Debug mode ----", - "Toggles debug mode, which prints debug messages to the console." }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - sender.sendMessage("§eDebug mode " + ((DebugMode = !DebugMode) ? "§aenabled." : "§cdisabled.")); - return true; - } - - public static void SendDebugMessage(String message) { - if (DebugMode) - if (PluginMain.Instance != null) - PluginMain.Instance.getLogger().info(message); - else - System.out.println(message); - } -} +package buttondevteam.chat.commands.ucmds.admin; + +import buttondevteam.chat.PluginMain; +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; +import org.bukkit.command.CommandSender; + +@CommandClass(helpText = { + "Debug mode", + "Toggles debug mode, which prints debug messages to the console." +}) +public class DebugCommand extends AdminCommandBase { + public static boolean DebugMode = false; + + @Command2.Subcommand + public boolean def(CommandSender sender, String alias, String[] args) { + sender.sendMessage("§eDebug mode " + ((DebugMode = !DebugMode) ? "§aenabled." : "§cdisabled.")); + return true; + } + + public static void SendDebugMessage(String message) { + if (DebugMode) + if (PluginMain.Instance != null) + PluginMain.Instance.getLogger().info(message); + else + System.out.println(message); + } +} diff --git a/src/main/java/buttondevteam/chat/components/announce/AddCommand.java b/src/main/java/buttondevteam/chat/components/announce/AddCommand.java deleted file mode 100644 index d236f56..0000000 --- a/src/main/java/buttondevteam/chat/components/announce/AddCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package buttondevteam.chat.components.announce; - -import org.bukkit.command.CommandSender; - -public class AddCommand extends AnnounceCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { - "§6---- Add announcement ----", - "This command adds a new announcement", - "Note: Please avoid using this command, if possible", - "Instead, use the command blocks in flatworld to set announcements", - "This makes editing announcements easier" }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, - String[] args) { - if (args.length < 1) { - return false; - } - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < args.length; i++) { - sb.append(args[i]); - if (i != args.length - 1) - sb.append(" "); - } - String finalmessage = sb.toString().replace('&', '§'); - AnnouncerComponent component = (AnnouncerComponent) getComponent(); - component.AnnounceMessages().get().add(finalmessage); - sender.sendMessage("§bAnnouncement added. - Plase avoid using this command if possible, see /u announce add without args.§r"); - return true; - } - -} diff --git a/src/main/java/buttondevteam/chat/components/announce/AnnounceCommand.java b/src/main/java/buttondevteam/chat/components/announce/AnnounceCommand.java new file mode 100644 index 0000000..050687d --- /dev/null +++ b/src/main/java/buttondevteam/chat/components/announce/AnnounceCommand.java @@ -0,0 +1,80 @@ +package buttondevteam.chat.components.announce; + +import buttondevteam.chat.commands.ucmds.UCommandBase; +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; +import buttondevteam.lib.chat.OptionallyPlayerCommandClass; +import lombok.RequiredArgsConstructor; +import lombok.val; +import org.bukkit.command.CommandSender; + +@CommandClass(modOnly = true) +@OptionallyPlayerCommandClass(playerOnly = false) +@RequiredArgsConstructor +public class AnnounceCommand extends UCommandBase { + private final AnnouncerComponent component; + + @Command2.Subcommand(helpText = { + "Add announcement", + "This command adds a new announcement", + }) + public boolean add(CommandSender sender, @Command2.TextArg String text) { + String finalmessage = text.replace('&', '§'); + component.AnnounceMessages().get().add(finalmessage); + sender.sendMessage("§bAnnouncement added.§r"); + return true; + } + + @Command2.Subcommand(helpText = { + "Edit announcement", + "This command lets you edit an announcement by its index.", + "Shouldn't be used directly, use either command blocks or click on an announcement in /u announce list (WIP) instead." //TODO: <-- + }) + public boolean edit(CommandSender sender, byte index, @Command2.TextArg String text) { + String finalmessage1 = text.replace('&', '§'); + if (index > 100) + return false; + while (component.AnnounceMessages().get().size() <= index) + component.AnnounceMessages().get().add(""); + component.AnnounceMessages().get().set(index, finalmessage1); + sender.sendMessage("Announcement edited."); + return true; + } + + @Command2.Subcommand(helpText = { + "List announcements", + "This command lists the announcements and the time between them" + }) + public boolean list(CommandSender sender) { + sender.sendMessage("§bList of announce messages:§r"); + sender.sendMessage("§bFormat: [index] message§r"); + int i = 0; + for (String message : component.AnnounceMessages().get()) + sender.sendMessage("[" + i++ + "] " + message); + sender.sendMessage("§bCurrent wait time between announcements: " + + component.AnnounceTime().get() / 60 / 1000 + " minute(s)§r"); + return true; + } + + @Command2.Subcommand(helpText = { + "Remove announcement", + "This command removes an announcement" + }) + public boolean remove(CommandSender sender, int index) { + val msgs = component.AnnounceMessages().get(); + if (index < 0 || index > msgs.size()) return false; + msgs.remove(index); + sender.sendMessage("Announcement removed."); + return true; + } + + @Command2.Subcommand(helpText = { + "Set time", + "This command sets the time between the announcements" + }) + public boolean settime(CommandSender sender, int minutes) { + component.AnnounceTime().set(minutes * 60 * 1000); + sender.sendMessage("Time set between announce messages to " + minutes + " minutes"); + return true; + } +} diff --git a/src/main/java/buttondevteam/chat/components/announce/AnnounceCommandBase.java b/src/main/java/buttondevteam/chat/components/announce/AnnounceCommandBase.java deleted file mode 100644 index 308a845..0000000 --- a/src/main/java/buttondevteam/chat/components/announce/AnnounceCommandBase.java +++ /dev/null @@ -1,13 +0,0 @@ -package buttondevteam.chat.components.announce; - -import buttondevteam.chat.commands.ucmds.UCommandBase; -import buttondevteam.lib.chat.CommandClass; -import buttondevteam.lib.chat.OptionallyPlayerCommandClass; - -@CommandClass(modOnly = true) -@OptionallyPlayerCommandClass(playerOnly = false) -public abstract class AnnounceCommandBase extends UCommandBase { - - public abstract String[] GetHelpText(String alias); - -} diff --git a/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java b/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java index 123b2c4..cecc285 100644 --- a/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java +++ b/src/main/java/buttondevteam/chat/components/announce/AnnouncerComponent.java @@ -44,11 +44,7 @@ public class AnnouncerComponent extends Component implements Runnabl @Override protected void enable() { target= TBMCSystemChatEvent.BroadcastTarget.add("announcements"); - registerCommand(new AddCommand()); - registerCommand(new EditCommand()); - registerCommand(new ListCommand()); - registerCommand(new RemoveCommand()); - registerCommand(new SetTimeCommand()); + registerCommand(new AnnounceCommand(this)); new Thread(this).start(); } diff --git a/src/main/java/buttondevteam/chat/components/announce/EditCommand.java b/src/main/java/buttondevteam/chat/components/announce/EditCommand.java deleted file mode 100644 index a53793b..0000000 --- a/src/main/java/buttondevteam/chat/components/announce/EditCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -package buttondevteam.chat.components.announce; - -import org.bukkit.command.BlockCommandSender; -import org.bukkit.command.CommandSender; - -public class EditCommand extends AnnounceCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Edit announcement ----", - "This command can only be used in a command block.", - "Usage: /u annonunce edit " }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, - String[] args) { - if (!(sender instanceof BlockCommandSender)) { - sender.sendMessage("§cError: This command can only be used from a command block. You can use add and remove, though it's not recommended."); - return true; - } - if (args.length < 1) { - return false; - } - StringBuilder sb1 = new StringBuilder(); - for (int i1 = 1; i1 < args.length; i1++) { - sb1.append(args[i1]); - if (i1 != args.length - 1) - sb1.append(" "); - } - String finalmessage1 = sb1.toString().replace('&', '§'); - int index = Integer.parseInt(args[0]); - if (index > 100) - return false; - AnnouncerComponent component = (AnnouncerComponent) getComponent(); - while (component.AnnounceMessages().get().size() <= index) - component.AnnounceMessages().get().add(""); - component.AnnounceMessages().get().set(Integer.parseInt(args[0]), - finalmessage1); - sender.sendMessage("Announcement edited."); - return true; - } - -} diff --git a/src/main/java/buttondevteam/chat/components/announce/ListCommand.java b/src/main/java/buttondevteam/chat/components/announce/ListCommand.java deleted file mode 100644 index 6c15593..0000000 --- a/src/main/java/buttondevteam/chat/components/announce/ListCommand.java +++ /dev/null @@ -1,27 +0,0 @@ -package buttondevteam.chat.components.announce; - -import org.bukkit.command.CommandSender; - -public class ListCommand extends AnnounceCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- List announcements ----", - "This command lists the announcements and the time between them" }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, - String[] args) { - sender.sendMessage("§bList of announce messages:§r"); - sender.sendMessage("§bFormat: [index] message§r"); - int i = 0; - AnnouncerComponent component = (AnnouncerComponent) getComponent(); - for (String message : component.AnnounceMessages().get()) - sender.sendMessage("[" + i++ + "] " + message); - sender.sendMessage("§bCurrent wait time between announcements: " - + component.AnnounceTime().get() / 60 / 1000 + " minute(s)§r"); - return true; - } - -} diff --git a/src/main/java/buttondevteam/chat/components/announce/RemoveCommand.java b/src/main/java/buttondevteam/chat/components/announce/RemoveCommand.java deleted file mode 100644 index 6f7ba30..0000000 --- a/src/main/java/buttondevteam/chat/components/announce/RemoveCommand.java +++ /dev/null @@ -1,28 +0,0 @@ -package buttondevteam.chat.components.announce; - -import org.bukkit.command.CommandSender; - -public class RemoveCommand extends AnnounceCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { - "§6---- Remove announcement ----", - "This command removes an announcement", - "Note: Please avoid using this command, if possible", - "Instead, use the command blocks in flatworld to set announcements", - "This makes editing announcements easier" }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, - String[] args) { - if (args.length < 1) { - sender.sendMessage("§cUsage: /u announce remove "); - return true; - } - ((AnnouncerComponent) getComponent()).AnnounceMessages().get().remove(Integer.parseInt(args[0])); - return true; - } - -} diff --git a/src/main/java/buttondevteam/chat/components/announce/SetTimeCommand.java b/src/main/java/buttondevteam/chat/components/announce/SetTimeCommand.java deleted file mode 100644 index ee8b849..0000000 --- a/src/main/java/buttondevteam/chat/components/announce/SetTimeCommand.java +++ /dev/null @@ -1,31 +0,0 @@ -package buttondevteam.chat.components.announce; - -import org.bukkit.command.CommandSender; - -public class SetTimeCommand extends AnnounceCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Set time ----", - "This command sets the time between the announcements", - "Usage: /u anonunce settime ", "Default: 15" }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, - String[] args) { - if (args.length < 1) { - return false; - } - try { - ((AnnouncerComponent) getComponent()).AnnounceTime().set(Integer.parseInt(args[0]) * 60 * 1000); - } catch (Exception e) { - sender.sendMessage("§cMinutes argument must be a number. Got: " - + args[0]); - return true; - } - sender.sendMessage("Time set between announce messages"); - return true; - } - -} diff --git a/src/main/java/buttondevteam/chat/components/flair/AcceptCommand.java b/src/main/java/buttondevteam/chat/components/flair/AcceptCommand.java index 51ae309..8ebd6ed 100644 --- a/src/main/java/buttondevteam/chat/components/flair/AcceptCommand.java +++ b/src/main/java/buttondevteam/chat/components/flair/AcceptCommand.java @@ -4,45 +4,46 @@ import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.PlayerJoinTimerTask; import buttondevteam.chat.commands.ucmds.UCommandBase; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.OptionallyPlayerCommandClass; import buttondevteam.lib.player.TBMCPlayer; +import lombok.RequiredArgsConstructor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.Timer; -@CommandClass(modOnly = false) +@CommandClass(modOnly = false, helpText = { + "Accept flair", // + "Accepts a flair from Reddit", // + "Use /u accept if you commented from multiple accounts" +}) @OptionallyPlayerCommandClass(playerOnly = true) +@RequiredArgsConstructor public class AcceptCommand extends UCommandBase { + private final FlairComponent component; - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Accept flair ----", // - "Accepts a flair from Reddit", // - "Use /u accept if you commented from multiple accounts" // - }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { + @Command2.Subcommand + public boolean def(CommandSender sender, @Command2.OptionalArg String username) { final Player player = (Player) sender; ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); - if (args.length < 1 && p.UserNames().size() > 1) { + if (username == null && p.UserNames().size() > 1) { player.sendMessage("§9Multiple users commented your name. §bPlease pick one using /u accept "); StringBuilder sb = new StringBuilder(); sb.append("§6Usernames:"); - for (String username : p.UserNames()) - sb.append(" ").append(username); + for (String name : p.UserNames()) + sb.append(" ").append(name); player.sendMessage(sb.toString()); return true; } if (p.FlairState().get().equals(FlairStates.NoComment) || p.UserNames().size() == 0) { - player.sendMessage("§cError: You need to write your username to the reddit thread at /r/ChromaGamers§r"); + player.sendMessage("§cError: You need to write your username to the reddit thread§r"); + player.sendMessage(component.FlairThreadURL().get()); return true; } - if (args.length > 0 && !p.UserNames().contains(args[0])) { - player.sendMessage("§cError: Unknown name: " + args[0] + "§r"); + if (username != null && !p.UserNames().contains(username)) { + player.sendMessage("§cError: Unknown name: " + username + "§r"); return true; } if (p.Working) { @@ -50,12 +51,12 @@ public class AcceptCommand extends UCommandBase { return true; } - if ((args.length > 0 ? args[0] : p.UserNames().get(0)).equals(p.UserName().get())) { + if ((username != null ? username : p.UserNames().get(0)).equals(p.UserName().get())) { player.sendMessage("§cYou already have this user's flair.§r"); return true; } - if (args.length > 0) - p.UserName().set(args[0]); + if (username != null) + p.UserName().set(username); else p.UserName().set(p.UserNames().get(0)); @@ -66,7 +67,7 @@ public class AcceptCommand extends UCommandBase { @Override public void run() { try { - FlairComponent.DownloadFlair(mp); + component.DownloadFlair(mp); } catch (Exception e) { TBMCCoreAPI.SendException( "An error occured while downloading flair for " + player.getCustomName() + "!", e); @@ -93,5 +94,4 @@ public class AcceptCommand extends UCommandBase { timer.schedule(tt, 20); return true; } - } diff --git a/src/main/java/buttondevteam/chat/components/flair/FlairComponent.java b/src/main/java/buttondevteam/chat/components/flair/FlairComponent.java index 89b4598..a5f4878 100644 --- a/src/main/java/buttondevteam/chat/components/flair/FlairComponent.java +++ b/src/main/java/buttondevteam/chat/components/flair/FlairComponent.java @@ -23,7 +23,7 @@ import java.text.SimpleDateFormat; import java.util.*; public class FlairComponent extends Component { - private ConfigData FlairThreadURL() { + ConfigData FlairThreadURL() { return getConfig().getData("flairThreadURL", "https://www.reddit.com/r/Chromagamers/comments/51ys94/flair_thread_for_the_mc_server/"); } @@ -39,7 +39,7 @@ public class FlairComponent extends Component { @Override protected void enable() { - registerCommand(new AcceptCommand()); + registerCommand(new AcceptCommand(this)); registerCommand(new IgnoreCommand()); registerCommand(new SetFlairCommand()); new Thread(this::FlairGetterThreadMethod).start(); @@ -106,7 +106,7 @@ public class FlairComponent extends Component { } } - public static void DownloadFlair(ChatPlayer mp) throws IOException { + void DownloadFlair(ChatPlayer mp) throws IOException { String[] flairdata = TBMCCoreAPI .DownloadString("http://karmadecay.com/thebutton-data.php?users=" + mp.UserName().get()) .replace("\"", "").split(":"); diff --git a/src/main/java/buttondevteam/chat/components/flair/IgnoreCommand.java b/src/main/java/buttondevteam/chat/components/flair/IgnoreCommand.java index a556455..3639587 100644 --- a/src/main/java/buttondevteam/chat/components/flair/IgnoreCommand.java +++ b/src/main/java/buttondevteam/chat/components/flair/IgnoreCommand.java @@ -2,24 +2,21 @@ package buttondevteam.chat.components.flair; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.commands.ucmds.UCommandBase; +import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.OptionallyPlayerCommandClass; import buttondevteam.lib.player.TBMCPlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -@CommandClass(modOnly = false) +@CommandClass(modOnly = false, helpText = { + "Ignore flair", + "Stop the \"write your name in the thread\" message from showing up" +}) @OptionallyPlayerCommandClass(playerOnly = true) public final class IgnoreCommand extends UCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Ignore flair ----", - "Stop the \"write your name in the thread\" message from showing up" }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { + @Command2.Subcommand + public boolean def(CommandSender sender) { final Player player = (Player) sender; ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); if (p.FlairState().get().equals(FlairStates.Accepted)) { @@ -39,5 +36,4 @@ public final class IgnoreCommand extends UCommandBase { player.sendMessage("§cYou already ignored the message.§r"); return true; } - } diff --git a/src/main/java/buttondevteam/chat/components/flair/SetFlairCommand.java b/src/main/java/buttondevteam/chat/components/flair/SetFlairCommand.java index dcd22ac..36d9275 100644 --- a/src/main/java/buttondevteam/chat/components/flair/SetFlairCommand.java +++ b/src/main/java/buttondevteam/chat/components/flair/SetFlairCommand.java @@ -2,65 +2,52 @@ package buttondevteam.chat.components.flair; import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase; +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.player.TBMCPlayerBase; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +@CommandClass(helpText = { + "§6---- Set flair -----", "Set a flair for a player", + "Usage: /u admin setflair [username]", + "Example 1: /u admin setflair NorbiPeti 19 false NorbiPeti --> orange (19s)", + "Example 2: /u admin setflair iie 0 true asde --> purple (0s)" +}) public class SetFlairCommand extends AdminCommandBase { - - @Override - public String[] GetHelpText(String alias) { - return new String[] { "§6---- Set flair -----", "Set a flair for a player", - "Usage: /u admin setflair [username]", - "Example 1: /u admin setflair NorbiPeti 19 false NorbiPeti --> orange (19s)", - "Example 2: /u admin setflair iie 0 true asde --> purple (0s)" }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - if (args.length < 3) { - return false; - } - Player p = Bukkit.getPlayer(args[0]); + @Command2.Subcommand + public boolean def(CommandSender sender, String player, String flairtime, boolean cheater, @Command2.OptionalArg String username) { + Player p = Bukkit.getPlayer(player); if (p == null) { sender.sendMessage("§cPlayer not found.&r"); return true; } - short flairtime = 0x00; - if (args[1].equalsIgnoreCase("non-presser")) - flairtime = ChatPlayer.FlairTimeNonPresser; - else if (args[1].equalsIgnoreCase("cant-press")) - flairtime = ChatPlayer.FlairTimeCantPress; - else if (args[1].equalsIgnoreCase("none")) - flairtime = ChatPlayer.FlairTimeNone; + short ft = 0x00; + if (flairtime.equalsIgnoreCase("non-presser")) + ft = ChatPlayer.FlairTimeNonPresser; + else if (flairtime.equalsIgnoreCase("cant-press")) + ft = ChatPlayer.FlairTimeCantPress; + else if (flairtime.equalsIgnoreCase("none")) + ft = ChatPlayer.FlairTimeNone; else { try { - flairtime = Short.parseShort(args[1]); + ft = Short.parseShort(flairtime); } catch (Exception e) { sender.sendMessage( "§cFlairtime must be a number, \"non-presser\", \"cant-press\" or \"none\". Run without args to see usage."); return true; } } - boolean cheater; - if (args[2].equalsIgnoreCase("true")) - cheater = true; - else if (args[2].equalsIgnoreCase("false")) - cheater = false; - else { - sender.sendMessage("§cUnknown value for cheater parameter."); - return false; - } ChatPlayer mp = TBMCPlayerBase.getPlayer(p.getUniqueId(), ChatPlayer.class); - mp.SetFlair(flairtime, cheater); + mp.SetFlair(ft, cheater); mp.FlairState().set(FlairStates.Accepted); - if (args.length < 4) + if (username == null) mp.UserName().set(""); else { - mp.UserName().set(args[3]); - if (!mp.UserNames().contains(args[3])) - mp.UserNames().add(args[3]); + mp.UserName().set(username); + if (!mp.UserNames().contains(username)) + mp.UserNames().add(username); } sender.sendMessage( "§bThe flair has been set. Player: " + mp.PlayerName() + " Flair: " + mp.GetFormattedFlair() + "§r"); diff --git a/src/main/java/buttondevteam/chat/components/towncolors/NColorCommand.java b/src/main/java/buttondevteam/chat/components/towncolors/NColorCommand.java index 5234490..d9a7792 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/NColorCommand.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/NColorCommand.java @@ -4,6 +4,7 @@ import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.commands.ucmds.UCommandBase; import buttondevteam.chat.components.towny.TownyComponent; import buttondevteam.lib.chat.Color; +import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.OptionallyPlayerCommandClass; import com.palmergames.bukkit.towny.object.Resident; @@ -16,21 +17,16 @@ import java.util.Arrays; import java.util.stream.Collectors; @OptionallyPlayerCommandClass(playerOnly = true) -@CommandClass +@CommandClass(helpText = { + "Name color", // + "This command allows you to set how the town colors look on your name.", // + "To use this command, you need to be in a town which has town colors set.", // + "Use a vertical line (or a colon) as a separator between the colors.", // + "Example: /u ncolor Norbi|Peti --> §6Norbi§ePeti" // +}) public class NColorCommand extends UCommandBase { - @Override - public String[] GetHelpText(String alias) { - return new String[] { // - "§6---- Name color ----", // - "This command allows you to set how the town colors look on your name.", // - "To use this command, you need to be in a town which has town colors set.", // - "Use a vertical line as a separator between the colors.", // - "Example: /u ncolor Norbi|Peti --> §6Norbi§ePeti" // - }; - } - - @Override - public boolean OnCommand(Player player, String alias, String[] args) { + @Command2.Subcommand + public boolean def(Player player, String nameWithLines) { Resident res; Town town; try { @@ -43,16 +39,14 @@ public class NColorCommand extends UCommandBase { player.sendMessage("§cYou need to be in a town. (" + e + ")"); return true; } - if (args.length == 0) - return false; final String name = ChatColor.stripColor(player.getDisplayName()).replace("~", ""); //Remove ~ - String arg = args[0]; //Don't add ~ for nicknames - if (!arg.replace("|", "").replace(":", "").equalsIgnoreCase(name)) { + //Don't add ~ for nicknames + if (!nameWithLines.replace("|", "").replace(":", "").equalsIgnoreCase(name)) { player.sendMessage("§cThe name you gave doesn't match your name. Make sure to use " + name + "§c with added vertical lines (|) or colons (:)."); return true; } - String[] nameparts = arg.split("[|:]"); + String[] nameparts = nameWithLines.split("[|:]"); Color[] towncolors = TownColorComponent.TownColors.get(town.getName().toLowerCase()); if (towncolors == null) { player.sendMessage("§cYour town doesn't have a color set. The town mayor can set it using /u towncolor."); diff --git a/src/main/java/buttondevteam/chat/components/towncolors/NationColorCommand.java b/src/main/java/buttondevteam/chat/components/towncolors/NationColorCommand.java index 4c4c1ad..c6789e9 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/NationColorCommand.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/NationColorCommand.java @@ -3,48 +3,38 @@ package buttondevteam.chat.components.towncolors; import buttondevteam.chat.commands.ucmds.UCommandBase; import buttondevteam.chat.components.towny.TownyComponent; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.OptionallyPlayerCommandClass; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; +import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Resident; import org.bukkit.entity.Player; -@CommandClass +@CommandClass(helpText = { + "Nation Color", // + "This command allows setting a color for a nation.", // + "Each town in the nation will have it's first color (border) set to this color.", // + "See the help text for /u towncolor for more details.", // +}) @OptionallyPlayerCommandClass(playerOnly = true) public class NationColorCommand extends UCommandBase { - @Override - public String[] GetHelpText(String alias) { - return new String[]{ // - "§6---- Nation Color ----", // - "This command allows setting a color for a nation.", // - "Each town in the nation will have it's first color (border) set to this color.", // - "See the help text for /u towncolor for more details.", // - "Usage: /" + GetCommandPath() + " ", // - "Example: /" + GetCommandPath() + " blue" // - }; - } - - @Override - public boolean OnCommand(Player player, String alias, String[] args) { + @Command2.Subcommand + public boolean def(Player player, String color) { Resident res; if (!(TownyComponent.TU.getResidentMap().containsKey(player.getName().toLowerCase()) && (res = TownyComponent.TU.getResidentMap().get(player.getName().toLowerCase())).isKing())) { player.sendMessage("§cYou need to be the king of a nation to set it's colors."); return true; } - if (args.length > 1) { - player.sendMessage("You can only use one color."); - return true; - } - String[] a = new String[args.length + 1]; - System.arraycopy(args, 0, a, 1, args.length); + final Nation n; try { - a[0] = res.getTown().getNation().getName(); + n = res.getTown().getNation(); } catch (NotRegisteredException e) { TBMCCoreAPI.SendException("Failed to set nation color for player " + player + "!", e); player.sendMessage("§cCouldn't find your town/nation... Error reported."); return true; } - return buttondevteam.chat.components.towncolors.admin.NationColorCommand.SetNationColor(player, alias, a); + return buttondevteam.chat.components.towncolors.admin.NationColorCommand.SetNationColor(player, n, color); } } diff --git a/src/main/java/buttondevteam/chat/components/towncolors/TownColorCommand.java b/src/main/java/buttondevteam/chat/components/towncolors/TownColorCommand.java index 685d5ac..88151bf 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/TownColorCommand.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/TownColorCommand.java @@ -3,54 +3,62 @@ package buttondevteam.chat.components.towncolors; import buttondevteam.chat.commands.ucmds.UCommandBase; import buttondevteam.chat.components.towny.TownyComponent; import buttondevteam.lib.TBMCCoreAPI; +import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.OptionallyPlayerCommandClass; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.object.Resident; +import com.palmergames.bukkit.towny.object.Town; +import lombok.RequiredArgsConstructor; import lombok.val; import org.bukkit.entity.Player; -@CommandClass // TODO: /u u when annotation not present +import java.lang.reflect.Method; + +@CommandClass(helpText = { + "Town Color", // + "This command allows setting a color for a town.", // + "The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", // + "The colors will split the name evenly but residents can override that with /u ncolor.", // +}) // TODO: /u u when annotation not present @OptionallyPlayerCommandClass(playerOnly = true) +@RequiredArgsConstructor public class TownColorCommand extends UCommandBase { + private final TownColorComponent component; @Override - public String GetHelpText(String alias)[] { + public String[] getHelpText(Method method, Command2.Subcommand ann) { StringBuilder cns = new StringBuilder(" "); - val comp = (TownColorComponent) getComponent(); - for (int i = 2; i <= comp.colorCount().get(); i++) + for (int i = 2; i <= component.colorCount().get(); i++) cns.append(" [colorname").append(i).append("]"); return new String[] { // - "§6---- Town Color ----", // - "This command allows setting a color for a town.", // - "The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", // - "The colors will split the name evenly.", // - "Usage: /" + GetCommandPath() + cns, // - "Example: /" + GetCommandPath() + " blue" // + "§6---- Town Color ----", // + "This command allows setting color(s) for a town.", // + "The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", // + "The colors will split the name evenly.", // }; } - @Override - public boolean OnCommand(Player player, String alias, String[] args) { + @Command2.Subcommand + public boolean def(Player player, String... colornames) { Resident res; if (!(TownyComponent.TU.getResidentMap().containsKey(player.getName().toLowerCase()) && (res = TownyComponent.TU.getResidentMap().get(player.getName().toLowerCase())).isMayor())) { - player.sendMessage("§cYou need to be the mayor of a town to set it's colors."); + player.sendMessage("§cYou need to be the mayor of a town to set its colors."); return true; } - val comp = (TownColorComponent) getComponent(); - if (args.length > comp.colorCount().get()) { - player.sendMessage("You can only use " + comp.colorCount().get() + " color" + (comp.colorCount().get() > 1 ? "s" : "") + "."); + val cc = component.colorCount().get(); + if (colornames.length > cc) { + player.sendMessage("You can only use " + cc + " color" + (cc > 1 ? "s" : "") + "."); return true; } - String[] a = new String[args.length + 1]; - System.arraycopy(args, 0, a, 1, args.length); + final Town t; try { - a[0] = res.getTown().getName(); + t = res.getTown(); } catch (NotRegisteredException e) { TBMCCoreAPI.SendException("Failed to set town color for player " + player + "!", e); player.sendMessage("§cCouldn't find your town... Error reported."); return true; } - return buttondevteam.chat.components.towncolors.admin.TownColorCommand.SetTownColor(player, alias, a); + return buttondevteam.chat.components.towncolors.admin.TownColorCommand.SetTownColor(player, t, colornames); } } diff --git a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java index 8b6314f..ab41374 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/TownColorComponent.java @@ -106,7 +106,7 @@ public class TownColorComponent extends Component implements Listene } }); - registerCommand(new TownColorCommand()); + registerCommand(new TownColorCommand(this)); if (useNationColors().get()) registerCommand(new NationColorCommand()); registerCommand(new buttondevteam.chat.components.towncolors.admin.TownColorCommand()); diff --git a/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java b/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java index 70ae07b..963cb05 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/admin/NationColorCommand.java @@ -6,40 +6,31 @@ import buttondevteam.chat.components.towncolors.TownColorComponent; import buttondevteam.chat.components.towncolors.TownyListener; import buttondevteam.chat.components.towny.TownyComponent; import buttondevteam.lib.chat.Color; +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Town; import lombok.val; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; +@CommandClass(helpText = { + "Nation color", // + "Sets the color of the nation.", // +}) public class NationColorCommand extends AdminCommandBase { - @Override - public String[] GetHelpText(String alias) { - return new String[]{ // - "§6---- Nation color ----", // - "Sets the color of the nation.", // - "Usage: /u admin nationcolor " // - }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - return SetNationColor(sender, alias, args); - } - - public static boolean SetNationColor(CommandSender sender, String alias, String[] args) { - if (args.length < 2) - return false; - if (args.length > 2) { - sender.sendMessage("§cYou can only use one color as a nation color."); + @Command2.Subcommand + public boolean def(CommandSender sender, String nation, String color) { + final Nation n = TownyComponent.TU.getNationsMap().get(nation.toLowerCase()); + if (n == null) { + sender.sendMessage("§cThe nation '" + nation + "' cannot be found."); return true; } - final Nation nation = TownyComponent.TU.getNationsMap().get(args[0].toLowerCase()); - if (nation == null) { - sender.sendMessage("§cThe nation '" + args[0] + "' cannot be found."); - return true; - } - val c = TownColorCommand.getColorOrSendError(args[1], sender); + return SetNationColor(sender, n, color); + } + + public static boolean SetNationColor(CommandSender sender, Nation nation, String color) { + val c = TownColorCommand.getColorOrSendError(color, sender); if (!c.isPresent()) return true; if (!c.get().getName().equals(Color.White.getName())) { //Default nation color for (val e : TownColorComponent.NationColor.entrySet()) { @@ -49,7 +40,7 @@ public class NationColorCommand extends AdminCommandBase { } } } - TownColorComponent.NationColor.put(args[0].toLowerCase(), c.get()); + TownColorComponent.NationColor.put(nation.getName().toLowerCase(), c.get()); Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> { for (Town t : nation.getTowns()) TownyListener.updateTownMembers(t); diff --git a/src/main/java/buttondevteam/chat/components/towncolors/admin/TCCount.java b/src/main/java/buttondevteam/chat/components/towncolors/admin/TCCount.java index a20b26a..fc91d6f 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/admin/TCCount.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/admin/TCCount.java @@ -2,28 +2,19 @@ package buttondevteam.chat.components.towncolors.admin; import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase; import buttondevteam.chat.components.towncolors.TownColorComponent; +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; import lombok.val; import org.bukkit.command.CommandSender; +@CommandClass(helpText = { + "Town Color Count", // + "Sets how many colors can be used for a town." // +}) public class TCCount extends AdminCommandBase { - @Override - public String[] GetHelpText(String alias) { - return new String[] { // - "§6---- Town Color Count", // - "Sets how many colors can be used for a town." // - }; - } - - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - byte count; - try { - if (args.length == 0 || (count = Byte.parseByte(args[0])) <= 0) - return false; - } catch (NumberFormatException e) { - return false; - } - val comp = (TownColorComponent) getComponent(); + @Command2.Subcommand + public boolean def(CommandSender sender, byte count) { + val comp = TownColorComponent.getComponent(); comp.colorCount().set(count); sender.sendMessage("Color count set to " + count); return true; diff --git a/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java b/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java index 7993b49..618ef06 100644 --- a/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java +++ b/src/main/java/buttondevteam/chat/components/towncolors/admin/TownColorCommand.java @@ -1,11 +1,12 @@ package buttondevteam.chat.components.towncolors.admin; -import buttondevteam.chat.PluginMain; import buttondevteam.chat.commands.ucmds.admin.AdminCommandBase; import buttondevteam.chat.components.towncolors.TownColorComponent; import buttondevteam.chat.components.towncolors.TownyListener; import buttondevteam.chat.components.towny.TownyComponent; import buttondevteam.lib.chat.Color; +import buttondevteam.lib.chat.Command2; +import buttondevteam.lib.chat.CommandClass; import com.palmergames.bukkit.towny.object.Town; import lombok.val; import org.bukkit.Bukkit; @@ -17,35 +18,27 @@ import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; -public class TownColorCommand extends AdminCommandBase { - @Override - public String GetHelpText(String alias)[] { // TODO: Command path aliases - return new String[]{ // - "§6---- Town Color ----", // - "This command allows setting a color for a town.", // - "The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", // - "The colors will split the name evenly.", // - "Usage: /" + GetCommandPath() + " [colorname2...]", // - "Example: /" + GetCommandPath() + " Alderon blue gray" // - }; - } +@CommandClass(helpText = { + "Town Color", // + "This command allows setting a color for a town.", // + "The town will be shown with this color on Dynmap and all players in the town will appear in chat with these colors.", // + "The colors will split the name evenly.", // +}) +public class TownColorCommand extends AdminCommandBase { //TODO: Command path aliases + @Command2.Subcommand + public boolean def(CommandSender sender, String town, String... colornames) { + if (!TownyComponent.TU.getTownsMap().containsKey(town.toLowerCase())) { + sender.sendMessage("§cThe town '" + town + "' cannot be found."); + return true; + } + Town targetTown = TownyComponent.TU.getTownsMap().get(town.toLowerCase()); + return SetTownColor(sender, targetTown, colornames); + } - @Override - public boolean OnCommand(CommandSender sender, String alias, String[] args) { - return SetTownColor(sender, alias, args); - } - - public static boolean SetTownColor(CommandSender sender, String alias, String[] args) { - if (args.length < 2) - return false; - if (!TownyComponent.TU.getTownsMap().containsKey(args[0].toLowerCase())) { - sender.sendMessage("§cThe town '" + args[0] + "' cannot be found."); - return true; - } - Color[] clrs = new Color[args.length - 1]; - Town targetTown = TownyComponent.TU.getTownsMap().get(args[0].toLowerCase()); - for (int i = 1; i < args.length; i++) { - val c = getColorOrSendError(args[i], sender); + public static boolean SetTownColor(CommandSender sender, Town town, String[] colors) { + Color[] clrs = new Color[colors.length]; + for (int i = 0; i < colors.length; i++) { + val c = getColorOrSendError(colors[i], sender); if (!c.isPresent()) return true; clrs[i - 1] = c.get(); @@ -54,7 +47,7 @@ public class TownColorCommand extends AdminCommandBase { boolean usenc = TownColorComponent.getComponent().useNationColors().get(); if (usenc) { try { - tnc = TownColorComponent.NationColor.get(targetTown.getNation().getName().toLowerCase()); + tnc = TownColorComponent.NationColor.get(town.getNation().getName().toLowerCase()); } catch (Exception e) { tnc = null; } @@ -83,16 +76,12 @@ public class TownColorCommand extends AdminCommandBase { } } } - TownColorComponent.TownColors.put(args[0].toLowerCase(), clrs); - TownyListener.updateTownMembers(targetTown); + TownColorComponent.TownColors.put(town.getName().toLowerCase(), clrs); + TownyListener.updateTownMembers(town); val dtp = (DynmapTownyPlugin) Bukkit.getPluginManager().getPlugin("Dynmap-Towny"); - if (dtp == null) { - sender.sendMessage("§cDynmap-Towny couldn't be found §6but otherwise §btown color set."); - PluginMain.Instance.getLogger().warning("Dynmap-Towny not found for setting town color!"); - return true; - } - TownColorComponent.setTownColor(dtp, targetTown.getName(), clrs, tnc); + if (dtp != null) //If it's not found then it's not loaded, it'll be noticed by the admins if needed + TownColorComponent.setTownColor(dtp, town.getName(), clrs, tnc); sender.sendMessage("§bColor(s) set."); return true; } diff --git a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java index b8390b1..9b1e999 100644 --- a/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java +++ b/src/main/java/buttondevteam/chat/listener/PlayerJoinLeaveListener.java @@ -57,7 +57,7 @@ public class PlayerJoinLeaveListener implements Listener { nwithoutformatting = p.getName(); PlayerListener.nicknames.forcePut(nwithoutformatting.toLowerCase(), p.getUniqueId()); //TODO: FormatterComponent - HistoryCommand.showHistory(e.getPlayer(), "u history", new String[0], null); + HistoryCommand.showHistory(e.getPlayer(), null); } @EventHandler