# Command System

## Introducing

Firstly, you need to create your command class.

Example code for ready command class:

```java
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

What is it?

Placeholders allows you to add a lot of args by using one method. So, you can add placeholder for anything you can imagine. For example: Loaded world names, Online players, Ready Values (100, 200, 300), e.t.c.

## SubCommands

SubCommand means arguments. You can provide permission to use this command and noPermission message.

You can also provide placeholders, using <%placeholderName%>, and arguments.

## Ending working with commands

After u created class, you need to register command. So, use the HCore#registerCommands(new YourCommandClass())


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hcore.gitbook.io/wiki/messaging/command-system.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
