mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 12:35:15 +01:00
Fix multiverse setup and don't allow unsafe blocks in setup
This commit is contained in:
parent
8bc0bcd9e6
commit
130274de86
@ -1380,25 +1380,23 @@ import java.util.zip.ZipInputStream;
|
|||||||
break;
|
break;
|
||||||
case "f":
|
case "f":
|
||||||
case "floor":
|
case "floor":
|
||||||
this.worlds.set(base + "plot.floor", new ArrayList<>(Arrays.asList(
|
this.worlds.set(base + "plot.floor",
|
||||||
StringMan.join(Configuration.BLOCKLIST.parseString(value), ",")
|
Configuration.BLOCK_BUCKET.parseString(value).toString());
|
||||||
.split(","))));
|
|
||||||
break;
|
break;
|
||||||
case "m":
|
case "m":
|
||||||
case "main":
|
case "main":
|
||||||
this.worlds.set(base + "plot.filling", new ArrayList<>(Arrays.asList(
|
this.worlds.set(base + "plot.filling",
|
||||||
StringMan.join(Configuration.BLOCKLIST.parseString(value), ",")
|
Configuration.BLOCK_BUCKET.parseString(value).toString());
|
||||||
.split(","))));
|
|
||||||
break;
|
break;
|
||||||
case "w":
|
case "w":
|
||||||
case "wall":
|
case "wall":
|
||||||
this.worlds.set(base + "wall.filling",
|
this.worlds.set(base + "wall.filling",
|
||||||
Configuration.BLOCK.parseString(value).toString());
|
Configuration.BLOCK_BUCKET.parseString(value).toString());
|
||||||
break;
|
break;
|
||||||
case "b":
|
case "b":
|
||||||
case "border":
|
case "border":
|
||||||
this.worlds.set(base + "wall.block",
|
this.worlds.set(base + "wall.block",
|
||||||
Configuration.BLOCK.parseString(value).toString());
|
Configuration.BLOCK_BUCKET.parseString(value).toString());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
PlotSquared.log("&cKey not found: &7" + element);
|
PlotSquared.log("&cKey not found: &7" + element);
|
||||||
|
@ -3,6 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.commands;
|
|||||||
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.C;
|
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.config.ConfigurationNode;
|
||||||
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
import com.github.intellectualsites.plotsquared.plot.generator.GeneratorWrapper;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||||
@ -246,7 +247,13 @@ import java.util.Map.Entry;
|
|||||||
step.getType().getType(), String.valueOf(step.getDefaultValue()));
|
step.getType().getType(), String.valueOf(step.getDefaultValue()));
|
||||||
return false;
|
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) {
|
if (valid) {
|
||||||
sendMessage(player, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
|
sendMessage(player, C.SETUP_VALID_ARG, step.getConstant(), args[0]);
|
||||||
step.setValue(args[0]);
|
step.setValue(args[0]);
|
||||||
|
@ -7,8 +7,6 @@ import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Configuration Utility
|
* Main Configuration Utility
|
||||||
*/
|
*/
|
||||||
@ -88,22 +86,7 @@ public class Configuration {
|
|||||||
return "FOREST";
|
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 =
|
public static final SettingValue<BlockBucket> BLOCK_BUCKET =
|
||||||
new SettingValue<BlockBucket>("BLOCK_BUCKET") {
|
new SettingValue<BlockBucket>("BLOCK_BUCKET") {
|
||||||
@Override public BlockBucket parseString(final String string) {
|
@Override public BlockBucket parseString(final String string) {
|
||||||
@ -129,6 +112,8 @@ public class Configuration {
|
|||||||
WorldUtil.IMP.getClosestBlock(block);
|
WorldUtil.IMP.getClosestBlock(block);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new UnknownBlockException(block);
|
throw new UnknownBlockException(block);
|
||||||
|
} else if (!value.best.isAir() && !WorldUtil.IMP.isBlockSolid(value.best)) {
|
||||||
|
throw new UnsafeBlockException(value.best);
|
||||||
}
|
}
|
||||||
blockBucket.addBlock(value.best, chance);
|
blockBucket.addBlock(value.best, chance);
|
||||||
}
|
}
|
||||||
@ -160,6 +145,8 @@ public class Configuration {
|
|||||||
WorldUtil.IMP.getClosestBlock(block);
|
WorldUtil.IMP.getClosestBlock(block);
|
||||||
if (value == null || value.match > 1) {
|
if (value == null || value.match > 1) {
|
||||||
return false;
|
return false;
|
||||||
|
} else if (!value.best.isAir() && !WorldUtil.IMP.isBlockSolid(value.best)) {
|
||||||
|
throw new UnsafeBlockException(value.best);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Throwable exception) {
|
} catch (final Throwable exception) {
|
||||||
@ -168,68 +155,6 @@ public class Configuration {
|
|||||||
return true;
|
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) {
|
public static int gcd(int a, int b) {
|
||||||
if (b == 0) {
|
if (b == 0) {
|
||||||
@ -278,4 +203,17 @@ public class Configuration {
|
|||||||
|
|
||||||
public abstract boolean validateValue(String string);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,10 @@ public class ConfigurationNode {
|
|||||||
try {
|
try {
|
||||||
Object result = this.type.parseString(string);
|
Object result = this.type.parseString(string);
|
||||||
return result != null;
|
return result != null;
|
||||||
} catch (Exception ignored) {
|
} catch (Exception e) {
|
||||||
|
if (e instanceof Configuration.UnknownBlockException) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user