Question

I tried myself on a bukkit plugin. I started with a little heal plugin, but i got some syntax errors here, would be awesome if you guys can help me with that, and explain it to me! thanks :)

Im getting this error on the last line:

Multiple markers at this line - Syntax error, insert "}" to complete MethodBody - Syntax error, insert "else Statement" to complete BlockStatements

package P1;

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

public class ultimateHeal extends JavaPlugin {

@Override
public void onEnable() {

    System.out.println("uHeal by xGumBax activated!");
}

@Override
public void onDisable() {

    System.out.println("uHeal by xGumBax deactivated!");
}

@SuppressWarnings("deprecation")
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if(cmd.getName().equalsIgnoreCase("heal")) {
    if(!(sender instanceof Player)) {

        System.out.println("Dieser Befehl ist nur für Spieler!");
        return true;

    }
    Player p = (Player) sender;
    if(args.length == 0) {
        if(p.hasPermission("uheal.heal.self")) {
            p.setHealth(20);
            p.setFoodLevel(40);
            p.sendMessage(ChatColor.DARK_RED + "[" + getDescription().getName() + "]" + ChatColor.GRAY + " Deine Lebensanzahl wurde aufgefüllt.");
            p.playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
            return true;
        }
        else {
            p.sendMessage(ChatColor.DARK_RED + "[" + getDescription().getName() + "]" + ChatColor.GRAY + " Du hast keine Rechte um diesen Befehl auszuführen!");
            return true;
        }



    }
    else if(args.length == 1) {
        if(p.hasPermission("uheal.heal.others")) {
        Player target = this.getServer().getPlayer(args[0]);
        target.setHealth(20);
        p.sendMessage(ChatColor.DARK_RED + "[" + getDescription().getName() + "]" + ChatColor.GRAY + " Spieler " + args[0] + " wurde geheilt!");
        target.playEffect(target.getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
        target.playEffect(target.getLocation(), Effect.POTION_BREAK, 1);
        target.sendMessage(ChatColor.DARK_RED + "[" + getDescription().getName() + "]" + ChatColor.GRAY + " Du wurdest geheilt!");  
    } else {
        p.sendMessage(ChatColor.DARK_RED + "[" + getDescription().getName() + "]" + ChatColor.GRAY + " Du hast keine Rechte um diesen Befehl auszuführen!");
    }

    return false;
}















} 
Was it helpful?

Solution

It looks like you have mis-matching brackets in your onCommand method.

The bracket at the end of your code finishes one of the if statements, but you do not have a bracket that finishes the method, or one that finishes the class.

If you add another two brackets at the end of your code, this problem should disappear. I'd encourage you to use your IDE or editor to help you to check that the brackets match correctly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top