Problem with creating a command

AiheQx

Member
Hello i am creating a test plugin because i want to look if i can make a nukkit plugin.

Now i have a problem, i created a command /hello and when a person execute it it will send a message Hello to the player. I want to create this command pure for a test
Now i made the command and registered the command in my Main.java en plugin.yml but when i execute it ingame it says this
1746772138937.png
I have it in dutch, so for the english people it says Use: /hello

This is my Main.java


Code:
package com.svenkoggel.nukkit;

import cn.nukkit.plugin.PluginBase;
import cn.nukkit.event.Listener;
import cn.nukkit.event.player.PlayerJoinEvent;
import cn.nukkit.command.PluginCommand;
import cn.nukkit.event.EventHandler;

public class Main extends PluginBase implements Listener {

    @Override
    public void onEnable() {
        getLogger().info("Plugin is geladen!");
        getServer().getPluginManager().registerEvents(new JoinEvent(), this);

        // Maak een PluginCommand-object en stel de executor in
        PluginCommand helloCommand = new PluginCommand("hello", this);
        helloCommand.setExecutor(new HelloCommand());

        // Registreer met de commandMap
        this.getServer().getCommandMap().register("hello", helloCommand);
    }
}
This is my HelloCommand.java


Code:
package com.svenkoggel.nukkit;

import cn.nukkit.command.Command;
import cn.nukkit.command.CommandExecutor;
import cn.nukkit.command.CommandSender;
import cn.nukkit.Player;
import cn.nukkit.utils.TextFormat;

public class HelloCommand implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (sender instanceof Player) {
            Player player = (Player) sender;
            player.sendMessage(TextFormat.RED + "Hallo!");
            return true;
        } else {
            sender.sendMessage(TextFormat.RED + "Dit commando kan alleen door een speler worden gebruikt.");
            return true;
        }
    }
}
And this is my plugin.yml


Code:
name: Nukkit
main: com.svenkoggel.nukkit.Main
version: 1.0
api: ["1.0.0"]

commands:
  hello:
    description: Zegt hallo in het rood
    usage: /hello
I hope someone can help me i appreciate it very much,

Thanks
 

PetteriM1

Moderator
Staff member
onCommand is only used in your plugin's main class when the command is registered through plugin.yml. Commands registered through command map should extend Command and implement boolean execute(CommandSender sender, String commandLabel, String[] args)
 
Top