Create powerful commands with built-in permission handling, tab completion, and argument validation
Foundation’s SimpleCommand class provides a robust framework for creating Bukkit commands with automatic registration, permission checks, cooldowns, and tab completion.
Extend SimpleCommand and implement the onCommand() method:
public class KitCommand extends SimpleCommand { public KitCommand() { super("kit|kits"); setDescription("Give yourself a kit"); setUsage("<kitName>"); setMinArguments(1); } @Override protected void onCommand() { checkConsole(); final Player player = getPlayer(); final String kitName = args[0]; // Your logic here tell("You received the " + kitName + " kit!"); }}
@Overrideprotected void onCommand() { // Find online player final Player target = findPlayer(args[0]); // Find offline player (async) findOfflinePlayer(args[0], offlinePlayer -> { tell("Player: " + offlinePlayer.getName()); }); // Get player or sender if no args final Player player = findPlayerOrSelf(0);}
// Parse integerfinal int amount = findNumber(0, "&cPlease enter a valid number!");// With boundsfinal int amount = findNumber(0, 1, 64, "&cAmount must be between {min} and {max}!");// Parse doublefinal double price = findNumber(Double.class, 0, "&cPlease enter a valid price!");
final GameMode mode = findEnum(GameMode.class, args[0], "&cInvalid game mode: {enum}! Available: {available}");
final CompMaterial material = findMaterial(args[0], "&cInvalid material: {item}!");
final World world = findWorld(args[0]);// Use ~ for player's current world// /teleport ~ 100 64 100
tell("&aKit given!");tellSuccess("Operation successful!");tellError("Something went wrong!");tellWarn("Be careful!");tellInfo("Useful information");tellQuestion("Are you sure?");
// Get last argumentfinal String last = getLastArg();// Join args from indexfinal String message = joinArgs(1); // "hello world" from "/msg player hello world"// Get range of argsfinal String[] range = rangeArgs(1, 3);
@Overrideprotected String[] getMultilineUsageMessage() { return new String[] { "/kit starter - Get the starter kit", "/kit pvp - Get the PVP kit", "/kit builder - Get the builder kit" };}