Bukkit插件语法错误:语法错误,插入“}”以完成ClassBody

时间:2013-11-03 20:31:24

标签: java syntax bukkit

这是我的代码。底部的最后一个花括号有错误。这非常烦人,我一直在努力修复它。是不是我有太多的支撑物?我真的很难过。请帮忙。

    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;
    }

2 个答案:

答案 0 :(得分:1)

你错过了两个"}"在文件的末尾。

  1. public boolean onCommand()
  2. class medicplugin1
  3. 第三个,jpw提到的实际上是一个开括号的问题,因为我认为你想在if子句的末尾返回true

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

    下次考虑使用你的IDE代码格式化程序,因为他们最有可能向你展示这样的问题。

    进一步......

       if (cmd.getName().equalsIgnoreCase("regen")){ ... }
    
       return true;
    
       if (cmd.getName().equalsIgnoreCase("resetfood")){ ... ]
    

    这段代码似乎错了..因为这会在编译时解决UnreachableCode错误。

答案 1 :(得分:0)

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

缺少右括号的块是:

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

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

public class medicplugin1 extends JavaPlugin