public Map<String, ProtectedRegion> getRegions() { HashMap<String, ProtectedRegion> ret = new HashMap<String, ProtectedRegion>(); ret.putAll(this.cRegions); ret.putAll(this.pRegions); for (Map.Entry<String, ProtectedRegion> entry : ret.entrySet()) { ProtectedRegion region = entry.getValue(); String parentId = region.getParentId(); if (parentId != null) { try { region.setParent(ret.get(parentId)); } catch (CircularInheritanceException ex) { } } else { try { region.setParent(null); } catch (CircularInheritanceException ex) { } } if (region.getOwners() == null) { region.setOwners(new DefaultDomain()); } else if (region.getMembers() == null) { region.setMembers(new DefaultDomain()); } } return ret; }
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); }
@Override public int getRegionCountOfPlayer(LocalPlayer player) { int count = 0; for (ProtectedRegion region : regions.values()) { if (region.getOwners().contains(player)) { count++; } } return count; }
/** * Copy attributes from another region. * * @param other the other region */ public void copyFrom(ProtectedRegion other) { checkNotNull(other); setMembers(other.getMembers()); setOwners(other.getOwners()); setFlags(other.getFlags()); setPriority(other.getPriority()); try { setParent(other.getParent()); } catch (CircularInheritanceException ignore) { // This should not be thrown } }
/** * Checks whether a player is a member OR OWNER of the region or any of its parents. * * @param player player to check * @return whether an owner or member */ public boolean isMember(LocalPlayer player) { if (owners.contains(player) || members.contains(player)) { return true; } ProtectedRegion curParent = getParent(); while (curParent != null) { if (curParent.getOwners().contains(player) || curParent.getMembers().contains(player)) { return true; } curParent = curParent.getParent(); } return false; }
/** * Checks whether a player is an owner of region or any of its parents. * * @param playerName player name to check * @return whether an owner * @deprecated Names are deprecated */ @Deprecated public boolean isOwner(String playerName) { checkNotNull(playerName); if (owners.contains(playerName)) { return true; } ProtectedRegion curParent = getParent(); while (curParent != null) { if (curParent.getOwners().contains(playerName)) { return true; } curParent = curParent.getParent(); } return false; }
@Override public boolean overlapsUnownedRegion(ProtectedRegion checkRegion, LocalPlayer player) { List<ProtectedRegion> appRegions = new ArrayList<ProtectedRegion>(); for (ProtectedRegion other : regions.values()) { if (other.getOwners().contains(player)) { continue; } appRegions.add(other); } List<ProtectedRegion> intersectRegions; try { intersectRegions = checkRegion.getIntersectingRegions(appRegions); } catch (UnsupportedIntersectionException e) { intersectRegions = new ArrayList<ProtectedRegion>(); } return intersectRegions.size() > 0; }
public void addTerritorytoTown(String territName) { if (localSender.isConsole()) { localSender.notifyConsoleNotSupported(); return; } boolean autoActive = !cmd.hasFlag(ECommand.DISABLE_AUTOACTIVE); boolean admin = cmd.hasFlag(ECommand.ADMIN); boolean adminAllowed = localSender.hasExternalPermissions(Perms.ADMIN.toString()); if (!adminAllowed && admin) { localSender.sendMessage( ChatColor.DARK_RED + "You're not permitted to run this command with administrative priviliges!"); return; } if (!(MCTConfig.MAYORS_CAN_BUY_TERRITORIES.getBoolean() || adminAllowed)) { localSender.sendMessage( ChatColor.BLUE + "Mayors are not allowed to add territories and you're not an admin."); return; } Town t = localSender.getActiveTown(); if (t == null) { localSender.notifyActiveTownNotSet(); return; } if ((t.getSize() < MCTConfig.MIN_NUM_PLAYERS_TO_BUY_TERRITORY.getInt()) && !admin) { localSender.sendMessage( ERR + "You don't have enough people in your town to buy territories yet."); localSender.sendMessage( ERR + "You have " + t.getSize() + " people, but you need a total of " + MCTConfig.MIN_NUM_PLAYERS_TO_BUY_TERRITORY.getInt() + "!"); return; } territName = MCTownsRegion.formatRegionName(t, TownLevel.TERRITORY, territName); World w = localSender.getPlayer().getWorld(); if (w == null) { localSender.sendMessage( ERR + "You are in an invalid World. (Player::getWorld() returned null)"); return; } ProtectedRegion region = this.getSelectedRegion(territName); if (region == null) { localSender.sendMessage(ERR + "No region selected!"); return; } int max = MCTConfig.TERRITORY_XZ_SIZE_LIMIT.getInt(), cur = WGUtils.getNumXZBlocksInRegion(region); if (cur > max && !localSender.hasExternalPermissions(Perms.ADMIN.toString())) { localSender.sendMessageF( "%sYou're not allowed to make a territory that big. (Current: %s, Limit: %s)", ERR, cur, max); return; } BigDecimal colPrice = new BigDecimal(MCTConfig.PRICE_PER_XZ_BLOCK.getString()); // charge the player if they're not running this as an admin and buyable territories is enabled // and the price is more than 0 if (!admin && colPrice.compareTo(BigDecimal.ZERO) > 0) { BigDecimal price = colPrice.multiply(new BigDecimal(WGUtils.getNumXZBlocksInRegion(region))); if (t.getBank().getCurrencyBalance().compareTo(price) < 0) { // If they can't afford it... localSender.sendMessage( ERR + "There is not enough money in your " + INFO + "town's bank account" + ERR + " to buy a region that large."); localSender.sendMessage(ERR + "Total Price: " + price); localSender.sendMessage( INFO + "Add money to your town's bank with: /town bank deposit currency <amount>"); return; } // otherwise... t.getBank().withdrawCurrency(price); localSender.sendMessage( ChatColor.GREEN + "Purchase success! Total price was: " + price.toString()); } try { townManager.addTerritory(territName, w, region, t); } catch (TownManager.InvalidWorldGuardRegionNameException | TownManager.RegionAlreadyExistsException ex) { localSender.sendMessage(ERR + ex.getLocalizedMessage()); return; } region.getOwners().addPlayer(UUIDs.getNameForUUID(t.getMayor())); for (String assistantName : t.getAssistantNames()) region.getOwners().addPlayer(assistantName); localSender.sendMessage(SUCC + "Territory added."); if (autoActive) { localSender.setActiveTerritory(townManager.getTerritory(territName)); localSender.sendMessage( ChatColor.LIGHT_PURPLE + "Active territory set to newly created territory."); } }
protected static void claim(String regionname, CommandSender sender) throws CommandException { Player player = WGExtender.getInstance().getWorldGuard().checkPlayer(sender); LocalPlayer localPlayer = WGExtender.getInstance().getWorldGuard().wrapPlayer(player); RegionPermissionModel permModel = getPermissionModel(sender); if (!permModel.mayClaim()) { throw new CommandPermissionsException(); } String id = checkRegionId(regionname, false); RegionManager manager = checkRegionManager(WGExtender.getInstance().getWorldGuard(), player.getWorld()); checkRegionDoesNotExist(manager, id, false); ProtectedRegion region = checkRegionFromSelection(player, id); WorldConfiguration wcfg = WGExtender.getInstance().getWorldGuard().getGlobalStateManager().get(player.getWorld()); if (!permModel.mayClaimRegionsUnbounded()) { int maxRegionCount = wcfg.getMaxRegionCount(player); if (maxRegionCount >= 0 && manager.getRegionCountOfPlayer(localPlayer) >= maxRegionCount) { throw new CommandException( "У вас слишком много регионов, удалите один из них перед тем как заприватить новый."); } } ProtectedRegion existing = manager.getRegion(id); if (existing != null) { if (!existing.getOwners().contains(localPlayer)) { throw new CommandException("Регион уже существует, и вы им не владеете."); } } ApplicableRegionSet regions = manager.getApplicableRegions(region); if (regions.size() > 0) { if (!regions.isOwnerOfAll(localPlayer)) { throw new CommandException("Это регион перекрывает чужой регион."); } } else { if (wcfg.claimOnlyInsideExistingRegions) { throw new CommandException("Вы можете приватить только внутри своих регионов."); } } if (wcfg.maxClaimVolume >= Integer.MAX_VALUE) { throw new CommandException( "The maximum claim volume get in the configuration is higher than is supported. " + "Currently, it must be " + Integer.MAX_VALUE + " or smaller. Please contact a server administrator."); } if (!permModel.mayClaimRegionsUnbounded()) { if (region instanceof ProtectedPolygonalRegion) { throw new CommandException("Полигональные регионы не поддерживаются."); } if (region.volume() > wcfg.maxClaimVolume) { player.sendMessage(ChatColor.RED + "Размер региона слишком большой."); player.sendMessage( ChatColor.RED + "Максимальный размер: " + wcfg.maxClaimVolume + ", ваш размер: " + region.volume()); return; } } RegionAdder task = new RegionAdder(WGExtender.getInstance().getWorldGuard(), manager, region); task.setLocatorPolicy(UserLocatorPolicy.UUID_ONLY); task.setOwnersInput(new String[] {player.getName()}); try { task.call(); sender.sendMessage(ChatColor.YELLOW + "Вы заприватили регион " + id); } catch (Exception e) { sender.sendMessage(ChatColor.YELLOW + "Произошла ошибка при привате региона " + id); e.printStackTrace(); } }
public void onPlayerInteract(PlayerInteractEvent event) { if (event.isCancelled()) { return; } Action action = event.getAction(); if (action == Action.RIGHT_CLICK_BLOCK || action == Action.RIGHT_CLICK_AIR) { Block block = event.getClickedBlock(); Material type = block.getType(); Player player = event.getPlayer(); GlobalConfiguration cfg = plugin.getGlobalConfiguration(); WorldConfiguration wcfg = cfg.getWorldConfig(event.getClickedBlock().getWorld().getName()); if (wcfg.useRegions && player.getItemInHand().getTypeId() == wcfg.regionWand) { Vector pt = toVector(block); RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName()); ApplicableRegionSet app = mgr.getApplicableRegions(pt); List<String> regions = mgr.getApplicableRegionsIDs(pt); if (regions.size() > 0) { player.sendMessage( ChatColor.YELLOW + "Can you build? " + (app.canBuild(BukkitPlayer.wrapPlayer(plugin, player)) ? "Yes" : "No")); StringBuilder str = new StringBuilder(); for (Iterator<String> it = regions.iterator(); it.hasNext(); ) { str.append(it.next()); if (it.hasNext()) { str.append(", "); } } player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString()); } else { player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!"); } } if (block.getType() == Material.CHEST || block.getType() == Material.DISPENSER || block.getType() == Material.FURNACE || block.getType() == Material.BURNING_FURNACE || block.getType() == Material.NOTE_BLOCK) { if (wcfg.useRegions) { Vector pt = toVector(block); LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player); RegionManager mgr = plugin.getGlobalRegionManager().getRegionManager(player.getWorld().getName()); if (!plugin.hasPermission(player, "region.bypass")) { ApplicableRegionSet set = mgr.getApplicableRegions(pt); if (!set.isStateFlagAllowed(Flags.CHEST_ACCESS) && !set.canBuild(localPlayer)) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; } } } } if (wcfg.useRegions && (type == Material.LEVER || type == Material.STONE_BUTTON)) { Vector pt = toVector(block); RegionManager mgr = cfg.getWorldGuardPlugin() .getGlobalRegionManager() .getRegionManager(player.getWorld().getName()); ApplicableRegionSet applicableRegions = mgr.getApplicableRegions(pt); LocalPlayer localPlayer = BukkitPlayer.wrapPlayer(plugin, player); if (!applicableRegions.isStateFlagAllowed(Flags.LEVER_AND_BUTTON, localPlayer)) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); event.setCancelled(true); return; } } if (wcfg.useRegions && type == Material.CAKE_BLOCK) { Vector pt = toVector(block); if (!cfg.canBuild(player, pt)) { player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area."); byte newData = (byte) (block.getData() - 1); newData = newData < 0 ? 0 : newData; block.setData(newData); player.setHealth(player.getHealth() - 3); return; } } if (wcfg.useRegions && wcfg.useiConomy && cfg.getiConomy() != null && (type == Material.SIGN_POST || type == Material.SIGN || type == Material.WALL_SIGN)) { BlockState blockstate = block.getState(); if (((Sign) blockstate).getLine(0).equalsIgnoreCase("[WorldGuard]") && ((Sign) blockstate).getLine(1).equalsIgnoreCase("For sale")) { String regionId = ((Sign) blockstate).getLine(2); // String regionComment = ((Sign)block).getLine(3); if (regionId != null && regionId != "") { RegionManager mgr = cfg.getWorldGuardPlugin() .getGlobalRegionManager() .getRegionManager(player.getWorld().getName()); ProtectedRegion region = mgr.getRegion(regionId); if (region != null) { RegionFlagContainer flags = region.getFlags(); if (flags.getBooleanFlag(Flags.BUYABLE).getValue(false)) { if (iConomy.getBank().hasAccount(player.getName())) { Account account = iConomy.getBank().getAccount(player.getName()); double balance = account.getBalance(); double regionPrice = flags.getDoubleFlag(Flags.PRICE).getValue(); if (balance >= regionPrice) { account.subtract(regionPrice); player.sendMessage( ChatColor.YELLOW + "You have bought the region " + regionId + " for " + iConomy.getBank().format(regionPrice)); DefaultDomain owners = region.getOwners(); owners.addPlayer(player.getName()); region.setOwners(owners); flags.getBooleanFlag(Flags.BUYABLE).setValue(false); account.save(); } else { player.sendMessage(ChatColor.YELLOW + "You have not enough money."); } } else { player.sendMessage(ChatColor.YELLOW + "You have not enough money."); } } else { player.sendMessage(ChatColor.RED + "Region: " + regionId + " is not buyable"); } } else { player.sendMessage( ChatColor.DARK_RED + "The region " + regionId + " does not exist."); } } else { player.sendMessage(ChatColor.DARK_RED + "No region specified."); } } } if (wcfg.getBlacklist() != null) { if (!wcfg.getBlacklist() .check( new BlockInteractBlacklistEvent( BukkitPlayer.wrapPlayer(plugin, player), toVector(block), block.getTypeId()), false, false)) { event.setCancelled(true); return; } } } }
@Override protected void action() throws CommandException { ProtectedRegion region = null; if (args.length == 1 || (args.length == 2 && args[1].equalsIgnoreCase("sel"))) { // No regionname specified. Get highest priority if (all) { // Allowed to get all regions region = getHighestPriorityRegion(); } else { // Only allowed to get their own regions region = getHighestOwnedPriorityRegion(true); } } else { validateRegionID(args[1]); // Check if valid region region = getRegion(args[1]); // Get the region by name if (!all) { // If not acces to all regions String playername = p.getName(); if (!region.getMembers().contains(p.getUniqueId()) && !region.getOwners().contains(p.getUniqueId())) { // Check if owner or member throw new IRGException("You are not the owner or member of the specified region."); } } } if (args[args.length - 1].equalsIgnoreCase("sel")) { // Select region if (p.hasPermission(Perm.select.toString())) { setPlayerSelection(region); } } RegionPrintoutBuilder builder = new RegionPrintoutBuilder(region, null); // Build the string try { // First line builder.append(ChatColor.GRAY); builder.append( "\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"); builder.append(" Region Info "); builder.append( "\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550"); builder.append("\n"); // Basic info builder.appendBasics(); builder.appendFlags(); builder.appendParents(); // Users builder.append(ChatColor.BLUE + "Owners: "); builder.append(uuidSetToString(region.getOwners())); builder.append("\n"); builder.append(ChatColor.BLUE + "Members: "); builder.append(uuidSetToString(region.getMembers())); builder.append("\n"); // Bounds builder.appendBounds(); // Send builder.send(p); } catch (Exception e) { Util.badMsg(p, "An error occurred, sorry!"); Log.warn("Error occurred (IRG Info Command): " + e.getMessage()); } }