2019-10-23 04:23:52 +00:00
|
|
|
package com.boydti.fawe.regions.general.integrations.plotquared;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
import com.boydti.fawe.util.EditSessionBuilder;
|
|
|
|
import com.boydti.fawe.util.TaskManager;
|
2019-02-17 08:47:32 +00:00
|
|
|
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
|
|
|
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
|
|
|
import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
|
|
|
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
|
|
|
import com.sk89q.worldedit.function.operation.Operations;
|
2019-11-06 09:29:20 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector2;
|
2019-01-09 07:13:44 +00:00
|
|
|
import com.sk89q.worldedit.math.BlockVector3;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
|
|
|
import com.sk89q.worldedit.world.World;
|
2019-09-19 20:43:21 +00:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
|
|
|
public class FaweChunkManager extends ChunkManager {
|
|
|
|
|
|
|
|
private ChunkManager parent;
|
|
|
|
|
|
|
|
public FaweChunkManager(ChunkManager parent) {
|
|
|
|
this.parent = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int[] countEntities(Plot plot) {
|
|
|
|
return parent.countEntities(plot);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-11-06 09:29:20 +00:00
|
|
|
public CompletableFuture loadChunk(String world, BlockVector2 loc, boolean force) {
|
2018-08-12 14:03:07 +00:00
|
|
|
return parent.loadChunk(world, loc, force);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-11-06 09:29:20 +00:00
|
|
|
public void unloadChunk(String world, BlockVector2 loc, boolean save) {
|
2019-09-19 20:43:21 +00:00
|
|
|
parent.unloadChunk(world, loc, save);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clearAllEntities(Location pos1, Location pos2) {
|
|
|
|
parent.clearAllEntities(pos1, pos2);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void swap(final Location pos1, final Location pos2, final Location pos3, final Location pos4, final Runnable whenDone) {
|
2019-06-04 15:48:30 +00:00
|
|
|
TaskManager.IMP.async(() -> {
|
|
|
|
synchronized (FaweChunkManager.class) {
|
|
|
|
EditSession sessionA = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
|
|
|
EditSession sessionB = new EditSessionBuilder(pos3.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
|
|
|
CuboidRegion regionA = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
|
|
|
|
CuboidRegion regionB = new CuboidRegion(BlockVector3.at(pos3.getX(), pos3.getY(), pos3.getZ()), BlockVector3.at(pos4.getX(), pos4.getY(), pos4.getZ()));
|
|
|
|
ForwardExtentCopy copyA = new ForwardExtentCopy(sessionA, regionA, sessionB, regionB.getMinimumPoint());
|
|
|
|
ForwardExtentCopy copyB = new ForwardExtentCopy(sessionB, regionB, sessionA, regionA.getMinimumPoint());
|
|
|
|
try {
|
|
|
|
Operations.completeLegacy(copyA);
|
|
|
|
Operations.completeLegacy(copyB);
|
|
|
|
sessionA.flushQueue();
|
|
|
|
sessionB.flushQueue();
|
|
|
|
} catch (MaxChangedBlocksException e) {
|
|
|
|
e.printStackTrace();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2019-06-04 15:48:30 +00:00
|
|
|
TaskManager.IMP.task(whenDone);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean copyRegion(final Location pos1, final Location pos2, final Location pos3, final Runnable whenDone) {
|
2019-06-04 15:48:30 +00:00
|
|
|
TaskManager.IMP.async(() -> {
|
|
|
|
synchronized (FaweChunkManager.class) {
|
|
|
|
EditSession from = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
|
|
|
EditSession to = new EditSessionBuilder(pos3.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
|
|
|
CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
|
|
|
|
ForwardExtentCopy copy = new ForwardExtentCopy(from, region, to, BlockVector3.at(pos3.getX(), pos3.getY(), pos3.getZ()));
|
|
|
|
try {
|
|
|
|
Operations.completeLegacy(copy);
|
|
|
|
to.flushQueue();
|
|
|
|
} catch (MaxChangedBlocksException e) {
|
|
|
|
e.printStackTrace();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
2019-06-04 15:48:30 +00:00
|
|
|
TaskManager.IMP.task(whenDone);
|
2018-08-12 14:03:07 +00:00
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean regenerateRegion(final Location pos1, final Location pos2, boolean ignore, final Runnable whenDone) {
|
2019-06-04 15:48:30 +00:00
|
|
|
TaskManager.IMP.async(() -> {
|
|
|
|
synchronized (FaweChunkManager.class) {
|
|
|
|
EditSession editSession = new EditSessionBuilder(pos1.getWorld()).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
|
|
|
World world = editSession.getWorld();
|
|
|
|
CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
|
2019-11-02 12:51:22 +00:00
|
|
|
editSession.regenerate(region);
|
2019-06-04 15:48:30 +00:00
|
|
|
editSession.flushQueue();
|
|
|
|
TaskManager.IMP.task(whenDone);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|