Use BlockBuckets everywhere.

This commit is contained in:
sauilitired 2018-12-19 17:19:54 +01:00
parent 361cc9e9f7
commit 8f23299e7d
20 changed files with 328 additions and 188 deletions

View File

@ -27,12 +27,12 @@ import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEconHandler;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEventUtil; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitEventUtil;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitHybridUtils; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitHybridUtils;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitInventoryUtil; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitInventoryUtil;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitLegacyMappings;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSchematicHandler; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSchematicHandler;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSetupUtils; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitSetupUtils;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitTaskManager; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitTaskManager;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitVersion; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitVersion;
import com.github.intellectualsites.plotsquared.bukkit.util.LegacyMappings;
import com.github.intellectualsites.plotsquared.bukkit.util.Metrics; import com.github.intellectualsites.plotsquared.bukkit.util.Metrics;
import com.github.intellectualsites.plotsquared.bukkit.util.SendChunk; import com.github.intellectualsites.plotsquared.bukkit.util.SendChunk;
import com.github.intellectualsites.plotsquared.bukkit.util.SetGenCB; import com.github.intellectualsites.plotsquared.bukkit.util.SetGenCB;
@ -71,6 +71,7 @@ import com.github.intellectualsites.plotsquared.plot.util.ConsoleColors;
import com.github.intellectualsites.plotsquared.plot.util.EconHandler; import com.github.intellectualsites.plotsquared.plot.util.EconHandler;
import com.github.intellectualsites.plotsquared.plot.util.EventUtil; import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil; import com.github.intellectualsites.plotsquared.plot.util.InventoryUtil;
import com.github.intellectualsites.plotsquared.plot.util.LegacyMappings;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils; import com.github.intellectualsites.plotsquared.plot.util.ReflectionUtils;
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler; import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
@ -115,7 +116,7 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<Material> { public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
@Getter private static WorldEdit worldEdit; @Getter private static WorldEdit worldEdit;
private static Map<String, Plugin> pluginMap; private static Map<String, Plugin> pluginMap;
@ -202,7 +203,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain<
this.pluginName = getDescription().getName(); this.pluginName = getDescription().getName();
getServer().getName(); getServer().getName();
LegacyMappings.initialize(); PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer);
new PlotSquared(this, "Bukkit"); new PlotSquared(this, "Bukkit");
if (Settings.Enabled_Components.METRICS) { if (Settings.Enabled_Components.METRICS) {

View File

@ -5,7 +5,6 @@ import com.github.intellectualsites.plotsquared.bukkit.object.BukkitLazyBlock;
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer; import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitVersion; import com.github.intellectualsites.plotsquared.bukkit.util.BukkitVersion;
import com.github.intellectualsites.plotsquared.bukkit.util.LegacyMappings;
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.Settings; import com.github.intellectualsites.plotsquared.plot.config.Settings;

View File

@ -12,7 +12,7 @@ import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
public interface IPlotMain<BlockType> extends ILogger { public interface IPlotMain extends ILogger {
/** /**
* Log a message to console. * Log a message to console.
@ -274,7 +274,7 @@ public interface IPlotMain<BlockType> extends ILogger {
List<String> getPluginIds(); List<String> getPluginIds();
BlockRegistry<BlockType> getBlockRegistry(); BlockRegistry<?> getBlockRegistry();
LegacyMappings getLegacyMappings(); LegacyMappings getLegacyMappings();

View File

@ -3,6 +3,7 @@ package com.github.intellectualsites.plotsquared.plot;
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection; import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
import com.github.intellectualsites.plotsquared.configuration.MemorySection; import com.github.intellectualsites.plotsquared.configuration.MemorySection;
import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration; import com.github.intellectualsites.plotsquared.configuration.file.YamlConfiguration;
import com.github.intellectualsites.plotsquared.configuration.serialization.ConfigurationSerialization;
import com.github.intellectualsites.plotsquared.plot.commands.WE_Anywhere; import com.github.intellectualsites.plotsquared.plot.commands.WE_Anywhere;
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.Configuration;
@ -96,6 +97,12 @@ import java.util.zip.ZipInputStream;
this.logger = iPlotMain; this.logger = iPlotMain;
Settings.PLATFORM = platform; Settings.PLATFORM = platform;
//
// Register configuration serializable classes
//
ConfigurationSerialization.registerClass(PlotBlock.class);
ConfigurationSerialization.registerClass(BlockBucket.class);
try { try {
new ReflectionUtils(this.IMP.getNMSPackage()); new ReflectionUtils(this.IMP.getNMSPackage());
try { try {

View File

@ -191,19 +191,19 @@ public class Area extends SubCommand {
break; break;
case "f": case "f":
case "floor": case "floor":
pa.TOP_BLOCK = Configuration.BLOCKLIST.parseString(pair[1]); pa.TOP_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]);
break; break;
case "m": case "m":
case "main": case "main":
pa.MAIN_BLOCK = Configuration.BLOCKLIST.parseString(pair[1]); pa.MAIN_BLOCK = Configuration.BLOCK_BUCKET.parseString(pair[1]);
break; break;
case "w": case "w":
case "wall": case "wall":
pa.WALL_FILLING = Configuration.BLOCK.parseString(pair[1]); pa.WALL_FILLING = Configuration.BLOCK_BUCKET.parseString(pair[1]);
break; break;
case "b": case "b":
case "border": case "border":
pa.WALL_BLOCK = Configuration.BLOCK.parseString(pair[1]); 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]);

View File

@ -4,6 +4,7 @@ import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
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.Configuration;
import com.github.intellectualsites.plotsquared.plot.config.Configuration.UnknownBlockException;
import com.github.intellectualsites.plotsquared.plot.flag.Flag; import com.github.intellectualsites.plotsquared.plot.flag.Flag;
import com.github.intellectualsites.plotsquared.plot.flag.FlagManager; import com.github.intellectualsites.plotsquared.plot.flag.FlagManager;
import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.flag.Flags;
@ -49,46 +50,37 @@ public class Set extends SubCommand {
C.PERMISSION_SET_COMPONENT.f(component)); C.PERMISSION_SET_COMPONENT.f(component));
return false; return false;
} }
PlotBlock[] blocks; // PlotBlock[] blocks;
BlockBucket bucket;
try { try {
if (args.length < 2) { if (args.length < 2) {
MainUtil.sendMessage(player, C.NEED_BLOCK); MainUtil.sendMessage(player, C.NEED_BLOCK);
return true; return true;
} }
String[] split = material.split(","); String[] split = material.split(",");
blocks = Configuration.BLOCKLIST.parseString(material); // blocks = Configuration.BLOCKLIST.parseString(material);
for (int i = 0; i < blocks.length; i++) {
PlotBlock block = blocks[i]; try {
if (block == null) { bucket = Configuration.BLOCK_BUCKET.parseString(material);
MainUtil.sendMessage(player, C.NOT_VALID_BLOCK, split[i]); } catch (final UnknownBlockException unknownBlockException) {
String name; final String unknownBlock = unknownBlockException.getUnknownValue();
if (split[i].contains("%")) { C.NOT_VALID_BLOCK.send(player, unknownBlock);
name = split[i].split("%")[1]; StringComparison<PlotBlock>.ComparisonResult match =
} else { WorldUtil.IMP.getClosestBlock(unknownBlock);
name = split[i]; if (match != null) {
final String found = WorldUtil.IMP.getClosestMatchingName(match.best);
if (found != null) {
MainUtil.sendMessage(player, C.DID_YOU_MEAN,
found.toLowerCase());
} }
StringComparison<PlotBlock>.ComparisonResult match =
WorldUtil.IMP.getClosestBlock(name);
if (match != null) {
name = WorldUtil.IMP.getClosestMatchingName(match.best);
if (name != null) {
MainUtil.sendMessage(player, C.DID_YOU_MEAN,
name.toLowerCase());
}
}
return false;
} else if (!allowUnsafe && (!block.isAir() && !WorldUtil.IMP
.isBlockSolid(block))) {
MainUtil
.sendMessage(player, C.NOT_ALLOWED_BLOCK, block.toString());
return false;
} }
return false;
} }
if (!allowUnsafe) { if (!allowUnsafe) {
for (PlotBlock block : blocks) { for (final PlotBlock block : bucket.getBlocks()) {
if (!block.isAir() && !WorldUtil.IMP.isBlockSolid(block)) { if (!block.isAir() && !WorldUtil.IMP.isBlockSolid(block)) {
MainUtil.sendMessage(player, C.NOT_ALLOWED_BLOCK, C.NOT_ALLOWED_BLOCK.send(player, block.toString());
block.toString());
return false; return false;
} }
} }
@ -103,7 +95,7 @@ public class Set extends SubCommand {
} }
plot.addRunning(); plot.addRunning();
for (Plot current : plot.getConnectedPlots()) { for (Plot current : plot.getConnectedPlots()) {
current.setComponent(component, blocks); current.setComponent(component, bucket);
} }
MainUtil.sendMessage(player, C.GENERATING_COMPONENT); MainUtil.sendMessage(player, C.GENERATING_COMPONENT);
GlobalBlockQueue.IMP.addTask(new Runnable() { GlobalBlockQueue.IMP.addTask(new Runnable() {

View File

@ -1,10 +1,13 @@
package com.github.intellectualsites.plotsquared.plot.config; package com.github.intellectualsites.plotsquared.plot.config;
import com.github.intellectualsites.plotsquared.plot.object.BlockBucket;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
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 java.util.ArrayList; import java.util.ArrayList;
import lombok.Getter;
import lombok.NonNull;
/** /**
* Main Configuration Utility * Main Configuration Utility
@ -101,6 +104,87 @@ public class Configuration {
return value.best; return value.best;
} }
}; };
public static final class UnknownBlockException extends IllegalArgumentException {
@Getter
private final String unknownValue;
public UnknownBlockException(@NonNull final String unknownValue) {
super(String.format("\"%s\" is not a valid block", unknownValue));
this.unknownValue = unknownValue;
}
}
public static final SettingValue<BlockBucket> BLOCK_BUCKET =
new SettingValue<BlockBucket>("BLOCK_BUCKET") {
@Override
public BlockBucket parseString(final String string) {
if (string == null || string.isEmpty()) {
return new BlockBucket();
}
final BlockBucket blockBucket = new BlockBucket();
final String[] parts = string.split(",");
for (final String part : parts) {
String block;
int chance = -1;
if (part.contains(":")) {
final String[] innerParts = part.split(":");
if (innerParts.length > 1) {
chance = Integer.parseInt(innerParts[1]);
}
block = innerParts[0];
} else {
block = part;
}
final StringComparison<PlotBlock>.ComparisonResult value =
WorldUtil.IMP.getClosestBlock(block);
if (value == null) {
throw new UnknownBlockException(block);
}
blockBucket.addBlock(value.best, chance);
}
blockBucket.compile(); // Pre-compile :D
return blockBucket;
}
@Override
public boolean validateValue(final String string) {
try {
if (string == null || string.isEmpty()) {
return false;
}
final String[] parts = string.split(",");
for (final String part : parts) {
String block;
if (part.contains(":")) {
final String[] innerParts = part.split(":");
if (innerParts.length > 1) {
final int chance = Integer.parseInt(innerParts[1]);
if (chance < 1 || chance > 100) {
return false;
}
}
block = innerParts[0];
} else {
block = part;
}
StringComparison<PlotBlock>.ComparisonResult value =
WorldUtil.IMP.getClosestBlock(block);
if (value == null || value.match > 1) {
return false;
}
}
} catch (final Throwable exception) {
return false;
}
return true;
}
};
public static final SettingValue<PlotBlock[]> BLOCKLIST = public static final SettingValue<PlotBlock[]> BLOCKLIST =
new SettingValue<PlotBlock[]>("BLOCKLIST") { new SettingValue<PlotBlock[]>("BLOCKLIST") {
@Override public boolean validateValue(String string) { @Override public boolean validateValue(String string) {

View File

@ -13,7 +13,7 @@ import java.util.ArrayList;
public class ClassicPlotManager extends SquarePlotManager { public class ClassicPlotManager extends SquarePlotManager {
@Override public boolean setComponent(PlotArea plotArea, PlotId plotId, String component, @Override public boolean setComponent(PlotArea plotArea, PlotId plotId, String component,
PlotBlock[] blocks) { BlockBucket blocks) {
switch (component) { switch (component) {
case "floor": case "floor":
setFloor(plotArea, plotId, blocks); setFloor(plotArea, plotId, blocks);
@ -45,15 +45,13 @@ public class ClassicPlotManager extends SquarePlotManager {
@Override public boolean unclaimPlot(PlotArea plotArea, Plot plot, Runnable whenDone) { @Override public boolean unclaimPlot(PlotArea plotArea, Plot plot, Runnable whenDone) {
ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea; ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea;
setWallFilling(dpw, plot.getId(), new PlotBlock[] {dpw.WALL_FILLING}); setWallFilling(dpw, plot.getId(), dpw.WALL_FILLING);
if (!dpw.WALL_BLOCK.isAir() || !dpw.WALL_BLOCK.equals(dpw.CLAIMED_WALL_BLOCK)) { setWall(dpw, plot.getId(), dpw.WALL_BLOCK);
setWall(dpw, plot.getId(), new PlotBlock[] {dpw.WALL_BLOCK});
}
GlobalBlockQueue.IMP.addTask(whenDone); GlobalBlockQueue.IMP.addTask(whenDone);
return true; return true;
} }
public boolean setFloor(PlotArea plotArea, PlotId plotId, PlotBlock[] blocks) { public boolean setFloor(PlotArea plotArea, PlotId plotId, BlockBucket blocks) {
Plot plot = plotArea.getPlotAbs(plotId); Plot plot = plotArea.getPlotAbs(plotId);
LocalBlockQueue queue = plotArea.getQueue(false); LocalBlockQueue queue = plotArea.getQueue(false);
if (plot.isBasePlot()) { if (plot.isBasePlot()) {
@ -70,7 +68,7 @@ public class ClassicPlotManager extends SquarePlotManager {
return true; return true;
} }
public boolean setAll(PlotArea plotArea, PlotId plotId, PlotBlock[] blocks) { public boolean setAll(PlotArea plotArea, PlotId plotId, BlockBucket blocks) {
Plot plot = plotArea.getPlotAbs(plotId); Plot plot = plotArea.getPlotAbs(plotId);
if (!plot.isBasePlot()) { if (!plot.isBasePlot()) {
return false; return false;
@ -86,7 +84,7 @@ public class ClassicPlotManager extends SquarePlotManager {
return true; return true;
} }
public boolean setAir(PlotArea plotArea, PlotId plotId, PlotBlock[] blocks) { public boolean setAir(PlotArea plotArea, PlotId plotId, BlockBucket blocks) {
Plot plot = plotArea.getPlotAbs(plotId); Plot plot = plotArea.getPlotAbs(plotId);
if (!plot.isBasePlot()) { if (!plot.isBasePlot()) {
return false; return false;
@ -104,7 +102,7 @@ public class ClassicPlotManager extends SquarePlotManager {
return true; return true;
} }
public boolean setMain(PlotArea plotArea, PlotId plotId, PlotBlock[] blocks) { public boolean setMain(PlotArea plotArea, PlotId plotId, BlockBucket blocks) {
Plot plot = plotArea.getPlotAbs(plotId); Plot plot = plotArea.getPlotAbs(plotId);
if (!plot.isBasePlot()) { if (!plot.isBasePlot()) {
return false; return false;
@ -121,7 +119,7 @@ public class ClassicPlotManager extends SquarePlotManager {
return true; return true;
} }
public boolean setMiddle(PlotArea plotArea, PlotId plotId, PlotBlock[] blocks) { public boolean setMiddle(PlotArea plotArea, PlotId plotId, BlockBucket blocks) {
Plot plot = plotArea.getPlotAbs(plotId); Plot plot = plotArea.getPlotAbs(plotId);
if (!plot.isBasePlot()) { if (!plot.isBasePlot()) {
return false; return false;
@ -132,12 +130,12 @@ public class ClassicPlotManager extends SquarePlotManager {
int x = MathMan.average(corners[0].getX(), corners[1].getX()); int x = MathMan.average(corners[0].getX(), corners[1].getX());
int z = MathMan.average(corners[0].getZ(), corners[1].getZ()); int z = MathMan.average(corners[0].getZ(), corners[1].getZ());
queue.setBlock(x, dpw.PLOT_HEIGHT, z, blocks[0]); queue.setBlock(x, dpw.PLOT_HEIGHT, z, blocks.getBlock());
queue.enqueue(); queue.enqueue();
return true; return true;
} }
public boolean setOutline(PlotArea plotArea, PlotId plotId, PlotBlock[] blocks) { public boolean setOutline(PlotArea plotArea, PlotId plotId, BlockBucket blocks) {
ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea; ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea;
if (dpw.ROAD_WIDTH == 0) { if (dpw.ROAD_WIDTH == 0) {
return false; return false;
@ -145,14 +143,13 @@ public class ClassicPlotManager extends SquarePlotManager {
Plot plot = plotArea.getPlotAbs(plotId); Plot plot = plotArea.getPlotAbs(plotId);
Location bottom = plot.getBottomAbs(); Location bottom = plot.getBottomAbs();
Location top = plot.getExtendedTopAbs(); Location top = plot.getExtendedTopAbs();
PseudoRandom random = new PseudoRandom();
LocalBlockQueue queue = plotArea.getQueue(false); LocalBlockQueue queue = plotArea.getQueue(false);
int maxY = plotArea.getPlotManager().getWorldHeight(); int maxY = plotArea.getPlotManager().getWorldHeight();
if (!plot.getMerged(0)) { if (!plot.getMerged(0)) {
int z = bottom.getZ(); int z = bottom.getZ();
for (int x = bottom.getX(); x <= top.getX(); x++) { for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int y = dpw.PLOT_HEIGHT; y <= maxY; y++) { for (int y = dpw.PLOT_HEIGHT; y <= maxY; y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
} }
@ -160,7 +157,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int x = bottom.getX(); int x = bottom.getX();
for (int z = bottom.getZ(); z <= top.getZ(); z++) { for (int z = bottom.getZ(); z <= top.getZ(); z++) {
for (int y = dpw.PLOT_HEIGHT; y <= maxY; y++) { for (int y = dpw.PLOT_HEIGHT; y <= maxY; y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
} }
@ -169,7 +166,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int z = top.getZ(); int z = top.getZ();
for (int x = bottom.getX(); x <= top.getX(); x++) { for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int y = dpw.PLOT_HEIGHT; y <= maxY; y++) { for (int y = dpw.PLOT_HEIGHT; y <= maxY; y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
} }
@ -177,7 +174,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int x = top.getX(); int x = top.getX();
for (int z = bottom.getZ(); z <= top.getZ(); z++) { for (int z = bottom.getZ(); z <= top.getZ(); z++) {
for (int y = dpw.PLOT_HEIGHT; y <= maxY; y++) { for (int y = dpw.PLOT_HEIGHT; y <= maxY; y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
} }
@ -192,7 +189,7 @@ public class ClassicPlotManager extends SquarePlotManager {
return true; return true;
} }
public boolean setWallFilling(PlotArea plotArea, PlotId plotId, PlotBlock[] blocks) { public boolean setWallFilling(PlotArea plotArea, PlotId plotId, BlockBucket blocks) {
ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea; ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea;
if (dpw.ROAD_WIDTH == 0) { if (dpw.ROAD_WIDTH == 0) {
return false; return false;
@ -201,13 +198,12 @@ public class ClassicPlotManager extends SquarePlotManager {
Location bot = plot.getExtendedBottomAbs() Location bot = plot.getExtendedBottomAbs()
.subtract(plot.getMerged(3) ? 0 : 1, 0, plot.getMerged(0) ? 0 : 1); .subtract(plot.getMerged(3) ? 0 : 1, 0, plot.getMerged(0) ? 0 : 1);
Location top = plot.getExtendedTopAbs().add(1, 0, 1); Location top = plot.getExtendedTopAbs().add(1, 0, 1);
PseudoRandom random = new PseudoRandom();
LocalBlockQueue queue = plotArea.getQueue(false); LocalBlockQueue queue = plotArea.getQueue(false);
if (!plot.getMerged(0)) { if (!plot.getMerged(0)) {
int z = bot.getZ(); int z = bot.getZ();
for (int x = bot.getX(); x < top.getX(); x++) { for (int x = bot.getX(); x < top.getX(); x++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
} }
@ -215,7 +211,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int x = bot.getX(); int x = bot.getX();
for (int z = bot.getZ(); z < top.getZ(); z++) { for (int z = bot.getZ(); z < top.getZ(); z++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
} }
@ -223,7 +219,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int z = top.getZ(); int z = top.getZ();
for (int x = bot.getX(); x < top.getX() + (plot.getMerged(1) ? 0 : 1); x++) { for (int x = bot.getX(); x < top.getX() + (plot.getMerged(1) ? 0 : 1); x++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
} }
@ -231,7 +227,7 @@ public class ClassicPlotManager extends SquarePlotManager {
int x = top.getX(); int x = top.getX();
for (int z = bot.getZ(); z < top.getZ() + (plot.getMerged(2) ? 0 : 1); z++) { for (int z = bot.getZ(); z < top.getZ() + (plot.getMerged(2) ? 0 : 1); z++) {
for (int y = 1; y <= dpw.WALL_HEIGHT; y++) { for (int y = 1; y <= dpw.WALL_HEIGHT; y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
} }
@ -239,7 +235,7 @@ public class ClassicPlotManager extends SquarePlotManager {
return true; return true;
} }
public boolean setWall(PlotArea plotArea, PlotId plotId, PlotBlock[] blocks) { public boolean setWall(PlotArea plotArea, PlotId plotId, BlockBucket blocks) {
ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea; ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea;
if (dpw.ROAD_WIDTH == 0) { if (dpw.ROAD_WIDTH == 0) {
return false; return false;
@ -254,25 +250,25 @@ public class ClassicPlotManager extends SquarePlotManager {
if (!plot.getMerged(0)) { if (!plot.getMerged(0)) {
int z = bot.getZ(); int z = bot.getZ();
for (int x = bot.getX(); x < top.getX(); x++) { for (int x = bot.getX(); x < top.getX(); x++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
if (!plot.getMerged(3)) { if (!plot.getMerged(3)) {
int x = bot.getX(); int x = bot.getX();
for (int z = bot.getZ(); z < top.getZ(); z++) { for (int z = bot.getZ(); z < top.getZ(); z++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
if (!plot.getMerged(2)) { if (!plot.getMerged(2)) {
int z = top.getZ(); int z = top.getZ();
for (int x = bot.getX(); x < top.getX() + (plot.getMerged(1) ? 0 : 1); x++) { for (int x = bot.getX(); x < top.getX() + (plot.getMerged(1) ? 0 : 1); x++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
if (!plot.getMerged(1)) { if (!plot.getMerged(1)) {
int x = top.getX(); int x = top.getX();
for (int z = bot.getZ(); z < top.getZ() + (plot.getMerged(2) ? 0 : 1); z++) { for (int z = bot.getZ(); z < top.getZ() + (plot.getMerged(2) ? 0 : 1); z++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]); queue.setBlock(x, y, z, blocks.getBlock());
} }
} }
queue.enqueue(); queue.enqueue();
@ -429,24 +425,14 @@ public class ClassicPlotManager extends SquarePlotManager {
* Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED). * Finishing off plot merging by adding in the walls surrounding the plot (OPTIONAL)(UNFINISHED).
*/ */
@Override public boolean finishPlotMerge(PlotArea plotArea, ArrayList<PlotId> plotIds) { @Override public boolean finishPlotMerge(PlotArea plotArea, ArrayList<PlotId> plotIds) {
PlotBlock block = ((ClassicPlotWorld) plotArea).CLAIMED_WALL_BLOCK; final BlockBucket block = ((ClassicPlotWorld) plotArea).CLAIMED_WALL_BLOCK;
PlotBlock unclaim = ((ClassicPlotWorld) plotArea).WALL_BLOCK; plotIds.forEach(id -> setWall(plotArea, id, block));
if (!block.isAir() || !block.equals(unclaim)) {
for (PlotId id : plotIds) {
setWall(plotArea, id, new PlotBlock[] {block});
}
}
return true; return true;
} }
@Override public boolean finishPlotUnlink(PlotArea plotArea, ArrayList<PlotId> plotIds) { @Override public boolean finishPlotUnlink(PlotArea plotArea, ArrayList<PlotId> plotIds) {
PlotBlock block = ((ClassicPlotWorld) plotArea).CLAIMED_WALL_BLOCK; final BlockBucket block = ((ClassicPlotWorld) plotArea).CLAIMED_WALL_BLOCK;
PlotBlock unclaim = ((ClassicPlotWorld) plotArea).WALL_BLOCK; plotIds.forEach(id -> setWall(plotArea, id, block));
for (PlotId id : plotIds) {
if (block.isAir() || !block.equals(unclaim)) {
setWall(plotArea, id, new PlotBlock[] {block});
}
}
return true; return true;
} }
@ -459,11 +445,8 @@ public class ClassicPlotManager extends SquarePlotManager {
} }
@Override public boolean claimPlot(PlotArea plotArea, Plot plot) { @Override public boolean claimPlot(PlotArea plotArea, Plot plot) {
PlotBlock unclaim = ((ClassicPlotWorld) plotArea).WALL_BLOCK; final BlockBucket claim = ((ClassicPlotWorld) plotArea).CLAIMED_WALL_BLOCK;
PlotBlock claim = ((ClassicPlotWorld) plotArea).CLAIMED_WALL_BLOCK; setWall(plotArea, plot.getId(), claim);
if (!claim.isAir() || !claim.equals(unclaim)) {
setWall(plotArea, plot.getId(), new PlotBlock[] {claim});
}
return true; return true;
} }

View File

@ -3,6 +3,7 @@ package com.github.intellectualsites.plotsquared.plot.generator;
import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection; import com.github.intellectualsites.plotsquared.configuration.ConfigurationSection;
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.object.BlockBucket;
import com.github.intellectualsites.plotsquared.plot.object.PlotBlock; import com.github.intellectualsites.plotsquared.plot.object.PlotBlock;
import com.github.intellectualsites.plotsquared.plot.object.PlotId; import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import com.github.intellectualsites.plotsquared.plot.util.StringMan; import com.github.intellectualsites.plotsquared.plot.util.StringMan;
@ -12,12 +13,12 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
public int ROAD_HEIGHT = 64; public int ROAD_HEIGHT = 64;
public int PLOT_HEIGHT = 64; public int PLOT_HEIGHT = 64;
public int WALL_HEIGHT = 64; public int WALL_HEIGHT = 64;
public PlotBlock[] MAIN_BLOCK = new PlotBlock[] {PlotBlock.get("stone")}; public BlockBucket MAIN_BLOCK = BlockBucket.withSingle(PlotBlock.get("stone")); // new PlotBlock[] {PlotBlock.get("stone")};
public PlotBlock[] TOP_BLOCK = new PlotBlock[] {PlotBlock.get("grass")}; public BlockBucket TOP_BLOCK = BlockBucket.withSingle(PlotBlock.get("grass")); //new PlotBlock[] {PlotBlock.get("grass")};
public PlotBlock WALL_BLOCK = PlotBlock.get((short) 44, (byte) 0); public BlockBucket WALL_BLOCK = BlockBucket.withSingle(PlotBlock.get("stone_slab")); // PlotBlock.get((short) 44, (byte) 0);
public PlotBlock CLAIMED_WALL_BLOCK = PlotBlock.get((short) 44, (byte) 1); public BlockBucket CLAIMED_WALL_BLOCK = BlockBucket.withSingle(PlotBlock.get("sandstone_slab")); // PlotBlock.get((short) 44, (byte) 1);
public PlotBlock WALL_FILLING = PlotBlock.get((short) 1, (byte) 0); public BlockBucket WALL_FILLING = BlockBucket.withSingle(PlotBlock.get("stone")); //PlotBlock.get((short) 1, (byte) 0);
public PlotBlock ROAD_BLOCK = PlotBlock.get((short) 155, (byte) 0); public BlockBucket ROAD_BLOCK = BlockBucket.withSingle(PlotBlock.get("quartz_block")); // PlotBlock.get((short) 155, (byte) 0);
public boolean PLOT_BEDROCK = true; public boolean PLOT_BEDROCK = true;
public ClassicPlotWorld(String worldName, String id, IndependentPlotGenerator generator, public ClassicPlotWorld(String worldName, String id, IndependentPlotGenerator generator,
@ -39,22 +40,22 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
new ConfigurationNode("plot.size", this.PLOT_WIDTH, "Plot width", new ConfigurationNode("plot.size", this.PLOT_WIDTH, "Plot width",
Configuration.INTEGER), Configuration.INTEGER),
new ConfigurationNode("plot.filling", this.MAIN_BLOCK, "Plot block", new ConfigurationNode("plot.filling", this.MAIN_BLOCK, "Plot block",
Configuration.BLOCKLIST), Configuration.BLOCK_BUCKET),
new ConfigurationNode("plot.floor", this.TOP_BLOCK, "Plot floor block", new ConfigurationNode("plot.floor", this.TOP_BLOCK, "Plot floor block",
Configuration.BLOCKLIST), Configuration.BLOCK_BUCKET),
new ConfigurationNode("wall.block", this.WALL_BLOCK, "Top wall block", new ConfigurationNode("wall.block", this.WALL_BLOCK, "Top wall block",
Configuration.BLOCK), Configuration.BLOCK_BUCKET),
new ConfigurationNode("wall.block_claimed", this.CLAIMED_WALL_BLOCK, new ConfigurationNode("wall.block_claimed", this.CLAIMED_WALL_BLOCK,
"Wall block (claimed)", "Wall block (claimed)",
Configuration.BLOCK), Configuration.BLOCK_BUCKET),
new ConfigurationNode("road.width", this.ROAD_WIDTH, "Road width", new ConfigurationNode("road.width", this.ROAD_WIDTH, "Road width",
Configuration.INTEGER), Configuration.INTEGER),
new ConfigurationNode("road.height", this.ROAD_HEIGHT, "Road height", new ConfigurationNode("road.height", this.ROAD_HEIGHT, "Road height",
Configuration.INTEGER), Configuration.INTEGER),
new ConfigurationNode("road.block", this.ROAD_BLOCK, "Road block", new ConfigurationNode("road.block", this.ROAD_BLOCK, "Road block",
Configuration.BLOCK), Configuration.BLOCK_BUCKET),
new ConfigurationNode("wall.filling", this.WALL_FILLING, "Wall filling block", new ConfigurationNode("wall.filling", this.WALL_FILLING, "Wall filling block",
Configuration.BLOCK), Configuration.BLOCK_BUCKET),
new ConfigurationNode("wall.height", this.WALL_HEIGHT, "Wall height", new ConfigurationNode("wall.height", this.WALL_HEIGHT, "Wall height",
Configuration.INTEGER), Configuration.INTEGER),
new ConfigurationNode("plot.bedrock", this.PLOT_BEDROCK, "Plot bedrock generation", new ConfigurationNode("plot.bedrock", this.PLOT_BEDROCK, "Plot bedrock generation",
@ -69,16 +70,16 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld {
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 = Configuration.BLOCKLIST this.MAIN_BLOCK = Configuration.BLOCK_BUCKET
.parseString(StringMan.join(config.getStringList("plot.filling"), ',')); .parseString(StringMan.join(config.getStringList("plot.filling"), ','));
this.TOP_BLOCK = Configuration.BLOCKLIST this.TOP_BLOCK = Configuration.BLOCK_BUCKET
.parseString(StringMan.join(config.getStringList("plot.floor"), ',')); .parseString(StringMan.join(config.getStringList("plot.floor"), ','));
this.WALL_BLOCK = Configuration.BLOCK.parseString(config.getString("wall.block")); this.WALL_BLOCK = Configuration.BLOCK_BUCKET.parseString(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 = Configuration.BLOCK.parseString(config.getString("road.block")); this.ROAD_BLOCK = Configuration.BLOCK_BUCKET.parseString(config.getString("road.block"));
this.WALL_FILLING = Configuration.BLOCK.parseString(config.getString("wall.filling")); this.WALL_FILLING = Configuration.BLOCK_BUCKET.parseString(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 =
Configuration.BLOCK.parseString(config.getString("wall.block_claimed")); Configuration.BLOCK_BUCKET.parseString(config.getString("wall.block_claimed"));
} }
} }

View File

@ -98,7 +98,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.getBlock());
} }
if (hpw.ROAD_SCHEMATIC_ENABLED) { if (hpw.ROAD_SCHEMATIC_ENABLED) {
placeSchem(hpw, result, rx[x], rz[z], x, z); placeSchem(hpw, result, rx[x], rz[z], x, z);
@ -109,7 +109,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.getBlock());
} }
if (hpw.ROAD_SCHEMATIC_ENABLED) { if (hpw.ROAD_SCHEMATIC_ENABLED) {
placeSchem(hpw, result, rx[x], rz[z], x, z); placeSchem(hpw, result, rx[x], rz[z], x, z);
@ -117,10 +117,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.getBlock());
} }
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.getBlock());
} else { } else {
placeSchem(hpw, result, rx[x], rz[z], x, z); placeSchem(hpw, result, rx[x], rz[z], x, z);
} }
@ -131,7 +131,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.getBlock());
} }
if (hpw.ROAD_SCHEMATIC_ENABLED) { if (hpw.ROAD_SCHEMATIC_ENABLED) {
placeSchem(hpw, result, rx[x], rz[z], x, z); placeSchem(hpw, result, rx[x], rz[z], x, z);
@ -139,10 +139,10 @@ 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.getBlock());
} }
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.getBlock());
} else { } else {
placeSchem(hpw, result, rx[x], rz[z], x, z); placeSchem(hpw, result, rx[x], rz[z], x, z);
} }
@ -150,10 +150,10 @@ public class HybridGen extends IndependentPlotGenerator {
// 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, result.setBlock(x, y, z,
hpw.MAIN_BLOCK[random.random(hpw.MAIN_BLOCK.length)]); hpw.MAIN_BLOCK.getBlock());
} }
result.setBlock(x, hpw.PLOT_HEIGHT, z, result.setBlock(x, hpw.PLOT_HEIGHT, z,
hpw.TOP_BLOCK[random.random(hpw.TOP_BLOCK.length)]); hpw.TOP_BLOCK.getBlock());
if (hpw.PLOT_SCHEMATIC) { if (hpw.PLOT_SCHEMATIC) {
placeSchem(hpw, result, rx[x], rz[z], x, z); placeSchem(hpw, result, rx[x], rz[z], x, z);
} }

View File

@ -157,8 +157,8 @@ public class HybridPlotManager extends ClassicPlotManager {
final boolean canRegen = final boolean canRegen =
(plotArea.TYPE == 0) && (plotArea.TERRAIN == 0) && REGENERATIVE_CLEAR; (plotArea.TYPE == 0) && (plotArea.TERRAIN == 0) && REGENERATIVE_CLEAR;
// The component blocks // The component blocks
final PlotBlock[] plotfloor = dpw.TOP_BLOCK; final BlockBucket plotfloor = dpw.TOP_BLOCK;
final PlotBlock[] filling = dpw.MAIN_BLOCK; final BlockBucket filling = dpw.MAIN_BLOCK;
final PlotBlock bedrock; final PlotBlock bedrock;
if (dpw.PLOT_BEDROCK) { if (dpw.PLOT_BEDROCK) {
bedrock = PlotBlock.get((short) 7, (byte) 0); bedrock = PlotBlock.get((short) 7, (byte) 0);

View File

@ -277,7 +277,7 @@ public class HybridPlotWorld extends ClassicPlotWorld {
} }
this.ROAD_SCHEMATIC_ENABLED = true; this.ROAD_SCHEMATIC_ENABLED = true;
// Do not populate road if using schematic population // Do not populate road if using schematic population
this.ROAD_BLOCK = PlotBlock.getEmptyData(this.ROAD_BLOCK); // PlotBlock.get(this.ROAD_BLOCK.id, (byte) 0); // TODO: What? this.ROAD_BLOCK = BlockBucket.empty(); // PlotBlock.getEmptyData(this.ROAD_BLOCK); // PlotBlock.get(this.ROAD_BLOCK.id, (byte) 0);
short[] ids1 = schematic1.getIds(); short[] ids1 = schematic1.getIds();
byte[] datas1 = schematic1.getDatas(); byte[] datas1 = schematic1.getDatas();

View File

@ -123,63 +123,6 @@ public abstract class HybridUtils {
return chunks; return chunks;
} }
/**
* Checks all connected plots.
*
* @param plot
* @param whenDone
*/
public void checkModified(final Plot plot, final RunnableVal<Integer> whenDone) {
if (whenDone == null) {
return;
}
PlotArea plotArea = plot.getArea();
if (!(plotArea instanceof ClassicPlotWorld)) {
whenDone.value = -1;
TaskManager.runTask(whenDone);
return;
}
whenDone.value = 0;
final ClassicPlotWorld cpw = (ClassicPlotWorld) plotArea;
final ArrayDeque<RegionWrapper> zones = new ArrayDeque<>(plot.getRegions());
final LocalBlockQueue queue = GlobalBlockQueue.IMP.getNewQueue(cpw.worldname, false);
Runnable run = new Runnable() {
@Override public void run() {
if (zones.isEmpty()) {
TaskManager.runTask(whenDone);
return;
}
RegionWrapper region = zones.poll();
Location pos1 =
new Location(plot.getWorldName(), region.minX, region.minY, region.minZ);
Location pos2 =
new Location(plot.getWorldName(), region.maxX, region.maxY, region.maxZ);
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
@Override public void run(int[] value) {
ChunkLoc loc = new ChunkLoc(value[0], value[1]);
ChunkManager.manager.loadChunk(plot.getWorldName(), loc, false);
int bx = value[2];
int bz = value[3];
int ex = value[4];
int ez = value[5];
whenDone.value +=
checkModified(queue, bx, ex, 1, cpw.PLOT_HEIGHT - 1, bz, ez,
cpw.MAIN_BLOCK);
whenDone.value +=
checkModified(queue, bx, ex, cpw.PLOT_HEIGHT, cpw.PLOT_HEIGHT, bz, ez,
cpw.TOP_BLOCK);
whenDone.value +=
checkModified(queue, bx, ex, cpw.PLOT_HEIGHT + 1, 255, bz, ez,
new PlotBlock[] {PlotBlock.get((short) 0, (byte) 0)});
}
}, this, 5);
}
};
run.run();
}
public boolean scheduleRoadUpdate(PlotArea area, int extend) { public boolean scheduleRoadUpdate(PlotArea area, int extend) {
if (HybridUtils.UPDATE) { if (HybridUtils.UPDATE) {
return false; return false;

View File

@ -1,11 +1,17 @@
package com.github.intellectualsites.plotsquared.plot.object; package com.github.intellectualsites.plotsquared.plot.object;
import com.github.intellectualsites.plotsquared.configuration.serialization.ConfigurationSerializable;
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.google.common.collect.ImmutableMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
@ -16,8 +22,9 @@ import lombok.RequiredArgsConstructor;
* 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
@SuppressWarnings({"unused", "WeakerAccess"}) @SuppressWarnings({"unused", "WeakerAccess"})
public final class BlockBucket implements Iterable<PlotBlock> { public final class BlockBucket implements Iterable<PlotBlock>, ConfigurationSerializable {
private final Random random = new Random(); private final Random random = new Random();
private final Map<Range, PlotBlock> ranges = new HashMap<>(); private final Map<Range, PlotBlock> ranges = new HashMap<>();
@ -25,6 +32,18 @@ public final class BlockBucket implements Iterable<PlotBlock> {
private final BucketIterator bucketIterator = new BucketIterator(); private final BucketIterator bucketIterator = new BucketIterator();
private boolean compiled; private boolean compiled;
public static BlockBucket withSingle(@NonNull final PlotBlock block) {
final BlockBucket blockBucket = new BlockBucket();
blockBucket.addBlock(block);
return blockBucket;
}
public static BlockBucket empty() {
final BlockBucket bucket = new BlockBucket();
bucket.compiled = true;
return bucket;
}
public BlockBucket() { public BlockBucket() {
this.blocks = new HashMap<>(); this.blocks = new HashMap<>();
} }
@ -38,10 +57,51 @@ public final class BlockBucket implements Iterable<PlotBlock> {
this.compiled = false; this.compiled = false;
} }
public boolean isEmpty() {
if (isCompiled()) {
return ranges.isEmpty();
}
return blocks.isEmpty();
}
/**
* Get all blocks that are configured in the bucket
*
* @return Immutable collection containing all blocks that can
* be found in the bucket
*/
public Collection<PlotBlock> getBlocks() {
if (!isCompiled()) {
this.compile();
}
return Collections.unmodifiableCollection(this.ranges.values());
}
/**
* 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<PlotBlock> getBlocks(final int count) {
final List<PlotBlock> blocks = new ArrayList<>(count);
for (int i = 0; i < count; i++) {
blocks.add(getBlock());
}
return Collections.unmodifiableCollection(blocks);
}
public void compile() { public void compile() {
if (isCompiled()) { if (isCompiled()) {
return; return;
} }
if (blocks.size() == 1) {
this.ranges.put(new Range(0, 100, true), blocks.keySet().toArray(new PlotBlock[1])[0]);
this.compiled = true;
return;
}
final Map<PlotBlock, Integer> temp = new HashMap<>(blocks.size()); final Map<PlotBlock, Integer> temp = new HashMap<>(blocks.size());
final List<PlotBlock> unassigned = new ArrayList<>(blocks.size()); final List<PlotBlock> unassigned = new ArrayList<>(blocks.size());
@ -91,7 +151,7 @@ public final class BlockBucket implements Iterable<PlotBlock> {
final int rangeStart = start; final int rangeStart = start;
final int rangeEnd = rangeStart + entry.getValue(); final int rangeEnd = rangeStart + entry.getValue();
start = rangeEnd + 1; start = rangeEnd + 1;
final Range range = new Range(rangeStart, rangeEnd); final Range range = new Range(rangeStart, rangeEnd, unassigned.contains(entry.getKey()));
this.ranges.put(range, entry.getKey()); this.ranges.put(range, entry.getKey());
} }
this.blocks.clear(); this.blocks.clear();
@ -116,6 +176,9 @@ public final class BlockBucket implements Iterable<PlotBlock> {
if (!isCompiled()) { if (!isCompiled()) {
this.compile(); this.compile();
} }
if (this.isEmpty()) {
return StringPlotBlock.EVERYTHING;
}
final int number = random.nextInt(101); final int number = random.nextInt(101);
for (final Map.Entry<Range, PlotBlock> entry : ranges.entrySet()) { for (final Map.Entry<Range, PlotBlock> entry : ranges.entrySet()) {
if (entry.getKey().isInRange(number)) { if (entry.getKey().isInRange(number)) {
@ -126,6 +189,34 @@ public final class BlockBucket implements Iterable<PlotBlock> {
return getBlock(); return getBlock();
} }
@Override public String toString() {
final StringBuilder builder = new StringBuilder();
final Iterator<Entry<Range, PlotBlock>> iterator = this.ranges.entrySet().iterator();
while (iterator.hasNext()) {
final Entry<Range, PlotBlock> entry = iterator.next();
builder.append(entry.getValue().getRawId());
if (!entry.getKey().isAutomatic()) {
builder.append(":").append(entry.getKey().getWeight());
}
if (iterator.hasNext()) {
builder.append(",");
}
}
return builder.toString();
}
@Override
public Map<String, Object> serialize() {
return ImmutableMap.of("blocks", this.toString());
}
public static BlockBucket deserialize(@NonNull final Map<String, Object> map) {
if (!map.containsKey("blocks")) {
return null;
}
return Configuration.BLOCK_BUCKET.parseString(map.get("blocks").toString());
}
private final class BucketIterator implements Iterator<PlotBlock> { private final class BucketIterator implements Iterator<PlotBlock> {
@Override @Override
@ -146,6 +237,12 @@ public final class BlockBucket implements Iterable<PlotBlock> {
private final int min; private final int min;
private final int max; private final int max;
@Getter
private final boolean automatic;
public int getWeight() {
return max - min;
}
public boolean isInRange(final int num) { public boolean isInRange(final int num) {
return num <= max && num >= min; return num <= max && num >= min;

View File

@ -1495,8 +1495,8 @@ public class Plot {
* (components are generator specific) * (components are generator specific)
*/ */
public boolean setComponent(String component, String blocks) { public boolean setComponent(String component, String blocks) {
PlotBlock[] parsed = Configuration.BLOCKLIST.parseString(blocks); BlockBucket parsed = Configuration.BLOCK_BUCKET.parseString(blocks);
return !(parsed == null || parsed.length == 0) && this.setComponent(component, parsed); return !(parsed == null || parsed.isEmpty()) && this.setComponent(component, parsed);
} }
/** /**
@ -2722,7 +2722,7 @@ public class Plot {
* @param blocks * @param blocks
* @return * @return
*/ */
public boolean setComponent(String component, PlotBlock[] blocks) { public boolean setComponent(String component, BlockBucket blocks) {
if (StringMan if (StringMan
.isEqualToAny(component, getManager().getPlotComponents(this.area, this.getId()))) { .isEqualToAny(component, getManager().getPlotComponents(this.area, this.getId()))) {
EventUtil.manager.callComponentSet(this, component); EventUtil.manager.callComponentSet(this, component);

View File

@ -1,12 +1,14 @@
package com.github.intellectualsites.plotsquared.plot.object; package com.github.intellectualsites.plotsquared.plot.object;
import com.github.intellectualsites.plotsquared.configuration.serialization.ConfigurationSerializable;
import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.config.Settings;
import com.google.common.collect.ImmutableMap;
import java.util.Collection;
import java.util.Map;
import lombok.NonNull; import lombok.NonNull;
import java.util.Collection; public abstract class PlotBlock implements ConfigurationSerializable {
public abstract class PlotBlock {
private static Class<?> conversionType; private static Class<?> conversionType;
private static BlockRegistry blockRegistry; private static BlockRegistry blockRegistry;
@ -38,6 +40,18 @@ public abstract class PlotBlock {
} }
} }
public static PlotBlock deserialize(@NonNull final Map<String, Object> map) {
if (map.containsKey("material")) {
final Object object = map.get("material");
return get(object);
}
return null;
}
@Override public Map<String, Object> serialize() {
return ImmutableMap.of("material", this.getRawId());
}
public abstract boolean isAir(); public abstract boolean isAir();
public static StringPlotBlock get(@NonNull final String itemId) { public static StringPlotBlock get(@NonNull final String itemId) {

View File

@ -42,7 +42,7 @@ public abstract class PlotManager {
public abstract String[] getPlotComponents(PlotArea plotArea, PlotId plotId); public abstract String[] getPlotComponents(PlotArea plotArea, PlotId plotId);
public abstract boolean setComponent(PlotArea plotArea, PlotId plotId, String component, public abstract boolean setComponent(PlotArea plotArea, PlotId plotId, String component,
PlotBlock[] blocks); BlockBucket blocks);
/* /*
* PLOT MERGING (return false if your generator does not support plot * PLOT MERGING (return false if your generator does not support plot

View File

@ -17,12 +17,31 @@ import java.nio.ByteBuffer;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import lombok.NonNull;
/** /**
* The abstract class supporting {@code BukkitPlayer} and {@code SpongePlayer}. * The abstract class supporting {@code BukkitPlayer} and {@code SpongePlayer}.
*/ */
public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer {
public interface PlotPlayerConverter<BaseObject> {
PlotPlayer convert(BaseObject object);
}
private static final Map<Class, PlotPlayerConverter> converters = new HashMap<>();
public static <T> PlotPlayer from(@NonNull final T object) {
if (!converters.containsKey(object.getClass())) {
throw new IllegalArgumentException(
String.format("There is no registered PlotPlayer converter for type %s",
object.getClass().getSimpleName()));
}
return converters.get(object.getClass()).convert(object);
}
public static <T> void registerConverter(@NonNull final Class<T> clazz, final PlotPlayerConverter<T> converter) {
converters.put(clazz, converter);
}
public static final String META_LAST_PLOT = "lastplot"; public static final String META_LAST_PLOT = "lastplot";
public static final String META_LOCATION = "location"; public static final String META_LOCATION = "location";

View File

@ -60,7 +60,7 @@ public class SinglePlotManager extends PlotManager {
} }
@Override public boolean setComponent(PlotArea plotArea, PlotId plotId, String component, @Override public boolean setComponent(PlotArea plotArea, PlotId plotId, String component,
PlotBlock[] blocks) { BlockBucket blocks) {
return false; return false;
} }

View File

@ -109,13 +109,13 @@ public abstract class LocalBlockQueue {
} }
} }
public void setCuboid(Location pos1, Location pos2, PlotBlock[] blocks) { public void setCuboid(Location pos1, Location pos2, BlockBucket blocks) {
for (int y = pos1.getY(); y <= Math.min(255, pos2.getY()); y++) { for (int y = pos1.getY(); y <= Math.min(255, pos2.getY()); y++) {
for (int x = pos1.getX(); x <= pos2.getX(); x++) { for (int x = pos1.getX(); x <= pos2.getX(); x++) {
for (int z = pos1.getZ(); z <= pos2.getZ(); z++) { for (int z = pos1.getZ(); z <= pos2.getZ(); z++) {
int i = PseudoRandom.random.random(blocks.length); // int i = PseudoRandom.random.random(blocks.length);
PlotBlock block = blocks[i]; // PlotBlock block = blocks[i];
setBlock(x, y, z, block); setBlock(x, y, z, blocks.getBlock());
} }
} }
} }