/help <pluginname> 有效,实际命令 returns 没有。我的世界 1.14.4 插件

/help <pluginname> works, actual command returns nothing. Minecraft 1.14.4 plugin

我正在尝试在 1.14.4 中编写一个 minecraft 插件,/help firstplugin 可以,但是 /hello 没有发送任何消息。

我的Main.Java:

package com.Epic_Waffle.firstplugin;

import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import com.mojang.brigadier.Command;

import net.md_5.bungee.api.ChatColor;

public class Main extends JavaPlugin{
    
    @Override
    public void onEnable() {
        System.out.println("FirstPlugin successfully enabled!");
    }
    
    @Override
    public void onDisable() {
        System.out.println("FirstPlugin disabled with no errors!");
    }
    
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        System.out.print(cmd);
        if(cmd.toString().equals("/hello")) {
            if(sender instanceof Player) {
                Player player = (Player) sender;
                
                player.sendMessage(ChatColor.YELLOW + "Hello!" + ChatColor.GREEN + player.getName() + ChatColor.YELLOW + "Your health has been restored!");
                player.setHealth(20.0);
                
                
            } else {
                System.out.println("You cannot use this command through console.");
            }
        }
        
        return false;
    }
    
}

我的plugin.yml

version: 1.0
name: FirstPlugin
main: com.Epic_Waffle.firstplugin.Main
author: Epic_Waffle
description: FirstPlugin
commands:
  hello:
    aliases: []
    description: Cool hello command!

您必须使用 Spigot API 注册每个命令,然后才会调用它(请参阅下面的 onEnable 方法)。您已经通过将命令添加到 plugin.yml 执行了第一步。我还在下面包含了此方法调用的文档。尽管这些是 1.16 的文档,但自 1.14 以来在注册 CommandExecutor 方面没有进行任何更改。确保您尝试注册的对象实现 CommandExecutor.

public void setExecutor​(@Nullable
CommandExecutor executor)
Sets the CommandExecutor to run when parsing this command
Parameters:
executor - New executor to run

Source for the documentation above.

@Override
public void onEnable() {
    this.getCommand("hello").setExecutor( this );
    System.out.println("FirstPlugin successfully enabled!");
}

此外,我建议在您的 onCommand 方法中使用 Command#getName() 而不是 toString(),如我的评论所述。