这是我的所有代码:
@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!");
当我删除分号时,“”中的消息是错误的,当我插入“}”或/和“{”时显示错误。
我该如何解决这个问题?
答案 0 :(得分: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
}
}
答案 1 :(得分:0)
问题是您有3种方法:onEnable()
,onCommand()
和onDisable()
但是最后两种方法是在onEnable()
中定义的,您无法做到。如果你放一个'}'在getLogger()...
电话结束后,您将在那里结束onEnable()
电话,然后您还需要删除跟踪'}'}你在向我们展示的街区尽头。
答案 2 :(得分: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