Bukkit插件:无法导入命令

时间:2017-04-14 13:24:47

标签: java eclipse plugins minecraft bukkit

前几天我开始研究bukkit插件,目的是在用户输入'/ hello'时在文本窗口中返回hello。但是这不起作用,因为我无法在eclipse中导入命令行。有什么建议?它说,“命令无法解析为类型”

package me.Nickedyerpants;

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

public class Plugin extends JavaPlugin{

@Override
public void onEnable(){     //what happens when plugin is enabled

    getLogger().info("First plugin starting up....");


}


@Override
public void onDisable(){   //for when plugin is disabled


    boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){

        if (cmd.getName().equalsIgnoreCase("hello") && sender instanceof Player){

            Player player = (Player) sender;

            player.sendMessage("hello");

        }

        return true;

    }



}

}

1 个答案:

答案 0 :(得分:2)

所以你的代码实际上很糟糕,你在onCommand方法中实现了onDisable,这是错误的,你的类没有正确关闭!

用这个替换你的整个代码:

package me.Nickedyerpants;

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

public class Plugin extends JavaPlugin {

    @Override
    public void onEnable() {     //what happens when plugin is enabled

        getLogger().info("First plugin starting up....");


    }


    @Override
    public void onDisable() {   //for when plugin is disabled
    }


    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {

        if (cmd.getName().equalsIgnoreCase("hello") && sender instanceof Player) {

            Player player = (Player) sender;

            player.sendMessage("hello");

        }

        return true;

    }


}

将方法放在类本身中,不要将它们放在另一个方法中。