Merge branch 'breaking' of https://github.com/IntellectualSites/PlotSquared into breaking

This commit is contained in:
dordsor21 2018-12-21 13:39:27 +00:00
commit e757c3e13c
4 changed files with 35 additions and 89 deletions

View File

@ -1380,25 +1380,23 @@ import java.util.zip.ZipInputStream;
break;
case "f":
case "floor":
this.worlds.set(base + "plot.floor", new ArrayList<>(Arrays.asList(
StringMan.join(Configuration.BLOCKLIST.parseString(value), ",")
.split(","))));
this.worlds.set(base + "plot.floor",
Configuration.BLOCK_BUCKET.parseString(value).toString());
break;
case "m":
case "main":
this.worlds.set(base + "plot.filling", new ArrayList<>(Arrays.asList(
StringMan.join(Configuration.BLOCKLIST.parseString(value), ",")
.split(","))));
this.worlds.set(base + "plot.filling",
Configuration.BLOCK_BUCKET.parseString(value).toString());
break;
case "w":
case "wall":
this.worlds.set(base + "wall.filling",
Configuration.BLOCK.parseString(value).toString());
Configuration.BLOCK_BUCKET.parseString(value).toString());
break;
case "b":
case "border":
this.worlds.set(base + "wall.block",
Configuration.BLOCK.parseString(value).toString());
Configuration.BLOCK_BUCKET.parseString(value).toString());
break;
default:
PlotSquared.log("&cKey not found: &7" + element);

View File

@ -3,6 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.commands;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.C;
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
import com.github.intellectualsites.plotsquared.plot.config.ConfigurationNode;
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
@ -246,7 +247,13 @@ import java.util.Map.Entry;
step.getType().getType(), String.valueOf(step.getDefaultValue()));
return false;
}
boolean valid = step.isValid(args[0]);
boolean valid = false;
try {
step.isValid(args[0]);
} catch (final Configuration.UnsafeBlockException e) {
C.NOT_ALLOWED_BLOCK.send(player, e.getUnsafeBlock().toString());
}
if (valid) {
sendMessage(player, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
step.setValue(args[0]);

View File

@ -7,8 +7,6 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import lombok.Getter;
import lombok.NonNull;
import java.util.ArrayList;
/**
* Main Configuration Utility
*/
@ -88,22 +86,7 @@ public class Configuration {
return "FOREST";
}
};
public static final SettingValue<PlotBlock> BLOCK = new SettingValue<PlotBlock>("BLOCK") {
@Override public boolean validateValue(String string) {
StringComparison<PlotBlock>.ComparisonResult value =
WorldUtil.IMP.getClosestBlock(string);
return !(value == null || value.match > 1);
}
@Override public PlotBlock parseString(String string) {
StringComparison<PlotBlock>.ComparisonResult value =
WorldUtil.IMP.getClosestBlock(string);
if (value == null || value.match > 1) {
return null;
}
return value.best;
}
};
public static final SettingValue<BlockBucket> BLOCK_BUCKET =
new SettingValue<BlockBucket>("BLOCK_BUCKET") {
@Override public BlockBucket parseString(final String string) {
@ -129,6 +112,8 @@ public class Configuration {
WorldUtil.IMP.getClosestBlock(block);
if (value == null) {
throw new UnknownBlockException(block);
} else if (!value.best.isAir() && !WorldUtil.IMP.isBlockSolid(value.best)) {
throw new UnsafeBlockException(value.best);
}
blockBucket.addBlock(value.best, chance);
}
@ -160,6 +145,8 @@ public class Configuration {
WorldUtil.IMP.getClosestBlock(block);
if (value == null || value.match > 1) {
return false;
} else if (!value.best.isAir() && !WorldUtil.IMP.isBlockSolid(value.best)) {
throw new UnsafeBlockException(value.best);
}
}
} catch (final Throwable exception) {
@ -168,68 +155,6 @@ public class Configuration {
return true;
}
};
public static final SettingValue<PlotBlock[]> BLOCKLIST =
new SettingValue<PlotBlock[]>("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];
}
StringComparison<PlotBlock>.ComparisonResult value =
WorldUtil.IMP.getClosestBlock(block);
if (value == null || value.match > 1) {
return false;
}
}
return true;
} catch (NumberFormatException ignored) {
return false;
}
}
@Override public PlotBlock[] parseString(String string) {
String[] blocks = string.split(",");
ArrayList<PlotBlock> 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++) {
try {
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;
}
}
StringComparison<PlotBlock>.ComparisonResult result =
WorldUtil.IMP.getClosestBlock(blocks[i]);
if (result != null && result.match < 2) {
values[i] = result.best;
}
} catch (NumberFormatException ignored) {
}
}
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[parsedvalues.size()]);
}
};
public static int gcd(int a, int b) {
if (b == 0) {
@ -278,4 +203,17 @@ public class Configuration {
public abstract boolean validateValue(String string);
}
public static final class UnsafeBlockException extends IllegalArgumentException {
@Getter
private final PlotBlock unsafeBlock;
public UnsafeBlockException(@NonNull final PlotBlock unsafeBlock) {
super(String.format("%s is not a valid block", unsafeBlock));
this.unsafeBlock = unsafeBlock;
}
}
}

View File

@ -36,7 +36,10 @@ public class ConfigurationNode {
try {
Object result = this.type.parseString(string);
return result != null;
} catch (Exception ignored) {
} catch (Exception e) {
if (e instanceof Configuration.UnknownBlockException) {
throw e;
}
return false;
}
}