From 744381ca065f0825382b04431228480611559f99 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 1 Jul 2023 08:54:13 +0700 Subject: [PATCH] make Command a class instead of an interface this is attempt 2 and it works now --- .../chayapak/chomens_bot/command/Command.java | 29 ++++++--- .../chomens_bot/commands/BotUserCommand.java | 36 ++++------- .../commands/BotVisibilityCommand.java | 40 ++++--------- .../chomens_bot/commands/BruhifyCommand.java | 33 ++++------- .../commands/ClearChatCommand.java | 33 ++++------- .../commands/ClearChatQueueCommand.java | 13 +++- .../chomens_bot/commands/CloopCommand.java | 36 ++++------- .../commands/CommandBlockCommand.java | 36 ++++------- .../chomens_bot/commands/CowsayCommand.java | 36 ++++------- .../chomens_bot/commands/CreatorCommand.java | 33 ++++------- .../chomens_bot/commands/DiscordCommand.java | 36 ++++------- .../chomens_bot/commands/EchoCommand.java | 34 ++++------- .../chomens_bot/commands/EndCommand.java | 36 ++++------- .../chomens_bot/commands/FilterCommand.java | 48 ++++++--------- .../commands/GenerateMazeCommand.java | 37 ++++-------- .../chomens_bot/commands/GrepLogCommand.java | 46 +++++---------- .../chomens_bot/commands/HelpCommand.java | 45 +++++--------- .../chomens_bot/commands/KickCommand.java | 39 ++++-------- .../chomens_bot/commands/ListCommand.java | 33 ++++------- .../chomens_bot/commands/MailCommand.java | 35 ++++------- .../chomens_bot/commands/MusicCommand.java | 59 ++++++++----------- .../commands/NetMessageCommand.java | 35 ++++------- .../commands/RandomTeleportCommand.java | 40 ++++--------- .../commands/RefillCoreCommand.java | 36 ++++------- .../chomens_bot/commands/SeenCommand.java | 33 ++++------- .../commands/ServerEvalCommand.java | 36 ++++------- .../commands/ServerInfoCommand.java | 35 ++++------- .../chomens_bot/commands/SudoAllCommand.java | 40 ++++--------- .../chomens_bot/commands/TPSBarCommand.java | 36 ++++------- .../chomens_bot/commands/TestCommand.java | 36 ++++------- .../chomens_bot/commands/ThrowCommand.java | 35 +++-------- .../chomens_bot/commands/TimeCommand.java | 37 ++++-------- .../commands/TranslateCommand.java | 35 ++++------- .../chomens_bot/commands/UUIDCommand.java | 40 ++++--------- .../chomens_bot/commands/UptimeCommand.java | 35 ++++------- .../chomens_bot/commands/UrbanCommand.java | 34 +++-------- .../chomens_bot/commands/ValidateCommand.java | 36 ++++------- .../chomens_bot/commands/WeatherCommand.java | 34 +++-------- .../commands/WikipediaCommand.java | 34 +++-------- .../plugins/CommandHandlerPlugin.java | 22 +++---- 40 files changed, 451 insertions(+), 991 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/command/Command.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/command/Command.java index 68c3635..4c2b7fb 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/command/Command.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/command/Command.java @@ -1,15 +1,28 @@ package land.chipmunk.chayapak.chomens_bot.command; +import lombok.Getter; import net.kyori.adventure.text.Component; -import java.util.List; +public abstract class Command { + @Getter private final String name; + @Getter private final String description; + @Getter private final String[] usages; + @Getter private final String[] aliases; + @Getter private final TrustLevel trustLevel; -public interface Command { - String name(); - String description(); - List usage(); - List alias(); - TrustLevel trustLevel(); + public Command ( + String name, + String description, + String[] usages, + String[] aliases, + TrustLevel trustLevel + ) { + this.name = name; + this.description = description; + this.usages = usages; + this.aliases = aliases; + this.trustLevel = trustLevel; + } - Component execute(CommandContext context, String[] args, String[] fullArgs) throws Exception; + public abstract Component execute (CommandContext context, String[] args, String[] fullArgs) throws Exception; } diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotUserCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotUserCommand.java index 57e2dd4..3096709 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotUserCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotUserCommand.java @@ -10,34 +10,18 @@ import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; -import java.util.List; - -public class BotUserCommand implements Command { - public String name() { return "botuser"; } - - public String description() { - return "Shows the bot's username and UUID"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class BotUserCommand extends Command { + public BotUserCommand () { + super( + "botuser", + "Shows the bot's username and UUID", + new String[] {}, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotVisibilityCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotVisibilityCommand.java index 5a0aa31..a282414 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotVisibilityCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BotVisibilityCommand.java @@ -8,38 +8,18 @@ import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; -import java.util.List; - -public class BotVisibilityCommand implements Command { - public String name() { return "botvisibility"; } - - public String description() { - return "Changes the bot's visibility"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(" "); - usages.add(" "); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("botvis"); - aliases.add("togglevis"); - aliases.add("togglevisibility"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.TRUSTED; +public class BotVisibilityCommand extends Command { + public BotVisibilityCommand () { + super( + "botvisibilty", + "Changes the bot's visibility", + new String[] { " ", " ", "" }, + new String[] { "botvis", "togglevis", "togglevisibility" }, + TrustLevel.TRUSTED + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BruhifyCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BruhifyCommand.java index 0d5ca0d..87cf4eb 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BruhifyCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/BruhifyCommand.java @@ -9,31 +9,18 @@ import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.List; -public class BruhifyCommand implements Command { - public String name() { return "bruhify"; } - - public String description() { - return "RecycleBot bruhify but actionbar"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("[{message}]"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class BruhifyCommand extends Command { + public BruhifyCommand () { + super( + "bruhify", + "RecycleBots bruhify but actionbar", + new String[] { "[{message}]" }, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ClearChatCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ClearChatCommand.java index f5b26f2..a0b16e0 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ClearChatCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ClearChatCommand.java @@ -12,31 +12,18 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -public class ClearChatCommand implements Command { - public String name() { return "clearchat"; } - - public String description() { - return "Clears the chat"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("[player]"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("cc"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class ClearChatCommand extends Command { + public ClearChatCommand () { + super( + "clearchat", + "Clears the chat", + new String[] { "[player]" }, + new String[] { "cc" }, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ClearChatQueueCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ClearChatQueueCommand.java index db22831..001c62e 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ClearChatQueueCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ClearChatQueueCommand.java @@ -9,7 +9,17 @@ import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.List; -public class ClearChatQueueCommand implements Command { +public class ClearChatQueueCommand extends Command { + public ClearChatQueueCommand () { + super( + "clearchatqueue", + "Clears the bots chat queue", + new String[] {}, + new String[] { "ccq" }, + TrustLevel.PUBLIC + ); + } + public String name() { return "clearchatqueue"; } public String description() { @@ -34,6 +44,7 @@ public class ClearChatQueueCommand implements Command { return TrustLevel.PUBLIC; } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CloopCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CloopCommand.java index 5784dde..fa730ea 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CloopCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CloopCommand.java @@ -14,34 +14,18 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class CloopCommand implements Command { - public String name() { return "cloop"; } - - public String description() { - return "Loop commands"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(" add <{command}>"); - usages.add(" remove "); - usages.add(" clear"); - usages.add(" list"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("commandloop"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.TRUSTED; +public class CloopCommand extends Command { + public CloopCommand () { + super( + "cloop", + "Loop commands", + new String[] { " add <{command}>", " remove ", " clear", " list" }, + new String[] { "commandloop" }, + TrustLevel.TRUSTED + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CommandBlockCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CommandBlockCommand.java index 5225d55..80e9d20 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CommandBlockCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CommandBlockCommand.java @@ -10,37 +10,21 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.JoinConfiguration; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; -import java.util.ArrayList; import java.util.List; import java.util.concurrent.CompletableFuture; -public class CommandBlockCommand implements Command { - public String name() { return "cb"; } - - public String description() { - return "Executes a command in the command core and return it's output"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("<{command}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("cmd"); - aliases.add("commandblock"); - aliases.add("run"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class CommandBlockCommand extends Command { + public CommandBlockCommand () { + super( + "cb", + "Executes a command in the command core and return its output", + new String[] { "" }, + new String[] { "cmd", "commandblock", "run" }, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CowsayCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CowsayCommand.java index 7d95bab..1776fcd 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CowsayCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CowsayCommand.java @@ -6,34 +6,18 @@ import land.chipmunk.chayapak.chomens_bot.command.CommandContext; import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; import net.kyori.adventure.text.Component; -import java.util.ArrayList; -import java.util.List; - -public class CowsayCommand implements Command { - public String name() { return "cowsay"; } - - public String description() { - return "Moo"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("<{message}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class CowsayCommand extends Command { + public CowsayCommand () { + super( + "cowsay", + "Moo", + new String[] { "<{message}>" }, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final String message = String.join(" ", args); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CreatorCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CreatorCommand.java index 76eb273..90f4a18 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CreatorCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/CreatorCommand.java @@ -10,31 +10,18 @@ import net.kyori.adventure.text.Component; import java.util.ArrayList; import java.util.List; -public class CreatorCommand implements Command { - public String name() { return "creator"; } - - public String description() { - return "Shows the bots creator"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class CreatorCommand extends Command { + public CreatorCommand () { + super( + "creator", + "Shows the bots creator", + new String[] {}, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/DiscordCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/DiscordCommand.java index f8c65a7..c6775ef 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/DiscordCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/DiscordCommand.java @@ -9,34 +9,18 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; -import java.util.List; - -public class DiscordCommand implements Command { - public String name() { return "discord"; } - - public String description() { - return "Shows the Discord invite"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class DiscordCommand extends Command { + public DiscordCommand () { + super( + "discord", + "Shows the Discord invite", + new String[] {}, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/EchoCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/EchoCommand.java index 00f1f39..7370942 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/EchoCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/EchoCommand.java @@ -6,32 +6,18 @@ import land.chipmunk.chayapak.chomens_bot.command.CommandContext; import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; import net.kyori.adventure.text.Component; -import java.util.ArrayList; -import java.util.List; - -public class EchoCommand implements Command { - public String name() { return "echo"; } - - public String description() { - return "Says a message"; +public class EchoCommand extends Command { + public EchoCommand () { + super( + "echo", + "Makes the bot say a message", + new String[] { "<{message}>" }, + new String[] { "say" }, + TrustLevel.PUBLIC + ); } - public List usage() { - final List usages = new ArrayList<>(); - usages.add("<{message}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("say"); - - return aliases; - } - - public TrustLevel trustLevel() { return TrustLevel.PUBLIC; } - + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/EndCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/EndCommand.java index 812fe9f..3f53fee 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/EndCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/EndCommand.java @@ -6,34 +6,18 @@ import land.chipmunk.chayapak.chomens_bot.command.CommandContext; import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; import net.kyori.adventure.text.Component; -import java.util.ArrayList; -import java.util.List; - -public class EndCommand implements Command { - public String name() { return "end"; } - - public String description() { - return "End/Restarts the bot"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("restart"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.TRUSTED; +public class EndCommand extends Command { + public EndCommand () { + super( + "end", + "End/Reconnects the bot", + new String[] { "" }, + new String[] { "reconnect", "restart" }, + TrustLevel.TRUSTED + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/FilterCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/FilterCommand.java index f3889a5..94d60c9 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/FilterCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/FilterCommand.java @@ -17,37 +17,23 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class FilterCommand implements Command { - public String name() { return "filter"; } - - public String description() { - return "Filter players"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(" add <{player}>"); - usages.add(" -ignorecase add <{player}>"); - usages.add(" -regex add <{player}>"); - usages.add(" -ignorecase -regex add <{player}>"); - usages.add(" remove "); - usages.add(" clear"); - usages.add(" list"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("filterplayer"); - aliases.add("ban"); - aliases.add("blacklist"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.TRUSTED; +public class FilterCommand extends Command { + public FilterCommand () { + super( + "filter", + "Filter players", + new String[] { + " add <{player}>", + " -ignorecase add <{player}>", + " -regex add <{player}>", + " -ignorecase -regex add <{player}>", + " remove ", + " clear", + " list" + }, + new String[] { "filterplayer", "ban", "blacklist" }, + TrustLevel.TRUSTED + ); } // most of these codes are from cloop and greplog diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GenerateMazeCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GenerateMazeCommand.java index 195ab39..23f5493 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GenerateMazeCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GenerateMazeCommand.java @@ -8,35 +8,18 @@ import land.chipmunk.chayapak.chomens_bot.util.MazeGenerator; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; -import java.util.List; - -public class GenerateMazeCommand implements Command { - public String name() { return "generatemaze"; } - - public String description() { - return "Generates a maze"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(" "); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("genmaze"); - aliases.add("mazegen"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class GenerateMazeCommand extends Command { + public GenerateMazeCommand () { + super( + "generatemaze", + "Generates a maze", + new String[] { " " }, + new String[] { "genmaze", "mazegen" }, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GrepLogCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GrepLogCommand.java index b9f173f..a78d0f1 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GrepLogCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/GrepLogCommand.java @@ -7,40 +7,26 @@ import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; -public class GrepLogCommand implements Command { - public String name() { return "greplog"; } - - public String description() { - return "Queries the bot's log files"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("<{input}>"); - usages.add("-ignorecase <{input}>"); - usages.add("-regex <{input}>"); - usages.add("-ignorecase -regex <{input}>"); - usages.add("stop"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("logquery"); - aliases.add("greplogs"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class GrepLogCommand extends Command { + public GrepLogCommand () { + super( + "greplog", + "Queries the bots log files", + new String[] { + "<{input}>", + "-ignorecase <{input}>", + "-regex <{input}>", + "-ignorecase -regex <{input}>", + "stop" + }, + new String[] { "logquery", "greplogs" }, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] _args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/HelpCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/HelpCommand.java index 7764b46..f3fada4 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/HelpCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/HelpCommand.java @@ -11,43 +11,30 @@ import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; -public class HelpCommand implements Command { - public String name() { return "help"; } - - public String description() { - return "Shows the help"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("[command]"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("heko"); - aliases.add("cmds"); - aliases.add("commands"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class HelpCommand extends Command { + public HelpCommand () { + super( + "help", + "Shows a command list or usage for a command", + new String[] { "[command]" }, + new String[] { "heko", "cmds", "commands" }, + TrustLevel.PUBLIC + ); } private Bot bot; private CommandContext context; + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { this.bot = context.bot(); this.context = context; + if (args.length == 0) { return sendCommandList(); } else { @@ -117,7 +104,7 @@ public class HelpCommand implements Command { final String prefix = context.prefix(); for (Command command : bot.commandHandler().commands()) { - if (!command.name().equals(args[0]) && !command.alias().contains(args[0])) continue; + if (!command.name().equals(args[0]) && !Arrays.stream(command.aliases()).toList().contains(args[0])) continue; final String commandName = command.name(); final List usages = new ArrayList<>(); @@ -126,8 +113,8 @@ public class HelpCommand implements Command { Component.empty() .append(Component.text(prefix + commandName).color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary()))) .append(Component.text( - (command.alias().size() > 0 && !command.alias().get(0).equals("")) ? - " (" + String.join(", ", command.alias()) + ")" : + (command.aliases().length > 0 && !command.aliases()[0].equals("")) ? + " (" + String.join(", ", command.aliases()) + ")" : "" )) .append(Component.text(" - " + command.description()).color(NamedTextColor.GRAY)) @@ -139,7 +126,7 @@ public class HelpCommand implements Command { .append(Component.text(command.trustLevel().name()).color(NamedTextColor.YELLOW)) ); - for (String usage : command.usage()) { + for (String usage : command.usages()) { usages.add( Component.empty() .append(Component.text(prefix + commandName).color(ColorUtilities.getColorByString(bot.config().colorPalette().secondary()))) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/KickCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/KickCommand.java index 320757b..d75ff53 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/KickCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/KickCommand.java @@ -1,43 +1,28 @@ package land.chipmunk.chayapak.chomens_bot.commands; import land.chipmunk.chayapak.chomens_bot.Bot; -import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; -import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry; import land.chipmunk.chayapak.chomens_bot.command.Command; import land.chipmunk.chayapak.chomens_bot.command.CommandContext; +import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; +import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry; import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; -import java.util.List; import java.util.UUID; -public class KickCommand implements Command { - public String name() { return "kick"; } - - public String description() { - return "Kicks a player using the complex NBT exploit (from KittyCorpBot)"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(" <{player}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.TRUSTED; +public class KickCommand extends Command { + public KickCommand () { + super( + "kick", + "Kicks a player", + new String[] { " <{player}>" }, + new String[] {}, + TrustLevel.TRUSTED + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ListCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ListCommand.java index e69e995..3500cda 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ListCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ListCommand.java @@ -15,31 +15,18 @@ import net.kyori.adventure.text.format.NamedTextColor; import java.util.ArrayList; import java.util.List; -public class ListCommand implements Command { - public String name() { return "list"; } - - public String description() { - return "Lists all players in the server (including vanished)"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class ListCommand extends Command { + public ListCommand () { + super( + "list", + "Lists all players in the server (including vanished)", + new String[] {}, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MailCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MailCommand.java index 6d24e42..44bce37 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MailCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MailCommand.java @@ -30,33 +30,18 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.CompletableFuture; -public class MailCommand implements Command { - public String name() { return "mail"; } - - public String description() { - return "Sends a mail"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("send <{message}>"); - usages.add("sendselecteditem "); - usages.add("read"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class MailCommand extends Command { + public MailCommand () { + super( + "mail", + "Sends a mail", + new String[] { "send <{message}>", "sendselecteditem ", "read" }, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { if (args.length < 1) return Component.text("Not enough arguments").color(NamedTextColor.RED); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java index 2d2981e..273b688 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/MusicCommand.java @@ -22,45 +22,34 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class MusicCommand implements Command { +public class MusicCommand extends Command { private Path root; - public String name() { return "music"; } - - public String description() { - return "Play musics"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("play <{song|URL}>"); - usages.add("stop"); - usages.add("loop "); - usages.add("list [{directory}]"); - usages.add("skip"); - usages.add("nowplaying"); - usages.add("queue"); - usages.add("goto "); - usages.add("pitch "); - usages.add("speed "); - usages.add("pause"); - usages.add("resume"); - usages.add("info"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("song"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; + public MusicCommand () { + super( + "music", + "Play musics", + new String[] { + "play <{song|URL}>", + "stop", + "loop ", + "list [{directory}]", + "skip", + "nowplaying", + "queue", + "goto ", + "pitch ", + "speed ", + "pause", + "resume", + "info" + }, + new String[] { "song" }, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { if (args.length < 1) return Component.text("Not enough arguments").color(NamedTextColor.RED); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/NetMessageCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/NetMessageCommand.java index 44dc510..bc0e8fa 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/NetMessageCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/NetMessageCommand.java @@ -9,35 +9,20 @@ import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; import java.util.List; -public class NetMessageCommand implements Command { - public String name() { return "netmsg"; } - - public String description() { - return "Broadcasts a message to all of the servers that the bot is connected"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("<{message}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("networkmessage"); - aliases.add("irc"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class NetMessageCommand extends Command { + public NetMessageCommand () { + super( + "netmsg", + "Broadcasts a message to all of the servers that the bot is connected", + new String[] { "<{message}>" }, + new String[] { "networkmessage", "irc" }, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); final List bots = bot.bots(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/RandomTeleportCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/RandomTeleportCommand.java index 2e3af0f..e06b581 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/RandomTeleportCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/RandomTeleportCommand.java @@ -1,43 +1,27 @@ package land.chipmunk.chayapak.chomens_bot.commands; import land.chipmunk.chayapak.chomens_bot.Bot; -import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; -import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry; import land.chipmunk.chayapak.chomens_bot.command.Command; import land.chipmunk.chayapak.chomens_bot.command.CommandContext; +import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; +import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry; import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities; import land.chipmunk.chayapak.chomens_bot.util.MathUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; -import java.util.List; - -public class RandomTeleportCommand implements Command { - public String name() { return "rtp"; } - - public String description() { - return "Randomly teleports you"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("randomteleport"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class RandomTeleportCommand extends Command { + public RandomTeleportCommand () { + super( + "rtp", + "Randomly teleports you", + new String[] {}, + new String[] { "randomteleport" }, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/RefillCoreCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/RefillCoreCommand.java index 52d4072..3b2c78d 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/RefillCoreCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/RefillCoreCommand.java @@ -6,34 +6,18 @@ import land.chipmunk.chayapak.chomens_bot.command.CommandContext; import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; import net.kyori.adventure.text.Component; -import java.util.ArrayList; -import java.util.List; - -public class RefillCoreCommand implements Command { - public String name() { return "refillcore"; } - - public String description() { - return "Refills and resets the bots command core"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("rc"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class RefillCoreCommand extends Command { + public RefillCoreCommand () { + super( + "refillcore", + "Refills and resets the bots command core", + new String[] {}, + new String[] { "rc" }, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SeenCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SeenCommand.java index 8efa16f..70c5eb2 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SeenCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SeenCommand.java @@ -18,31 +18,18 @@ import org.joda.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; -public class SeenCommand implements Command { - public String name() { return "seen"; } - - public String description() { - return "Shows the last seen of a player"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("<{player}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("lastseen"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class SeenCommand extends Command { + public SeenCommand () { + super( + "seen", + "Shows the last seen of a player", + new String[] { "<{player}>" }, + new String[] { "lastseen" }, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ServerEvalCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ServerEvalCommand.java index fd75577..cbd75a3 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ServerEvalCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ServerEvalCommand.java @@ -9,34 +9,18 @@ import net.kyori.adventure.text.format.NamedTextColor; import org.luaj.vm2.LuaValue; import org.luaj.vm2.lib.jse.CoerceJavaToLua; -import java.util.ArrayList; -import java.util.List; - -public class ServerEvalCommand implements Command { - public String name() { return "servereval"; } - - public String description() { - return "Evaluate codes using LuaJ"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(" <{code}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.OWNER; +public class ServerEvalCommand extends Command { + public ServerEvalCommand () { + super( + "servereval", + "Evaluate codes using LuaJ", + new String[] { " <{code}>" }, + new String[] { "lastseen" }, + TrustLevel.OWNER + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { try { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ServerInfoCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ServerInfoCommand.java index 7c172e5..6b29609 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ServerInfoCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ServerInfoCommand.java @@ -17,36 +17,21 @@ import java.net.InetAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; import java.util.Optional; -public class ServerInfoCommand implements Command { - public String name() { return "serverinfo"; } - - public String description() { - return "Shows the info about the server that is hosting the bot"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class ServerInfoCommand extends Command { + public ServerInfoCommand () { + super( + "serverinfo", + "Shows the info about the server that is hosting the bot", + new String[] {}, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) throws UnknownHostException { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SudoAllCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SudoAllCommand.java index 5db9054..0a9c173 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SudoAllCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SudoAllCommand.java @@ -1,41 +1,25 @@ package land.chipmunk.chayapak.chomens_bot.commands; import land.chipmunk.chayapak.chomens_bot.Bot; -import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; -import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry; import land.chipmunk.chayapak.chomens_bot.command.Command; import land.chipmunk.chayapak.chomens_bot.command.CommandContext; +import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; +import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry; import net.kyori.adventure.text.Component; -import java.util.ArrayList; -import java.util.List; - // ayunsudo renamed. -public class SudoAllCommand implements Command { - public String name() { return "sudoall"; } - - public String description() { - return "Sudoes everyone"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(" <{c:message|command}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("ayunsudo"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.TRUSTED; +public class SudoAllCommand extends Command { + public SudoAllCommand () { + super( + "sudoall", + "Sudoes everyone", + new String[] { " <{c:message|command}>" }, + new String[] { "ayunsudo" }, + TrustLevel.TRUSTED + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TPSBarCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TPSBarCommand.java index 7eb70f1..c4adf15 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TPSBarCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TPSBarCommand.java @@ -8,34 +8,18 @@ import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; -import java.util.List; - -public class TPSBarCommand implements Command { - public String name() { return "tpsbar"; } - - public String description() { - return "Shows the server's TPS using Minecraft Bossbar"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("tps"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class TPSBarCommand extends Command { + public TPSBarCommand () { + super( + "tpsbar", + "Shows the server's TPS using Minecraft Bossbar", + new String[] { "" }, + new String[] { "tps" }, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TestCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TestCommand.java index 43eb29e..32969ad 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TestCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TestCommand.java @@ -6,34 +6,18 @@ import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; -import java.util.List; - -public class TestCommand implements Command { - public String name() { return "test"; } - - public String description() { - return "Tests if the bot is working"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("[{args}]"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class TestCommand extends Command { + public TestCommand () { + super( + "test", + "Tests if the bot is working", + new String[] { "[{args}]" }, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { return Component.translatable( "Hello, World! Username: %s, Sender UUID: %s, Prefix: %s, Args: %s", diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ThrowCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ThrowCommand.java index 7e4fbc4..891e785 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ThrowCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ThrowCommand.java @@ -5,32 +5,15 @@ import land.chipmunk.chayapak.chomens_bot.command.CommandContext; import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; import net.kyori.adventure.text.Component; -import java.util.ArrayList; -import java.util.List; - -public class ThrowCommand implements Command { - public String name() { return "throw"; } - - public String description() { - return "A command to throw an error, kinda useless"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("[{message}]"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("throwerror"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class ThrowCommand extends Command { + public ThrowCommand () { + super( + "throw", + "Throws a Java Exception, kinda useless", + new String[] { "[{message}]" }, + new String[] { "throwerror" }, + TrustLevel.PUBLIC + ); } public Component execute(CommandContext context, String[] args, String[] fullArgs) throws Exception { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TimeCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TimeCommand.java index ad0add4..0fc22e9 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TimeCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TimeCommand.java @@ -12,35 +12,18 @@ import org.joda.time.DateTimeZone; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.List; - -public class TimeCommand implements Command { - public String name() { return "time"; } - - public String description() { - return "Shows the date and time for the specified timezone"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("dateandtime"); - aliases.add("date"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class TimeCommand extends Command { + public TimeCommand () { + super( + "time", + "Shows the date and time for the specified timezone", + new String[] { "" }, + new String[] { "dateandtime", "date" }, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TranslateCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TranslateCommand.java index 8c3ec14..950f95b 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TranslateCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TranslateCommand.java @@ -15,35 +15,20 @@ import net.kyori.adventure.text.format.NamedTextColor; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.Arrays; -import java.util.List; -public class TranslateCommand implements Command { - public String name() { return "translate"; } - - public String description() { - return "Translate a message using Google Translate"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(" <{message}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class TranslateCommand extends Command { + public TranslateCommand () { + super( + "translate", + "Translates a message using Google Translate", + new String[] { " <{message}>" }, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UUIDCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UUIDCommand.java index 36c4c73..6f94629 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UUIDCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UUIDCommand.java @@ -1,44 +1,28 @@ package land.chipmunk.chayapak.chomens_bot.commands; -import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; -import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry; import land.chipmunk.chayapak.chomens_bot.Bot; import land.chipmunk.chayapak.chomens_bot.command.Command; import land.chipmunk.chayapak.chomens_bot.command.CommandContext; +import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; +import land.chipmunk.chayapak.chomens_bot.data.chat.MutablePlayerListEntry; import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; -import java.util.List; - -public class UUIDCommand implements Command { - public String name() { return "uuid"; } - - public String description() { - return "Shows your UUID or other player's UUID"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("[{username}]"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class UUIDCommand extends Command { + public UUIDCommand () { + super( + "uuid", + "Shows your UUID or other player's UUID", + new String[] { "[{username}]" }, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UptimeCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UptimeCommand.java index bf473c6..5ad3b7d 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UptimeCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UptimeCommand.java @@ -9,35 +9,20 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import java.lang.management.ManagementFactory; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.TimeUnit; -public class UptimeCommand implements Command { - public String name() { return "uptime"; } - - public String description() { - return "Shows the bots uptime"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class UptimeCommand extends Command { + public UptimeCommand () { + super( + "uptime", + "Shows the bots uptime", + new String[] { " <{message}>" }, + new String[] {}, + TrustLevel.PUBLIC + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final Bot bot = context.bot(); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UrbanCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UrbanCommand.java index 0847502..6d1ed0d 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UrbanCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/UrbanCommand.java @@ -18,32 +18,16 @@ import net.kyori.adventure.text.format.TextDecoration; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -public class UrbanCommand implements Command { - public String name() { return "urban"; } - - public String description() { - return "Urban Dictionary in Minecraft"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("<{term}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class UrbanCommand extends Command { + public UrbanCommand () { + super( + "urban", + "Urban Dictionary in Minecraft", + new String[] { "<{term}>" }, + new String[] {}, + TrustLevel.PUBLIC + ); } public Component execute (CommandContext context, String[] args, String[] fullArgs) { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java index 8c5f812..0d1b117 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/ValidateCommand.java @@ -6,34 +6,18 @@ import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; -import java.util.ArrayList; -import java.util.List; - -public class ValidateCommand implements Command { - public String name() { return "validate"; } - - public String description() { - return "Validates a hash"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add(""); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("checkhash"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.TRUSTED; +public class ValidateCommand extends Command { + public ValidateCommand () { + super( + "validate", + "Validates a hash", + new String[] { "" }, + new String[] { "checkhash" }, + TrustLevel.TRUSTED + ); } + @Override public Component execute(CommandContext context, String[] args, String[] fullArgs) { final String hash = fullArgs[0]; diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/WeatherCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/WeatherCommand.java index b97abe7..7b0648f 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/WeatherCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/WeatherCommand.java @@ -18,32 +18,16 @@ import org.joda.time.format.DateTimeFormatter; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -public class WeatherCommand implements Command { - public String name() { return "weather"; } - - public String description() { - return "Shows the weather in a place"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("<{location}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add(""); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class WeatherCommand extends Command { + public WeatherCommand () { + super( + "weather", + "Shows the weather in a place", + new String[] { "<{location}>" }, + new String[] {}, + TrustLevel.TRUSTED + ); } public Component execute (CommandContext context, String[] args, String[] fullArgs) { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/WikipediaCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/WikipediaCommand.java index df95f20..b3a62c4 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/WikipediaCommand.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/WikipediaCommand.java @@ -14,32 +14,16 @@ import java.io.FileNotFoundException; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -public class WikipediaCommand implements Command { - public String name() { return "wikipedia"; } - - public String description() { - return "Wikipedia in Minecraft"; - } - - public List usage() { - final List usages = new ArrayList<>(); - usages.add("<{page}>"); - - return usages; - } - - public List alias() { - final List aliases = new ArrayList<>(); - aliases.add("wiki"); - - return aliases; - } - - public TrustLevel trustLevel() { - return TrustLevel.PUBLIC; +public class WikipediaCommand extends Command { + public WikipediaCommand () { + super( + "wikipedia", + "Wikipedia in Minecraft", + new String[] { "<{page}>" }, + new String[] { "wiki" }, + TrustLevel.PUBLIC + ); } public Component execute (CommandContext context, String[] args, String[] fullArgs) { diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java index 97e16af..8c60e3e 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java @@ -101,10 +101,10 @@ public class CommandHandlerPlugin { final String[] fullArgs = Arrays.copyOfRange(splitInput, 1, splitInput.length); // TODO: improve these minimum args and maximum args stuff, the current one really sucks.,., - final int shortestUsageIndex = getShortestUsageIndex(command.usage()); - final int longestUsageIndex = getLongestUsageIndex(command.usage()); - final String shortestUsage = command.usage().get(shortestUsageIndex); - final String longestUsage = command.usage().get(longestUsageIndex); + final int shortestUsageIndex = getShortestUsageIndex(command.usages()); + final int longestUsageIndex = getLongestUsageIndex(command.usages()); + final String shortestUsage = command.usages()[shortestUsageIndex]; + final String longestUsage = command.usages()[longestUsageIndex]; final int minimumArgs = getMinimumArgs(shortestUsage, inGame, command.trustLevel()); final int maximumArgs = getMaximumArgs(longestUsage, inGame, command.trustLevel()); @@ -181,7 +181,7 @@ public class CommandHandlerPlugin { if ( ( command.name().equals(searchTerm.toLowerCase()) || - command.alias().contains(searchTerm.toLowerCase()) + Arrays.stream(command.aliases()).toList().contains(searchTerm.toLowerCase()) ) && !searchTerm.equals("") // ig yup ) { @@ -191,14 +191,14 @@ public class CommandHandlerPlugin { return null; } - private int getLongestUsageIndex(List usages) { + private int getLongestUsageIndex(String[] usages) { int longestIndex = 0; int maxLength = 0; - final int usagesSize = usages.size(); + final int usagesSize = usages.length; for (int i = 0; i < usagesSize; i++) { - String[] args = usages.get(i).split("\\s+"); + String[] args = usages[i].split("\\s+"); if (args.length > maxLength) { longestIndex = i; maxLength = args.length; @@ -207,14 +207,14 @@ public class CommandHandlerPlugin { return longestIndex; } - private int getShortestUsageIndex(List usages) { + private int getShortestUsageIndex(String[] usages) { int shortestIndex = 0; int minLength = Integer.MAX_VALUE; - final int usagesSize = usages.size(); + final int usagesSize = usages.length; for (int i = 0; i < usagesSize; i++) { - String[] args = usages.get(i).split("\\s+"); + String[] args = usages[i].split("\\s+"); if (args.length < minLength) { shortestIndex = i; minLength = args.length;