1

ここにすべての私のコードがあります:

@Override
public void onEnable()
{
    getLogger().info("Plugin Enabled!");

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
    {
        if(cmd.getName().equalsIgnoreCase("Plugin"))
        { 
            // If the player typed /plugin then do the following...
            if (sender instanceof Player) 
            {
                Player player = (Player) sender;

                // Gives player item
                return true;
            } 
            else 
            {
                sender.sendMessage("You must be a player!");
                return false;
            }
        }   
    }

    @Override
    public void onDisable() 
    {
        getLogger().info("Plugin Disabled!");
    }
}

ご存じないかもしれませんが、これは Minecraft Bukkit のプラグインです。

エラー行は次のとおりです。

getLogger().info("Plugin Enabled!");

セミコロンを削除すると「 」内のメッセージがエラーになり、「}」または「{」を挿入するとエラーが表示されます。

これを修正するにはどうすればよいですか?

4

3 に答える 3

1

別のメソッド ( onCommand) 内にメソッド ( ) がありますonEnable- これは不可能です。

}の前に右中括弧がないと思いますpublic boolean onCommand

public void onEnable() {
    getLogger().info("Plugin Enabled!");
} //HERE ADD THE MISSING BRACE

public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (cmd.getName().equalsIgnoreCase("Plugin")) { // If the player typed /plugin then do the following...
        if (sender instanceof Player) {
            Player player = (Player) sender;

            // Gives player item
            return true;
        } else {
            sender.sendMessage("You must be a player!");
            return false;
        }
    } else {
        return false; //HERE YOU NEED TO RETURN FROM THE ELSE TOO
    }
}
于 2013-01-27T13:51:33.050 に答える
0

問題は、次の 3 つのメソッドがあることですがonEnable()、最後の 2 つのメソッドは定義されており、その中onCommand()では実行できません。呼び出しの後に「}」を置くと、そこで呼び出しが終了します。次に、表示しているブロックの最後にある末尾の「}」も削除する必要があります。onDisable()onEnable()getLogger()...onEnable()

于 2013-01-27T13:55:01.903 に答える
0
public void onEnable(){
    getLogger().info("Plugin Enabled!");
}// Add braces

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
        if(cmd.getName().equalsIgnoreCase("Plugin")){ // If the player typed /plugin then do the following...
            if (sender instanceof Player) {
                   Player player = (Player) sender;

                   // Gives player item
                   return true;
                } else {
                   sender.sendMessage("You must be a player!");
                   return false;
                }
        } 

    }

@Override
public void onDisable() {
    getLogger().info("Plugin Disabled!");
}
// } Delete this braces
于 2013-01-27T14:03:28.777 に答える