aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/commands/SimpleCommand.java
blob: 49a02a8d4b7ddb4ae03eee24e7ccf35042faa5ef (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
62
63
64
65
66
67
68
69
70
71
72
package com.thatgravyboat.skyblockhud.commands;

import java.util.List;
import net.minecraft.command.CommandBase;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.BlockPos;

/**
 @author Moulberry
 **/
public class SimpleCommand extends CommandBase {

  private String commandName;
  private ProcessCommandRunnable runnable;
  private TabCompleteRunnable tabRunnable;

  public SimpleCommand(String commandName, ProcessCommandRunnable runnable) {
    this.commandName = commandName;
    this.runnable = runnable;
  }

  public SimpleCommand(
    String commandName,
    ProcessCommandRunnable runnable,
    TabCompleteRunnable tabRunnable
  ) {
    this.commandName = commandName;
    this.runnable = runnable;
    this.tabRunnable = tabRunnable;
  }

  public abstract static class ProcessCommandRunnable {

    public abstract void processCommand(ICommandSender sender, String[] args);
  }

  public abstract static class TabCompleteRunnable {

    public abstract List<String> tabComplete(
      ICommandSender sender,
      String[] args,
      BlockPos pos
    );
  }

  public boolean canCommandSenderUseCommand(ICommandSender sender) {
    return true;
  }

  public String getCommandName() {
    return commandName;
  }

  public String getCommandUsage(ICommandSender sender) {
    return "/" + commandName;
  }

  public void processCommand(ICommandSender sender, String[] args)
    throws CommandException {
    runnable.processCommand(sender, args);
  }

  public List<String> addTabCompletionOptions(
    ICommandSender sender,
    String[] args,
    BlockPos pos
  ) {
    if (tabRunnable != null) return tabRunnable.tabComplete(sender, args, pos);
    return null;
  }
}