mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Continue implementation of new queue system
- Move ChunkCoordinatorBuild to Core - Add core ChunkCoordinator - Add Factories for ChunkCoordinator and its Builder - Reimplement refreshChunk but in WorldUtil - Allow custom Consumers to be used by the Queue when sent to the ChunkCoordinator - Start switching ChunkTasks to use the new ChunkCoordinator system - Replace GlobalBlockQueue's "empty task" system with normal sync TaskManager - Remove lombok from the queue system - Add back forceSync and chunkObject from LocalBlockQueue
This commit is contained in:
@ -42,6 +42,8 @@ import com.plotsquared.core.util.MainUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.task.RunnableVal2;
|
||||
import com.plotsquared.core.util.task.RunnableVal3;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -91,7 +93,7 @@ public class Clear extends Command {
|
||||
final long start = System.currentTimeMillis();
|
||||
boolean result = plot.clear(true, false, () -> {
|
||||
plot.unlink();
|
||||
this.blockQueue.addEmptyTask(() -> {
|
||||
TaskManager.runTask(() -> {
|
||||
plot.removeRunning();
|
||||
// If the state changes, then mark it as no longer done
|
||||
if (DoneFlag.isDone(plot)) {
|
||||
|
@ -70,20 +70,17 @@ public class Template extends SubCommand {
|
||||
private final YamlConfiguration worldConfiguration;
|
||||
private final File worldFile;
|
||||
private final SetupUtils setupUtils;
|
||||
private final GlobalBlockQueue globalBlockQueue;
|
||||
private final WorldUtil worldUtil;
|
||||
|
||||
@Inject public Template(@Nonnull final PlotAreaManager plotAreaManager,
|
||||
@WorldConfig @Nonnull final YamlConfiguration worldConfiguration,
|
||||
@WorldFile @Nonnull final File worldFile,
|
||||
@Nonnull final SetupUtils setupUtils,
|
||||
@Nonnull final GlobalBlockQueue globalBlockQueue,
|
||||
@Nonnull final WorldUtil worldUtil) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.worldConfiguration = worldConfiguration;
|
||||
this.worldFile = worldFile;
|
||||
this.setupUtils = setupUtils;
|
||||
this.globalBlockQueue = globalBlockQueue;
|
||||
this.worldUtil = worldUtil;
|
||||
}
|
||||
|
||||
@ -216,7 +213,7 @@ public class Template extends SubCommand {
|
||||
.worldName(world);
|
||||
|
||||
this.setupUtils.setupWorld(builder);
|
||||
this.globalBlockQueue.addEmptyTask(() -> {
|
||||
TaskManager.runTask(() -> {
|
||||
MainUtil.sendMessage(player, "Done!");
|
||||
player.teleport(this.worldUtil.getSpawn(world), TeleportCause.COMMAND);
|
||||
});
|
||||
|
@ -25,7 +25,6 @@
|
||||
*/
|
||||
package com.plotsquared.core.generator;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.location.Direction;
|
||||
import com.plotsquared.core.location.Location;
|
||||
@ -37,6 +36,7 @@ import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.BlockUtil;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
@ -92,7 +92,8 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
.equals(classicPlotWorld.CLAIMED_WALL_BLOCK)) {
|
||||
setWall(plot.getId(), classicPlotWorld.WALL_BLOCK.toPattern());
|
||||
}
|
||||
return PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(whenDone);
|
||||
TaskManager.runTask(whenDone);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean setFloor(PlotId plotId, Pattern blocks) {
|
||||
|
@ -510,7 +510,7 @@ public class HybridUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
blockQueue.addEmptyTask(() -> TaskManager.runTaskLater(task, TaskTime.seconds(1L)));
|
||||
TaskManager.runTaskLater(task, TaskTime.seconds(1L));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -25,12 +25,16 @@
|
||||
*/
|
||||
package com.plotsquared.core.inject.factory;
|
||||
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.plotsquared.core.queue.ChunkCoordinatorBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public interface QueueCoordinatorFactory {
|
||||
public interface ChunkCoordinatorBuilderFactory {
|
||||
|
||||
@Nonnull QueueCoordinator create();
|
||||
@Inject @Nonnull ChunkCoordinatorBuilder create(
|
||||
@Assisted @NotNull ChunkCoordinatorFactory chunkCoordinatorFactory);
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* _____ _ _ _____ _
|
||||
* | __ \| | | | / ____| | |
|
||||
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
||||
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
||||
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
||||
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
||||
* | |
|
||||
* |_|
|
||||
* PlotSquared plot management system for Minecraft
|
||||
* Copyright (C) 2020 IntellectualSites
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.core.inject.factory;
|
||||
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
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;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface ChunkCoordinatorFactory {
|
||||
|
||||
@Nonnull ChunkCoordinator create(@Assisted final long maxIterationTime,
|
||||
@Assisted final int initialBatchSize,
|
||||
@NotNull @Assisted final Consumer<BlockVector2> chunkConsumer,
|
||||
@NotNull @Assisted final World world,
|
||||
@NotNull @Assisted final Collection<BlockVector2> requestedChunks,
|
||||
@NotNull @Assisted final Runnable whenDone,
|
||||
@NotNull @Assisted final Consumer<Throwable> throwableConsumer);
|
||||
|
||||
}
|
@ -965,7 +965,7 @@ public class Plot {
|
||||
manager.claimPlot(current);
|
||||
}
|
||||
}
|
||||
blockQueue.addEmptyTask(run);
|
||||
TaskManager.runTask(run);
|
||||
return;
|
||||
}
|
||||
Plot current = queue.poll();
|
||||
@ -1061,12 +1061,10 @@ public class Plot {
|
||||
current.setMerged(merged);
|
||||
}
|
||||
if (createSign) {
|
||||
blockQueue.addEmptyTask(() -> {
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
for (Plot current : plots) {
|
||||
current.setSign(MainUtil.getName(current.getOwnerAbs()));
|
||||
}
|
||||
});
|
||||
TaskManager.runTaskAsync(() -> {
|
||||
for (Plot current : plots) {
|
||||
current.setSign(MainUtil.getName(current.getOwnerAbs()));
|
||||
}
|
||||
});
|
||||
}
|
||||
if (createRoad) {
|
||||
@ -1687,7 +1685,8 @@ public class Plot {
|
||||
* This should not need to be called
|
||||
*/
|
||||
public void refreshChunks() {
|
||||
QueueCoordinator queue = this.blockQueue.getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(getWorldName()), false);
|
||||
QueueCoordinator queue = this.blockQueue
|
||||
.getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(getWorldName()), false);
|
||||
HashSet<BlockVector2> chunks = new HashSet<>();
|
||||
for (CuboidRegion region : Plot.this.getRegions()) {
|
||||
for (int x = region.getMinimumPoint().getX() >> 4;
|
||||
@ -1695,7 +1694,7 @@ public class Plot {
|
||||
for (int z = region.getMinimumPoint().getZ() >> 4;
|
||||
z <= region.getMaximumPoint().getZ() >> 4; z++) {
|
||||
if (chunks.add(BlockVector2.at(x, z))) {
|
||||
queue.refreshChunk(x, z);
|
||||
worldUtil.refreshChunk(x, z, getWorldName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1711,7 +1710,8 @@ public class Plot {
|
||||
return;
|
||||
}
|
||||
Location location = manager.getSignLoc(this);
|
||||
QueueCoordinator queue = this.blockQueue.getNewQueue(getWorldName(), false);
|
||||
QueueCoordinator queue =
|
||||
this.blockQueue.getNewQueue(worldUtil.getWeWorld(getWorldName()), false);
|
||||
queue.setBlock(location.getX(), location.getY(), location.getZ(),
|
||||
BlockTypes.AIR.getDefaultState());
|
||||
queue.enqueue();
|
||||
|
@ -31,7 +31,6 @@ import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
@ -39,7 +38,7 @@ import java.util.Objects;
|
||||
|
||||
public class AreaBoundDelegateQueueCoordinator extends DelegateQueueCoordinator {
|
||||
|
||||
@Getter private final PlotArea area;
|
||||
private final PlotArea area;
|
||||
|
||||
public AreaBoundDelegateQueueCoordinator(@Nonnull final PlotArea area,
|
||||
@Nullable final QueueCoordinator parent) {
|
||||
@ -47,6 +46,10 @@ public class AreaBoundDelegateQueueCoordinator extends DelegateQueueCoordinator
|
||||
this.area = Objects.requireNonNull(area);
|
||||
}
|
||||
|
||||
public PlotArea getArea() {
|
||||
return this.area;
|
||||
}
|
||||
|
||||
@Override public boolean setBlock(int x, int y, int z, BlockState id) {
|
||||
if (area.contains(x, z)) {
|
||||
return super.setBlock(x, y, z, id);
|
||||
|
@ -33,22 +33,23 @@ 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 lombok.Getter;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
|
||||
private final World world;
|
||||
@Getter private final ConcurrentHashMap<BlockVector2, LocalChunk> blockChunks =
|
||||
private final ConcurrentHashMap<BlockVector2, LocalChunk> blockChunks =
|
||||
new ConcurrentHashMap<>();
|
||||
private long modified;
|
||||
private LocalChunk lastWrappedChunk;
|
||||
private int lastX = Integer.MIN_VALUE;
|
||||
private int lastZ = Integer.MIN_VALUE;
|
||||
@Getter private boolean settingBiomes = false;
|
||||
@Getter private boolean settingTiles = false;
|
||||
private boolean settingBiomes = false;
|
||||
private boolean settingTiles = false;
|
||||
private Consumer<BlockVector2> consumer = null;
|
||||
|
||||
private GlobalBlockQueue globalBlockQueue;
|
||||
|
||||
@ -97,7 +98,7 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
return setBlock(x, y, z, id.toBaseBlock());
|
||||
}
|
||||
|
||||
@Override public final boolean setBiome(int x, int z, BiomeType biomeType) {
|
||||
@Override public boolean setBiome(int x, int z, BiomeType biomeType) {
|
||||
LocalChunk chunk = getChunk(x >> 4, z >> 4);
|
||||
for (int y = 0; y < 256; y++) {
|
||||
chunk.setBiome(x & 15, y, z & 15, biomeType);
|
||||
@ -113,17 +114,37 @@ public abstract class BasicQueueCoordinator extends QueueCoordinator {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public final boolean setTile(int x, int y, int z, CompoundTag tag) {
|
||||
@Override public boolean isSettingBiomes() {
|
||||
return this.settingBiomes;
|
||||
}
|
||||
|
||||
@Override public boolean setTile(int x, int y, int z, CompoundTag tag) {
|
||||
LocalChunk chunk = getChunk(x >> 4, z >> 4);
|
||||
chunk.setTile(x, y, z, tag);
|
||||
settingTiles = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public boolean isSettingTiles() {
|
||||
return this.settingTiles;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<BlockVector2, LocalChunk> getBlockChunks() {
|
||||
return this.blockChunks;
|
||||
}
|
||||
|
||||
public final void setChunk(LocalChunk chunk) {
|
||||
this.blockChunks.put(BlockVector2.at(chunk.getX(), chunk.getZ()), chunk);
|
||||
}
|
||||
|
||||
public final Consumer<BlockVector2> getChunkConsumer() {
|
||||
return this.consumer;
|
||||
}
|
||||
|
||||
public final void setChunkConsumer(Consumer<BlockVector2> consumer) {
|
||||
this.consumer = consumer;
|
||||
}
|
||||
|
||||
private LocalChunk getChunk(final int chunkX, final int chunkZ) {
|
||||
if (chunkX != lastX || chunkZ != lastZ) {
|
||||
lastX = chunkX;
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.plotsquared.core.queue;
|
||||
|
||||
import com.plotsquared.core.util.task.PlotSquaredTask;
|
||||
|
||||
public abstract class ChunkCoordinator implements PlotSquaredTask {
|
||||
|
||||
@Override public abstract void runTask();
|
||||
|
||||
@Override public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public void cancel() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
public abstract void start();
|
||||
|
||||
public abstract int getRemainingChunks();
|
||||
|
||||
public abstract int getTotalChunks();
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package com.plotsquared.core.queue;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
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.world.World;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ChunkCoordinatorBuilder {
|
||||
|
||||
private final List<BlockVector2> requestedChunks = new LinkedList<>();
|
||||
private Consumer<Throwable> throwableConsumer = Throwable::printStackTrace;
|
||||
private World world;
|
||||
private Consumer<BlockVector2> chunkConsumer;
|
||||
private Runnable whenDone = () -> {
|
||||
};
|
||||
private long maxIterationTime = 60; // A little over 1 tick;
|
||||
private int initialBatchSize = 4;
|
||||
private final ChunkCoordinatorFactory chunkCoordinatorFactory;
|
||||
|
||||
@Inject public ChunkCoordinatorBuilder(@Nonnull ChunkCoordinatorFactory chunkCoordinatorFactory) {
|
||||
this.chunkCoordinatorFactory = chunkCoordinatorFactory;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder inWorld(@NotNull final World world) {
|
||||
this.world = Preconditions.checkNotNull(world, "World may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withChunk(@NotNull 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) {
|
||||
chunkLocations.forEach(this::withChunk);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withRegion(Location pos1, Location pos2) {
|
||||
final int p1x = pos1.getX();
|
||||
final int p1z = pos1.getZ();
|
||||
final int p2x = pos2.getX();
|
||||
final int p2z = pos2.getZ();
|
||||
final int bcx = p1x >> 4;
|
||||
final int bcz = p1z >> 4;
|
||||
final int tcx = p2x >> 4;
|
||||
final int tcz = p2z >> 4;
|
||||
final ArrayList<BlockVector2> chunks = new ArrayList<>();
|
||||
|
||||
for (int x = bcx; x <= tcx; x++) {
|
||||
for (int z = bcz; z <= tcz; z++) {
|
||||
chunks.add(BlockVector2.at(x, z));
|
||||
}
|
||||
}
|
||||
|
||||
chunks.forEach(this::withChunk);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withConsumer(
|
||||
@NotNull 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) {
|
||||
this.whenDone = Preconditions.checkNotNull(whenDone, "Final action may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull 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) {
|
||||
Preconditions.checkArgument(initialBatchSize > 0, "Initial batch size must be positive");
|
||||
this.initialBatchSize = initialBatchSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull public ChunkCoordinatorBuilder withThrowableConsumer(
|
||||
@NotNull final Consumer<Throwable> throwableConsumer) {
|
||||
this.throwableConsumer =
|
||||
Preconditions.checkNotNull(throwableConsumer, "Throwable consumer may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull 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);
|
||||
}
|
||||
|
||||
}
|
@ -27,11 +27,14 @@ package com.plotsquared.core.queue;
|
||||
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
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 java.util.function.Consumer;
|
||||
|
||||
public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||
|
||||
private final QueueCoordinator parent;
|
||||
@ -111,4 +114,8 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||
@Override public void setCompleteTask(Runnable whenDone) {
|
||||
parent.setCompleteTask(whenDone);
|
||||
}
|
||||
|
||||
@Override public void setChunkConsumer(Consumer<BlockVector2> consumer) {
|
||||
parent.setChunkConsumer(consumer);
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,6 @@ package com.plotsquared.core.queue;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -37,7 +35,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
public class GlobalBlockQueue {
|
||||
|
||||
private final ConcurrentLinkedDeque<QueueCoordinator> activeQueues;
|
||||
@Getter @Setter private QueueProvider provider;
|
||||
private QueueProvider provider;
|
||||
|
||||
public GlobalBlockQueue(QueueProvider provider) {
|
||||
this.provider = provider;
|
||||
@ -54,6 +52,14 @@ public class GlobalBlockQueue {
|
||||
return queue;
|
||||
}
|
||||
|
||||
public QueueProvider getProvider() {
|
||||
return this.provider;
|
||||
}
|
||||
|
||||
public void setQueueProvider(QueueProvider provider) {
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Documentation needed.
|
||||
*
|
||||
|
@ -6,18 +6,17 @@ import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LocalChunk {
|
||||
@Getter private final BasicQueueCoordinator parent;
|
||||
@Getter private final int z;
|
||||
@Getter private final int x;
|
||||
private final BasicQueueCoordinator parent;
|
||||
private final int x;
|
||||
private final int z;
|
||||
|
||||
@Getter private final BaseBlock[][] baseblocks;
|
||||
@Getter private final BiomeType[][] biomes;
|
||||
@Getter private final HashMap<BlockVector3, CompoundTag> tiles = new HashMap<>();
|
||||
private final BaseBlock[][] baseblocks;
|
||||
private final BiomeType[][] biomes;
|
||||
private final HashMap<BlockVector3, CompoundTag> tiles = new HashMap<>();
|
||||
|
||||
public LocalChunk(BasicQueueCoordinator parent, int x, int z) {
|
||||
this.parent = parent;
|
||||
@ -27,6 +26,30 @@ public class LocalChunk {
|
||||
biomes = new BiomeType[16][];
|
||||
}
|
||||
|
||||
public BasicQueueCoordinator getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return this.z;
|
||||
}
|
||||
|
||||
public BaseBlock[][] getBaseblocks() {
|
||||
return this.baseblocks;
|
||||
}
|
||||
|
||||
public BiomeType[][] getBiomes() {
|
||||
return this.biomes;
|
||||
}
|
||||
|
||||
public HashMap<BlockVector3, CompoundTag> getTiles() {
|
||||
return this.tiles;
|
||||
}
|
||||
|
||||
public void setBiome(final int x, final int y, final int z, final BiomeType biomeType) {
|
||||
final int i = MainUtil.CACHE_I[y][x][z];
|
||||
final int j = MainUtil.CACHE_J[y][x][z];
|
||||
|
@ -31,20 +31,21 @@ import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.util.PatternUtil;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
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 lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public abstract class QueueCoordinator {
|
||||
|
||||
@Getter @Setter private boolean forceSync = false;
|
||||
@Getter @Setter @Nullable private Object chunkObject;
|
||||
private boolean forceSync = false;
|
||||
@Nullable private Object chunkObject;
|
||||
|
||||
@Inject private GlobalBlockQueue blockQueue;
|
||||
|
||||
@ -63,6 +64,22 @@ public abstract class QueueCoordinator {
|
||||
|
||||
public abstract void setModified(long modified);
|
||||
|
||||
public boolean isForceSync() {
|
||||
return forceSync;
|
||||
}
|
||||
|
||||
public void setForceSync(boolean forceSync) {
|
||||
this.forceSync = forceSync;
|
||||
}
|
||||
|
||||
@Nullable public Object getChunkObject() {
|
||||
return chunkObject;
|
||||
}
|
||||
|
||||
public void setChunkObject(@NotNull Object chunkObject) {
|
||||
this.chunkObject = chunkObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the block at the coordinates provided to the given id.
|
||||
*
|
||||
@ -103,6 +120,8 @@ public abstract class QueueCoordinator {
|
||||
|
||||
public abstract void setCompleteTask(Runnable whenDone);
|
||||
|
||||
public abstract void setChunkConsumer(Consumer<BlockVector2> consumer);
|
||||
|
||||
public void setCuboid(Location pos1, Location pos2, BlockState block) {
|
||||
int yMin = Math.min(pos1.getY(), pos2.getY());
|
||||
int yMax = Math.min(255, Math.max(pos1.getY(), pos2.getY()));
|
||||
|
@ -26,10 +26,12 @@
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
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.ChunkCoordinatorBuilder;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.task.RunnableVal;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
@ -55,7 +57,8 @@ public abstract class RegionManager {
|
||||
public static RegionManager manager = null;
|
||||
private final ChunkManager chunkManager;
|
||||
|
||||
public RegionManager(@Nonnull final ChunkManager chunkManager, @Nonnull WorldUtil worldUtil) {
|
||||
public RegionManager(@Nonnull final ChunkManager chunkManager, @Nonnull WorldUtil worldUtil,
|
||||
@Nonnull ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory) {
|
||||
this.chunkManager = chunkManager;
|
||||
}
|
||||
|
||||
@ -95,12 +98,13 @@ public abstract class RegionManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
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)));
|
||||
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)));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -118,6 +118,8 @@ public abstract class WorldUtil {
|
||||
|
||||
public abstract com.sk89q.worldedit.world.World getWeWorld(String world);
|
||||
|
||||
public abstract void refreshChunk(int x, int z, String world);
|
||||
|
||||
public void upload(@Nonnull final Plot plot, UUID uuid, String file,
|
||||
RunnableVal<URL> whenDone) {
|
||||
plot.getHome(home -> MainUtil.upload(uuid, file, "zip", new RunnableVal<OutputStream>() {
|
||||
|
Reference in New Issue
Block a user