-
Notifications
You must be signed in to change notification settings - Fork 0
F | Creating Custom Commands
Sartaj Singh edited this page May 28, 2025
·
2 revisions
Learn how to add player/server commands, subcommands, and tab completion.
Recommended location: com.noctify.Custom.Commands
public class GreetCommand implements CommandExecutor, TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player player)) {
sender.sendMessage("Only players can use this command.");
return true;
}
if (args.length == 0) {
player.sendMessage("Usage: /greet <name>");
return true;
}
player.sendMessage("Hello, " + args[0] + "!");
return true;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 1) {
return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
}
return Collections.emptyList();
}
}In CommandRegistry:
registerCommand(plugin, "greet", GreetCommand.class);Add subcommands as needed:
if (args[0].equalsIgnoreCase("help")) {
player.sendMessage("/greet <name> - Greets a player.");
return true;
}Check permissions in your command:
if (!player.hasPermission("fxitems.greet")) {
player.sendMessage(ChatColor.RED + "No permission.");
return true;
}- Register and reload server.
- Use
/greet <name>and test tab completion.
- Command class with
onCommand() - Optional: TabCompleter for suggestions
- Register in
CommandRegistry - (Optional) Permissions, subcommands
- Home
- A | Getting Started & Plugin Overview
- B | The Registry System: Items, Foods, Commands, Events
- C | Creating Custom Items
- D | Creating Custom Foods
- E | Advanced: Custom Effects in FXItems
- F | Creating Custom Commands
- G | Creating Custom Events & Behaviors
- H | Utility: CooldownUtils
- I | Utility: CustomItemUtils
- J | Utility: EffectUtils
- K | Utility: ManaUtils
- L | Utility: OneTimeCraftUtils
- M | Utility: TeleportUtils
- N | Utility: ProjectileUtils
- O | Utility: GammaUtils
- P | Utility: EntitySizeUtils
- Q | FXItems API (com.noctify.API) & Making Addons
- R | Advanced Techniques, Gotchas & FAQ
- S | Auto-Registration System
- T | Migration Guide (v1.1 → v1.2+)
- U | Changelog