有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

令牌“}”上的java语法错误,{应为

这个问题一直存在。我无法移除它。请帮忙! 我试过很多不同的方法,但都不管用

package me.swoq;

import org.bukkit.command.Command;

import org.bukkit.command.CommandSender;
import java.util.Random;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Material;


public class RTPPlus extends JavaPlugin {

    public Permission playerPermission = new Permission("rtp.teleport");

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

    if (cmd.getName().equalsIgnoreCase("rtp") && sender instanceof Player) {
        Player player = (Player) sender;                
        Location originalLocation = player.getLocation();
        Random random = new Random();

        int x = random.nextInt(1000) + 1;
        int y = 70;
        int z = random.nextInt(1000) + 1;

        boolean isOnLand = false;

        while (isOnLand == false) {

        Location teleportLocation = new Location(player.getWorld(), x, y, z);

        if (teleportLocation.getBlock().getType() != Material.AIR) {
             isOnLand = true;



        player.teleport(teleportLocation);

        player.sendMessage(ChatColor.GREEN + "You have been teleported " + (int)teleportLocation.distance(originalLocation) + " blocks away!");




        }

        return true;

        }

    } 
    return false;       
    }
    return false;
    }
}
}

共 (1) 个答案

  1. # 1 楼答案

    查看最后的2return false语句,检查方法的作用域

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        //method content
        }
        return false;       
    }
    return false;
    }
    

    在关闭该方法的大括号后,还有一条return语句。请格式化你的代码,然后你就会看到出了什么问题

    移除最后一个return false并关闭大括号("}")