From ae49777007a408ea9c387193678b5df6e1761997 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 8 Mar 2019 22:22:12 +0100 Subject: [PATCH] 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; + } + } }