Start switching to WorldEdit Worlds

This commit is contained in:
dordsor21 2020-07-17 17:21:32 +01:00
parent 74c6fc954e
commit 66b94ab9f1
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B
11 changed files with 29 additions and 33 deletions

View File

@ -74,16 +74,13 @@ public class BukkitChunkManager extends ChunkManager {
int sx = pos1.getX() << 4; int sx = pos1.getX() << 4;
int sz = pos1.getZ() << 4; int sz = pos1.getZ() << 4;
String worldName1 = world1.getName();
String worldName2 = world2.getName();
BukkitWorld bukkitWorld1 = new BukkitWorld(world1); BukkitWorld bukkitWorld1 = new BukkitWorld(world1);
BukkitWorld bukkitWorld2 = new BukkitWorld(world2); BukkitWorld bukkitWorld2 = new BukkitWorld(world2);
QueueCoordinator queue1 = QueueCoordinator queue1 =
PlotSquared.platform().getGlobalBlockQueue().getNewQueue(worldName1, false); PlotSquared.platform().getGlobalBlockQueue().getNewQueue(bukkitWorld1, false);
QueueCoordinator queue2 = QueueCoordinator queue2 =
PlotSquared.platform().getGlobalBlockQueue().getNewQueue(worldName2, false); PlotSquared.platform().getGlobalBlockQueue().getNewQueue(bukkitWorld2, false);
for (int x = Math.max(r1.getMinimumPoint().getX(), sx); for (int x = Math.max(r1.getMinimumPoint().getX(), sx);
x <= Math.min(r1.getMaximumPoint().getX(), sx + 15); x++) { x <= Math.min(r1.getMaximumPoint().getX(), sx + 15); x++) {

View File

@ -41,6 +41,7 @@ import com.plotsquared.core.util.ChunkManager;
import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MainUtil;
import com.plotsquared.core.util.RegionManager; import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.RegionUtil; import com.plotsquared.core.util.RegionUtil;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.entity.EntityCategories; import com.plotsquared.core.util.entity.EntityCategories;
import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager; import com.plotsquared.core.util.task.TaskManager;
@ -84,9 +85,12 @@ public class BukkitRegionManager extends RegionManager {
private static final Logger logger = private static final Logger logger =
LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName()); LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName());
private final WorldUtil worldUtil;
@Inject public BukkitRegionManager(@Nonnull final ChunkManager chunkManager) { @Inject public BukkitRegionManager(@Nonnull final ChunkManager chunkManager,
super(chunkManager); @Nonnull final WorldUtil worldUtil) {
super(chunkManager, worldUtil);
this.worldUtil = worldUtil;
} }
public static boolean isIn(CuboidRegion region, int x, int z) { public static boolean isIn(CuboidRegion region, int x, int z) {
@ -210,15 +214,11 @@ public class BukkitRegionManager extends RegionManager {
final CuboidRegion region = final CuboidRegion region =
RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ()); RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
final World oldWorld = Bukkit.getWorld(pos1.getWorldName()); final BukkitWorld oldWorld = new BukkitWorld((World) pos1.getWorld());
final BukkitWorld oldBukkitWorld = new BukkitWorld(oldWorld); final BukkitWorld newWorld = new BukkitWorld((World) newPos.getWorld());
final World newWorld = Bukkit.getWorld(newPos.getWorldName());
assert newWorld != null;
assert oldWorld != null;
final String newWorldName = newWorld.getName();
final ContentMap map = new ContentMap(); final ContentMap map = new ContentMap();
final QueueCoordinator queue = final QueueCoordinator queue =
PlotSquared.platform().getGlobalBlockQueue().getNewQueue(newWorldName, false); PlotSquared.platform().getGlobalBlockQueue().getNewQueue(newWorld, false);
ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() { ChunkManager.chunkTask(pos1, pos2, new RunnableVal<int[]>() {
@Override public void run(int[] value) { @Override public void run(int[] value) {
int bx = value[2]; int bx = value[2];
@ -232,7 +232,7 @@ public class BukkitRegionManager extends RegionManager {
.thenAccept(chunk1 -> map.saveEntitiesIn(chunk1, region)).thenRun(() -> { .thenAccept(chunk1 -> map.saveEntitiesIn(chunk1, region)).thenRun(() -> {
for (int x = bx & 15; x <= (tx & 15); x++) { for (int x = bx & 15; x <= (tx & 15); x++) {
for (int z = bz & 15; z <= (tz & 15); z++) { for (int z = bz & 15; z <= (tz & 15); z++) {
map.saveBlocks(oldBukkitWorld, 256, cxx + x, czz + z, relX, relZ); map.saveBlocks(oldWorld, 256, cxx + x, czz + z, relX, relZ);
} }
} }
}); });
@ -250,7 +250,7 @@ public class BukkitRegionManager extends RegionManager {
} }
queue.setCompleteTask(() -> { queue.setCompleteTask(() -> {
//map.restoreBlocks(newWorld, 0, 0); //map.restoreBlocks(newWorld, 0, 0);
map.restoreEntities(newWorld, relX, relZ); map.restoreEntities((World) newPos.getWorld(), relX, relZ);
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
}); });
queue.enqueue(); queue.enqueue();

View File

@ -190,7 +190,7 @@ public class Trim extends SubCommand {
} }
} }
} }
final QueueCoordinator queue = blockQueue.getNewQueue(world, false); final QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world), false);
TaskManager.getPlatformImplementation().objectTask(chunks, new RunnableVal<BlockVector2>() { TaskManager.getPlatformImplementation().objectTask(chunks, new RunnableVal<BlockVector2>() {
@Override public void run(BlockVector2 value) { @Override public void run(BlockVector2 value) {
queue.regenChunk(value.getX(), value.getZ()); queue.regenChunk(value.getX(), value.getZ());

View File

@ -87,7 +87,7 @@ public class AugmentedUtils {
IndependentPlotGenerator generator = area.getGenerator(); IndependentPlotGenerator generator = area.getGenerator();
// Mask // Mask
if (queue == null) { if (queue == null) {
queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false); queue = PlotSquared.platform().getGlobalBlockQueue().getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(world), false);
queue.setChunkObject(chunkObject); queue.setChunkObject(chunkObject);
} }
QueueCoordinator primaryMask; QueueCoordinator primaryMask;

View File

@ -128,7 +128,7 @@ public class HybridUtils {
* *
*/ */
TaskManager.runTaskAsync(() -> { TaskManager.runTaskAsync(() -> {
final QueueCoordinator queue = blockQueue.getNewQueue(world, false); final QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world), false);
final BlockVector3 bot = region.getMinimumPoint(); final BlockVector3 bot = region.getMinimumPoint();
final BlockVector3 top = region.getMaximumPoint(); final BlockVector3 top = region.getMaximumPoint();
@ -520,7 +520,7 @@ public class HybridUtils {
public boolean setupRoadSchematic(Plot plot) { public boolean setupRoadSchematic(Plot plot) {
final String world = plot.getWorldName(); final String world = plot.getWorldName();
final QueueCoordinator queue = blockQueue.getNewQueue(world, false); final QueueCoordinator queue = blockQueue.getNewQueue(worldUtil.getWeWorld(world), false);
Location bot = plot.getBottomAbs().subtract(1, 0, 1); Location bot = plot.getBottomAbs().subtract(1, 0, 1);
Location top = plot.getTopAbs(); Location top = plot.getTopAbs();
final HybridPlotWorld plotworld = (HybridPlotWorld) plot.getArea(); final HybridPlotWorld plotworld = (HybridPlotWorld) plot.getArea();
@ -607,7 +607,7 @@ public class HybridUtils {
z -= plotWorld.ROAD_OFFSET_Z; z -= plotWorld.ROAD_OFFSET_Z;
final int finalX = x; final int finalX = x;
final int finalZ = z; final int finalZ = z;
QueueCoordinator queue = this.blockQueue.getNewQueue(plotWorld.getWorldName(), false); QueueCoordinator queue = this.blockQueue.getNewQueue(worldUtil.getWeWorld(plotWorld.getWorldName()), false);
if (id1 == null || id2 == null || id1 != id2) { if (id1 == null || id2 == null || id1 != id2) {
this.chunkManager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> { this.chunkManager.loadChunk(area.getWorldName(), chunk, false).thenRun(() -> {
if (id1 != null) { if (id1 != null) {

View File

@ -1687,7 +1687,7 @@ public class Plot {
* This should not need to be called * This should not need to be called
*/ */
public void refreshChunks() { public void refreshChunks() {
QueueCoordinator queue = this.blockQueue.getNewQueue(getWorldName(), false); QueueCoordinator queue = this.blockQueue.getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(getWorldName()), false);
HashSet<BlockVector2> chunks = new HashSet<>(); HashSet<BlockVector2> chunks = new HashSet<>();
for (CuboidRegion region : Plot.this.getRegions()) { for (CuboidRegion region : Plot.this.getRegions()) {
for (int x = region.getMinimumPoint().getX() >> 4; for (int x = region.getMinimumPoint().getX() >> 4;

View File

@ -27,6 +27,7 @@ package com.plotsquared.core.plot;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.collection.QuadMap; import com.plotsquared.core.collection.QuadMap;
import com.plotsquared.core.configuration.CaptionUtility; import com.plotsquared.core.configuration.CaptionUtility;
import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Captions;
@ -172,7 +173,7 @@ public abstract class PlotArea {
@Nonnull protected abstract PlotManager createManager(); @Nonnull protected abstract PlotManager createManager();
public QueueCoordinator getQueue(final boolean autoQueue) { public QueueCoordinator getQueue(final boolean autoQueue) {
return this.globalBlockQueue.getNewQueue(worldName, autoQueue); return this.globalBlockQueue.getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(worldName), autoQueue);
} }
/** /**

View File

@ -26,13 +26,9 @@
package com.plotsquared.core.queue; package com.plotsquared.core.queue;
import com.plotsquared.core.PlotSquared; import com.plotsquared.core.PlotSquared;
<<<<<<< HEAD import com.sk89q.worldedit.world.World;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
=======
import com.plotsquared.core.util.task.RunnableVal2;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.task.TaskTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -48,7 +44,7 @@ public class GlobalBlockQueue {
this.activeQueues = new ConcurrentLinkedDeque<>(); this.activeQueues = new ConcurrentLinkedDeque<>();
} }
public QueueCoordinator getNewQueue(String world, boolean autoQueue) { public QueueCoordinator getNewQueue(World world, boolean autoQueue) {
QueueCoordinator queue = provider.getNewQueue(world); QueueCoordinator queue = provider.getNewQueue(world);
// Auto-inject into the queue // Auto-inject into the queue
PlotSquared.platform().getInjector().injectMembers(queue); PlotSquared.platform().getInjector().injectMembers(queue);

View File

@ -25,6 +25,8 @@
*/ */
package com.plotsquared.core.queue; package com.plotsquared.core.queue;
import com.sk89q.worldedit.world.World;
public abstract class QueueProvider { public abstract class QueueProvider {
public static QueueProvider of(final Class<? extends QueueCoordinator> primary, public static QueueProvider of(final Class<? extends QueueCoordinator> primary,
final Class<? extends QueueCoordinator> fallback) { final Class<? extends QueueCoordinator> fallback) {
@ -32,7 +34,7 @@ public abstract class QueueProvider {
private boolean failed = false; private boolean failed = false;
@Override public QueueCoordinator getNewQueue(String world) { @Override public QueueCoordinator getNewQueue(World world) {
if (!failed) { if (!failed) {
try { try {
return (QueueCoordinator) primary.getConstructors()[0].newInstance(world); return (QueueCoordinator) primary.getConstructors()[0].newInstance(world);
@ -51,5 +53,5 @@ public abstract class QueueProvider {
}; };
} }
public abstract QueueCoordinator getNewQueue(String world); public abstract QueueCoordinator getNewQueue(World world);
} }

View File

@ -51,7 +51,7 @@ public abstract class ChunkManager {
public static void setChunkInPlotArea(RunnableVal<ScopedQueueCoordinator> force, public static void setChunkInPlotArea(RunnableVal<ScopedQueueCoordinator> force,
RunnableVal<ScopedQueueCoordinator> add, String world, BlockVector2 loc) { RunnableVal<ScopedQueueCoordinator> add, String world, BlockVector2 loc) {
QueueCoordinator queue = QueueCoordinator queue =
PlotSquared.platform().getGlobalBlockQueue().getNewQueue(world, false); PlotSquared.platform().getGlobalBlockQueue().getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(world), false);
if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get() if (PlotSquared.get().getPlotAreaManager().isAugmented(world) && PlotSquared.get()
.isNonStandardGeneration(world, loc)) { .isNonStandardGeneration(world, loc)) {
int blockX = loc.getX() << 4; int blockX = loc.getX() << 4;

View File

@ -55,7 +55,7 @@ public abstract class RegionManager {
public static RegionManager manager = null; public static RegionManager manager = null;
private final ChunkManager chunkManager; private final ChunkManager chunkManager;
public RegionManager(@Nonnull final ChunkManager chunkManager) { public RegionManager(@Nonnull final ChunkManager chunkManager, @Nonnull WorldUtil worldUtil) {
this.chunkManager = chunkManager; this.chunkManager = chunkManager;
} }