I'am trying to resolve owner of region so far i have stuck trying to select region this is my 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 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");
}
}
}
}
}
}
And the problem is in this 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 {
// The world has no region support or region data failed to load
}
there is red underline under world and when i hover it, it gives me this: world cannot be resolved to a variable. I can't figure it out why is it happend becouse this is copy-past from WorldGuard API page - http://docs.enginehub.org/manual/worldguard/latest/developer/regions/managers/ Please help me
The code from the WorldGuard API to get a region by name is only an example. Your IDE is complaining because it can't actually find the variable called
world
which you passed to the get() method. You will need to provide your ownworld
object to the container.get(world) method, which in this case could be the player's world in your event listener method. For example:container.get(player.getWorld());
will probably work.