diff --git a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java index 19d8613d..07907f2d 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/WorldConfiguration.java @@ -23,8 +23,10 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -153,6 +155,8 @@ public class WorldConfiguration { public boolean regionInvinciblityRemovesMobs; public boolean disableDeathMessages; public boolean disableObsidianGenerators; + + private Map maxRegionCounts; /* Configuration data end */ @@ -249,6 +253,30 @@ private List getStringList(String node, List def) { return res; } + private List getKeys(String node) { + List res = parentConfig.getKeys(node); + + if (res == null || res.size() == 0) { + parentConfig.setProperty(node, new ArrayList()); + } + + if (config.getProperty(node) != null) { + res = config.getKeys(node); + } + + return res; + } + + private Object getProperty(String node) { + Object res = parentConfig.getProperty(node); + + if (config.getProperty(node) != null) { + res = config.getProperty(node); + } + + return res; + } + /** * Load the configuration. */ @@ -340,8 +368,20 @@ private void loadConfiguration() { regionWand = getInt("regions.wand", 287); maxClaimVolume = getInt("regions.max-claim-volume", 30000); claimOnlyInsideExistingRegions = getBoolean("regions.claim-only-inside-existing-regions", false); - maxRegionCountPerPlayer = getInt("regions.max-region-count-per-player", 7); - + + maxRegionCountPerPlayer = getInt("regions.max-region-count-per-player.default", 7); + maxRegionCounts = new HashMap(); + maxRegionCounts.put(null, maxRegionCountPerPlayer); + + for (String key : getKeys("regions.max-region-count-per-player")) { + if (!key.equalsIgnoreCase("default")) { + Object val = getProperty("regions.max-region-count-per-player." + key); + if (val != null && val instanceof Number) { + maxRegionCounts.put(key, ((Number) val).intValue()); + } + } + } + // useiConomy = getBoolean("iconomy.enable", false); // buyOnClaim = getBoolean("iconomy.buy-on-claim", false); // buyOnClaimPrice = getDouble("iconomy.buy-on-claim-price", 1.0); @@ -504,4 +544,18 @@ public boolean isAdjacentChestProtected(Block block, Player player) { public ChestProtection getChestProtection() { return chestProtection; } + + public int getMaxRegionCount(Player player) { + int max = -1; + for (String group : plugin.getGroups(player)) { + if (maxRegionCounts.containsKey(group)) { + int groupMax = maxRegionCounts.get(group); + if (max < groupMax) max = groupMax; + } + } + if (max <= -1) { + max = maxRegionCountPerPlayer; + } + return max; + } } diff --git a/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionCommands.java b/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionCommands.java index 464ad343..5652167c 100755 --- a/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionCommands.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionCommands.java @@ -255,8 +255,9 @@ public void claim(CommandContext args, CommandSender sender) throws CommandExcep if (!plugin.hasPermission(sender, "worldguard.region.unlimited")) { // Check whether the player has created too many regions - if (wcfg.maxRegionCountPerPlayer >= 0 - && mgr.getRegionCountOfPlayer(localPlayer) >= wcfg.maxRegionCountPerPlayer) { + int maxRegionCount = wcfg.getMaxRegionCount(player); + if (maxRegionCount >= 0 + && mgr.getRegionCountOfPlayer(localPlayer) >= maxRegionCount) { throw new CommandException("You own too many regions, delete one first to claim a new one."); } } diff --git a/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java b/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java index 45204fd7..7a9672c4 100644 --- a/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java +++ b/src/main/java/com/sk89q/worldguard/bukkit/commands/RegionMemberCommands.java @@ -104,9 +104,12 @@ public void addOwner(CommandContext args, CommandSender sender) throws CommandEx Boolean flag = region.getFlag(DefaultFlag.BUYABLE); DefaultDomain owners = region.getOwners(); if (flag != null && flag == true && owners != null && owners.size() == 0) { - if (mgr.getRegionCountOfPlayer(localPlayer) - >= plugin.getGlobalStateManager().get(world).maxRegionCountPerPlayer) { - throw new CommandException("You already own the maximum allowed amount of regions."); + if (!plugin.hasPermission(player, "worldguard.region.unlimited")) { + int maxRegionCount = plugin.getGlobalStateManager().get(world).getMaxRegionCount(player); + if (maxRegionCount >= 0 && mgr.getRegionCountOfPlayer(localPlayer) + >= maxRegionCount) { + throw new CommandException("You already own the maximum allowed amount of regions."); + } } plugin.checkPermission(sender, "worldguard.region.addowner.unclaimed." + id.toLowerCase()); } else {