Skip to content
This repository was archived by the owner on Apr 20, 2025. It is now read-only.
Nont Nonnipat edited this page Nov 20, 2024 · 11 revisions

Welcome to the Experiences-Lib wiki!

Coming Soon full version in 2025!

Creating Command

Simple way to create a command using SimpleCommand

import com.pinont.experiences.api.commands.SimpleCommand;
import com.pinont.experiences.api.commands.SimpleCommandManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Map;

public class SomeCommand extends SimpleCommand {

    public SomeCommand() {
        this.addCommand(new SimpleCommandManager("a") {
            @Nullable
            @Override
            public Map<Integer, List<String>> args() {
                return Map.of(0, List.of("a", "b", "c"));
            }

            @Override
            public void execute(CommandSender sender, Command command, String[] args) {
                sender.sendMessage("Hello World!");
            }
        }, CommandSenderType.BOTH);
    }

}

- TabComplete()

But if you want to edit the way tabComplete works, you can override the tabComplete method

import com.pinont.experiences.api.commands.SimpleCommand;
import com.pinont.experiences.api.commands.SimpleCommandManager;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Map;

public class SomeCommand extends SimpleCommand {

    public SomeCommand() {
        this.addCommand(new SimpleCommandManager("a") {
            @Nullable
            @Override
            public Map<Integer, List<String>> args() {
                return Map.of(0, List.of("args1", "args2", "args3"));
            }

            @Override
            public void execute(CommandSender sender, Command command, String[] args) {
                sender.sendMessage("Hello World!");
            }
            
            @Override
            public List<String> tabComplete(CommandSender sender, Command command, String[] args) {
                return List.of("a", "b", "c"); // or else
            }
        }, CommandSenderType.BOTH);
    }

}

You may ask why should I need to write this.addCommand(). It's just because the SimpleCommand Can handle multiple commands in one class. So you can add multiple commands in one class!

- args()

This is a simple way to add arguments to the command. so you don't need to wasting time by checking strings length for providing an argument.

- execute()

This method works the same as the onCommand method in the CommandExecutor interface.

- CommandSenderType

I saw that when ever I create a command, I always need to check if the command can be executed by console or player. So I created a CommandSenderType to make it easier to check if the command can be executed by console or player.

  • CommandSenderType.BOTH - Command can be executed by both console and player
  • CommandSenderType.CONSOLE - Command can only be executed by console
  • CommandSenderType.PLAYER - Command can only be executed by player

Coming soon full version on 2025!

Clone this wiki locally