Commits

James Crasta  committed b97066e

Split config up into multiple parts, and finish up limit groups

  • Participants
  • Parent commits 4125272

Comments (0)

Files changed (5)

File config-example.yml

+########################
+## Basic Configuration
+
+
+# Valid values: SuperPerms, Vault
+permissions: SuperPerms
+
+# Sign/Chest protection.
+# You probably want to use the defaults, the only reason the options are
+# provided is if you have some other protection and definitely don't want
+# MondoChest protection.
+protection:
+    signs: true
+    chest_break: true
+    chest_open: false
+
+
+#######################
+## Access Control Lists
+# MondoChest 0.7 adds fine-grained access control to each MondoChest.
+# See ACL documentation on website: http://goo.gl/tB44w
+
+acl_fallback_role: configure_me
+
+
+###################################
+## Limits to keep performance sane.
+
+# 'radius' limits are in number of blocks.
+# Setting any limit to -1 or 'unlimited' makes it infinite.
+limits:
+    # How far away you can be when doing a /mondo find
+    find_max_radius: 300
+    # Allows limiting how many MondoChests(masters)  a given user can make.
+    mondochests_per_user: unlimited
+    # How many slaves can be added per master.
+    slaves_per_master: unlimited
+    # How far away from a mondo chest the slave can be
+    slave_max_add_radius: 150
+
+# Group Limits feature allows you to set up different limits for different user classes.
+# You can create as many groups as you want, but the performance of MondoChest is directly
+# affected by the number of groups, so delete this whole section if you don't need it.
+group_limits:
+    # This group is enabled with permission mondochest.limits.donators
+    donators:
+        find_max_radius: 300
+        mondochests_per_user: 5
+        slaves_per_master: 20
+        slave_max_add_radius: 150
+    # This group uses permission mondochest.limits.admins
+    admins:
+        slaves_per_master: unlimited
+        mondochests_per_user: unlimited
+
+
+#######################
+## Restacking feature
+
+# Allow restacking of materials for the master chest.  Restacking will allow
+# various materials which can't stack or stack to less than 64 to be stacked to
+# the maximum value.
+restack_master: false
+
+# Restack materials for the slave chests if 'restack' is on the second line.
+restack_slaves: false
+
+# What materials to restack to the maximum 64
+restack_materials:
+  - SIGN
+  - SNOW_BALL
+  - EGG
+
+
+#####################
+## Specialty options
+
+special:
+    # signs look for slaves up and down two from the sign.
+    # This allows you to hide signs in the floor or ceiling.
+    slave_vertical_two: false
+
+    # signs look 2 to the left and right.
+    slave_horizontal_two: false
-########################
-## Basic Configuration
-
-
-# Valid values: SuperPerms, Vault
 permissions: SuperPerms
 
-# Sign/Chest protection.
-# You probably want to use the defaults, the only reason the options are
-# provided is if you have some other protection and definitely don't want
-# MondoChest protection.
 protection:
     signs: true
     chest_break: true
     chest_open: false
 
-
-#######################
-## Access Control Lists
-# MondoChest 0.7 adds fine-grained access control to each MondoChest.
-# See ACL documentation on website: http://goo.gl/tB44w
-
 acl_fallback_role: configure_me
 
+limits:
+    find_max_radius: 300
+    mondochests_per_user: unlimited
+    slaves_per_master: unlimited
+    slave_max_add_radius: 150
 
-###################################
-## Limits to keep performance sane.
-
-# 'radius' limits are in number of blocks.
-# Setting any limit to -1 or 'unlimited' makes it infinite.
-limits:
-    # How far away you can be when doing a /mondo find
-    find_max_radius: 300
-
-    slaves:
-        # How many slaves can be added per master.
-        per_master: unlimited
-        # How far away from a mondo chest the slave can be
-        max_add_radius: 150
-
-    mondochests:
-        # Allows limiting how many MondoChests(masters)  a given user can make.
-        per_user: unlimited
-
-
-#######################
-## Restacking feature
-
-# Allow restacking of materials for the master chest.  Restacking will allow
-# various materials which can't stack or stack to less than 64 to be stacked to
-# the maximum value.
 restack_master: false
-
-# Restack materials for the slave chests if 'restack' is on the second line.
 restack_slaves: false
-
-# What materials to restack to the maximum 64
-restack_materials:
-  - SIGN
-  - SNOW_BALL
-  - EGG
-
-
-#####################
-## Specialty options
+restack_materials: []
 
 special:
-    # signs look for slaves up and down two from the sign.
-    # This allows you to hide signs in the floor or ceiling.
     slave_vertical_two: false
-
-    # signs look 2 to the left and right.
     slave_horizontal_two: false
 #!/bin/bash
 cd bin
-cp ../plugin.yml ../config.yml .
+cp ../plugin.yml ../config.yml ../config-example.yml .
 #mkdir -p res
 #cp ../config.yml res/config-t.yml
 rsync -av \

File src/us/crast/mondochest/MondoChest.java

 		} else {
 			bankManager.load();
 		}
-		if (!(new File(this.getDataFolder(), "config.yml").exists())) { 
-			saveDefaultConfig();
+		File configFile = new File(this.getDataFolder(), "config.yml");
+		if (!configFile.exists()) {
+		    this.saveResource("config-example.yml", true);
+		    File exampleFile = new File(this.getDataFolder(), "config-example.yml");
+		    exampleFile.renameTo(configFile);
 		}
 		if (++num_reloads > 1) {
 			reloadConfig();

File src/us/crast/mondochest/MondoConfig.java

 package us.crast.mondochest;
 
+import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.logging.Logger;
 
 import net.milkbowl.vault.permission.Permission;
 
 import org.bukkit.Material;
+import org.bukkit.configuration.ConfigurationSection;
 import org.bukkit.configuration.file.FileConfiguration;
 import org.bukkit.entity.Player;
 import org.bukkit.plugin.RegisteredServiceProvider;
 	public static String FALLBACK_ROLE = MondoConstants.ROLE_NONE;
     public static boolean ACL_ENABLED = true;
     private static Limits GLOBAL_LIMITS = null;
+    private static List<Limits> groupLimits = new ArrayList<Limits>();
 
 	private static List<String> decodeErrors = null;
 
 	
 	public static void configure(MondoChest plugin, FileConfiguration config, Logger log) {
 		MondoConfig.log = log;
-		GLOBAL_LIMITS = new Limits(config);
+		GLOBAL_LIMITS = new Limits(config.getConfigurationSection("limits"), null);
 		RESTACK_MASTER = config.getBoolean("restack_master");
 		RESTACK_SLAVES = config.getBoolean("restack_slaves");
 		PROTECTION_SIGNS = config.getBoolean("protection.signs");
 	        FALLBACK_ROLE = MondoConstants.ROLE_NONE;
 	        ACL_ENABLED = false;
 	    }
+	    configureGroupLimits(config.getConfigurationSection("group_limits"));
 	}
 	
-	public static void setupRoles() {
+	private static void configureGroupLimits(ConfigurationSection s) {
+        if (s == null) return;
+        for (Map.Entry<String, Object> e : s.getValues(false).entrySet()) {
+            if (s.isConfigurationSection(e.getKey())) {
+                groupLimits.add(
+                    new Limits((ConfigurationSection) e.getValue(), GLOBAL_LIMITS)
+                );
+            }
+        }
+        
+    }
+
+    public static void setupRoles() {
         /** Create roles hard-coded for now*/
         Role.create("none");
         
 	}
 
 	public static void logDecodeError(String error) {
-		if (decodeErrors == null) decodeErrors = new java.util.ArrayList<String>();
+		if (decodeErrors == null) decodeErrors = new ArrayList<String>();
 		log.warning(error);
 		decodeErrors.add(error);
 	}
 	
 	public static Limits getLimits(final Player player) {
+	    for (Limits limits : groupLimits) {
+	        if (limits.checker.check(player)) {
+	            return limits;
+	        }
+	    }
 	    return GLOBAL_LIMITS;
 	}
 }