blob: 6bb62acff8ecd1688fbecb4564ba2df863efda69 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
package com.thatgravyboat.skyblockhud.commands;
import java.util.List;
import java.util.Set;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.BlockPos;
import org.apache.commons.lang3.ArrayUtils;
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) {}
}
|