Java Code Examples for com.sk89q.worldguard.protection.managers.RegionManager#getRegion()
The following examples show how to use
com.sk89q.worldguard.protection.managers.RegionManager#getRegion() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Worldguard.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
public ProtectedRegion getRegion(final com.sk89q.worldguard.LocalPlayer player, final Location loc) { RegionManager manager = this.worldguard.getRegionManager(loc.getWorld()); if (manager == null) { if (this.worldguard.getGlobalStateManager().get(loc.getWorld()).useRegions) { System.out.println("Region capability is not enabled for WorldGuard."); } else { System.out.println("WorldGuard is not enabled for that world."); } return null; } final ProtectedRegion global = manager.getRegion("__global__"); if (global != null && isAllowed(player, global)) { return global; } final ApplicableRegionSet regions = manager.getApplicableRegions(loc); for (final ProtectedRegion region : regions) { if (isAllowed(player, region)) { return region; } } return null; }
Example 2
Source File: RegionObjective.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
/** * Return true if location is inside region * * @param loc Location to Check * @return boolean True if in region */ private boolean isInsideRegion(Location loc) { if (loc == null || loc.getWorld() == null) { return false; } WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform(); RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(loc.getWorld())); if (manager == null) { return false; } ProtectedRegion region = manager.getRegion(name); if (region == null) { return false; } return region.contains(BukkitAdapter.asBlockVector(loc)); }
Example 3
Source File: RegionCondition.java From BetonQuest with GNU General Public License v3.0 | 6 votes |
@Override protected Boolean execute(String playerID) { Player player = PlayerConverter.getPlayer(playerID); WorldGuardPlatform worldguardPlatform = WorldGuard.getInstance().getPlatform(); RegionManager manager = worldguardPlatform.getRegionContainer().get(BukkitAdapter.adapt(player.getWorld())); if (manager == null) { return false; } ProtectedRegion region = manager.getRegion(name); ApplicableRegionSet set = manager.getApplicableRegions(BlockVector3.at(player.getLocation().getX(), player.getLocation().getY(), player.getLocation().getZ())); for (ProtectedRegion compare : set) { if (compare.equals(region)) return true; } return false; }
Example 4
Source File: WorldGuard7FAWEHook.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override public void deserialize(final Fields fields) throws StreamCorruptedException, NotSerializableException { final String r = fields.getAndRemoveObject("region", String.class); fields.setFields(this); RegionManager regionManager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)); final ProtectedRegion region = regionManager.getRegion(r); if (region == null) throw new StreamCorruptedException("Invalid region " + r + " in world " + world); this.region = region; }
Example 5
Source File: WorldGuard7FAWEHook.java From Skript with GNU General Public License v3.0 | 5 votes |
@Override @Nullable public Region getRegion_i(final World world, final String name) { RegionManager manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)); final ProtectedRegion r = manager.getRegion(name); if (r != null) return new WorldGuardRegion(world, r); return null; }
Example 6
Source File: WorldGuardHandler.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public static void islandLock(final CommandSender sender, final String islandName) { try { RegionManager regionManager = getRegionManager(uSkyBlock.getInstance().getWorldManager().getWorld()); if (regionManager.hasRegion(islandName + "island")) { ProtectedRegion region = regionManager.getRegion(islandName + "island"); updateLockStatus(region, true); sender.sendMessage(tr("\u00a7eYour island is now locked. Only your party members may enter.")); } else { sender.sendMessage(tr("\u00a74You must be the party leader to lock your island!")); } } catch (Exception ex) { LogUtil.log(Level.SEVERE, "ERROR: Failed to lock " + islandName + "'s Island (" + sender.getName() + ")", ex); } }
Example 7
Source File: WorldGuardHandler.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public static void islandUnlock(final CommandSender sender, final String islandName) { try { RegionManager regionManager = getRegionManager(uSkyBlock.getInstance().getWorldManager().getWorld()); if (regionManager.hasRegion(islandName + "island")) { ProtectedRegion region = regionManager.getRegion(islandName + "island"); updateLockStatus(region, false); sender.sendMessage(tr("\u00a7eYour island is unlocked and anyone may enter, however only you and your party members may build or remove blocks.")); } else { sender.sendMessage(tr("\u00a74You must be the party leader to unlock your island!")); } } catch (Exception ex) { LogUtil.log(Level.SEVERE, "ERROR: Failed to unlock " + islandName + "'s Island (" + sender.getName() + ")", ex); } }
Example 8
Source File: WorldGuard.java From Modern-LWC with MIT License | 4 votes |
@Override public void onAccessRequest(LWCAccessEvent event) { if (event.getAccess() != Permission.Access.NONE) { // Player already has access. return; } // WorldGuard must be running and LWC must be configured to interface // with it. if (worldGuardPlugin == null) { return; } if (!configuration.getBoolean("worldguard.enabled", false)) { return; } if (!configuration .getBoolean("worldguard.allowRegionPermissions", true)) { return; } Protection protection = event.getProtection(); LocalPlayer wgPlayer = worldGuardPlugin.wrapPlayer(event.getPlayer()); for (Permission permission : protection.getPermissions()) { if (permission.getType() != Permission.Type.REGION) { continue; } String regionName = permission.getName(); if (regionName.equalsIgnoreCase("#this")) { // Handle the special value which tells us to not actually look // up a region but // check just the player's WG build permissions on the block. It // may be in multiple // regions or none; we don't care here. That's WorldGuard's // domain. if (!canBuild(event.getPlayer(), protection.getBlock())) { continue; } } else if (regionName.startsWith("#")) { // Silently disallow looking up regions by index, a newer WG // feature. // Iterating through potentially thousands of regions each time // we check a block's // ACL is not a good idea. It would be cleaner to use // regionManager.getRegionExact() // below, but that would break compatibility with older versions // of WG. continue; } else { // Region name specified, go look it up World world; int c = regionName.indexOf(':'); if (c < 0) { // No world specified in ACL. Use the block's world. world = protection.getBlock().getWorld(); } else { // World specified. Partition the string and look up the // world. String worldName = regionName.substring(c + 1); world = event.getLWC().getPlugin().getServer() .getWorld(worldName); regionName = regionName.substring(0, c); } if (world == null) { continue; } RegionManager regionManager = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer().get(BukkitAdapter.adapt(world)); if (regionManager == null) { continue; } ProtectedRegion region = regionManager.getRegion(regionName); if (region == null) { continue; } // Check the region (and its parents) to see if the player is a // member (or an owner). if (!region.isMember(wgPlayer)) { continue; } } // We match the region, so bump up our access level. Whether we get // PLAYER access or // ADMIN access depends solely on the LWC permission entry. (I.e., // WG owner does not // imply LWC admin.) if (permission.getAccess().ordinal() > event.getAccess().ordinal()) { event.setAccess(permission.getAccess()); if (event.getAccess().ordinal() >= Permission.Access.ADMIN .ordinal()) { return; } // else we just have PLAYER access. Keep looking; maybe we match // another region // that grants us ADMIN. } } }