java - Minecraft plugin WorldEdit get region -
i'am trying resolve owner of region far have stuck trying select region code:
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 no vault dependency found!", getdescription().getname())); getserver().getpluginmanager().disableplugin(this); return; } } private worldguardplugin getworldguard() { plugin plugin = getserver().getpluginmanager().getplugin("worldguard"); // worldguard may not loaded if (plugin == null || !(plugin instanceof worldguardplugin)) { return null; // maybe want throw 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 { // world has no region support or region data failed 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"); } } } } } }
and problem in part:
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 { // world has no region support or region data failed load }
there red underline under world , when hover it, gives me this: world cannot resolved variable. can't figure out why happend becouse copy-past worldguard api page - http://docs.enginehub.org/manual/worldguard/latest/developer/regions/managers/ please me
the code worldguard api region name example. ide complaining because can't find variable called world
passed get() method. need provide own world
object container.get(world) method, in case player's world in event listener method. example: container.get(player.getworld());
work.
Comments
Post a Comment