mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Config reading/writing
This commit is contained in:
parent
d254633b77
commit
d34f5cc97e
@ -209,20 +209,20 @@ import java.util.Set;
|
|||||||
break;
|
break;
|
||||||
case "f":
|
case "f":
|
||||||
case "floor":
|
case "floor":
|
||||||
pa.TOP_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]).getPattern();
|
pa.TOP_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]);
|
||||||
break;
|
break;
|
||||||
case "m":
|
case "m":
|
||||||
case "main":
|
case "main":
|
||||||
pa.MAIN_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]).getPattern();
|
pa.MAIN_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]);
|
||||||
break;
|
break;
|
||||||
case "w":
|
case "w":
|
||||||
case "wall":
|
case "wall":
|
||||||
pa.WALL_FILLING =
|
pa.WALL_FILLING =
|
||||||
Configuration.BLOCK_BUCKET.parseString(pair[1]).getPattern();
|
Configuration.BLOCK_BUCKET.parseString(pair[1]);
|
||||||
break;
|
break;
|
||||||
case "b":
|
case "b":
|
||||||
case "border":
|
case "border":
|
||||||
pa.WALL_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]).getPattern();
|
pa.WALL_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]);
|
||||||
break;
|
break;
|
||||||
case "terrain":
|
case "terrain":
|
||||||
pa.TERRAIN = Integer.parseInt(pair[1]);
|
pa.TERRAIN = Integer.parseInt(pair[1]);
|
||||||
|
@ -3,6 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.config;
|
|||||||
import com.github.intellectualsites.plotsquared.plot.object.BlockBucket;
|
import com.github.intellectualsites.plotsquared.plot.object.BlockBucket;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
|
import com.github.intellectualsites.plotsquared.plot.util.StringComparison;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
||||||
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
@ -10,7 +11,6 @@ import lombok.Getter;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main Configuration Utility
|
* Main Configuration Utility
|
||||||
@ -62,67 +62,19 @@ public class Configuration {
|
|||||||
public static final SettingValue<BlockBucket> BLOCK_BUCKET =
|
public static final SettingValue<BlockBucket> BLOCK_BUCKET =
|
||||||
new SettingValue<BlockBucket>("BLOCK_BUCKET") {
|
new SettingValue<BlockBucket>("BLOCK_BUCKET") {
|
||||||
|
|
||||||
private Pattern pattern = Pattern.compile("((?<namespace>[A-Za-z_]+):)?(?<block>([A-Za-z_]+(\\[?[\\S\\s]+\\])?))(:(?<chance>[0-9]{1,3}))?");
|
|
||||||
|
|
||||||
@Override public BlockBucket parseString(final String string) {
|
@Override public BlockBucket parseString(final String string) {
|
||||||
if (string == null || string.isEmpty()) {
|
BlockBucket bucket = new BlockBucket(string);
|
||||||
return new BlockBucket();
|
bucket.compile();
|
||||||
}
|
Pattern pattern = bucket.toPattern();
|
||||||
final BlockBucket blockBucket = new BlockBucket();
|
return pattern != null ? bucket : null;
|
||||||
final String[] parts = string.split(",(?![^\\(\\[]*[\\]\\)])");
|
|
||||||
for (final String part : parts) {
|
|
||||||
Matcher matcher = pattern.matcher(part);
|
|
||||||
matcher.find();
|
|
||||||
String namespace = matcher.group("namespace");
|
|
||||||
String block = matcher.group("block");
|
|
||||||
String chanceStr = matcher.group("chance");
|
|
||||||
if (namespace == null) namespace = "minecraft";
|
|
||||||
int chance = chanceStr == null ? -1 : Integer.parseInt(chanceStr);
|
|
||||||
final StringComparison<BlockState>.ComparisonResult value =
|
|
||||||
WorldUtil.IMP.getClosestBlock(block);
|
|
||||||
if (value == null) {
|
|
||||||
throw new UnknownBlockException(block);
|
|
||||||
} else if (Settings.Enabled_Components.PREVENT_UNSAFE && !value.best.getBlockType().getMaterial().isAir()
|
|
||||||
&& !WorldUtil.IMP.isBlockSolid(value.best)) {
|
|
||||||
throw new UnsafeBlockException(value.best);
|
|
||||||
}
|
|
||||||
blockBucket.addBlock(value.best, chance);
|
|
||||||
}
|
|
||||||
blockBucket.compile(); // Pre-compile :D
|
|
||||||
return blockBucket;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean validateValue(final String string) {
|
@Override public boolean validateValue(final String string) {
|
||||||
try {
|
try {
|
||||||
if (string == null || string.isEmpty()) {
|
return parseString(string) != null;
|
||||||
|
} catch (Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String[] parts = string.split(",(?![^\\(\\[]*[\\]\\)])");
|
|
||||||
for (final String part : parts) {
|
|
||||||
Matcher matcher = pattern.matcher(part);
|
|
||||||
matcher.find();
|
|
||||||
String namespace = matcher.group("namespace");
|
|
||||||
String block = matcher.group("block");
|
|
||||||
String chanceStr = matcher.group("chance");
|
|
||||||
if (namespace == null) namespace = "minecraft";
|
|
||||||
int chance = chanceStr == null ? -1 : Integer.parseInt(chanceStr);
|
|
||||||
|
|
||||||
if ((chance != -1 && (chance < 1 || chance > 100)) || block == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
StringComparison<BlockState>.ComparisonResult value =
|
|
||||||
WorldUtil.IMP.getClosestBlock(block);
|
|
||||||
if (value == null || value.match > 1) {
|
|
||||||
return false;
|
|
||||||
} else if (Settings.Enabled_Components.PREVENT_UNSAFE && !value.best.getBlockType().getMaterial().isAir()
|
|
||||||
&& !WorldUtil.IMP.isBlockSolid(value.best)) {
|
|
||||||
throw new UnsafeBlockException(value.best);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (final Throwable exception) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.generator;
|
package com.github.intellectualsites.plotsquared.plot.generator;
|
||||||
|
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.BlockBucket;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.Direction;
|
import com.github.intellectualsites.plotsquared.plot.object.Direction;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||||
@ -52,9 +53,9 @@ public class ClassicPlotManager extends SquarePlotManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean unClaimPlot(Plot plot, Runnable whenDone) {
|
@Override public boolean unClaimPlot(Plot plot, Runnable whenDone) {
|
||||||
setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING);
|
setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING.toPattern());
|
||||||
if (!isAir(classicPlotWorld.WALL_BLOCK) || !classicPlotWorld.WALL_BLOCK.equals(classicPlotWorld.CLAIMED_WALL_BLOCK)) {
|
if (!classicPlotWorld.WALL_BLOCK.isAir() || !classicPlotWorld.WALL_BLOCK.equals(classicPlotWorld.CLAIMED_WALL_BLOCK)) {
|
||||||
setWall(plot.getId(), classicPlotWorld.WALL_BLOCK);
|
setWall(plot.getId(), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||||
}
|
}
|
||||||
return GlobalBlockQueue.IMP.addEmptyTask(whenDone);
|
return GlobalBlockQueue.IMP.addEmptyTask(whenDone);
|
||||||
}
|
}
|
||||||
@ -292,15 +293,15 @@ public class ClassicPlotManager extends SquarePlotManager {
|
|||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 0, sz + 1),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 0, sz + 1),
|
||||||
new Location(classicPlotWorld.worldname, ex, 0, ez - 1), BlockUtil.get((short) 7, (byte) 0));
|
new Location(classicPlotWorld.worldname, ex, 0, ez - 1), BlockUtil.get((short) 7, (byte) 0));
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 1, sz + 1),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 1, sz + 1),
|
||||||
new Location(classicPlotWorld.worldname, sx, classicPlotWorld.WALL_HEIGHT, ez - 1), classicPlotWorld.WALL_FILLING);
|
new Location(classicPlotWorld.worldname, sx, classicPlotWorld.WALL_HEIGHT, ez - 1), classicPlotWorld.WALL_FILLING.toPattern());
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.WALL_HEIGHT + 1, sz + 1),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.WALL_HEIGHT + 1, sz + 1),
|
||||||
new Location(classicPlotWorld.worldname, sx, classicPlotWorld.WALL_HEIGHT + 1, ez - 1), classicPlotWorld.WALL_BLOCK);
|
new Location(classicPlotWorld.worldname, sx, classicPlotWorld.WALL_HEIGHT + 1, ez - 1), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, ex, 1, sz + 1),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, ex, 1, sz + 1),
|
||||||
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.WALL_HEIGHT, ez - 1), classicPlotWorld.WALL_FILLING);
|
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.WALL_HEIGHT, ez - 1), classicPlotWorld.WALL_FILLING.toPattern());
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, ex, classicPlotWorld.WALL_HEIGHT + 1, sz + 1),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, ex, classicPlotWorld.WALL_HEIGHT + 1, sz + 1),
|
||||||
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.WALL_HEIGHT + 1, ez - 1), classicPlotWorld.WALL_BLOCK);
|
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.WALL_HEIGHT + 1, ez - 1), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz + 1),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz + 1),
|
||||||
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK);
|
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern());
|
||||||
return queue.enqueue();
|
return queue.enqueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,15 +321,15 @@ public class ClassicPlotManager extends SquarePlotManager {
|
|||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 0, sz),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 0, sz),
|
||||||
new Location(classicPlotWorld.worldname, ex - 1, 0, ez), BlockUtil.get((short) 7, (byte) 0));
|
new Location(classicPlotWorld.worldname, ex - 1, 0, ez), BlockUtil.get((short) 7, (byte) 0));
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz),
|
||||||
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.WALL_HEIGHT, sz), classicPlotWorld.WALL_FILLING);
|
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.WALL_HEIGHT, sz), classicPlotWorld.WALL_FILLING.toPattern());
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, classicPlotWorld.WALL_HEIGHT + 1, sz),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, classicPlotWorld.WALL_HEIGHT + 1, sz),
|
||||||
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.WALL_HEIGHT + 1, sz), classicPlotWorld.WALL_BLOCK);
|
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.WALL_HEIGHT + 1, sz), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, ez),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, ez),
|
||||||
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.WALL_HEIGHT, ez), classicPlotWorld.WALL_FILLING);
|
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.WALL_HEIGHT, ez), classicPlotWorld.WALL_FILLING.toPattern());
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, classicPlotWorld.WALL_HEIGHT + 1, ez),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, classicPlotWorld.WALL_HEIGHT + 1, ez),
|
||||||
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.WALL_HEIGHT + 1, ez), classicPlotWorld.WALL_BLOCK);
|
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.WALL_HEIGHT + 1, ez), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz + 1),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz + 1),
|
||||||
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK);
|
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern());
|
||||||
return queue.enqueue();
|
return queue.enqueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +347,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
|||||||
new Location(classicPlotWorld.worldname, ex - 1, 0, ez - 1),
|
new Location(classicPlotWorld.worldname, ex - 1, 0, ez - 1),
|
||||||
BlockUtil.get((short) 7, (byte) 0));
|
BlockUtil.get((short) 7, (byte) 0));
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz + 1),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz + 1),
|
||||||
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK);
|
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.ROAD_HEIGHT, ez - 1), classicPlotWorld.ROAD_BLOCK.toPattern());
|
||||||
return queue.enqueue();
|
return queue.enqueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -364,9 +365,9 @@ public class ClassicPlotManager extends SquarePlotManager {
|
|||||||
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
||||||
BlockUtil.get((short) 0, (byte) 0));
|
BlockUtil.get((short) 0, (byte) 0));
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 1, sz + 1),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 1, sz + 1),
|
||||||
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.PLOT_HEIGHT - 1, ez - 1), classicPlotWorld.MAIN_BLOCK);
|
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.PLOT_HEIGHT - 1, ez - 1), classicPlotWorld.MAIN_BLOCK.toPattern());
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.PLOT_HEIGHT, sz + 1),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.PLOT_HEIGHT, sz + 1),
|
||||||
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.PLOT_HEIGHT, ez - 1), classicPlotWorld.TOP_BLOCK);
|
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.PLOT_HEIGHT, ez - 1), classicPlotWorld.TOP_BLOCK.toPattern());
|
||||||
return queue.enqueue();
|
return queue.enqueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,9 +385,9 @@ public class ClassicPlotManager extends SquarePlotManager {
|
|||||||
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
||||||
BlockUtil.get((short) 0, (byte) 0));
|
BlockUtil.get((short) 0, (byte) 0));
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, 1, sz),
|
||||||
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.PLOT_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK);
|
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.PLOT_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK.toPattern());
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, classicPlotWorld.PLOT_HEIGHT, sz),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx + 1, classicPlotWorld.PLOT_HEIGHT, sz),
|
||||||
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.PLOT_HEIGHT, ez), classicPlotWorld.TOP_BLOCK);
|
new Location(classicPlotWorld.worldname, ex - 1, classicPlotWorld.PLOT_HEIGHT, ez), classicPlotWorld.TOP_BLOCK.toPattern());
|
||||||
return queue.enqueue();
|
return queue.enqueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,9 +402,9 @@ public class ClassicPlotManager extends SquarePlotManager {
|
|||||||
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.getPlotManager().getWorldHeight(), ez),
|
||||||
BlockUtil.get((short) 0, (byte) 0));
|
BlockUtil.get((short) 0, (byte) 0));
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 1, sz),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, 1, sz),
|
||||||
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.ROAD_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK);
|
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.ROAD_HEIGHT - 1, ez), classicPlotWorld.MAIN_BLOCK.toPattern());
|
||||||
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.ROAD_HEIGHT, sz),
|
queue.setCuboid(new Location(classicPlotWorld.worldname, sx, classicPlotWorld.ROAD_HEIGHT, sz),
|
||||||
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.ROAD_HEIGHT, ez), classicPlotWorld.TOP_BLOCK);
|
new Location(classicPlotWorld.worldname, ex, classicPlotWorld.ROAD_HEIGHT, ez), classicPlotWorld.TOP_BLOCK.toPattern());
|
||||||
return queue.enqueue();
|
return queue.enqueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,26 +414,26 @@ public class ClassicPlotManager extends SquarePlotManager {
|
|||||||
* @return false if part of the merge failed, otherwise true if successful.
|
* @return false if part of the merge failed, otherwise true if successful.
|
||||||
*/
|
*/
|
||||||
@Override public boolean finishPlotMerge(List<PlotId> plotIds) {
|
@Override public boolean finishPlotMerge(List<PlotId> plotIds) {
|
||||||
final Pattern claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
||||||
if (!isAir(claim) || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
|
if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
|
||||||
for (PlotId plotId : plotIds) {
|
for (PlotId plotId : plotIds) {
|
||||||
setWall(plotId, claim);
|
setWall(plotId, claim.toPattern());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Settings.General.MERGE_REPLACE_WALL) {
|
if (Settings.General.MERGE_REPLACE_WALL) {
|
||||||
final Pattern wallBlock = classicPlotWorld.WALL_FILLING;
|
final BlockBucket wallBlock = classicPlotWorld.WALL_FILLING;
|
||||||
for (PlotId id : plotIds) {
|
for (PlotId id : plotIds) {
|
||||||
setWallFilling(id, wallBlock);
|
setWallFilling(id, wallBlock.toPattern());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean finishPlotUnlink(List<PlotId> plotIds) {
|
@Override public boolean finishPlotUnlink(List<PlotId> plotIds) {
|
||||||
final Pattern claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
||||||
if (!isAir(claim) || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
|
if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
|
||||||
for (PlotId id : plotIds) {
|
for (PlotId id : plotIds) {
|
||||||
setWall(id, claim);
|
setWall(id, claim.toPattern());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true; // return false if unlink has been denied
|
return true; // return false if unlink has been denied
|
||||||
@ -447,9 +448,9 @@ public class ClassicPlotManager extends SquarePlotManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean claimPlot(Plot plot) {
|
@Override public boolean claimPlot(Plot plot) {
|
||||||
final Pattern claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
||||||
if (!isAir(claim) || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
|
if (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK)) {
|
||||||
return setWall(plot.getId(), claim);
|
return setWall(plot.getId(), claim.toPattern());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
|||||||
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
|
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.config.Settings;
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.object.BlockBucket;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil;
|
||||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||||
@ -20,17 +21,17 @@ import java.util.Locale;
|
|||||||
public int ROAD_HEIGHT = 62;
|
public int ROAD_HEIGHT = 62;
|
||||||
public int PLOT_HEIGHT = 62;
|
public int PLOT_HEIGHT = 62;
|
||||||
public int WALL_HEIGHT = 62;
|
public int WALL_HEIGHT = 62;
|
||||||
public Pattern MAIN_BLOCK = new BlockPattern(BlockTypes.STONE.getDefaultState());
|
public BlockBucket MAIN_BLOCK = new BlockBucket(BlockTypes.STONE);
|
||||||
// new BlockState[] {BlockUtil.get("stone")};
|
// new BlockState[] {BlockUtil.get("stone")};
|
||||||
public Pattern TOP_BLOCK = new BlockPattern(BlockTypes.GRASS_BLOCK.getDefaultState());
|
public BlockBucket TOP_BLOCK = new BlockBucket(BlockTypes.GRASS_BLOCK);
|
||||||
//new BlockState[] {BlockUtil.get("grass")};
|
//new BlockState[] {BlockUtil.get("grass")};
|
||||||
public Pattern WALL_BLOCK = new BlockPattern(BlockTypes.STONE_SLAB.getDefaultState());
|
public BlockBucket WALL_BLOCK = new BlockBucket(BlockTypes.STONE_SLAB);
|
||||||
// BlockUtil.get((short) 44, (byte) 0);
|
// BlockUtil.get((short) 44, (byte) 0);
|
||||||
public Pattern CLAIMED_WALL_BLOCK = new BlockPattern(BlockTypes.SANDSTONE_SLAB.getDefaultState());
|
public BlockBucket CLAIMED_WALL_BLOCK = new BlockBucket(BlockTypes.SANDSTONE_SLAB);
|
||||||
// BlockUtil.get((short) 44, (byte) 1);
|
// BlockUtil.get((short) 44, (byte) 1);
|
||||||
public Pattern WALL_FILLING = new BlockPattern(BlockTypes.STONE.getDefaultState());
|
public BlockBucket WALL_FILLING = new BlockBucket(BlockTypes.STONE);
|
||||||
//BlockUtil.get((short) 1, (byte) 0);
|
//BlockUtil.get((short) 1, (byte) 0);
|
||||||
public Pattern ROAD_BLOCK = new BlockPattern(BlockTypes.QUARTZ_BLOCK.getDefaultState());
|
public BlockBucket ROAD_BLOCK = new BlockBucket(BlockTypes.QUARTZ_BLOCK);
|
||||||
// BlockUtil.get((short) 155, (byte) 0);
|
// BlockUtil.get((short) 155, (byte) 0);
|
||||||
public boolean PLOT_BEDROCK = true;
|
public boolean PLOT_BEDROCK = true;
|
||||||
|
|
||||||
@ -83,16 +84,16 @@ import java.util.Locale;
|
|||||||
super.loadConfiguration(config);
|
super.loadConfiguration(config);
|
||||||
this.PLOT_BEDROCK = config.getBoolean("plot.bedrock");
|
this.PLOT_BEDROCK = config.getBoolean("plot.bedrock");
|
||||||
this.PLOT_HEIGHT = Math.min(255, config.getInt("plot.height"));
|
this.PLOT_HEIGHT = Math.min(255, config.getInt("plot.height"));
|
||||||
this.MAIN_BLOCK = new BlockPattern(BlockUtil.get(config.getString("plot.filling")));
|
this.MAIN_BLOCK = new BlockBucket(BlockUtil.get(config.getString("plot.filling")));
|
||||||
this.TOP_BLOCK = new BlockPattern(BlockUtil.get(config.getString("plot.floor")));
|
this.TOP_BLOCK = new BlockBucket(BlockUtil.get(config.getString("plot.floor")));
|
||||||
this.WALL_BLOCK = new BlockPattern(BlockUtil.get(config.getString("wall.block")));
|
this.WALL_BLOCK = new BlockBucket(BlockUtil.get(config.getString("wall.block")));
|
||||||
this.ROAD_HEIGHT = Math.min(255, config.getInt("road.height"));
|
this.ROAD_HEIGHT = Math.min(255, config.getInt("road.height"));
|
||||||
this.ROAD_BLOCK = new BlockPattern(BlockUtil.get(config.getString("road.block")));
|
this.ROAD_BLOCK = new BlockBucket(BlockUtil.get(config.getString("road.block")));
|
||||||
this.WALL_FILLING =
|
this.WALL_FILLING =
|
||||||
new BlockPattern(BlockUtil.get(config.getString("wall.filling")));
|
new BlockBucket(BlockUtil.get(config.getString("wall.filling")));
|
||||||
this.WALL_HEIGHT = Math.min(254, config.getInt("wall.height"));
|
this.WALL_HEIGHT = Math.min(254, config.getInt("wall.height"));
|
||||||
this.CLAIMED_WALL_BLOCK =
|
this.CLAIMED_WALL_BLOCK =
|
||||||
new BlockPattern(BlockUtil.get(config.getString("wall.block_claimed")));
|
new BlockBucket(BlockUtil.get(config.getString("wall.block_claimed")));
|
||||||
|
|
||||||
// Dump world settings
|
// Dump world settings
|
||||||
if (Settings.DEBUG) {
|
if (Settings.DEBUG) {
|
||||||
|
@ -96,7 +96,7 @@ public class HybridGen extends IndependentPlotGenerator {
|
|||||||
for (short z = 0; z < 16; z++) {
|
for (short z = 0; z < 16; z++) {
|
||||||
// Road
|
// Road
|
||||||
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
|
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
|
||||||
result.setBlock(x, y, z, hpw.ROAD_BLOCK);
|
result.setBlock(x, y, z, hpw.ROAD_BLOCK.toPattern());
|
||||||
}
|
}
|
||||||
if (hpw.ROAD_SCHEMATIC_ENABLED) {
|
if (hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||||
placeSchem(hpw, result, rx[x], rz[z], x, z, true);
|
placeSchem(hpw, result, rx[x], rz[z], x, z, true);
|
||||||
@ -107,7 +107,7 @@ public class HybridGen extends IndependentPlotGenerator {
|
|||||||
if (gz[z]) {
|
if (gz[z]) {
|
||||||
// road
|
// road
|
||||||
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
|
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
|
||||||
result.setBlock(x, y, z, hpw.ROAD_BLOCK);
|
result.setBlock(x, y, z, hpw.ROAD_BLOCK.toPattern());
|
||||||
}
|
}
|
||||||
if (hpw.ROAD_SCHEMATIC_ENABLED) {
|
if (hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||||
placeSchem(hpw, result, rx[x], rz[z], x, z, true);
|
placeSchem(hpw, result, rx[x], rz[z], x, z, true);
|
||||||
@ -115,10 +115,10 @@ public class HybridGen extends IndependentPlotGenerator {
|
|||||||
} else {
|
} else {
|
||||||
// wall
|
// wall
|
||||||
for (int y = 1; y <= hpw.WALL_HEIGHT; y++) {
|
for (int y = 1; y <= hpw.WALL_HEIGHT; y++) {
|
||||||
result.setBlock(x, y, z, hpw.WALL_FILLING);
|
result.setBlock(x, y, z, hpw.WALL_FILLING.toPattern());
|
||||||
}
|
}
|
||||||
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||||
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK);
|
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK.toPattern());
|
||||||
} else {
|
} else {
|
||||||
placeSchem(hpw, result, rx[x], rz[z], x, z, true);
|
placeSchem(hpw, result, rx[x], rz[z], x, z, true);
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ public class HybridGen extends IndependentPlotGenerator {
|
|||||||
if (gz[z]) {
|
if (gz[z]) {
|
||||||
// road
|
// road
|
||||||
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
|
for (int y = 1; y <= hpw.ROAD_HEIGHT; y++) {
|
||||||
result.setBlock(x, y, z, hpw.ROAD_BLOCK);
|
result.setBlock(x, y, z, hpw.ROAD_BLOCK.toPattern());
|
||||||
}
|
}
|
||||||
if (hpw.ROAD_SCHEMATIC_ENABLED) {
|
if (hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||||
placeSchem(hpw, result, rx[x], rz[z], x, z, true);
|
placeSchem(hpw, result, rx[x], rz[z], x, z, true);
|
||||||
@ -137,19 +137,19 @@ public class HybridGen extends IndependentPlotGenerator {
|
|||||||
} else if (wz[z]) {
|
} else if (wz[z]) {
|
||||||
// wall
|
// wall
|
||||||
for (int y = 1; y <= hpw.WALL_HEIGHT; y++) {
|
for (int y = 1; y <= hpw.WALL_HEIGHT; y++) {
|
||||||
result.setBlock(x, y, z, hpw.WALL_FILLING);
|
result.setBlock(x, y, z, hpw.WALL_FILLING.toPattern());
|
||||||
}
|
}
|
||||||
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
|
||||||
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK);
|
result.setBlock(x, hpw.WALL_HEIGHT + 1, z, hpw.WALL_BLOCK.toPattern());
|
||||||
} else {
|
} else {
|
||||||
placeSchem(hpw, result, rx[x], rz[z], x, z, true);
|
placeSchem(hpw, result, rx[x], rz[z], x, z, true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// plot
|
// plot
|
||||||
for (int y = 1; y < hpw.PLOT_HEIGHT; y++) {
|
for (int y = 1; y < hpw.PLOT_HEIGHT; y++) {
|
||||||
result.setBlock(x, y, z, hpw.MAIN_BLOCK);
|
result.setBlock(x, y, z, hpw.MAIN_BLOCK.toPattern());
|
||||||
}
|
}
|
||||||
result.setBlock(x, hpw.PLOT_HEIGHT, z, hpw.TOP_BLOCK);
|
result.setBlock(x, hpw.PLOT_HEIGHT, z, hpw.TOP_BLOCK.toPattern());
|
||||||
if (hpw.PLOT_SCHEMATIC) {
|
if (hpw.PLOT_SCHEMATIC) {
|
||||||
placeSchem(hpw, result, rx[x], rz[z], x, z, false);
|
placeSchem(hpw, result, rx[x], rz[z], x, z, false);
|
||||||
}
|
}
|
||||||
|
@ -174,8 +174,8 @@ public class HybridPlotManager extends ClassicPlotManager {
|
|||||||
final boolean canRegen =
|
final boolean canRegen =
|
||||||
(hybridPlotWorld.TYPE == 0) && (hybridPlotWorld.TERRAIN == 0) && REGENERATIVE_CLEAR;
|
(hybridPlotWorld.TYPE == 0) && (hybridPlotWorld.TERRAIN == 0) && REGENERATIVE_CLEAR;
|
||||||
// The component blocks
|
// The component blocks
|
||||||
final Pattern plotfloor = hybridPlotWorld.TOP_BLOCK;
|
final Pattern plotfloor = hybridPlotWorld.TOP_BLOCK.toPattern();
|
||||||
final Pattern filling = hybridPlotWorld.MAIN_BLOCK;
|
final Pattern filling = hybridPlotWorld.MAIN_BLOCK.toPattern();
|
||||||
final BlockState bedrock;
|
final BlockState bedrock;
|
||||||
if (hybridPlotWorld.PLOT_BEDROCK) {
|
if (hybridPlotWorld.PLOT_BEDROCK) {
|
||||||
bedrock = BlockUtil.get((short) 7, (byte) 0);
|
bedrock = BlockUtil.get((short) 7, (byte) 0);
|
||||||
|
@ -2,54 +2,56 @@ package com.github.intellectualsites.plotsquared.plot.object;
|
|||||||
|
|
||||||
import com.github.intellectualsites.plotsquared.configuration.serialization.ConfigurationSerializable;
|
import com.github.intellectualsites.plotsquared.configuration.serialization.ConfigurationSerializable;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
|
import com.github.intellectualsites.plotsquared.plot.config.Configuration;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.collection.RandomCollection;
|
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.world.BlockUtil;
|
||||||
|
import com.github.intellectualsites.plotsquared.plot.util.world.PatternUtil;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.sk89q.worldedit.extent.NullExtent;
|
|
||||||
import com.sk89q.worldedit.function.mask.BlockMask;
|
|
||||||
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
import com.sk89q.worldedit.function.pattern.BlockPattern;
|
||||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||||
import com.sk89q.worldedit.function.pattern.RandomPattern;
|
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.regex.Matcher;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A block bucket is a container of block types, where each block
|
* A block bucket is a container of block types, where each block
|
||||||
* has a specified chance of being randomly picked
|
* has a specified chance of being randomly picked
|
||||||
*/
|
*/
|
||||||
@EqualsAndHashCode(of={"blocks"}) @SuppressWarnings({"unused", "WeakerAccess"}) public final class BlockBucket
|
@EqualsAndHashCode(of={"input"}) @SuppressWarnings({"unused", "WeakerAccess"})
|
||||||
implements Iterable<BlockState>, ConfigurationSerializable {
|
public final class BlockBucket implements ConfigurationSerializable {
|
||||||
|
private boolean compiled;
|
||||||
|
|
||||||
private final Random random = new Random();
|
private StringBuilder input;
|
||||||
private final Map<BlockState, Double> blocks;
|
|
||||||
|
|
||||||
private final BucketIterator bucketIterator = new BucketIterator();
|
|
||||||
private boolean compiled, singleItem;
|
|
||||||
private BlockState head;
|
|
||||||
|
|
||||||
private RandomCollection<BlockState> randomBlocks;
|
|
||||||
private BlockState single;
|
private BlockState single;
|
||||||
private Pattern pattern;
|
private Pattern pattern;
|
||||||
private BlockMask mask;
|
|
||||||
|
public BlockBucket(BlockType type) {
|
||||||
|
this(type.getId());
|
||||||
|
this.single = type.getDefaultState();
|
||||||
|
this.pattern = new BlockPattern(this.single);
|
||||||
|
this.compiled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockBucket(BlockState state) {
|
||||||
|
this(state.getAsString());
|
||||||
|
this.single = state;
|
||||||
|
this.pattern = new BlockPattern(this.single);
|
||||||
|
this.compiled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockBucket(String input) {
|
||||||
|
this.input = new StringBuilder(input);
|
||||||
|
}
|
||||||
|
|
||||||
public BlockBucket() {
|
public BlockBucket() {
|
||||||
this.blocks = new HashMap<>();
|
this.input = new StringBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BlockBucket withSingle(@NonNull final BlockState block) {
|
public static BlockBucket withSingle(@NonNull final BlockState block) {
|
||||||
@ -74,158 +76,75 @@ import java.util.stream.Collectors;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addBlock(@NonNull final BlockState block, double chance) {
|
private void addBlock(@NonNull final BlockState block, double chance) {
|
||||||
if (chance == -1)
|
if (chance == -1) chance = 1;
|
||||||
chance = 1;
|
String prefix = input.length() == 0 ? "" : ",";
|
||||||
this.blocks.put(block, chance);
|
input.append(prefix).append(chance + "%" + prefix);
|
||||||
this.compiled = false;
|
this.compiled = false;
|
||||||
if (head == null) {
|
|
||||||
head = block;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEmpty() {
|
public boolean isEmpty() {
|
||||||
return blocks.isEmpty();
|
return input == null || input.length() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private static java.util.regex.Pattern regex = java.util.regex.Pattern.compile("((?<namespace>[A-Za-z_]+):)?(?<block>([A-Za-z_]+(\\[?[\\S\\s]+\\])?))(:(?<chance>[0-9]{1,3}))?");
|
||||||
* Get all blocks that are configured in the bucket
|
|
||||||
*
|
|
||||||
* @return Immutable collection containing all blocks that can
|
|
||||||
* be found in the bucket
|
|
||||||
*/
|
|
||||||
public Collection<BlockState> getBlocks() {
|
|
||||||
this.compile();
|
|
||||||
return Collections.unmodifiableCollection(this.blocks.keySet());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a collection containing a specified amount of randomly selected blocks
|
|
||||||
*
|
|
||||||
* @param count Number of blocks
|
|
||||||
* @return Immutable collection containing randomly selected blocks
|
|
||||||
*/
|
|
||||||
public Collection<BlockState> getBlocks(final int count) {
|
|
||||||
return Arrays.asList(getBlockArray(count));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get an array containing a specified amount of randomly selected blocks
|
|
||||||
*
|
|
||||||
* @param count Number of blocks
|
|
||||||
* @return Immutable collection containing randomly selected blocks
|
|
||||||
*/
|
|
||||||
public BlockState[] getBlockArray(final int count) {
|
|
||||||
final BlockState[] blocks = new BlockState[count];
|
|
||||||
if (this.singleItem) {
|
|
||||||
Arrays.fill(blocks, 0, count, getBlock());
|
|
||||||
} else {
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
blocks[i] = getBlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasSingleItem() {
|
|
||||||
return this.singleItem;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void compile() {
|
public void compile() {
|
||||||
if (isCompiled()) {
|
if (isCompiled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.compiled = true;
|
this.compiled = true;
|
||||||
switch (blocks.size()) {
|
String string = this.input.toString();
|
||||||
case 0:
|
if (string.isEmpty()) {
|
||||||
single = null;
|
this.single = null;
|
||||||
this.randomBlocks = null;
|
|
||||||
this.pattern = null;
|
this.pattern = null;
|
||||||
this.mask = new BlockMask(new NullExtent());
|
return;
|
||||||
break;
|
}
|
||||||
case 1:
|
// Convert legacy format
|
||||||
single = blocks.keySet().iterator().next();
|
boolean legacy = false;
|
||||||
this.randomBlocks = null;
|
String[] blocksStr = string.split(",(?![^\\(\\[]*[\\]\\)])");
|
||||||
|
if (blocksStr.length == 1) {
|
||||||
|
try {
|
||||||
|
this.single = BlockUtil.get(string);
|
||||||
this.pattern = new BlockPattern(single);
|
this.pattern = new BlockPattern(single);
|
||||||
this.mask = new BlockMask(new NullExtent(), single.toBaseBlock());
|
return;
|
||||||
break;
|
} catch (Exception ignore) {}
|
||||||
default:
|
|
||||||
single = null;
|
|
||||||
this.randomBlocks = RandomCollection.of(blocks, random);
|
|
||||||
RandomPattern randomPattern = new RandomPattern();
|
|
||||||
for (Entry<BlockState, Double> entry : this.blocks.entrySet()) {
|
|
||||||
randomPattern.add(new BlockPattern(entry.getKey()), entry.getValue());
|
|
||||||
}
|
}
|
||||||
this.pattern = randomPattern;
|
for (int i = 0; i < blocksStr.length; i++) {
|
||||||
List<BaseBlock> baseBlocks = getBlocks().stream().map(BlockState::toBaseBlock)
|
String entry = blocksStr[i];
|
||||||
.collect(Collectors.toList());
|
Matcher matcher = regex.matcher(entry);
|
||||||
this.mask = new BlockMask(new NullExtent(), baseBlocks);
|
if (matcher.find()) {
|
||||||
break;
|
String chanceStr = matcher.group("chance");
|
||||||
|
if (chanceStr != null && MathMan.isInteger(chanceStr)) {
|
||||||
|
String[] parts = entry.split(":");
|
||||||
|
parts = Arrays.copyOf(parts, parts.length - 1);
|
||||||
|
entry = chanceStr + "%" + StringMan.join(parts, ":");
|
||||||
|
blocksStr[i] = entry;
|
||||||
|
legacy = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@NotNull @Override public Iterator<BlockState> iterator() {
|
if (legacy) {
|
||||||
return this.bucketIterator;
|
string = StringMan.join(blocksStr, ",");
|
||||||
|
}
|
||||||
|
pattern = PatternUtil.parse(null, string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isCompiled() {
|
public boolean isCompiled() {
|
||||||
return this.compiled;
|
return this.compiled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Pattern toPattern() {
|
||||||
* Get a random block out of the bucket
|
|
||||||
*
|
|
||||||
* @return Randomly picked block (cased on specified rates)
|
|
||||||
*/
|
|
||||||
public BlockState getBlock() {
|
|
||||||
if (!isCompiled()) {
|
|
||||||
this.compile();
|
|
||||||
}
|
|
||||||
if (single != null) {
|
|
||||||
return single;
|
|
||||||
}
|
|
||||||
if (randomBlocks != null) {
|
|
||||||
return randomBlocks.next();
|
|
||||||
}
|
|
||||||
return BlockTypes.AIR.getDefaultState();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Pattern getPattern() {
|
|
||||||
this.compile();
|
this.compile();
|
||||||
return this.pattern;
|
return this.pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BlockMask getMask() {
|
|
||||||
this.compile();
|
|
||||||
return this.mask;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public String toString() {
|
@Override public String toString() {
|
||||||
if (!isCompiled()) {
|
return input.toString();
|
||||||
compile();
|
|
||||||
}
|
|
||||||
if (blocks.size() == 1) {
|
|
||||||
return blocks.entrySet().iterator().next().getKey().toString();
|
|
||||||
}
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
|
||||||
Iterator<Entry<BlockState, Double>> iterator = blocks.entrySet().iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Entry<BlockState, Double> entry = iterator.next();
|
|
||||||
BlockState block = entry.getKey();
|
|
||||||
builder.append(block);
|
|
||||||
Double weight = entry.getValue();
|
|
||||||
if (weight != 1) {
|
|
||||||
builder.append(":").append(weight.intValue());
|
|
||||||
}
|
|
||||||
if (iterator.hasNext()) {
|
|
||||||
builder.append(",");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAir() {
|
public boolean isAir() {
|
||||||
compile();
|
compile();
|
||||||
return blocks.isEmpty() || (single != null && single.getBlockType().getMaterial().isAir());
|
return isEmpty() || (single != null && single.getBlockType().getMaterial().isAir());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Map<String, Object> serialize() {
|
@Override public Map<String, Object> serialize() {
|
||||||
@ -249,16 +168,4 @@ import java.util.stream.Collectors;
|
|||||||
return num <= max && num >= min;
|
return num <= max && num >= min;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private final class BucketIterator implements Iterator<BlockState> {
|
|
||||||
|
|
||||||
@Override public boolean hasNext() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public BlockState next() {
|
|
||||||
return getBlock();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,6 @@ import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue
|
|||||||
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
|
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
|
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis;
|
import com.github.intellectualsites.plotsquared.plot.util.expiry.PlotAnalysis;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.world.PatternUtil;
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
@ -1597,7 +1596,7 @@ public class Plot {
|
|||||||
if (parsed != null && parsed.isEmpty()) {
|
if (parsed != null && parsed.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return this.setComponent(component, parsed.getPattern());
|
return this.setComponent(component, parsed.toPattern());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,14 +29,18 @@ public class PatternUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Pattern parse(PlotPlayer plotPlayer, String input) {
|
public static Pattern parse(PlotPlayer plotPlayer, String input) {
|
||||||
Actor actor = plotPlayer.toActor();
|
|
||||||
ParserContext context = new ParserContext();
|
ParserContext context = new ParserContext();
|
||||||
|
if (plotPlayer != null) {
|
||||||
|
Actor actor = plotPlayer.toActor();
|
||||||
context.setActor(actor);
|
context.setActor(actor);
|
||||||
if (actor instanceof Player) {
|
if (actor instanceof Player) {
|
||||||
context.setWorld(((Player) actor).getWorld());
|
context.setWorld(((Player) actor).getWorld());
|
||||||
}
|
}
|
||||||
context.setSession(WorldEdit.getInstance().getSessionManager().get(actor));
|
context.setSession(WorldEdit.getInstance().getSessionManager().get(actor));
|
||||||
context.setRestricted(true);
|
context.setRestricted(true);
|
||||||
|
} else {
|
||||||
|
context.setRestricted(false);
|
||||||
|
}
|
||||||
context.setPreferringWildcard(false);
|
context.setPreferringWildcard(false);
|
||||||
context.setTryLegacy(true);
|
context.setTryLegacy(true);
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user