From a67e03fec44a2e4a3042c1ecf0df06cb95318a0e Mon Sep 17 00:00:00 2001 From: boy0001 Date: Fri, 24 Oct 2014 11:29:18 +1100 Subject: [PATCH] Added percentage support for block lists (untested) e.g. (I put block names instead of Ids as I can't remember what they are) floor - 90%stone - 5%gravel - 1%diamond - 4%tnt It doesn't need to add up to 100%, they are just ratios. so there is 1 part diamond to 90 parts stone. People's brains just work better when using percentages. --- .../plot/Configuration.java | 47 ++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java b/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java index 2bbb26e7a..50dbff7eb 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/Configuration.java @@ -147,12 +147,29 @@ public class Configuration { return ((PlotBlock) object).id + ":" + ((PlotBlock) object).data; } }; + + public static int gcd(int a, int b) { + if (b==0) return a; + return gcd(b,a%b); + } + private static int gcd(int[] a) + { + int result = a[0]; + for(int i = 1; i < a.length; i++) + result = gcd(result, a[i]); + return result; + } public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") { @Override public boolean validateValue(String string) { try { for (String block : string.split(",")) { + if (block.contains("%")) { + String[] split = block.split("%"); + Integer.parseInt(split[0]); + block = split[1]; + } if (block.contains(":")) { String[] split = block.split(":"); Short.parseShort(split[0]); @@ -172,8 +189,28 @@ public class Configuration { @Override public Object parseString(String string) { String[] blocks = string.split(","); + ArrayList parsedvalues = new ArrayList(); + + PlotBlock[] values = new PlotBlock[blocks.length]; + int[] counts = new int[blocks.length]; + int min = 100; for (int i = 0; i < blocks.length; i++) { + if (blocks[i].contains("%")) { + String[] split = blocks[i].split("%"); + blocks[i] = split[1]; + int value = Integer.parseInt(split[0]); + counts[i] = value; + if (value