make Command a class instead of an interface

this is attempt 2 and it works now
This commit is contained in:
Chayapak 2023-07-01 08:54:13 +07:00
parent e276976594
commit 744381ca06
40 changed files with 451 additions and 991 deletions

View file

@ -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<String> usage();
List<String> 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;
}

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<hash> <true|false>");
usages.add("<hash> <on|off>");
usages.add("<hash>");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<hash> <true|false>", "<hash> <on|off>", "<hash>" },
new String[] { "botvis", "togglevis", "togglevisibility" },
TrustLevel.TRUSTED
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("[{message}]");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("[player]");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<hash> add <interval> <{command}>");
usages.add("<hash> remove <index>");
usages.add("<hash> clear");
usages.add("<hash> list");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<hash> add <interval> <{command}>", "<hash> remove <index>", "<hash> clear", "<hash> list" },
new String[] { "commandloop" },
TrustLevel.TRUSTED
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<{command}>");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<command>" },
new String[] { "cmd", "commandblock", "run" },
TrustLevel.PUBLIC
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<{message}>");
return usages;
}
public List<String> alias() {
final List<String> 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);

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<{message}>");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<hash>");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<hash>" },
new String[] { "reconnect", "restart" },
TrustLevel.TRUSTED
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<hash> add <{player}>");
usages.add("<hash> -ignorecase add <{player}>");
usages.add("<hash> -regex add <{player}>");
usages.add("<hash> -ignorecase -regex add <{player}>");
usages.add("<hash> remove <index>");
usages.add("<hash> clear");
usages.add("<hash> list");
return usages;
}
public List<String> alias() {
final List<String> 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[] {
"<hash> add <{player}>",
"<hash> -ignorecase add <{player}>",
"<hash> -regex add <{player}>",
"<hash> -ignorecase -regex add <{player}>",
"<hash> remove <index>",
"<hash> clear",
"<hash> list"
},
new String[] { "filterplayer", "ban", "blacklist" },
TrustLevel.TRUSTED
);
}
// most of these codes are from cloop and greplog

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<x> <y> <z> <width> <long>");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<x> <y> <z> <width> <long>" },
new String[] { "genmaze", "mazegen" },
TrustLevel.PUBLIC
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> 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<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("[command]");
return usages;
}
public List<String> alias() {
final List<String> 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<Component> 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())))

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<hash> <{player}>");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<hash> <{player}>" },
new String[] {},
TrustLevel.TRUSTED
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("send <player> <{message}>");
usages.add("sendselecteditem <player>");
usages.add("read");
return usages;
}
public List<String> alias() {
final List<String> 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 <player> <{message}>", "sendselecteditem <player>", "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);

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("play <{song|URL}>");
usages.add("stop");
usages.add("loop <current|all|off>");
usages.add("list [{directory}]");
usages.add("skip");
usages.add("nowplaying");
usages.add("queue");
usages.add("goto <timestamp>");
usages.add("pitch <pitch>");
usages.add("speed <speed>");
usages.add("pause");
usages.add("resume");
usages.add("info");
return usages;
}
public List<String> alias() {
final List<String> 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 <current|all|off>",
"list [{directory}]",
"skip",
"nowplaying",
"queue",
"goto <timestamp>",
"pitch <pitch>",
"speed <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);

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<{message}>");
return usages;
}
public List<String> alias() {
final List<String> 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<Bot> bots = bot.bots();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<{player}>");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<ownerHash> <{code}>");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<ownerHash> <{code}>" },
new String[] { "lastseen" },
TrustLevel.OWNER
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
try {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<hash> <{c:message|command}>");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<hash> <{c:message|command}>" },
new String[] { "ayunsudo" },
TrustLevel.TRUSTED
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<on|off>");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<on|off>" },
new String[] { "tps" },
TrustLevel.PUBLIC
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("[{args}]");
return usages;
}
public List<String> alias() {
final List<String> 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",

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("[{message}]");
return usages;
}
public List<String> alias() {
final List<String> 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 {

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<timezone>");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<timezone>" },
new String[] { "dateandtime", "date" },
TrustLevel.PUBLIC
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<from> <to> <{message}>");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<fromLanguage> <toLanguage> <{message}>" },
new String[] {},
TrustLevel.PUBLIC
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("[{username}]");
return usages;
}
public List<String> alias() {
final List<String> 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();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<fromLanguage> <toLanguage> <{message}>" },
new String[] {},
TrustLevel.PUBLIC
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot();

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<{term}>");
return usages;
}
public List<String> alias() {
final List<String> 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) {

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<hash|ownerHash>");
return usages;
}
public List<String> alias() {
final List<String> 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[] { "<hash|ownerHash>" },
new String[] { "checkhash" },
TrustLevel.TRUSTED
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final String hash = fullArgs[0];

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<{location}>");
return usages;
}
public List<String> alias() {
final List<String> 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) {

View file

@ -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<String> usage() {
final List<String> usages = new ArrayList<>();
usages.add("<{page}>");
return usages;
}
public List<String> alias() {
final List<String> 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) {

View file

@ -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<String> 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<String> 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;