mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Many Much
- Add readregions to queues for when we're setting our own consumer (usually meaning the queue writes its own blocks, so it doesn't know which chunks to actually load) - Finish removing chunk/regionTasks - Allow the queue to not remove tickets from chunks (useful for swapping chunks so they don't unload needlessly) - Remove a lot of unused methods - Implement entities to queues - Remove chunk unloading (the server should really handle it)
This commit is contained in:
@ -27,8 +27,6 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.inject.annotations.WorldConfig;
|
||||
import com.plotsquared.core.inject.annotations.WorldFile;
|
||||
import com.plotsquared.core.configuration.Captions;
|
||||
import com.plotsquared.core.configuration.ConfigurationSection;
|
||||
import com.plotsquared.core.configuration.ConfigurationUtil;
|
||||
@ -36,6 +34,8 @@ import com.plotsquared.core.configuration.file.YamlConfiguration;
|
||||
import com.plotsquared.core.events.TeleportCause;
|
||||
import com.plotsquared.core.generator.AugmentedUtils;
|
||||
import com.plotsquared.core.generator.HybridPlotWorld;
|
||||
import com.plotsquared.core.inject.annotations.WorldConfig;
|
||||
import com.plotsquared.core.inject.annotations.WorldFile;
|
||||
import com.plotsquared.core.inject.factory.HybridPlotWorldFactory;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
@ -46,6 +46,8 @@ import com.plotsquared.core.plot.PlotAreaType;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
import com.plotsquared.core.plot.message.PlotMessage;
|
||||
import com.plotsquared.core.plot.world.PlotAreaManager;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.setup.PlotAreaBuilder;
|
||||
import com.plotsquared.core.util.FileUtils;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
@ -57,7 +59,6 @@ import com.plotsquared.core.util.SchematicHandler;
|
||||
import com.plotsquared.core.util.SetupUtils;
|
||||
import com.plotsquared.core.util.StringMan;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -68,12 +69,11 @@ import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
||||
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
@ -100,14 +100,14 @@ public class Area extends SubCommand {
|
||||
private final SetupUtils setupUtils;
|
||||
private final WorldUtil worldUtil;
|
||||
private final RegionManager regionManager;
|
||||
private final GlobalBlockQueue blockQueue;
|
||||
|
||||
@Inject public Area(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
||||
@WorldFile @Nonnull final File worldFile,
|
||||
@Nonnull final HybridPlotWorldFactory hybridPlotWorldFactory,
|
||||
@Nonnull final SetupUtils setupUtils,
|
||||
@Nonnull final WorldUtil worldUtil,
|
||||
@Nonnull final RegionManager regionManager) {
|
||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
||||
@WorldFile @Nonnull final File worldFile,
|
||||
@Nonnull final HybridPlotWorldFactory hybridPlotWorldFactory,
|
||||
@Nonnull final SetupUtils setupUtils, @Nonnull final WorldUtil worldUtil,
|
||||
@Nonnull final RegionManager regionManager, @Nonnull final GlobalBlockQueue blockQueue) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldConfiguration = worldConfiguration;
|
||||
this.worldFile = worldFile;
|
||||
@ -115,6 +115,7 @@ public class Area extends SubCommand {
|
||||
this.setupUtils = setupUtils;
|
||||
this.worldUtil = worldUtil;
|
||||
this.regionManager = regionManager;
|
||||
this.blockQueue = blockQueue;
|
||||
}
|
||||
|
||||
@Override public boolean onCommand(final PlotPlayer<?> player, String[] args) {
|
||||
@ -129,27 +130,32 @@ public class Area extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
if (!Permissions.hasPermission(player, Captions.PERMISSION_AREA_CREATE)) {
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION, Captions.PERMISSION_AREA_CREATE);
|
||||
MainUtil.sendMessage(player, Captions.NO_PERMISSION,
|
||||
Captions.PERMISSION_AREA_CREATE);
|
||||
return false;
|
||||
}
|
||||
if (args.length < 2) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NEEDS_NAME);
|
||||
return false;
|
||||
}
|
||||
final PlotArea existingArea = this.plotAreaManager.getPlotArea(player.getLocation().getWorldName(), args[1]);
|
||||
final PlotArea existingArea =
|
||||
this.plotAreaManager.getPlotArea(player.getLocation().getWorldName(), args[1]);
|
||||
if (existingArea != null && existingArea.getId().equalsIgnoreCase(args[1])) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NAME_TAKEN);
|
||||
return false;
|
||||
}
|
||||
final LocalSession localSession = WorldEdit.getInstance().getSessionManager().getIfPresent(player.toActor());
|
||||
final LocalSession localSession =
|
||||
WorldEdit.getInstance().getSessionManager().getIfPresent(player.toActor());
|
||||
if (localSession == null) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_MISSING_SELECTION);
|
||||
return false;
|
||||
}
|
||||
Region playerSelectedRegion = null;
|
||||
try {
|
||||
playerSelectedRegion = localSession.getSelection(((Player) player.toActor()).getWorld());
|
||||
} catch (final Exception ignored) {}
|
||||
playerSelectedRegion =
|
||||
localSession.getSelection(((Player) player.toActor()).getWorld());
|
||||
} catch (final Exception ignored) {
|
||||
}
|
||||
if (playerSelectedRegion == null) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_MISSING_SELECTION);
|
||||
return false;
|
||||
@ -158,23 +164,28 @@ public class Area extends SubCommand {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_NOT_SQUARE);
|
||||
return false;
|
||||
}
|
||||
if (this.plotAreaManager.getPlotAreas(
|
||||
Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(), CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) {
|
||||
if (this.plotAreaManager
|
||||
.getPlotAreas(Objects.requireNonNull(playerSelectedRegion.getWorld()).getName(),
|
||||
CuboidRegion.makeCuboid(playerSelectedRegion)).length != 0) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_OVERLAPPING);
|
||||
}
|
||||
// Alter the region
|
||||
final BlockVector3 playerSelectionMin = playerSelectedRegion.getMinimumPoint();
|
||||
final BlockVector3 playerSelectionMax = playerSelectedRegion.getMaximumPoint();
|
||||
// Create a new selection that spans the entire vertical range of the world
|
||||
final CuboidRegion selectedRegion = new CuboidRegion(playerSelectedRegion.getWorld(),
|
||||
BlockVector3.at(playerSelectionMin.getX(), 0, playerSelectionMin.getZ()),
|
||||
BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ()));
|
||||
final CuboidRegion selectedRegion =
|
||||
new CuboidRegion(playerSelectedRegion.getWorld(),
|
||||
BlockVector3.at(playerSelectionMin.getX(), 0, playerSelectionMin.getZ()),
|
||||
BlockVector3.at(playerSelectionMax.getX(), 255, playerSelectionMax.getZ()));
|
||||
// There's only one plot in the area...
|
||||
final PlotId plotId = PlotId.of(1, 1);
|
||||
final HybridPlotWorld hybridPlotWorld = this.hybridPlotWorldFactory.create(player.getLocation().getWorldName(), args[1],
|
||||
Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), plotId, plotId);
|
||||
final HybridPlotWorld hybridPlotWorld = this.hybridPlotWorldFactory
|
||||
.create(player.getLocation().getWorldName(), args[1],
|
||||
Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(),
|
||||
plotId, plotId);
|
||||
// Plot size is the same as the region width
|
||||
hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth();
|
||||
hybridPlotWorld.PLOT_WIDTH =
|
||||
hybridPlotWorld.SIZE = (short) selectedRegion.getWidth();
|
||||
// We use a schematic generator
|
||||
hybridPlotWorld.setTerrain(PlotAreaTerrainType.NONE);
|
||||
// It is always a partial plot world
|
||||
@ -182,23 +193,30 @@ public class Area extends SubCommand {
|
||||
// We save the schematic :D
|
||||
hybridPlotWorld.PLOT_SCHEMATIC = true;
|
||||
// Set the road width to 0
|
||||
hybridPlotWorld.ROAD_WIDTH = hybridPlotWorld.ROAD_OFFSET_X = hybridPlotWorld.ROAD_OFFSET_Z = 0;
|
||||
hybridPlotWorld.ROAD_WIDTH =
|
||||
hybridPlotWorld.ROAD_OFFSET_X = hybridPlotWorld.ROAD_OFFSET_Z = 0;
|
||||
// Set the plot height to the selection height
|
||||
hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT = hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY();
|
||||
hybridPlotWorld.PLOT_HEIGHT = hybridPlotWorld.ROAD_HEIGHT =
|
||||
hybridPlotWorld.WALL_HEIGHT = playerSelectionMin.getBlockY();
|
||||
// No sign plz
|
||||
hybridPlotWorld.setAllowSigns(false);
|
||||
final File parentFile = FileUtils.getFile(PlotSquared.platform().getDirectory(), "schematics" + File.separator +
|
||||
"GEN_ROAD_SCHEMATIC" + File.separator + hybridPlotWorld.getWorldName() + File.separator +
|
||||
hybridPlotWorld.getId());
|
||||
final File parentFile = FileUtils.getFile(PlotSquared.platform().getDirectory(),
|
||||
"schematics" + File.separator + "GEN_ROAD_SCHEMATIC" + File.separator
|
||||
+ hybridPlotWorld.getWorldName() + File.separator + hybridPlotWorld
|
||||
.getId());
|
||||
if (!parentFile.exists() && !parentFile.mkdirs()) {
|
||||
MainUtil.sendMessage(player, Captions.SINGLE_AREA_COULD_NOT_MAKE_DIRECTORIES);
|
||||
return false;
|
||||
}
|
||||
final File file = new File(parentFile, "plot.schem");
|
||||
try (final ClipboardWriter clipboardWriter = BuiltInClipboardFormat.SPONGE_SCHEMATIC.getWriter(new FileOutputStream(file))) {
|
||||
try (final ClipboardWriter clipboardWriter = BuiltInClipboardFormat.SPONGE_SCHEMATIC
|
||||
.getWriter(new FileOutputStream(file))) {
|
||||
final BlockArrayClipboard clipboard = new BlockArrayClipboard(selectedRegion);
|
||||
final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory().getEditSession(selectedRegion.getWorld(), -1);
|
||||
final ForwardExtentCopy forwardExtentCopy = new ForwardExtentCopy(editSession, selectedRegion, clipboard, selectedRegion.getMinimumPoint());
|
||||
final EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
|
||||
.getEditSession(selectedRegion.getWorld(), -1);
|
||||
final ForwardExtentCopy forwardExtentCopy =
|
||||
new ForwardExtentCopy(editSession, selectedRegion, clipboard,
|
||||
selectedRegion.getMinimumPoint());
|
||||
forwardExtentCopy.setCopyingBiomes(true);
|
||||
forwardExtentCopy.setCopyingEntities(true);
|
||||
Operations.complete(forwardExtentCopy);
|
||||
@ -221,14 +239,14 @@ public class Area extends SubCommand {
|
||||
|
||||
// Now the schematic is saved, which is wonderful!
|
||||
PlotAreaBuilder singleBuilder = PlotAreaBuilder.ofPlotArea(hybridPlotWorld)
|
||||
.plotManager(PlotSquared.platform().getPluginName())
|
||||
.generatorName(PlotSquared.platform().getPluginName())
|
||||
.maximumId(plotId)
|
||||
.minimumId(plotId);
|
||||
.plotManager(PlotSquared.platform().getPluginName())
|
||||
.generatorName(PlotSquared.platform().getPluginName()).maximumId(plotId)
|
||||
.minimumId(plotId);
|
||||
Runnable singleRun = () -> {
|
||||
final String path =
|
||||
"worlds." + hybridPlotWorld.getWorldName() + ".areas." + hybridPlotWorld.getId() + '-'
|
||||
+ singleBuilder.minimumId() + '-' + singleBuilder.maximumId();
|
||||
"worlds." + hybridPlotWorld.getWorldName() + ".areas." + hybridPlotWorld
|
||||
.getId() + '-' + singleBuilder.minimumId() + '-' + singleBuilder
|
||||
.maximumId();
|
||||
final int offsetX = singlePos1.getX();
|
||||
final int offsetZ = singlePos1.getZ();
|
||||
if (offsetX != 0) {
|
||||
@ -314,19 +332,20 @@ public class Area extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
PlotAreaBuilder builder = PlotAreaBuilder.ofPlotArea(area)
|
||||
.plotManager(PlotSquared.platform().getPluginName())
|
||||
.generatorName(PlotSquared.platform().getPluginName())
|
||||
.minimumId(PlotId.of(1, 1))
|
||||
.maximumId(PlotId.of(numX, numZ));
|
||||
.plotManager(PlotSquared.platform().getPluginName())
|
||||
.generatorName(PlotSquared.platform().getPluginName())
|
||||
.minimumId(PlotId.of(1, 1)).maximumId(PlotId.of(numX, numZ));
|
||||
final String path =
|
||||
"worlds." + area.getWorldName() + ".areas." + area.getId() + '-'
|
||||
+ builder.minimumId() + '-' + builder.maximumId();
|
||||
Runnable run = () -> {
|
||||
if (offsetX != 0) {
|
||||
this.worldConfiguration.set(path + ".road.offset.x", offsetX);
|
||||
this.worldConfiguration
|
||||
.set(path + ".road.offset.x", offsetX);
|
||||
}
|
||||
if (offsetZ != 0) {
|
||||
this.worldConfiguration.set(path + ".road.offset.z", offsetZ);
|
||||
this.worldConfiguration
|
||||
.set(path + ".road.offset.z", offsetZ);
|
||||
}
|
||||
final String world = this.setupUtils.setupWorld(builder);
|
||||
if (this.worldUtil.isWorld(world)) {
|
||||
@ -335,14 +354,13 @@ public class Area extends SubCommand {
|
||||
player.teleport(this.worldUtil.getSpawn(world),
|
||||
TeleportCause.COMMAND);
|
||||
if (area.getTerrain() != PlotAreaTerrainType.ALL) {
|
||||
this.regionManager.largeRegionTask(world, region,
|
||||
new RunnableVal<BlockVector2>() {
|
||||
@Override public void run(BlockVector2 value) {
|
||||
AugmentedUtils
|
||||
.generate(null, world, value.getX(),
|
||||
value.getZ(), null);
|
||||
}
|
||||
}, null);
|
||||
QueueCoordinator queue =
|
||||
blockQueue.getNewQueue(worldUtil.getWeWorld(world));
|
||||
queue.setChunkConsumer(chunk -> AugmentedUtils
|
||||
.generate(null, world, chunk.getX(), chunk.getZ(),
|
||||
queue));
|
||||
queue.setReadRegion(region);
|
||||
queue.enqueue();
|
||||
}
|
||||
} else {
|
||||
MainUtil.sendMessage(player,
|
||||
@ -368,14 +386,16 @@ public class Area extends SubCommand {
|
||||
}
|
||||
PlotAreaBuilder builder = PlotAreaBuilder.newBuilder();
|
||||
builder.worldName(split[0]);
|
||||
final HybridPlotWorld pa = this.hybridPlotWorldFactory.create(builder.worldName(),
|
||||
id, PlotSquared.platform().getDefaultGenerator(), null, null);
|
||||
final HybridPlotWorld pa = this.hybridPlotWorldFactory
|
||||
.create(builder.worldName(), id,
|
||||
PlotSquared.platform().getDefaultGenerator(), null, null);
|
||||
PlotArea other = this.plotAreaManager.getPlotArea(pa.getWorldName(), id);
|
||||
if (other != null && Objects.equals(pa.getId(), other.getId())) {
|
||||
Captions.SETUP_WORLD_TAKEN.send(player, pa.toString());
|
||||
return false;
|
||||
}
|
||||
Set<PlotArea> areas = this.plotAreaManager.getPlotAreasSet(pa.getWorldName());
|
||||
Set<PlotArea> areas =
|
||||
this.plotAreaManager.getPlotAreasSet(pa.getWorldName());
|
||||
if (!areas.isEmpty()) {
|
||||
PlotArea area = areas.iterator().next();
|
||||
pa.setType(area.getType());
|
||||
@ -454,7 +474,8 @@ public class Area extends SubCommand {
|
||||
if (!this.worldConfiguration.contains(path)) {
|
||||
this.worldConfiguration.createSection(path);
|
||||
}
|
||||
ConfigurationSection section = this.worldConfiguration.getConfigurationSection(path);
|
||||
ConfigurationSection section =
|
||||
this.worldConfiguration.getConfigurationSection(path);
|
||||
pa.saveConfiguration(section);
|
||||
pa.loadConfiguration(section);
|
||||
builder.plotManager(PlotSquared.platform().getPluginName());
|
||||
@ -581,7 +602,8 @@ public class Area extends SubCommand {
|
||||
Captions.COMMAND_SYNTAX.send(player, getCommandString() + " list [#]");
|
||||
return false;
|
||||
}
|
||||
final List<PlotArea> areas = new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas()));
|
||||
final List<PlotArea> areas =
|
||||
new ArrayList<>(Arrays.asList(this.plotAreaManager.getAllPlotAreas()));
|
||||
paginate(player, areas, 8, page,
|
||||
new RunnableVal3<Integer, PlotArea, PlotMessage>() {
|
||||
@Override public void run(Integer i, PlotArea area, PlotMessage message) {
|
||||
@ -596,7 +618,8 @@ public class Area extends SubCommand {
|
||||
PlotId max = area.getMax();
|
||||
name = area.getWorldName() + ';' + area.getId() + ';' + min + ';'
|
||||
+ max;
|
||||
int size = (max.getX() - min.getX() + 1) * (max.getY() - min.getY() + 1);
|
||||
int size =
|
||||
(max.getX() - min.getX() + 1) * (max.getY() - min.getY() + 1);
|
||||
percent = claimed == 0 ? 0 : size / (double) claimed;
|
||||
region = area.getRegion().toString();
|
||||
} else {
|
||||
@ -641,14 +664,14 @@ public class Area extends SubCommand {
|
||||
"$4Stop the server and delete: " + area.getWorldName() + "/region");
|
||||
return false;
|
||||
}
|
||||
this.regionManager.largeRegionTask(area.getWorldName(), area.getRegion(),
|
||||
new RunnableVal<BlockVector2>() {
|
||||
@Override public void run(BlockVector2 value) {
|
||||
AugmentedUtils
|
||||
.generate(null, area.getWorldName(), value.getX(), value.getZ(),
|
||||
null);
|
||||
}
|
||||
}, () -> player.sendMessage("Regen complete"));
|
||||
|
||||
QueueCoordinator queue =
|
||||
blockQueue.getNewQueue(worldUtil.getWeWorld(area.getWorldName()));
|
||||
queue.setChunkConsumer(chunk -> AugmentedUtils
|
||||
.generate(null, area.getWorldName(), chunk.getX(), chunk.getZ(), queue));
|
||||
queue.setReadRegion(area.getRegion());
|
||||
queue.setCompleteTask(() -> player.sendMessage("Regen complete"));
|
||||
queue.enqueue();
|
||||
return true;
|
||||
}
|
||||
case "goto":
|
||||
@ -676,11 +699,13 @@ public class Area extends SubCommand {
|
||||
} else {
|
||||
CuboidRegion region = area.getRegion();
|
||||
center = Location.at(area.getWorldName(), region.getMinimumPoint().getX()
|
||||
+ (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2,
|
||||
+ (region.getMaximumPoint().getX() - region.getMinimumPoint().getX()) / 2,
|
||||
0, region.getMinimumPoint().getZ()
|
||||
+ (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ()) / 2);
|
||||
this.worldUtil.getHighestBlock(area.getWorldName(), center.getX(), center.getZ(), y ->
|
||||
player.teleport(center.withY(1 + y), TeleportCause.COMMAND));
|
||||
+ (region.getMaximumPoint().getZ() - region.getMinimumPoint().getZ())
|
||||
/ 2);
|
||||
this.worldUtil
|
||||
.getHighestBlock(area.getWorldName(), center.getX(), center.getZ(),
|
||||
y -> player.teleport(center.withY(1 + y), TeleportCause.COMMAND));
|
||||
}
|
||||
return true;
|
||||
case "delete":
|
||||
|
@ -72,6 +72,7 @@ public class AugmentedUtils {
|
||||
if (areas.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
boolean enqueue = false;
|
||||
boolean generationResult = false;
|
||||
for (final PlotArea area : areas) {
|
||||
// A normal plot world may not contain any clusters
|
||||
@ -81,14 +82,18 @@ public class AugmentedUtils {
|
||||
}
|
||||
// This means that full vanilla generation is used
|
||||
// so we do not interfere
|
||||
if (area.getTerrain() == PlotAreaTerrainType.ALL) {
|
||||
if (area.getTerrain() == PlotAreaTerrainType.ALL || !area.contains(blockX, blockZ)) {
|
||||
continue;
|
||||
}
|
||||
IndependentPlotGenerator generator = area.getGenerator();
|
||||
// Mask
|
||||
if (queue == null) {
|
||||
queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(world));
|
||||
queue.setChunkObject(chunkObject);
|
||||
enqueue = true;
|
||||
queue = PlotSquared.platform().getGlobalBlockQueue()
|
||||
.getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(world));
|
||||
if (chunkObject != null) {
|
||||
queue.setChunkObject(chunkObject);
|
||||
}
|
||||
}
|
||||
QueueCoordinator primaryMask;
|
||||
// coordinates
|
||||
@ -109,7 +114,6 @@ public class AugmentedUtils {
|
||||
relativeTopX = relativeTopZ = 15;
|
||||
primaryMask = queue;
|
||||
}
|
||||
|
||||
QueueCoordinator secondaryMask;
|
||||
BlockState air = BlockTypes.AIR.getDefaultState();
|
||||
if (area.getTerrain() == PlotAreaTerrainType.ROAD) {
|
||||
@ -147,10 +151,12 @@ public class AugmentedUtils {
|
||||
}
|
||||
generationResult = true;
|
||||
}
|
||||
primaryMask.setChunkObject(chunkObject);
|
||||
primaryMask.setForceSync(true);
|
||||
secondaryMask.setChunkObject(chunkObject);
|
||||
secondaryMask.setForceSync(true);
|
||||
if (chunkObject != null) {
|
||||
primaryMask.setChunkObject(chunkObject);
|
||||
}
|
||||
if (chunkObject != null) {
|
||||
secondaryMask.setChunkObject(chunkObject);
|
||||
}
|
||||
|
||||
ScopedQueueCoordinator scoped =
|
||||
new ScopedQueueCoordinator(secondaryMask, Location.at(world, blockX, 0, blockZ),
|
||||
@ -158,8 +164,7 @@ public class AugmentedUtils {
|
||||
generator.generateChunk(scoped, area);
|
||||
generator.populateChunk(scoped, area);
|
||||
}
|
||||
if (queue != null) {
|
||||
queue.setForceSync(true);
|
||||
if (enqueue) {
|
||||
queue.enqueue();
|
||||
}
|
||||
return generationResult;
|
||||
|
@ -42,6 +42,7 @@ import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.WorldUtil;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
@ -247,6 +248,8 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
|
||||
final BiomeType biome = hybridPlotWorld.getPlotBiome();
|
||||
final QueueCoordinator queue = hybridPlotWorld.getQueue();
|
||||
queue.setReadRegion(new CuboidRegion(plot.getExtendedBottomAbs().getBlockVector3(),
|
||||
plot.getExtendedTopAbs().getBlockVector3()));
|
||||
queue.setChunkConsumer(blockVector2 -> {
|
||||
// If the chunk isn't near the edge and it isn't an augmented world we can just regen the whole chunk
|
||||
if (canRegen && ChunkUtil.isWholeChunk(pos1, pos2, blockVector2)) {
|
||||
|
@ -161,7 +161,7 @@ public class HybridUtils {
|
||||
System.gc();
|
||||
|
||||
QueueCoordinator queue = area.getQueue();
|
||||
|
||||
queue.setReadRegion(region);
|
||||
queue.setChunkConsumer(blockVector2 -> {
|
||||
int X = blockVector2.getX();
|
||||
int Z = blockVector2.getZ();
|
||||
@ -438,7 +438,6 @@ public class HybridUtils {
|
||||
if (!regenedRoad && Settings.DEBUG) {
|
||||
logger.info("[P2] Failed to regenerate roads");
|
||||
}
|
||||
chunkManager.unloadChunk(area.getWorldName(), chunk, true);
|
||||
}
|
||||
if (Settings.DEBUG) {
|
||||
logger.info("[P2] Cancelled road task");
|
||||
@ -500,15 +499,6 @@ public class HybridUtils {
|
||||
logger.error(
|
||||
"[P2] Error! Could not update '{}/region/r.{}.{}.mca' (Corrupt chunk?)",
|
||||
area.getWorldHash(), loc.getX(), loc.getZ());
|
||||
int sx = loc.getX() << 5;
|
||||
int sz = loc.getZ() << 5;
|
||||
for (int x = sx; x < sx + 32; x++) {
|
||||
for (int z = sz; z < sz + 32; z++) {
|
||||
chunkManager
|
||||
.unloadChunk(area.getWorldName(), BlockVector2.at(x, z),
|
||||
true);
|
||||
}
|
||||
}
|
||||
}
|
||||
TaskManager.runTaskLater(task, TaskTime.seconds(1L));
|
||||
});
|
||||
|
@ -28,7 +28,6 @@ package com.plotsquared.core.inject.factory;
|
||||
import com.plotsquared.core.queue.ChunkCoordinator;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
@ -37,8 +36,8 @@ import java.util.function.Consumer;
|
||||
public interface ChunkCoordinatorFactory {
|
||||
|
||||
@Nonnull ChunkCoordinator create(final long maxIterationTime, final int initialBatchSize,
|
||||
@NotNull final Consumer<BlockVector2> chunkConsumer, @NotNull final World world,
|
||||
@NotNull final Collection<BlockVector2> requestedChunks, @NotNull final Runnable whenDone,
|
||||
@NotNull final Consumer<Throwable> throwableConsumer);
|
||||
@Nonnull final Consumer<BlockVector2> chunkConsumer, @Nonnull final World world,
|
||||
@Nonnull final Collection<BlockVector2> requestedChunks, @Nonnull final Runnable whenDone,
|
||||
@Nonnull final Consumer<Throwable> throwableConsumer, final boolean unloadAfter);
|
||||
|
||||
}
|
||||
|
@ -3312,9 +3312,7 @@ public class Plot {
|
||||
Location pos2 = corners[1];
|
||||
Location pos3 =
|
||||
pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
|
||||
Location pos4 =
|
||||
pos2.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
|
||||
regionManager.swap(pos1, pos2, pos3, pos4, this);
|
||||
regionManager.swap(pos1, pos2, pos3, this);
|
||||
}
|
||||
}
|
||||
}.run();
|
||||
|
@ -27,12 +27,16 @@ package com.plotsquared.core.queue;
|
||||
|
||||
import com.plotsquared.core.util.PatternUtil;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.entity.EntityTypes;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@ -53,6 +57,8 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
private int[] regenStart;
|
||||
private int[] regenEnd;
|
||||
private Consumer<BlockVector2> consumer = null;
|
||||
private boolean unloadAfter = true;
|
||||
private CuboidRegion readRegion = null;
|
||||
|
||||
private GlobalBlockQueue globalBlockQueue;
|
||||
|
||||
@ -61,12 +67,6 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
this.modified = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public LocalChunk getLocalChunk(int x, int z) {
|
||||
return new LocalChunk(this, x, z) {
|
||||
// Allow implementation-specific custom stuff here
|
||||
};
|
||||
}
|
||||
|
||||
@Override public abstract BlockState getBlock(int x, int y, int z);
|
||||
|
||||
@Override public final World getWorld() {
|
||||
@ -132,12 +132,30 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
return this.settingTiles;
|
||||
}
|
||||
|
||||
@Override public boolean setEntity(Entity entity) {
|
||||
if (entity.getState() == null || entity.getState().getType() == EntityTypes.PLAYER) {
|
||||
return false;
|
||||
}
|
||||
Location location = entity.getBlockLocation();
|
||||
LocalChunk chunk = getChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
||||
chunk.setEntity(location, entity.getState());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public CuboidRegion getReadRegion() {
|
||||
return this.readRegion;
|
||||
}
|
||||
|
||||
@Override public void setReadRegion(CuboidRegion readRegion) {
|
||||
this.readRegion = readRegion;
|
||||
}
|
||||
|
||||
@Override public void regenChunk(int x, int z) {
|
||||
regen = true;
|
||||
// There will never only be one nullified coordinate pair
|
||||
if (regenStart == null) {
|
||||
regenStart = new int[]{x, z};
|
||||
regenEnd = new int[]{x, z};
|
||||
regenStart = new int[] {x, z};
|
||||
regenEnd = new int[] {x, z};
|
||||
return;
|
||||
}
|
||||
if (x < regenStart[0]) {
|
||||
@ -154,6 +172,14 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean isUnloadAfter() {
|
||||
return this.unloadAfter;
|
||||
}
|
||||
|
||||
@Override public void setUnloadAfter(boolean unloadAfter) {
|
||||
this.unloadAfter = unloadAfter;
|
||||
}
|
||||
|
||||
public int[] getRegenStart() {
|
||||
return regenStart;
|
||||
}
|
||||
@ -189,7 +215,7 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
BlockVector2 pair = BlockVector2.at(chunkX, chunkZ);
|
||||
lastWrappedChunk = this.blockChunks.get(pair);
|
||||
if (lastWrappedChunk == null) {
|
||||
lastWrappedChunk = this.getLocalChunk(chunkX, chunkZ);
|
||||
lastWrappedChunk = new LocalChunk(this, chunkX, chunkZ);
|
||||
LocalChunk previous = this.blockChunks.put(pair, lastWrappedChunk);
|
||||
if (previous == null) {
|
||||
return lastWrappedChunk;
|
||||
@ -199,6 +225,4 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
}
|
||||
return lastWrappedChunk;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import com.google.inject.Inject;
|
||||
import com.plotsquared.core.inject.factory.ChunkCoordinatorFactory;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -51,30 +52,32 @@ public class ChunkCoordinatorBuilder {
|
||||
};
|
||||
private long maxIterationTime = 60; // A little over 1 tick;
|
||||
private int initialBatchSize = 4;
|
||||
private boolean unloadAfter = true;
|
||||
private CuboidRegion readRegion = null;
|
||||
|
||||
@Inject
|
||||
public ChunkCoordinatorBuilder(@Nonnull ChunkCoordinatorFactory chunkCoordinatorFactory) {
|
||||
this.chunkCoordinatorFactory = chunkCoordinatorFactory;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder inWorld(@NotNull final World world) {
|
||||
@Nonnull public ChunkCoordinatorBuilder inWorld(@Nonnull final World world) {
|
||||
this.world = Preconditions.checkNotNull(world, "World may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withChunk(@NotNull final BlockVector2 chunkLocation) {
|
||||
@Nonnull public ChunkCoordinatorBuilder withChunk(@Nonnull final BlockVector2 chunkLocation) {
|
||||
this.requestedChunks
|
||||
.add(Preconditions.checkNotNull(chunkLocation, "Chunk location may not be null"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withChunks(
|
||||
@NotNull final Collection<BlockVector2> chunkLocations) {
|
||||
@Nonnull public ChunkCoordinatorBuilder withChunks(
|
||||
@Nonnull final Collection<BlockVector2> chunkLocations) {
|
||||
chunkLocations.forEach(this::withChunk);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withRegion(Location pos1, Location pos2) {
|
||||
@Nonnull public ChunkCoordinatorBuilder withRegion(Location pos1, Location pos2) {
|
||||
final int p1x = pos1.getX();
|
||||
final int p1z = pos1.getZ();
|
||||
final int p2x = pos2.getX();
|
||||
@ -95,45 +98,50 @@ public class ChunkCoordinatorBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withConsumer(
|
||||
@NotNull final Consumer<BlockVector2> chunkConsumer) {
|
||||
@Nonnull public ChunkCoordinatorBuilder withConsumer(
|
||||
@Nonnull final Consumer<BlockVector2> chunkConsumer) {
|
||||
this.chunkConsumer =
|
||||
Preconditions.checkNotNull(chunkConsumer, "Chunk consumer may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withFinalAction(@NotNull final Runnable whenDone) {
|
||||
@Nonnull public ChunkCoordinatorBuilder withFinalAction(@Nonnull final Runnable whenDone) {
|
||||
this.whenDone = Preconditions.checkNotNull(whenDone, "Final action may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withMaxIterationTime(final long maxIterationTime) {
|
||||
@Nonnull public ChunkCoordinatorBuilder withMaxIterationTime(final long maxIterationTime) {
|
||||
Preconditions.checkArgument(maxIterationTime > 0, "Max iteration time must be positive");
|
||||
this.maxIterationTime = maxIterationTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withInitialBatchSize(final int initialBatchSize) {
|
||||
@Nonnull public ChunkCoordinatorBuilder withInitialBatchSize(final int initialBatchSize) {
|
||||
Preconditions.checkArgument(initialBatchSize > 0, "Initial batch size must be positive");
|
||||
this.initialBatchSize = initialBatchSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withThrowableConsumer(
|
||||
@NotNull final Consumer<Throwable> throwableConsumer) {
|
||||
@Nonnull public ChunkCoordinatorBuilder withThrowableConsumer(
|
||||
@Nonnull final Consumer<Throwable> throwableConsumer) {
|
||||
this.throwableConsumer =
|
||||
Preconditions.checkNotNull(throwableConsumer, "Throwable consumer may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinator build() {
|
||||
@Nonnull public ChunkCoordinatorBuilder unloadAfter(final boolean unloadAfter) {
|
||||
this.unloadAfter = unloadAfter;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull public ChunkCoordinator build() {
|
||||
Preconditions.checkNotNull(this.world, "No world was supplied");
|
||||
Preconditions.checkNotNull(this.chunkConsumer, "No chunk consumer was supplied");
|
||||
Preconditions.checkNotNull(this.whenDone, "No final action was supplied");
|
||||
Preconditions.checkNotNull(this.throwableConsumer, "No throwable consumer was supplied");
|
||||
return chunkCoordinatorFactory
|
||||
.create(this.maxIterationTime, this.initialBatchSize, this.chunkConsumer, this.world,
|
||||
this.requestedChunks, this.whenDone, this.throwableConsumer);
|
||||
this.requestedChunks, this.whenDone, this.throwableConsumer, this.unloadAfter);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,8 +26,10 @@
|
||||
package com.plotsquared.core.queue;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
@ -113,6 +115,13 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean setEntity(Entity entity) {
|
||||
if (parent != null) {
|
||||
return parent.setEntity(entity);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public void regenChunk(int x, int z) {
|
||||
if (parent != null) {
|
||||
parent.regenChunk(x, z);
|
||||
@ -170,4 +179,31 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||
parent.setChunkConsumer(consumer);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public CuboidRegion getReadRegion() {
|
||||
if (parent != null) {
|
||||
return parent.getReadRegion();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public void setReadRegion(CuboidRegion readRegion) {
|
||||
if (parent != null) {
|
||||
parent.setReadRegion(readRegion);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public boolean isUnloadAfter() {
|
||||
if (parent != null) {
|
||||
return parent.isUnloadAfter();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public void setUnloadAfter(boolean setUnloadAfter) {
|
||||
if (parent != null) {
|
||||
parent.setUnloadAfter(setUnloadAfter);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -26,25 +26,27 @@
|
||||
package com.plotsquared.core.queue;
|
||||
|
||||
import com.plotsquared.core.util.ChunkUtil;
|
||||
import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LocalChunk {
|
||||
private final BasicQueueCoordinator parent;
|
||||
private final QueueCoordinator parent;
|
||||
private final int x;
|
||||
private final int z;
|
||||
|
||||
private final BaseBlock[][] baseblocks;
|
||||
private final BiomeType[][] biomes;
|
||||
private final HashMap<BlockVector3, CompoundTag> tiles = new HashMap<>();
|
||||
private final HashMap<Location, BaseEntity> entities = new HashMap<>();
|
||||
|
||||
public LocalChunk(BasicQueueCoordinator parent, int x, int z) {
|
||||
public LocalChunk(QueueCoordinator parent, int x, int z) {
|
||||
this.parent = parent;
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
@ -52,7 +54,7 @@ public class LocalChunk {
|
||||
biomes = new BiomeType[16][];
|
||||
}
|
||||
|
||||
public BasicQueueCoordinator getParent() {
|
||||
public QueueCoordinator getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
@ -103,4 +105,12 @@ public class LocalChunk {
|
||||
public void setTile(final int x, final int y, final int z, final CompoundTag tag) {
|
||||
tiles.put(BlockVector3.at(x, y, z), tag);
|
||||
}
|
||||
|
||||
public void setEntity(Location location, BaseEntity entity) {
|
||||
this.entities.put(location, entity);
|
||||
}
|
||||
|
||||
public HashMap<Location, BaseEntity> getEntities() {
|
||||
return this.entities;
|
||||
}
|
||||
}
|
||||
|
@ -30,8 +30,10 @@ import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.util.PatternUtil;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
@ -40,6 +42,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class QueueCoordinator {
|
||||
@ -108,6 +111,22 @@ public abstract class QueueCoordinator {
|
||||
|
||||
public abstract boolean isSettingBiomes();
|
||||
|
||||
public void addEntities(List<? extends Entity> entities) {
|
||||
for (Entity e : entities) {
|
||||
this.setEntity(e);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract boolean setEntity(Entity entity);
|
||||
|
||||
public abstract CuboidRegion getReadRegion();
|
||||
|
||||
public abstract void setReadRegion(CuboidRegion readRegion);
|
||||
|
||||
public abstract void setUnloadAfter(boolean unloadAfter);
|
||||
|
||||
public abstract boolean isUnloadAfter();
|
||||
|
||||
public abstract void regenChunk(int x, int z);
|
||||
|
||||
public abstract World getWorld();
|
||||
|
@ -28,23 +28,12 @@ package com.plotsquared.core.queue;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
public abstract class QueueProvider {
|
||||
public static QueueProvider of(final Class<? extends QueueCoordinator> primary,
|
||||
final Class<? extends QueueCoordinator> fallback) {
|
||||
public static QueueProvider of(final Class<? extends QueueCoordinator> primary) {
|
||||
return new QueueProvider() {
|
||||
|
||||
private boolean failed = false;
|
||||
|
||||
@Override public QueueCoordinator getNewQueue(World world) {
|
||||
if (!failed) {
|
||||
try {
|
||||
return (QueueCoordinator) primary.getConstructors()[0].newInstance(world);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
try {
|
||||
return (QueueCoordinator) fallback.getConstructors()[0].newInstance(world);
|
||||
return (QueueCoordinator) primary.getConstructors()[0].newInstance(world);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ package com.plotsquared.core.util;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.queue.ScopedQueueCoordinator;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
@ -98,21 +97,4 @@ public abstract class ChunkManager {
|
||||
@Deprecated
|
||||
public abstract CompletableFuture loadChunk(String world, BlockVector2 loc, boolean force);
|
||||
|
||||
@Deprecated public abstract void unloadChunk(String world, BlockVector2 loc, boolean save);
|
||||
|
||||
public Plot hasPlot(String world, BlockVector2 chunk) {
|
||||
int x1 = chunk.getX() << 4;
|
||||
int z1 = chunk.getZ() << 4;
|
||||
int x2 = x1 + 15;
|
||||
int z2 = z1 + 15;
|
||||
Location bot = Location.at(world, x1, 0, z1);
|
||||
Plot plot = bot.getOwnedPlotAbs();
|
||||
if (plot != null) {
|
||||
return plot;
|
||||
}
|
||||
Location top = Location.at(world, x2, 0, z2);
|
||||
plot = top.getOwnedPlotAbs();
|
||||
return plot;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -25,24 +25,27 @@
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.inject.factory.ChunkCoordinatorBuilderFactory;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotManager;
|
||||
import com.plotsquared.core.queue.BasicQueueCoordinator;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.plotsquared.core.util.task.TaskTime;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
@ -55,12 +58,9 @@ public abstract class RegionManager {
|
||||
LoggerFactory.getLogger("P2/" + RegionManager.class.getSimpleName());
|
||||
|
||||
public static RegionManager manager = null;
|
||||
private final ChunkManager chunkManager;
|
||||
|
||||
public RegionManager(@Nonnull final ChunkManager chunkManager, @Nonnull WorldUtil worldUtil,
|
||||
@Nonnull ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory) {
|
||||
this.chunkManager = chunkManager;
|
||||
}
|
||||
@Inject private WorldUtil worldUtil;
|
||||
@Inject private ChunkManager chunkManager;
|
||||
@Inject private GlobalBlockQueue blockQueue;
|
||||
|
||||
public static BlockVector2 getRegion(Location location) {
|
||||
int x = location.getX() >> 9;
|
||||
@ -68,46 +68,6 @@ public abstract class RegionManager {
|
||||
return BlockVector2.at(x, z);
|
||||
}
|
||||
|
||||
public void largeRegionTask(final String world, final CuboidRegion region,
|
||||
final RunnableVal<BlockVector2> task, final Runnable whenDone) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
HashSet<BlockVector2> chunks = new HashSet<>();
|
||||
Set<BlockVector2> mcrs = this.getChunkChunks(world);
|
||||
for (BlockVector2 mcr : mcrs) {
|
||||
int bx = mcr.getX() << 9;
|
||||
int bz = mcr.getZ() << 9;
|
||||
int tx = bx + 511;
|
||||
int tz = bz + 511;
|
||||
if (bx <= region.getMaximumPoint().getX() && tx >= region.getMinimumPoint().getX()
|
||||
&& bz <= region.getMaximumPoint().getZ() && tz >= region.getMinimumPoint()
|
||||
.getZ()) {
|
||||
for (int x = bx >> 4; x <= (tx >> 4); x++) {
|
||||
int cbx = x << 4;
|
||||
int ctx = cbx + 15;
|
||||
if (cbx <= region.getMaximumPoint().getX() && ctx >= region
|
||||
.getMinimumPoint().getX()) {
|
||||
for (int z = bz >> 4; z <= (tz >> 4); z++) {
|
||||
int cbz = z << 4;
|
||||
int ctz = cbz + 15;
|
||||
if (cbz <= region.getMaximumPoint().getZ() && ctz >= region
|
||||
.getMinimumPoint().getZ()) {
|
||||
chunks.add(BlockVector2.at(x, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TaskManager.getPlatformImplementation()
|
||||
.objectTask(chunks, new RunnableVal<BlockVector2>() {
|
||||
@Override public void run(BlockVector2 value) {
|
||||
chunkManager.loadChunk(world, value, false).thenRun(() -> task.run(value));
|
||||
}
|
||||
}).thenAccept(ignore -> TaskManager.getPlatformImplementation()
|
||||
.taskLater(whenDone, TaskTime.ticks(1L)));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 0 = Entity
|
||||
* 1 = Animal
|
||||
@ -115,9 +75,6 @@ public abstract class RegionManager {
|
||||
* 3 = Mob
|
||||
* 4 = Boat
|
||||
* 5 = Misc
|
||||
*
|
||||
* @param plot
|
||||
* @return
|
||||
*/
|
||||
public abstract int[] countEntities(Plot plot);
|
||||
|
||||
@ -146,10 +103,6 @@ public abstract class RegionManager {
|
||||
return chunks;
|
||||
}
|
||||
|
||||
public void deleteRegionFiles(String world, Collection<BlockVector2> chunks) {
|
||||
deleteRegionFiles(world, chunks, null);
|
||||
}
|
||||
|
||||
public void deleteRegionFiles(final String world, final Collection<BlockVector2> chunks,
|
||||
final Runnable whenDone) {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
@ -167,16 +120,10 @@ public abstract class RegionManager {
|
||||
});
|
||||
}
|
||||
|
||||
public boolean setCuboids(final PlotArea area, final Set<CuboidRegion> regions,
|
||||
final Pattern blocks, int minY, int maxY) {
|
||||
return setCuboids(area, regions, blocks, minY, maxY, null);
|
||||
}
|
||||
|
||||
|
||||
public boolean setCuboids(final PlotArea area, final Set<CuboidRegion> regions,
|
||||
final Pattern blocks, int minY, int maxY, @Nullable QueueCoordinator queue) {
|
||||
boolean enqueue = false;
|
||||
if(queue == null) {
|
||||
if (queue == null) {
|
||||
queue = area.getQueue();
|
||||
enqueue = true;
|
||||
}
|
||||
@ -209,27 +156,116 @@ public abstract class RegionManager {
|
||||
/**
|
||||
* Copy a region to a new location (in the same world)
|
||||
*/
|
||||
public abstract boolean copyRegion(Location pos1, Location pos2, Location newPos,
|
||||
Runnable whenDone);
|
||||
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos,
|
||||
final Runnable whenDone) {
|
||||
final int relX = newPos.getX() - pos1.getX();
|
||||
final int relZ = newPos.getZ() - pos1.getZ();
|
||||
final com.sk89q.worldedit.world.World oldWorld = worldUtil.getWeWorld(pos1.getWorldName());
|
||||
final com.sk89q.worldedit.world.World newWorld =
|
||||
worldUtil.getWeWorld(newPos.getWorldName());
|
||||
final QueueCoordinator copyFrom = blockQueue.getNewQueue(oldWorld);
|
||||
final BasicQueueCoordinator copyTo =
|
||||
(BasicQueueCoordinator) blockQueue.getNewQueue(newWorld);
|
||||
copyFromTo(pos1, pos2, relX, relZ, oldWorld, copyFrom, copyTo, false);
|
||||
copyFrom.setCompleteTask(copyTo::enqueue);
|
||||
copyFrom.setReadRegion(new CuboidRegion(BlockVector3.at(pos1.getX(), 0, pos1.getZ()),
|
||||
BlockVector3.at(pos2.getX(), 0, pos2.getZ())));
|
||||
copyTo.setCompleteTask(whenDone);
|
||||
copyFrom.enqueue();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumptions:<br>
|
||||
* - pos1 and pos2 are in the same plot<br>
|
||||
* It can be harmful to the world if parameters outside this scope are provided
|
||||
*
|
||||
* @param pos1
|
||||
* @param pos2
|
||||
* @param whenDone
|
||||
* @return
|
||||
*/
|
||||
public abstract boolean regenerateRegion(Location pos1, Location pos2, boolean ignoreAugment,
|
||||
Runnable whenDone);
|
||||
|
||||
public abstract void clearAllEntities(Location pos1, Location pos2);
|
||||
|
||||
public abstract void swap(Location bot1, Location top1, Location bot2, Location top2,
|
||||
Runnable whenDone);
|
||||
public void swap(Location pos1, Location pos2, Location swapPos, final Runnable whenDone) {
|
||||
int relX = swapPos.getX() - pos1.getX();
|
||||
int relZ = swapPos.getZ() - pos1.getZ();
|
||||
|
||||
public abstract void setBiome(CuboidRegion region, int extendBiome, BiomeType biome,
|
||||
String world, Runnable whenDone);
|
||||
World world1 = worldUtil.getWeWorld(pos1.getWorldName());
|
||||
World world2 = worldUtil.getWeWorld(swapPos.getWorldName());
|
||||
|
||||
QueueCoordinator fromQueue1 = blockQueue.getNewQueue(world1);
|
||||
QueueCoordinator fromQueue2 = blockQueue.getNewQueue(world2);
|
||||
fromQueue1.setUnloadAfter(false);
|
||||
fromQueue2.setUnloadAfter(false);
|
||||
fromQueue1.setReadRegion(new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()));
|
||||
fromQueue2.setReadRegion(new CuboidRegion(swapPos.getBlockVector3(), BlockVector3
|
||||
.at(swapPos.getX() + pos2.getX() - pos1.getX(), 0,
|
||||
swapPos.getZ() + pos2.getZ() - pos1.getZ())));
|
||||
QueueCoordinator toQueue1 = blockQueue.getNewQueue(world1);
|
||||
QueueCoordinator toQueue2 = blockQueue.getNewQueue(world2);
|
||||
|
||||
copyFromTo(pos1, pos2, relX, relZ, world1, fromQueue1, toQueue2, true);
|
||||
copyFromTo(pos1, pos2, relX, relZ, world1, fromQueue2, toQueue1, true);
|
||||
fromQueue1.setCompleteTask(fromQueue2::enqueue);
|
||||
fromQueue2.setCompleteTask(toQueue1::enqueue);
|
||||
toQueue1.setCompleteTask(toQueue2::enqueue);
|
||||
toQueue2.setCompleteTask(whenDone);
|
||||
}
|
||||
|
||||
private void copyFromTo(Location pos1, Location pos2, int relX, int relZ, World world1,
|
||||
QueueCoordinator fromQueue, QueueCoordinator toQueue, boolean removeEntities) {
|
||||
fromQueue.setChunkConsumer(chunk -> {
|
||||
int cx = chunk.getX();
|
||||
int cz = chunk.getZ();
|
||||
int cbx = cx << 4;
|
||||
int cbz = cz << 4;
|
||||
int bx = Math.max(pos1.getX() & 15, 0);
|
||||
int bz = Math.max(pos1.getZ() & 15, 0);
|
||||
int tx = Math.min(pos2.getX() & 15, 15);
|
||||
int tz = Math.min(pos2.getZ() & 15, 15);
|
||||
for (int y = 0; y < 256; y++) {
|
||||
for (int x = bx; x <= tx; x++) {
|
||||
for (int z = bz; z <= tz; z++) {
|
||||
int rx = cbx + x;
|
||||
int rz = cbz + z;
|
||||
BlockVector3 loc = BlockVector3.at(rx, y, rz);
|
||||
toQueue.setBlock(rx + relX, y, rz + relZ, world1.getFullBlock(loc));
|
||||
toQueue.setBiome(rx + relX, y, rz + relZ, world1.getBiome(loc));
|
||||
}
|
||||
}
|
||||
}
|
||||
Region region = new CuboidRegion(BlockVector3.at(cbx + bx, 0, cbz + bz),
|
||||
BlockVector3.at(cbx + tx, 255, cbz + tz));
|
||||
toQueue.addEntities(world1.getEntities(region));
|
||||
if (removeEntities) {
|
||||
for (Entity entity : world1.getEntities(region)) {
|
||||
entity.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setBiome(final CuboidRegion region, final int extendBiome, final BiomeType biome,
|
||||
final String world, final Runnable whenDone) {
|
||||
Location pos1 = Location.at(world, region.getMinimumPoint().getX() - extendBiome,
|
||||
region.getMinimumPoint().getY(), region.getMinimumPoint().getZ() - extendBiome);
|
||||
Location pos2 = Location.at(world, region.getMaximumPoint().getX() + extendBiome,
|
||||
region.getMaximumPoint().getY(), region.getMaximumPoint().getZ() + extendBiome);
|
||||
final QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world));
|
||||
|
||||
final int minX = pos1.getX();
|
||||
final int minZ = pos1.getZ();
|
||||
final int maxX = pos2.getX();
|
||||
final int maxZ = pos2.getZ();
|
||||
queue.setReadRegion(region);
|
||||
queue.setChunkConsumer(blockVector2 -> {
|
||||
final int cx = blockVector2.getX() << 4;
|
||||
final int cz = blockVector2.getZ() << 4;
|
||||
WorldUtil
|
||||
.setBiome(world, Math.max(minX, cx), Math.max(minZ, cz), Math.min(maxX, cx + 15),
|
||||
Math.min(maxZ, cz + 15), biome);
|
||||
worldUtil.refreshChunk(blockVector2.getBlockX(), blockVector2.getBlockZ(), world);
|
||||
});
|
||||
queue.setCompleteTask(whenDone);
|
||||
queue.enqueue();
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +330,8 @@ public abstract class SchematicHandler {
|
||||
final int bcz = p1z >> 4;
|
||||
final int tcx = p2x >> 4;
|
||||
final int tcz = p2z >> 4;
|
||||
|
||||
queue.setReadRegion(
|
||||
new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()));
|
||||
queue.setChunkConsumer(blockVector2 -> {
|
||||
int x = blockVector2.getX();
|
||||
int z = blockVector2.getZ();
|
||||
|
Reference in New Issue
Block a user