-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Coming Soon full version in 2025!
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);
}
}
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!
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.
This method works the same as the onCommand
method in the CommandExecutor
interface.
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!
Coming soon full version on 2025!