Added per-group region claim maximums

This commit is contained in:
zml2008 2011-12-04 00:54:33 -08:00
parent 5948855da7
commit 67f78ae8b5
3 changed files with 65 additions and 7 deletions

View File

@ -23,8 +23,10 @@
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -153,6 +155,8 @@ public class WorldConfiguration {
public boolean regionInvinciblityRemovesMobs; public boolean regionInvinciblityRemovesMobs;
public boolean disableDeathMessages; public boolean disableDeathMessages;
public boolean disableObsidianGenerators; public boolean disableObsidianGenerators;
private Map<String, Integer> maxRegionCounts;
/* Configuration data end */ /* Configuration data end */
@ -249,6 +253,30 @@ private List<String> getStringList(String node, List<String> def) {
return res; return res;
} }
private List<String> getKeys(String node) {
List<String> res = parentConfig.getKeys(node);
if (res == null || res.size() == 0) {
parentConfig.setProperty(node, new ArrayList<String>());
}
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. * Load the configuration.
*/ */
@ -340,8 +368,20 @@ private void loadConfiguration() {
regionWand = getInt("regions.wand", 287); regionWand = getInt("regions.wand", 287);
maxClaimVolume = getInt("regions.max-claim-volume", 30000); maxClaimVolume = getInt("regions.max-claim-volume", 30000);
claimOnlyInsideExistingRegions = getBoolean("regions.claim-only-inside-existing-regions", false); 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<String, Integer>();
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); // useiConomy = getBoolean("iconomy.enable", false);
// buyOnClaim = getBoolean("iconomy.buy-on-claim", false); // buyOnClaim = getBoolean("iconomy.buy-on-claim", false);
// buyOnClaimPrice = getDouble("iconomy.buy-on-claim-price", 1.0); // buyOnClaimPrice = getDouble("iconomy.buy-on-claim-price", 1.0);
@ -504,4 +544,18 @@ public boolean isAdjacentChestProtected(Block block, Player player) {
public ChestProtection getChestProtection() { public ChestProtection getChestProtection() {
return chestProtection; 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;
}
} }

View File

@ -255,8 +255,9 @@ public void claim(CommandContext args, CommandSender sender) throws CommandExcep
if (!plugin.hasPermission(sender, "worldguard.region.unlimited")) { if (!plugin.hasPermission(sender, "worldguard.region.unlimited")) {
// Check whether the player has created too many regions // Check whether the player has created too many regions
if (wcfg.maxRegionCountPerPlayer >= 0 int maxRegionCount = wcfg.getMaxRegionCount(player);
&& mgr.getRegionCountOfPlayer(localPlayer) >= wcfg.maxRegionCountPerPlayer) { if (maxRegionCount >= 0
&& mgr.getRegionCountOfPlayer(localPlayer) >= maxRegionCount) {
throw new CommandException("You own too many regions, delete one first to claim a new one."); throw new CommandException("You own too many regions, delete one first to claim a new one.");
} }
} }

View File

@ -104,9 +104,12 @@ public void addOwner(CommandContext args, CommandSender sender) throws CommandEx
Boolean flag = region.getFlag(DefaultFlag.BUYABLE); Boolean flag = region.getFlag(DefaultFlag.BUYABLE);
DefaultDomain owners = region.getOwners(); DefaultDomain owners = region.getOwners();
if (flag != null && flag == true && owners != null && owners.size() == 0) { if (flag != null && flag == true && owners != null && owners.size() == 0) {
if (mgr.getRegionCountOfPlayer(localPlayer) if (!plugin.hasPermission(player, "worldguard.region.unlimited")) {
>= plugin.getGlobalStateManager().get(world).maxRegionCountPerPlayer) { int maxRegionCount = plugin.getGlobalStateManager().get(world).getMaxRegionCount(player);
throw new CommandException("You already own the maximum allowed amount of regions."); 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()); plugin.checkPermission(sender, "worldguard.region.addowner.unclaimed." + id.toLowerCase());
} else { } else {