From 78910b3a71c23ab6463e83167460717db7b2f81e Mon Sep 17 00:00:00 2001 From: sk89q Date: Fri, 31 Dec 2010 14:49:49 -0800 Subject: [PATCH] Simplified the max blocks change limit to be binary (either you have it or not). Also separated the 'max' limit and the 'default' limit in terms of configuration. --- src/WorldEditListener.java | 51 ++++--- .../worldedit/GroupRestrictionsManager.java | 126 ------------------ 2 files changed, 25 insertions(+), 152 deletions(-) delete mode 100644 src/com/sk89q/worldedit/GroupRestrictionsManager.java diff --git a/src/WorldEditListener.java b/src/WorldEditListener.java index aeb8e5e45..f8d14159a 100755 --- a/src/WorldEditListener.java +++ b/src/WorldEditListener.java @@ -76,14 +76,10 @@ public class WorldEditListener extends PluginListener { */ private HashMap commands = new HashMap(); - /** - * Group restrictions manager. - */ - private GroupRestrictionsManager restrictions = new GroupRestrictionsManager(); - private boolean profile; private HashSet allowedBlocks; private int defaultChangeLimit = -1; + private int maxChangeLimit = -1; private String shellSaveType; private SnapshotRepository snapshotRepo; private int maxRadius = -1; @@ -188,11 +184,19 @@ public class WorldEditListener extends PluginListener { return sessions.get(player); } else { WorldEditSession session = new WorldEditSession(); - int changeLimit = restrictions.getGreatestChangeLimit(player.getGroups()); - if (changeLimit == -2) { - changeLimit = defaultChangeLimit; + if (!player.getPlayerObject().canUseCommand("/worldeditnomax") + && maxChangeLimit > -1) { + if (defaultChangeLimit < 0) { + // No infinite! + session.setBlockChangeLimit(maxChangeLimit); + } else { + // Bound + session.setBlockChangeLimit( + Math.min(defaultChangeLimit, maxChangeLimit)); + } + } else { + session.setBlockChangeLimit(defaultChangeLimit); } - session.setBlockChangeLimit(changeLimit); session.setUseInventory(useInventory && (!useInventoryOverride || !player.getPlayerObject().canUseCommand("/worldeditunlimited"))); @@ -595,13 +599,17 @@ public class WorldEditListener extends PluginListener { } else if (split[0].equalsIgnoreCase("//limit")) { checkArgs(split, 1, 1, split[0]); int limit = Math.max(-1, Integer.parseInt(split[1])); - int allowableMax = restrictions.getGreatestChangeLimit(player.getGroups()); - if (allowableMax >= 0 && (limit == -1 || limit > allowableMax)) { - player.printError("Your maximum allowable limit is " + allowableMax + "."); - } else { - session.setBlockChangeLimit(limit); - player.print("Block change limit set to " + limit + "."); + if (!player.getPlayerObject().canUseCommand("/worldeditnomax") + && maxChangeLimit > -1) { + if (limit > maxChangeLimit) { + player.printError("Your maximum allowable limit is " + maxChangeLimit + "."); + return true; + } } + + session.setBlockChangeLimit(limit); + player.print("Block change limit set to " + limit + "."); + return true; // Set super pick axe mode @@ -2030,8 +2038,8 @@ public class WorldEditListener extends PluginListener { } catch (DisallowedItemException e4) { ply.sendMessage(Colors.Rose + "Block '" + e4.getID() + "' not allowed (see WorldEdit configuration)."); } catch (MaxChangedBlocksException e5) { - ply.sendMessage(Colors.Rose + "The maximum number of blocks changed (" - + e5.getBlockLimit() + ") in an instance was reached."); + ply.sendMessage(Colors.Rose + "Max blocks changed in an operation reached (" + + e5.getBlockLimit() + ")."); } catch (MaxRadiusException e) { ply.sendMessage(Colors.Rose + "Maximum radius: " + maxRadius); } catch (UnknownDirectionException ue) { @@ -2190,15 +2198,6 @@ public class WorldEditListener extends PluginListener { logger.removeHandler(handler); } } - - try { - restrictions.load("worldedit-restrictions.txt"); - logger.log(Level.INFO, "WorldEdit group restrictions loaded"); - } catch (FileNotFoundException e) { - } catch (IOException e) { - logger.log(Level.WARNING, "Could not load WorldEdit restrictions: " - + e.getMessage()); - } } /** diff --git a/src/com/sk89q/worldedit/GroupRestrictionsManager.java b/src/com/sk89q/worldedit/GroupRestrictionsManager.java deleted file mode 100644 index 5a0e58135..000000000 --- a/src/com/sk89q/worldedit/GroupRestrictionsManager.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package com.sk89q.worldedit; - -import java.util.Map; -import java.util.HashMap; -import java.util.logging.Logger; -import java.io.*; - -/** - * - * @author sk89q - */ -public class GroupRestrictionsManager { - /** - * Logger. - */ - private static final Logger logger = Logger.getLogger("Minecraft.WorldEdit"); - - /** - * Store block change limits. - */ - private Map changeLimits - = new HashMap(); - - /** - * Get a group's change limit. Returns -2 if there is no setting. - * - * @param group - * @return - */ - public int getChangeLimit(String group) { - group = group.toLowerCase(); - if (changeLimits.containsKey(group.toLowerCase())) { - return changeLimits.get(group); - } else { - return -2; - } - } - - /** - * Get the highest change limit of a list of groups. - * Returns -2 if there is no setting. - * - * @param group - * @return - */ - public int getGreatestChangeLimit(String[] groups) { - int highestLimit = -2; - - for (String group : groups) { - int changeLimit = getChangeLimit(group); - if (changeLimit == -1) { - return -1; - } else if (changeLimit > highestLimit) { - highestLimit = changeLimit; - } - } - - return highestLimit; - } - - /** - * Load group restrictions from a file. - * - * @param file - * @throws IOException - */ - public void load(String file) throws IOException { - load(new File(file)); - } - - /** - * Load group restrictions from a file. - * - * @param file - * @throws IOException - */ - public void load(File file) throws IOException { - FileReader input = null; - Map changeLimits = new HashMap(); - - try { - input = new FileReader(file); - BufferedReader buff = new BufferedReader(input); - - String line; - while ((line = buff.readLine()) != null) { - line = line.trim(); - - // Blank line - if (line.length() == 0) { - continue; - } - - // Comment - if (line.charAt(0) == ';' || line.charAt(0) == '#' || line.equals("")) { - continue; - } - - String[] parts = line.split(":"); - - String groupID = parts[0].toLowerCase(); - try { - int changeLimit = parts.length > 1 ? Integer.parseInt(parts[1]) : -1; - changeLimits.put(groupID, changeLimit); - } catch (NumberFormatException e) { - logger.warning("Integer expected in" - + "WorldEdit group permissions line: " + line); - } - } - - this.changeLimits = changeLimits; - } finally { - try { - if (input != null) { - input.close(); - } - } catch (IOException e2) { - } - } - } -}