public void deleteRegion(Player player, String[] args) { if (args.length != 2) { player.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } String id = "icp_" + player.getName() + "_" + args[1]; World world = player.getWorld(); LocalPlayer localPlayer = plugin.wrapPlayer(player); RegionManager mgr = plugin.getGlobalRegionManager().get(world); ProtectedRegion region = mgr.getRegion(id); if (region == null) { player.sendMessage(ChatColor.RED + "Could not find a region by that name."); return; } if (region.isOwner(localPlayer)) { mgr.removeRegion(id); player.sendMessage(ChatColor.YELLOW + "Region " + args[1] + " removed."); try { mgr.save(); } catch (IOException e) { player.sendMessage( ChatColor.RED + "(shouldn't happen) Failed to write regions file: " + e.getMessage()); } } }
public Boolean addPlayer(String name) { Player p = Bukkit.getServer().getPlayer(name); if (p == null) { return false; } if (p.getName().equals(leader)) { return false; } members.add(name); /* Dodanie gracza do cuboidu i configu */ RegionManager regionManager = getRegionManager(world); String prefix = Config.getPrefix(); DefaultDomain dd = regionManager.getRegion(prefix + akronim).getMembers(); dd.addPlayer(name); regionManager.getRegion(prefix + akronim).setMembers(dd); try { regionManager.save(); } catch (ProtectionDatabaseException ex) { Logger.getLogger(Wioska.class.getName()).log(Level.SEVERE, null, ex); } saveWioska(); return true; }
@Override public boolean execute(CommandSender executor, String identifier, String[] args) { if (!(executor instanceof Player)) { Messaging.send(executor, "Can not create sub regions through console!"); return false; } String redefineRegion = args[0]; Player player = (Player) executor; Citizen citizen = getCitizen(player); // Get and validate the region ID String id = validateRegionId(redefineRegion, false); // Can't replace regions with this command RegionManager regionManager = wgp.getGlobalRegionManager().get(player.getWorld()); if (!regionManager.hasRegion(id)) { Messaging.send( executor, "That region doesn't exist, use " + "/town region create <childRegion> <parentRegion>" + id); return true; } ChildRegion foundRegion = null; if (manager.get(redefineRegion) != null && manager.get(redefineRegion).getName().equalsIgnoreCase(redefineRegion)) { Messaging.send(executor, "You can not redefine your Town region!"); return true; } else { ChildRegion temp = plugin.getWorldGuardManager().getChildRegion(regionManager.getRegion(redefineRegion)); if (temp != null && temp.getParent() instanceof Town) foundRegion = temp; } Town town = citizen.getTown(); if (foundRegion != null && foundRegion.getParent() instanceof Town) { // Means we found a child region belonging to a Town if (!foundRegion.getParent().equals(town)) { town = (Town) foundRegion.getParent(); } } else { Messaging.send(executor, "The region you want to redefine isn't part of a Town!"); return true; } if (!manager.getRegionManager().checkOwner(player, foundRegion)) { Messaging.send( executor, "You aren't a Region Owner! only Region Owners or Town Mayors can redefine regions!"); return true; } ChildRegion newRegion = manager.getRegionManager().redefineChildRegion(getSelection(player), foundRegion, town); // Delete old region manager.getRegionManager().addChildRegion(town, newRegion); plugin.getStorageManager().getStorage().saveCitizenGroup(town, false); plugin.getStorageManager().getStorage().saveManagerData(manager); Messaging.send(executor, "You have successfully redefined the region: " + id); return true; }
/** * Load region information for a world. * * @param world */ public void load(World world) { String name = world.getName(); File file = getPath(name); try { // Create a manager RegionManager manager = new FlatRegionManager(new CSVDatabase(file)); managers.put(name, manager); manager.load(); logger.warning( "WorldGuard: " + manager.getRegions().size() + " " + " regions loaded for '" + name + "'"); // Store the last modification date so we can track changes lastModified.put(name, file.lastModified()); } catch (FileNotFoundException e) { } catch (IOException e) { logger.warning( "WorldGuard: Failed to load regions from file " + file.getAbsolutePath() + " : " + e.getMessage()); } }
protected static boolean existArea(String area, World w) { RegionManager rg = RegionTeleport.getWorldGuard().getRegionManager(w); if (rg.getRegion(area) != null) { return true; } else { return false; } }
public void deleteCuboid() { WioskiFile wioskiFile = plugin.getWioskiFile(); WorldGuardPlugin wgp = WorldGuard.getWorldGuard(plugin); World w = Bukkit.getServer().getWorld(world); RegionManager regionManager = wgp.getRegionManager(w); String prefix = Config.getPrefix(); regionManager.removeRegion(prefix + getAkronim()); }
/* * Called when a block is destroyed from burning. */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockBurn(BlockBurnEvent event) { ConfigurationManager cfg = plugin.getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld()); if (cfg.activityHaltToggle) { event.setCancelled(true); return; } if (wcfg.disableFireSpread) { event.setCancelled(true); return; } if (wcfg.fireSpreadDisableToggle) { Block block = event.getBlock(); event.setCancelled(true); checkAndDestroyAround( block.getWorld(), block.getX(), block.getY(), block.getZ(), BlockID.FIRE); return; } if (wcfg.disableFireSpreadBlocks.size() > 0) { Block block = event.getBlock(); if (wcfg.disableFireSpreadBlocks.contains(block.getTypeId())) { event.setCancelled(true); checkAndDestroyAround( block.getWorld(), block.getX(), block.getY(), block.getZ(), BlockID.FIRE); return; } } if (wcfg.isChestProtected(event.getBlock())) { event.setCancelled(true); return; } if (wcfg.useRegions) { Block block = event.getBlock(); int x = block.getX(); int y = block.getY(); int z = block.getZ(); Vector pt = toVector(block); RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld()); ApplicableRegionSet set = mgr.getApplicableRegions(pt); if (!set.allows(DefaultFlag.FIRE_SPREAD)) { checkAndDestroyAround(block.getWorld(), x, y, z, BlockID.FIRE); event.setCancelled(true); return; } } }
/** * Checks to see whether a flag is allowed. * * @param flag * @param loc * @return */ public boolean allows(StateFlag flag, Location loc) { World world = loc.getWorld(); WorldConfiguration worldConfig = config.get(world); if (!worldConfig.useRegions) { return true; } RegionManager mgr = plugin.getGlobalRegionManager().get(world); return mgr.getApplicableRegions(toVector(loc)).allows(flag); }
public static void giveStall(Player player, String zone, String number) { WorldGuardPlugin worldGuard = getWorldGuard(); World world = player.getWorld(); RegionManager regionManager = worldGuard.getRegionManager(world); ProtectedRegion region = regionManager.getRegion("stall_" + zone.toLowerCase() + number); DefaultDomain owners = region.getOwners(); owners.addPlayer(player.getName()); region.setOwners(owners); editPlotSign(player, zone, number, region); }
public void checkRegion(Player sender, String[] args) { if (!sender.hasPermission("iceprotect.buy")) { sender.sendMessage(ChatColor.RED + "You don't have permission!"); return; } if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } String id = "icp__tempregion"; Location loc = sender.getLocation(); BlockVector min = new BlockVector(loc.getX() - 1, loc.getY() - 1, loc.getZ() - 1); BlockVector max = new BlockVector(loc.getX() + 1, loc.getY() + 1, loc.getZ() + 1); ProtectedRegion region = new ProtectedCuboidRegion(id, min, max); RegionManager mgr = plugin.getGlobalRegionManager().get(sender.getWorld()); ApplicableRegionSet regions = mgr.getApplicableRegions(region); ProtectedRegion appReg = null; for (ProtectedRegion r : regions) { if (econ.isRegionForSale(r.getId())) { appReg = r; break; } } if (appReg == null) { sender.sendMessage(ChatColor.RED + "No nearby regions for sale!"); return; } else { double cost = regionsForSale.getDouble("regions." + appReg.getId() + ".price", 0D); if (cost == 0) { sender.sendMessage( ChatColor.RED + "(this shouldn't happen) You can't buy this region. Notify an admin!"); return; } sender.sendMessage( ChatColor.YELLOW + "This region " + appReg.getId() + " is for sale by " + regionsForSale.getString("regions." + appReg.getId() + ".seller")); sender.sendMessage(ChatColor.YELLOW + "And costs $" + cost + "."); } }
/** * Returns true or false. Based on the previous Factions source. * * @param loc * @return */ public static boolean checkForRegionsInChunk(Location currentLocation) { // This is pretty much the exact same as Factions 1.6.x source's method // except it's inside FactionsPlus! World world = currentLocation.getWorld(); Chunk chunk = world.getChunkAt(currentLocation); int minChunkX = chunk.getX() << 4; int minChunkZ = chunk.getZ() << 4; int maxChunkX = minChunkX + 15; int maxChunkZ = minChunkZ + 15; int worldHeight = world.getMaxHeight(); BlockVector minChunk = new BlockVector(minChunkX, 0, minChunkZ); BlockVector maxChunk = new BlockVector(maxChunkX, worldHeight, maxChunkZ); RegionManager regionManager = FP.worldGuardPlugin.getRegionManager(world); ProtectedCuboidRegion region = new ProtectedCuboidRegion("factionsplus_tempoverlapcheck", minChunk, maxChunk); Map<String, ProtectedRegion> allregions = regionManager.getRegions(); List<ProtectedRegion> allregionslist = new ArrayList<ProtectedRegion>(allregions.values()); List<ProtectedRegion> overlaps; boolean foundregions = false; try { overlaps = region.getIntersectingRegions(allregionslist); if (overlaps == null || overlaps.isEmpty()) { foundregions = false; } else { foundregions = true; } } catch (Exception e) { e.printStackTrace(); } region = null; allregionslist = null; overlaps = null; return (foundregions); }
public void allowUser(Player player, String[] args) { if (args.length != 3) { player.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } String id = "icp_" + player.getName() + "_" + args[2]; World world = player.getWorld(); LocalPlayer localPlayer = plugin.wrapPlayer(player); RegionManager mgr = plugin.getGlobalRegionManager().get(world); ProtectedRegion region = mgr.getRegion(id); if (region == null) { player.sendMessage(ChatColor.RED + "Could not find a region by that name."); return; } if (region.isOwner(localPlayer)) { region.getMembers().addPlayer(args[1]); player.sendMessage( ChatColor.GREEN + "Allowed " + ChatColor.RED + args[1] + ChatColor.GREEN + " to region " + ChatColor.RED + args[2] + ChatColor.GREEN + "."); Player targetPlayer = Bukkit.getServer().getPlayerExact(args[1]); if (targetPlayer != null) { targetPlayer.sendMessage( ChatColor.GREEN + player.getName() + " has added you as a member in the " + ChatColor.RED + args[2] + ChatColor.GREEN + " region."); } } else { player.sendMessage(ChatColor.RED + "(shouldn't happen) You don't own the region " + args[2]); } }
public boolean isWGRegion(Block block) { try { if (wg == null) { return false; } RegionManager manager = wg.getRegionManager(block.getWorld()); ApplicableRegionSet regions = manager.getApplicableRegions(block.getLocation()); return regions != null && regions.size() > 0; } catch (Exception ex) { return false; } }
private void createCuboid() throws Exception { RegionManager regionManager = getRegionManager(world); String prefix = Config.getPrefix(); ProtectedCuboidRegion pr = new ProtectedCuboidRegion(prefix + akronim, getPos1(), getPos2()); DefaultDomain dd = new DefaultDomain(); dd.addPlayer(leader); for (String s : members) { dd.addPlayer(s); } pr.setMembers(dd); pr.setFlag(DefaultFlag.USE, State.DENY); regionManager.addRegion(pr); }
@EventHandler public void move(PlayerMoveEvent event) { if (worldGuard == null) return; Player player = event.getPlayer(); if (!regionsVisited.containsKey(player.getUniqueId())) regionsVisited.put(player.getUniqueId(), new ArrayList<>()); RegionContainer container = worldGuard.getWorldGuard().getRegionContainer(); RegionManager manager = container.get(player.getWorld()); if (manager == null) return; ApplicableRegionSet regions = manager.getApplicableRegions(event.getTo()); List<ProtectedRegion> visited = regionsVisited.get(player.getUniqueId()); try { for (ProtectedRegion region : regions.getRegions()) { if (!visited.contains(region)) { // i've never seen this place before in my life... or maybe in 30 seconds visited.add(region); Bukkit.getScheduler() .runTaskLaterAsynchronously( JavaPlugin.getPlugin(Tyrant.class), () -> enter(player, region), 1); } } Bukkit.getScheduler() .runTaskLater( JavaPlugin.getPlugin(Tyrant.class), () -> { for (ProtectedRegion region2 : visited) { if (!regions.getRegions().contains(region2)) { // leaving the tavern visited.remove(region2); Bukkit.getScheduler() .runTaskLaterAsynchronously( JavaPlugin.getPlugin(Tyrant.class), () -> exit(player), 1); } } }, 1); } catch (ConcurrentModificationException e) { e.printStackTrace(); } }
/** * Check if a player has permission to build at a location. * * @param player * @param loc * @return */ public boolean canBuild(Player player, Location loc) { World world = loc.getWorld(); WorldConfiguration worldConfig = config.get(world); if (!worldConfig.useRegions) { return true; } LocalPlayer localPlayer = plugin.wrapPlayer(player); if (!hasBypass(player, world)) { RegionManager mgr = get(world); if (!mgr.getApplicableRegions(BukkitUtil.toVector(loc)).canBuild(localPlayer)) { return false; } } return true; }
/** * Called when a block is destroyed from burning * * @param event Relevant event details */ @Override public void onBlockBurn(BlockBurnEvent event) { if (event.isCancelled()) { return; } ConfigurationManager cfg = plugin.getGlobalConfiguration(); WorldConfiguration wcfg = cfg.get(event.getBlock().getWorld()); if (wcfg.disableFireSpread) { event.setCancelled(true); return; } if (wcfg.fireSpreadDisableToggle) { event.setCancelled(true); return; } if (wcfg.disableFireSpreadBlocks.size() > 0) { Block block = event.getBlock(); if (wcfg.disableFireSpreadBlocks.contains(block.getTypeId())) { event.setCancelled(true); return; } } if (wcfg.useRegions) { Block block = event.getBlock(); Vector pt = toVector(block); RegionManager mgr = plugin.getGlobalRegionManager().get(block.getWorld()); ApplicableRegionSet set = mgr.getApplicableRegions(pt); if (!set.allows(DefaultFlag.FIRE_SPREAD)) { event.setCancelled(true); return; } } }
public Boolean removePlayer(String name) { if (!members.contains(name)) { return false; } members.remove(name); /* Usunięcie gracza z cuboidu i configu */ RegionManager regionManager = getRegionManager(world); String prefix = Config.getPrefix(); DefaultDomain dd = regionManager.getRegion(prefix + akronim).getMembers(); dd.removePlayer(name); regionManager.getRegion(prefix + akronim).setMembers(dd); try { regionManager.save(); } catch (ProtectionDatabaseException ex) { Logger.getLogger(Wioska.class.getName()).log(Level.SEVERE, null, ex); } saveWioska(); return true; }
public void listRegions(Player player, String[] args) { World world = player.getWorld(); RegionManager mgr = plugin.getGlobalRegionManager().get(world); StringBuilder regions = new StringBuilder(); Set<String> keySet = mgr.getRegions().keySet(); for (String regionName : keySet) { if (regionName.startsWith("icp_" + player.getName().toLowerCase() + "_")) { regions.append( regionName.replaceFirst("icp_" + player.getName().toLowerCase() + "_", "") + ", "); } } if (regions.length() == 0) { player.sendMessage(ChatColor.RED + "You don't have regions in this world."); } else { player.sendMessage(ChatColor.AQUA + "Your regions:"); regions.deleteCharAt(regions.length() - 2); player.sendMessage(ChatColor.AQUA + regions.toString()); } }
public void buyRegion(Player sender, String[] args) { if (!sender.hasPermission("iceprotect.buy")) { sender.sendMessage(ChatColor.RED + "You don't have permission!"); return; } if (args.length != 1) { sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } String id = "icp__tempregion"; Location loc = sender.getLocation(); BlockVector min = new BlockVector(loc.getX() - 1, loc.getY() - 1, loc.getZ() - 1); BlockVector max = new BlockVector(loc.getX() + 1, loc.getY() + 1, loc.getZ() + 1); ProtectedRegion region = new ProtectedCuboidRegion(id, min, max); RegionManager mgr = plugin.getGlobalRegionManager().get(sender.getWorld()); ApplicableRegionSet regions = mgr.getApplicableRegions(region); ProtectedRegion appReg = null; for (ProtectedRegion r : regions) { if (econ.isRegionForSale(r.getId())) { appReg = r; break; } } if (appReg == null) { sender.sendMessage(ChatColor.RED + "No nearby regions for sale!"); return; } econ.buyRegion(appReg, sender, mgr); }
@Test public void testExit() throws Exception { ApplicableRegionSet appl; appl = manager.getApplicableRegions(inExit); // ProtectedRegion rg = appl.iterator().next(); // System.out.println("rg " + rg.getId()); // System.out.println("own " + rg.getOwners().toGroupsString()); // System.out.println("flag " + appl.getFlag(DefaultFlag.EXIT)); // System.out.println("grp " + appl.getFlag(DefaultFlag.EXIT.getRegionGroupFlag())); // System.out.println("==="); assertTrue("Allowed Exit", appl.allows(DefaultFlag.EXIT, builder_player)); assertFalse("Forbidden Exit", appl.allows(DefaultFlag.EXIT, vip_player)); }
public void denyUser(Player player, String[] args) { if (args.length != 3) { player.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } String id = "icp_" + player.getName() + "_" + args[2]; World world = player.getWorld(); LocalPlayer localPlayer = plugin.wrapPlayer(player); RegionManager mgr = plugin.getGlobalRegionManager().get(world); ProtectedRegion region = mgr.getRegion(id); if (region == null) { player.sendMessage(ChatColor.RED + "Could not find a region by that name."); return; } if (region.isOwner(localPlayer)) { region.getMembers().removePlayer(args[1]); player.sendMessage( ChatColor.GREEN + "Removed player " + ChatColor.RED + args[1] + ChatColor.GREEN + " from region " + ChatColor.RED + args[2] + ChatColor.GREEN + "."); } else { player.sendMessage(ChatColor.RED + "(shouldn't happen) You don't own the region " + args[2]); } }
public void sellRegion(Player sender, String[] args) { if (!sender.hasPermission("iceprotect.sell")) { sender.sendMessage(ChatColor.RED + "You don't have permission!"); return; } if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Something went wrong!"); sender.sendMessage(ChatColor.RED + "Usage: /psell <region_name> <price>"); return; } if (!ProtectedRegion.isValidId(args[0])) { sender.sendMessage(ChatColor.RED + "Invalid region name specified!"); return; } RegionManager mgr = plugin.getGlobalRegionManager().get(sender.getLocation().getWorld()); if (!mgr.hasRegion(args[0])) { sender.sendMessage(ChatColor.RED + "Nonexistent region name specified!"); return; } regionsForSale.setProperty("regions." + args[0] + ".price", Double.parseDouble(args[1])); regionsForSale.setProperty("regions." + args[0] + ".seller", sender.getName()); regionsForSale.save(); sender.sendMessage( ChatColor.GREEN + "You successfully added " + ChatColor.YELLOW + args[0] + ChatColor.GREEN + " to the sell list."); }
void setUpExitRegion() throws Exception { DefaultDomain domain = new DefaultDomain(); domain.addGroup(BUILDER_GROUP); ProtectedRegion region = new ProtectedCuboidRegion( EXIT_ID, new BlockVector(-1, 0, -1), new BlockVector(-10, 255, -10)); region.setOwners(domain); manager.addRegion(region); entryRegion = region; // same as above entryRegion.setFlag(DefaultFlag.EXIT, StateFlag.State.DENY); entryRegion.setFlag(DefaultFlag.EXIT.getRegionGroupFlag(), RegionGroup.NON_OWNERS); }
void setUpEntryRegion() { DefaultDomain domain = new DefaultDomain(); domain.addGroup(VIP_GROUP); ProtectedRegion region = new ProtectedCuboidRegion(ENTRY_ID, new BlockVector(1, 0, 1), new BlockVector(10, 255, 10)); region.setMembers(domain); manager.addRegion(region); entryRegion = region; // this is the way it's supposed to work // whatever the group flag is set to is the group that the flag APPLIES to // in this case, non members (esskay) should be DENIED entry entryRegion.setFlag(DefaultFlag.ENTRY, StateFlag.State.DENY); entryRegion.setFlag(DefaultFlag.ENTRY.getRegionGroupFlag(), RegionGroup.NON_MEMBERS); }
/* * Called when a block gets ignited. */ @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onBlockIgnite(BlockIgniteEvent event) { IgniteCause cause = event.getCause(); Block block = event.getBlock(); World world = block.getWorld(); ConfigurationManager cfg = plugin.getGlobalStateManager(); WorldConfiguration wcfg = cfg.get(world); if (cfg.activityHaltToggle) { event.setCancelled(true); return; } boolean isFireSpread = cause == IgniteCause.SPREAD; if (wcfg.preventLightningFire && cause == IgniteCause.LIGHTNING) { event.setCancelled(true); return; } if (wcfg.preventLavaFire && cause == IgniteCause.LAVA) { event.setCancelled(true); return; } if (wcfg.disableFireSpread && isFireSpread) { event.setCancelled(true); return; } if (wcfg.blockLighter && (cause == IgniteCause.FLINT_AND_STEEL || cause == IgniteCause.FIREBALL) && event.getPlayer() != null && !plugin.hasPermission(event.getPlayer(), "worldguard.override.lighter")) { event.setCancelled(true); return; } if (wcfg.fireSpreadDisableToggle && isFireSpread) { event.setCancelled(true); return; } if (wcfg.disableFireSpreadBlocks.size() > 0 && isFireSpread) { int x = block.getX(); int y = block.getY(); int z = block.getZ(); if (wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y - 1, z)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x + 1, y, z)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x - 1, y, z)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y, z - 1)) || wcfg.disableFireSpreadBlocks.contains(world.getBlockTypeIdAt(x, y, z + 1))) { event.setCancelled(true); return; } } if (wcfg.useRegions) { Vector pt = toVector(block); Player player = event.getPlayer(); RegionManager mgr = plugin.getGlobalRegionManager().get(world); ApplicableRegionSet set = mgr.getApplicableRegions(pt); if (player != null && !plugin.getGlobalRegionManager().hasBypass(player, world)) { LocalPlayer localPlayer = plugin.wrapPlayer(player); // this is preliminarily handled in the player listener under handleBlockRightClick // why it's handled here too, no one knows if (cause == IgniteCause.FLINT_AND_STEEL || cause == IgniteCause.FIREBALL) { if (!set.allows(DefaultFlag.LIGHTER) && !set.canBuild(localPlayer) && !plugin.hasPermission(player, "worldguard.override.lighter")) { event.setCancelled(true); return; } } } if (wcfg.highFreqFlags && isFireSpread && !set.allows(DefaultFlag.FIRE_SPREAD)) { event.setCancelled(true); return; } if (wcfg.highFreqFlags && cause == IgniteCause.LAVA && !set.allows(DefaultFlag.LAVA_FIRE)) { event.setCancelled(true); return; } if (cause == IgniteCause.FIREBALL && event.getPlayer() == null) { // wtf bukkit, FIREBALL is supposed to be reserved to players if (!set.allows(DefaultFlag.GHAST_FIREBALL)) { event.setCancelled(true); return; } } if (cause == IgniteCause.LIGHTNING && !set.allows(DefaultFlag.LIGHTNING)) { event.setCancelled(true); return; } } }
public void setRegion(Player sender, String[] args) { if (args.length != 2) { sender.sendMessage(ChatColor.RED + "Wrong usage. /pr help"); return; } LocalPlayer wgPlayer = plugin.wrapPlayer(sender); String id = "icp_" + sender.getName() + "_" + args[1]; if (!ProtectedRegion.isValidId(id)) { sender.sendMessage(ChatColor.RED + "Invalid region name specified!"); return; } Selection sel = worldEdit.getSelection(sender); if (sel == null) { sender.sendMessage(ChatColor.RED + "Select a region with a wooden axe first."); return; } RegionManager mgr = plugin.getGlobalRegionManager().get(sel.getWorld()); if (mgr.hasRegion(id)) { sender.sendMessage( ChatColor.RED + "That region name is already taken. Please choose a new name."); return; } int regionCount = mgr.getRegionCountOfPlayer(wgPlayer); if (regionCount > Economy.maxDonatorAllowedRegions && !sender.isOp() && sender.hasPermission("iceprotect.freeprotect")) { sender.sendMessage( ChatColor.RED + "You have reached the maximum allowed regions per user (" + Economy.maxDonatorAllowedRegions + ")."); sender.sendMessage(ChatColor.RED + "Please contact an admin."); return; } ProtectedRegion region = null; if (sel instanceof Polygonal2DSelection) { Polygonal2DSelection polySel = (Polygonal2DSelection) sel; int minY = polySel.getNativeMinimumPoint().getBlockY(); int maxY = polySel.getNativeMaximumPoint().getBlockY(); region = new ProtectedPolygonalRegion(id, polySel.getNativePoints(), minY, maxY); } else if (sel instanceof CuboidSelection) { BlockVector min = sel.getNativeMinimumPoint().toBlockVector(); BlockVector max = sel.getNativeMaximumPoint().toBlockVector(); region = new ProtectedCuboidRegion(id, min, max); } else { sender.sendMessage( ChatColor.RED + "(shouldn't happen) Something went wrong. The type of region selected is unsupported!"); return; } String[] names = new String[1]; names[0] = sender.getName(); region.setOwners(RegionUtil.parseDomainString(names, 0)); ApplicableRegionSet regions = mgr.getApplicableRegions(region); if (!regions.isOwnerOfAll(wgPlayer)) { sender.sendMessage(ChatColor.RED + "That region overlaps with another one not owned by you!"); return; } double cost = (int) Math.ceil(econ.getCost(region.volume())); if (cost > Economy.maxDonatorAllowedCost && sender.hasPermission("iceprotect.freeprotect")) { sender.sendMessage( ChatColor.RED + "You have exceeded the maximum allowed price for this region!"); sender.sendMessage( ChatColor.RED + "Cost: " + ChatColor.GRAY + "$" + cost + ChatColor.RED + ", " + ChatColor.GRAY + "$" + Economy.maxDonatorAllowedCost + " allowed."); return; } if (!sender.hasPermission("iceprotect.freeprotect") && !econ.chargePlayer(sender, cost)) { sender.sendMessage(ChatColor.RED + "You don't have enough money! $" + cost + " needed."); return; } mgr.addRegion(region); try { mgr.save(); sender.sendMessage( ChatColor.YELLOW + "Region saved as " + args[1] + ". " + (sender.hasPermission("iceprotect.freeprotect") ? "" : "Cost: $" + cost + ".")); } catch (IOException e) { sender.sendMessage( ChatColor.RED + "(shouldn't happen) Failed to write regions file: " + e.getMessage()); e.printStackTrace(); return; } }
protected static boolean inAnyArea(Player sender) { RegionManager rm = RegionTeleport.getWorldGuard().getRegionManager(sender.getWorld()); ApplicableRegionSet set = rm.getApplicableRegions(sender.getLocation()); return set.size() > 0; }
public void setFlags(Player sender, String[] args) { Player player = null; try { player = plugin.checkPlayer(sender); } catch (CommandException e1) { e1.printStackTrace(); return; } World world = player.getWorld(); LocalPlayer localPlayer = plugin.wrapPlayer(player); String value = null; if (args.length == 4) { value = args[3]; } else if (args.length == 3) { // } else { player.sendMessage(ChatColor.RED + "Wrong usage! /pr help"); return; } String id = "icp_" + player.getName() + "_" + args[1]; String flagName = args[2]; if (!(flagName.equals("use") || flagName.equals("chest-access") || flagName.equals("snow-fall") || flagName.equals("snow-melt") || flagName.equals("ice-form") || flagName.equals("ice-melt"))) { player.sendMessage(ChatColor.RED + "Unsupported flag! /pr help flags"); return; } RegionManager mgr = plugin.getGlobalRegionManager().get(world); ProtectedRegion region = mgr.getRegion(id); if (region == null) { player.sendMessage(ChatColor.RED + "Could not find a region by that name."); return; } Flag<?> foundFlag = null; for (Flag<?> flag : DefaultFlag.getFlags()) { if (flag.getName().replace("-", "").equalsIgnoreCase(flagName.replace("-", ""))) { foundFlag = flag; break; } } if (foundFlag == null) { StringBuilder list = new StringBuilder(); for (Flag<?> flag : DefaultFlag.getFlags()) { if (list.length() > 0) { list.append(", "); } if (!region.isOwner(localPlayer)) { continue; } list.append(flag.getName()); } player.sendMessage(ChatColor.RED + "Unknown flag specified: " + flagName); player.sendMessage(ChatColor.RED + "Available flags: " + list); return; } if (region.isOwner(localPlayer)) { if (value != null) { try { setFlag(region, foundFlag, sender, value); } catch (InvalidFlagFormat e) { player.sendMessage(ChatColor.RED + e.getMessage()); return; } sender.sendMessage( ChatColor.YELLOW + "Region flag " + ChatColor.GREEN + foundFlag.getName() + ChatColor.YELLOW + " set."); } else { region.setFlag(foundFlag, null); sender.sendMessage( ChatColor.YELLOW + "Region flag " + ChatColor.GREEN + foundFlag.getName() + ChatColor.YELLOW + " cleared."); } } else { sender.sendMessage(ChatColor.RED + "(shouldn't happen) You don't own this region!"); return; } try { mgr.save(); } catch (IOException e) { player.sendMessage(ChatColor.RED + "Failed to write regions file: " + e.getMessage()); } }
protected static String getAreaName(Player sender) { RegionManager rm = RegionTeleport.getWorldGuard().getRegionManager(sender.getWorld()); ApplicableRegionSet set = rm.getApplicableRegions(sender.getLocation()); String id = set.iterator().next().getId(); return id; }