From c7f04b8731f764cff15749c94e2e61ea50fcca54 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 16 Mar 2019 03:07:33 +0100 Subject: [PATCH] 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