aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleSubCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleSubCommand.java')
-rw-r--r--src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleSubCommand.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleSubCommand.java b/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleSubCommand.java
new file mode 100644
index 0000000..7169c6d
--- /dev/null
+++ b/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleSubCommand.java
@@ -0,0 +1,62 @@
+package com.thatgravyboat.skyblockhud.commands;
+
+import net.minecraft.command.CommandBase;
+import net.minecraft.command.ICommandSender;
+import net.minecraft.util.BlockPos;
+import org.apache.commons.lang3.ArrayUtils;
+
+import java.util.List;
+import java.util.Set;
+
+public abstract class SimpleSubCommand extends CommandBase {
+
+ private final String commandName;
+ private final Set<String> subCommands;
+
+ public SimpleSubCommand(String commandName, Set<String> subCommands) {
+ this.commandName = commandName;
+ this.subCommands = subCommands;
+ }
+
+ @Override
+ public String getCommandName() {
+ return commandName;
+ }
+
+ @Override
+ public String getCommandUsage(ICommandSender sender) {
+ return "/"+commandName;
+ }
+
+ @Override
+ public void processCommand(ICommandSender sender, String[] args) {
+ if (args.length == 0) {
+ processNoSubCommand(sender);
+ return;
+ }
+ if (subCommands.contains(args[0])){
+ processSubCommand(sender, args[0], ArrayUtils.remove(args, 0));
+ return;
+ }
+ processBadSubCommand(sender, args[0]);
+ }
+
+ @Override
+ public boolean canCommandSenderUseCommand(ICommandSender sender) {
+ return true;
+ }
+
+ @Override
+ public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) {
+ if (args.length == 1){
+ return getListOfStringsMatchingLastWord(args,subCommands);
+ }
+ return null;
+ }
+
+ abstract void processSubCommand(ICommandSender sender, String subCommand, String[] args);
+
+ abstract void processNoSubCommand(ICommandSender sender);
+
+ public void processBadSubCommand(ICommandSender sender, String subCommand){}
+}