mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
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.
This commit is contained in:
parent
2ffb2d08a6
commit
a67e03fec4
@ -148,11 +148,28 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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") {
|
public static final SettingValue BLOCKLIST = new SettingValue("BLOCKLIST") {
|
||||||
@Override
|
@Override
|
||||||
public boolean validateValue(String string) {
|
public boolean validateValue(String string) {
|
||||||
try {
|
try {
|
||||||
for (String block : string.split(",")) {
|
for (String block : string.split(",")) {
|
||||||
|
if (block.contains("%")) {
|
||||||
|
String[] split = block.split("%");
|
||||||
|
Integer.parseInt(split[0]);
|
||||||
|
block = split[1];
|
||||||
|
}
|
||||||
if (block.contains(":")) {
|
if (block.contains(":")) {
|
||||||
String[] split = block.split(":");
|
String[] split = block.split(":");
|
||||||
Short.parseShort(split[0]);
|
Short.parseShort(split[0]);
|
||||||
@ -172,8 +189,28 @@ public class Configuration {
|
|||||||
@Override
|
@Override
|
||||||
public Object parseString(String string) {
|
public Object parseString(String string) {
|
||||||
String[] blocks = string.split(",");
|
String[] blocks = string.split(",");
|
||||||
|
ArrayList<PlotBlock> parsedvalues = new ArrayList<PlotBlock>();
|
||||||
|
|
||||||
|
|
||||||
PlotBlock[] values = new PlotBlock[blocks.length];
|
PlotBlock[] values = new PlotBlock[blocks.length];
|
||||||
|
int[] counts = new int[blocks.length];
|
||||||
|
int min = 100;
|
||||||
for (int i = 0; i < blocks.length; i++) {
|
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<min) {
|
||||||
|
min = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
counts[i] = 1;
|
||||||
|
if (1<min) {
|
||||||
|
min = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (blocks[i].contains(":")) {
|
if (blocks[i].contains(":")) {
|
||||||
String[] split = blocks[i].split(":");
|
String[] split = blocks[i].split(":");
|
||||||
values[i] = new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
|
values[i] = new PlotBlock(Short.parseShort(split[0]), Byte.parseByte(split[1]));
|
||||||
@ -182,7 +219,15 @@ public class Configuration {
|
|||||||
values[i] = new PlotBlock(Short.parseShort(blocks[i]), (byte) 0);
|
values[i] = new PlotBlock(Short.parseShort(blocks[i]), (byte) 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return values;
|
int gcd = gcd(counts);
|
||||||
|
for (int i = 0; i < counts.length; i++) {
|
||||||
|
int num = counts[i];
|
||||||
|
for (int j = 0; j<num/gcd; j++) {
|
||||||
|
parsedvalues.add(values[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return parsedvalues.toArray(new PlotBlock[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user