57 lines
1.9 KiB
Java
57 lines
1.9 KiB
Java
package net.knarcraft.crateregistry.command;
|
|
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.command.TabExecutor;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* The main command for the CrateRegistry plugin
|
|
*/
|
|
public class CrateRegistryCommand extends PluginCommand {
|
|
|
|
private final TabExecutor claimExecutor;
|
|
private final TabExecutor giveExecutor;
|
|
|
|
/**
|
|
* Instantiates a new crate registry command
|
|
*/
|
|
public CrateRegistryCommand() {
|
|
claimExecutor = new ClaimCommand();
|
|
giveExecutor = new GiveCommand();
|
|
}
|
|
|
|
@Override
|
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
|
@NotNull String[] arguments) {
|
|
return switch (arguments[0].toLowerCase()) {
|
|
case "givekey" -> giveExecutor.onCommand(sender, command, label, arguments);
|
|
case "claim" -> claimExecutor.onCommand(sender, command, label, arguments);
|
|
default -> false;
|
|
};
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
|
@NotNull String[] args) {
|
|
if (args.length == 1) {
|
|
if (sender.hasPermission("crateregistry.give")) {
|
|
return filterMatchingStartsWith(List.of("giveKey", "claim"), args[0]);
|
|
} else {
|
|
return filterMatchingStartsWith(List.of("claim"), args[0]);
|
|
}
|
|
} else {
|
|
return switch (args[0].toLowerCase()) {
|
|
case "givekey" -> giveExecutor.onTabComplete(sender, command, label, args);
|
|
case "claim" -> claimExecutor.onTabComplete(sender, command, label, args);
|
|
default -> List.of();
|
|
};
|
|
}
|
|
}
|
|
|
|
}
|