Command System
hCore allows you to create your custom commands without any editing plugin.yml.
Introducing
import com.hakan.core.command.executors.base.BaseCommand;
import com.hakan.core.command.executors.placeholder.Placeholder;
import com.hakan.core.command.executors.sub.SubCommand;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import java.util.ArrayList;
import java.util.List;
@BaseCommand(
aliases = { "alias" } /* Aliases means like what label you need to use for this command*/,
name = "example command",
usage = "/customcommand",
description = "This is the description of the custom command"
)
public class CustomCommand {
@SubCommand(
permission = "needed.permission",
permissionMessage = "§cYou have no perms for using this command!"
)
public void mainCommand(CommandSender sender, String[] args) {
sender.sendMessage("You used main command without any args! You also can use /alias for calling this command");
}
// After executing this command sender will get message if player is currently online or offline
@SubCommand(
permission = "online.check",
args = { "<%player%>" }
)
public void checkOnlineCommand(CommandSender sender, String[] args) {
sender.sendMessage("Player is currently " + (Bukkit.getOfflinePlayer(args[0]).isOnline() ? "online" : "offline"));
}
/* Placeholders allows you to add how many u want tab completions (in this situation is player names) */
@Placeholder(
name = "player"
)
public List<String> getPlayers() {
return Bukkit.getOnlinePlayers().map(player -> player.name);
}
}Placeholders
SubCommands
Ending working with commands
Last updated