我正在尝试使用多个类创建插件,但是当我在Minecraft中键入命令时,它会显示命令语法错误消息(语法错误!只需键入/ ct create。)。我认为这是一个愚蠢的错误,但我找不到它。
我的core.java:
public class Core extends JavaPlugin {
public ArrayList<Block> chests = new ArrayList<>();
public boolean createMode = false;
public void onEnabled() {
getCommand("ct").setExecutor(new Commands(this));
getServer().getPluginManager().registerEvents(new Listeners(this), this);
}
}
我的Commands.java:
public class Commands implements CommandExecutor {
private Core plugin;
public Commands(Core core) {
this.plugin = core;
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("ct")) {
sender.sendMessage("lol");
if(args.length > 0) {
sender.sendMessage("hi");
if(args[0].equalsIgnoreCase("create")) {
plugin.createMode = true;
sender.sendMessage(ChatColor.GOLD + "[ChestTreasure] " + ChatColor.RESET + "Now rightclick the chest");
}
} else {
sender.sendMessage(ChatColor.GOLD + "[ChestTreasure] " + ChatColor.RESET + "Too few arguments!");
}
}
return false;
}
}
我的plugin.yml:
name: ChestTreasure
description: this plugin...
main: me.sudoman281.chestTreasure.Core
version: 1.0
author: sudoman281
commands:
ct:
description: ...
permission: ct.create
usage: Syntax error! Simply type /ct create.
答案 0 :(得分:2)
您必须通过具有相同名称和方法签名/返回类型来正确覆盖该方法。为此,您必须执行以下操作:
onEnabled
方法应为onEnable
@Override
注释来表示您正在覆盖超类方法。 (可选,但强烈建议用于查找错误和约定。如果没有这个,它将起作用)您的onEnable
应如下所示:
@Override
public void onEnable() {
/* Do stuff when plugin starts */
}