Minecraft 插件 WorldEdit 获取区域

Minecraft plugin WorldEdit get region

我正在尝试解析区域的所有者,到目前为止我一直在尝试 select 区域这是我的代码:

package pl.maccraft.regs;


import java.util.logging.Logger;

import net.milkbowl.vault.economy.Economy;

import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerInteractEvent;

import com.sk89q.worldguard.bukkit.RegionContainer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;

import org.bukkit.plugin.Plugin;



public final class egs extends JavaPlugin implements Listener {
    private static final Logger log = Logger.getLogger("Minecraft");
    public static Economy econ = null;
    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
        getWorldGuard();
        if (!setupEconomy() ) {
            log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
            getServer().getPluginManager().disablePlugin(this);
            return;
        }
    }
    private WorldGuardPlugin getWorldGuard() {
        Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");

        // WorldGuard may not be loaded
        if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
            return null; // Maybe you want throw an exception instead
        }

        return (WorldGuardPlugin) plugin;

    }
    private boolean setupEconomy() {
        if (getServer().getPluginManager().getPlugin("Vault") == null) {
            return false;
        }
        RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
        if (rsp == null) {
            return false;
        }
        econ = rsp.getProvider();
        return econ != null;
    }
    @EventHandler
    public void playerInteract(PlayerInteractEvent event){
        Player player = event.getPlayer();
        if(event.getAction() == org.bukkit.event.block.Action.LEFT_CLICK_BLOCK){
        Block b = event.getClickedBlock();
        if (b.getType() == (Material.SIGN) || b.getType() == (Material.SIGN_POST) || b.getType() == (Material.WALL_SIGN)){
            Sign sign = (Sign) b.getState();
            if (sign.getLine(0).equals("[sell]")){
                event.setCancelled(true);
                RegionContainer container = getWorldGuard().getRegionContainer();
                RegionManager regions = container.get(world);
                if (regions != null) {
                    ProtectedRegion region = regions.getRegion("spawn");
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "say stan:" + region);
                } else {
                    // The world has no region support or region data failed to load
                }
                    sign.setLine(0, ChatColor.DARK_RED + "[sprzedam]");
                    sign.setLine(1, player.getName());
                    sign.setLine(3, ChatColor.DARK_RED + sign.getLine(2));
                    sign.update(true);  

            }
        }
        }
        if(event.getAction() == org.bukkit.event.block.Action.RIGHT_CLICK_BLOCK){
            Block b = event.getClickedBlock();
            if (b.getType() == (Material.SIGN) || b.getType() == (Material.SIGN_POST) || b.getType() == (Material.WALL_SIGN)){
                Sign sign = (Sign) b.getState();
                if (sign.getLine(0).equals(ChatColor.DARK_RED + "[sprzedam]")){
                    if (event.getPlayer().getName() != sign.getLine(1)){
                        sign.setLine(0, ChatColor.DARK_RED + "[sprzedane]");
                        sign.setLine(2, event.getPlayer().getName());
                        sign.update(true);
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "say stan:" + econ.getBalance(player));
                    }else{
                        Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "say nie możesz kupić własnej działki");
                    }
                }
            }
        }


    }

}

问题出在这部分:

RegionContainer container = getWorldGuard().getRegionContainer();
            RegionManager regions = container.get(world);
            if (regions != null) {
                ProtectedRegion region = regions.getRegion("spawn");
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "say stan:" + region);
            } else {
                // The world has no region support or region data failed to load
            }

world 下方有红色下划线,当我将其悬停时,它会提示:world 无法解析为变量。我不明白为什么会这样,因为这是从 WorldGuard API 页面复制过来的 - http://docs.enginehub.org/manual/worldguard/latest/developer/regions/managers/ 请帮助我

WorldGuard API 中通过名称获取区域的代码只是一个示例。您的 IDE 正在抱怨,因为它实际上找不到您传递给 get() 方法的名为 world 的变量。您需要向 container.get(world) 方法提供您自己的 world 对象,在本例中,它可能是事件侦听器方法中玩家的世界。例如:container.get(player.getWorld()); 可能会起作用。