0

这是我的代码。底部的最后一个大括号有错误。这很烦人,我一直在努力解决它。是我的牙套太多还是怎么的?我真的很难过。请帮忙。

    enter code here

package me.sapita.medic;

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

public class medicplugin1 extends JavaPlugin {


    public void onEnable() {
        Bukkit.getServer().getLogger().info("Medic enabled!");
    }

    public void onDisable() {
        Bukkit.getServer().getLogger().info("Medic disabled!");
    }

    @SuppressWarnings("deprecation")
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){

    if (!(sender instanceof Player)){
        sender.sendMessage(ChatColor.RED + "The console cannot be regenerated!");
        return true;
    }

    Player player = (Player) sender;


    if (cmd.getName().equalsIgnoreCase("regen")){
        Player target = Bukkit.getServer().getPlayer(args[0]);
        if (target == null){
            player.sendMessage(ChatColor.RED + "Could not find user.");
            return true;
        }

        if (args.length == 0){
            player.setHealth(20);
            player.setFoodLevel(20);
            player.sendMessage(ChatColor.GREEN + "Your health & food have been regenerated!");
        }
        if (target == null){
            player.sendMessage("Please specify a player to regenerate.");
        }

        sender.sendMessage(target.getName() + "has been regenerated!");

        target.setHealth(20);
        target.sendMessage(sender.getName()+ "has regenerated your health & food!");
        return true;

        }

    return true;

    if (cmd.getName().equalsIgnoreCase("resetfood")){

        Player target = Bukkit.getServer().getPlayer(args[0]);
    if (target == null){
        player.setFoodLevel(20);
        player.sendMessage(ChatColor.GREEN + "Your food health has been regenerated!");
        return true;
    }

    if (args.length == 0){
        sender.sendMessage(ChatColor.GREEN + "You have fed yourself!");

        player.setFoodLevel(20);
        return true;
    }


    target.setFoodLevel(20);



    target.sendMessage(sender.getName() + "has regenerated your food!");

    sender.sendMessage(ChatColor.GREEN + target.getName() + "has been food health has been regenerated!");{
        return true;
    }
4

2 回答 2

1

您在文件末尾缺少两个“}”。

  1. 公共布尔 onCommand()
  2. 类medicplugin1

jpw 提到的第三个实际上是左括号的问题,因为我认为您想true在 if 子句的末尾返回。

sender.sendMessage( ... ); ---> { <---
    return true;
}

下次考虑使用您的 IDE 代码格式化程序,因为它们很可能会向您显示此类问题。

更远 ...

   if (cmd.getName().equalsIgnoreCase("regen")){ ... }

   return true;

   if (cmd.getName().equalsIgnoreCase("resetfood")){ ... ]

此代码似乎错误.. 因为这将在编译时解决 UnreachableCode 错误。

于 2013-11-03T20:36:31.350 回答
0

你实际上}在最后错过了三 (3) 个。适当的缩进会使这一点变得非常快。

缺少右括号的块是:

if (cmd.getName().equalsIgnoreCase("resetfood"))

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

public class medicplugin1 extends JavaPlugin

于 2013-11-03T20:36:26.880 回答