2020-02-12 21:18:36 +00:00
|
|
|
package com.boydti.fawe.bukkit.regions.plotsquared;
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.boydti.fawe.util.EditSessionBuilder;
|
|
|
|
import com.boydti.fawe.util.TaskManager;
|
2020-07-02 13:34:05 +00:00
|
|
|
import com.plotsquared.core.configuration.Settings;
|
|
|
|
import com.plotsquared.core.generator.HybridPlotManager;
|
|
|
|
import com.plotsquared.core.generator.HybridPlotWorld;
|
2020-04-21 10:39:42 +00:00
|
|
|
import com.plotsquared.core.location.Location;
|
|
|
|
import com.plotsquared.core.plot.Plot;
|
2020-05-20 08:44:59 +00:00
|
|
|
import com.plotsquared.core.plot.PlotArea;
|
2020-07-02 13:34:05 +00:00
|
|
|
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
|
|
|
import com.plotsquared.core.plot.PlotAreaType;
|
|
|
|
import com.plotsquared.core.plot.PlotManager;
|
2020-05-14 15:20:17 +00:00
|
|
|
import com.plotsquared.core.util.RegionManager;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.MaxChangedBlocksException;
|
2020-02-12 21:18:36 +00:00
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
2020-07-04 11:45:00 +00:00
|
|
|
import com.sk89q.worldedit.extent.Extent;
|
|
|
|
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
2020-07-02 13:34:05 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
|
|
|
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
2020-05-14 15:20:17 +00:00
|
|
|
import com.sk89q.worldedit.function.FlatRegionFunction;
|
|
|
|
import com.sk89q.worldedit.function.biome.BiomeReplace;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
|
|
|
import com.sk89q.worldedit.function.operation.Operations;
|
2020-05-20 08:44:59 +00:00
|
|
|
import com.sk89q.worldedit.function.pattern.Pattern;
|
2020-05-14 15:20:17 +00:00
|
|
|
import com.sk89q.worldedit.function.visitor.FlatRegionVisitor;
|
2020-07-04 11:45:00 +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;
|
2020-05-20 08:44:59 +00:00
|
|
|
import com.sk89q.worldedit.regions.Region;
|
2018-08-12 14:03:07 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2020-05-14 15:20:17 +00:00
|
|
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
2020-07-02 13:51:09 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockType;
|
2020-07-02 13:34:05 +00:00
|
|
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2020-07-02 13:34:05 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.IOException;
|
2020-05-20 08:44:59 +00:00
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import static org.bukkit.Bukkit.getWorld;
|
|
|
|
|
2020-05-14 15:20:17 +00:00
|
|
|
public class FaweRegionManager extends RegionManager {
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2020-05-14 15:20:17 +00:00
|
|
|
private RegionManager parent;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2020-05-14 15:20:17 +00:00
|
|
|
public FaweRegionManager(RegionManager parent) {
|
2018-08-12 14:03:07 +00:00
|
|
|
this.parent = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int[] countEntities(Plot plot) {
|
|
|
|
return parent.countEntities(plot);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clearAllEntities(Location pos1, Location pos2) {
|
|
|
|
parent.clearAllEntities(pos1, pos2);
|
|
|
|
}
|
|
|
|
|
2020-05-20 08:44:59 +00:00
|
|
|
@Override
|
|
|
|
public boolean setCuboids(final PlotArea area, final Set<CuboidRegion> regions, final Pattern blocks, final int minY, final int maxY) {
|
|
|
|
TaskManager.IMP.async(() -> {
|
|
|
|
synchronized (FaweRegionManager.class) {
|
|
|
|
World world = BukkitAdapter.adapt(getWorld(area.getWorldName()));
|
|
|
|
EditSession session = new EditSessionBuilder(world).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
|
|
|
for (CuboidRegion region : regions) {
|
|
|
|
region.setPos1(region.getPos1().withY(minY));
|
|
|
|
region.setPos2(region.getPos2().withY(maxY));
|
|
|
|
session.setBlocks((Region) region, blocks);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
session.flushQueue();
|
|
|
|
} catch (MaxChangedBlocksException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-07-02 13:34:05 +00:00
|
|
|
@Override
|
|
|
|
public boolean notifyClear(PlotManager manager) {
|
|
|
|
if (!(manager instanceof HybridPlotManager)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final HybridPlotWorld hpw = ((HybridPlotManager) manager).getHybridPlotWorld();
|
|
|
|
return hpw.getType() != PlotAreaType.AUGMENTED || hpw.getTerrain() == PlotAreaTerrainType.NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean handleClear(final Plot plot, final Runnable whenDone, final PlotManager manager) {
|
|
|
|
if (!(manager instanceof HybridPlotManager)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
TaskManager.IMP.async(() -> {
|
|
|
|
synchronized (FaweRegionManager.class) {
|
|
|
|
final HybridPlotWorld hybridPlotWorld = ((HybridPlotManager) manager).getHybridPlotWorld();
|
|
|
|
EditSession editSession = new EditSessionBuilder(BukkitAdapter.adapt(getWorld(hybridPlotWorld.getWorldName()))).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
|
|
|
|
|
|
|
if (!hybridPlotWorld.PLOT_SCHEMATIC || !Settings.Schematics.PASTE_ON_TOP) {
|
2020-07-02 13:51:09 +00:00
|
|
|
final BlockType bedrock;
|
|
|
|
final BlockType air = BlockTypes.AIR;
|
2020-07-02 13:34:05 +00:00
|
|
|
if (hybridPlotWorld.PLOT_BEDROCK) {
|
2020-07-02 13:51:09 +00:00
|
|
|
bedrock = BlockTypes.BEDROCK;
|
2020-07-02 13:34:05 +00:00
|
|
|
} else {
|
|
|
|
bedrock = air;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Pattern filling = hybridPlotWorld.MAIN_BLOCK.toPattern();
|
|
|
|
final Pattern plotfloor = hybridPlotWorld.TOP_BLOCK.toPattern();
|
2020-07-04 11:45:00 +00:00
|
|
|
final BiomeType biome = hybridPlotWorld.getPlotBiome();
|
2020-07-02 13:34:05 +00:00
|
|
|
|
|
|
|
BlockVector3 pos1 = plot.getBottomAbs().getBlockVector3();
|
|
|
|
BlockVector3 pos2 = plot.getExtendedTopAbs().getBlockVector3();
|
|
|
|
|
|
|
|
Region bedrockRegion = new CuboidRegion(pos1.withY(0), pos2.withY(0));
|
|
|
|
Region fillingRegion = new CuboidRegion(pos1.withY(1), pos2.withY(hybridPlotWorld.PLOT_HEIGHT - 1));
|
|
|
|
Region floorRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.PLOT_HEIGHT),
|
|
|
|
pos2.withY(hybridPlotWorld.PLOT_HEIGHT));
|
|
|
|
Region airRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.PLOT_HEIGHT + 1),
|
|
|
|
pos2.withY(manager.getWorldHeight()));
|
|
|
|
|
2020-07-04 11:45:00 +00:00
|
|
|
Clipboard clipboard = new BlockArrayClipboard(new CuboidRegion(pos1, pos2));
|
|
|
|
|
|
|
|
clipboard.setBlocks(bedrockRegion, bedrock);
|
|
|
|
clipboard.setBlocks(fillingRegion, filling);
|
|
|
|
clipboard.setBlocks(floorRegion, plotfloor);
|
|
|
|
clipboard.setBlocks(airRegion, air);
|
|
|
|
for (int x = pos1.getX(); x <= pos2.getX(); x ++) {
|
|
|
|
for (int z = pos1.getX(); z <= pos2.getX(); z ++) {
|
|
|
|
clipboard.setBiome(BlockVector2.at(x, z), biome);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboard.paste(editSession, pos1, true, false, true);
|
2020-07-02 13:34:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hybridPlotWorld.PLOT_SCHEMATIC) {
|
|
|
|
File schematicFile = new File(hybridPlotWorld.getRoot(), "plot.schem");
|
|
|
|
if (!schematicFile.exists()) {
|
|
|
|
schematicFile = new File(hybridPlotWorld.getRoot(), "plot.schematic");
|
|
|
|
}
|
|
|
|
BlockVector3 to = plot.getBottomAbs().getBlockVector3().withY(Settings.Schematics.PASTE_ON_TOP ? hybridPlotWorld.SCHEM_Y : 1);
|
|
|
|
try {
|
|
|
|
Clipboard clip = ClipboardFormats.findByFile(schematicFile).getReader(new FileInputStream(schematicFile)).read();
|
|
|
|
clip.paste(editSession, to, true, true, true);
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
editSession.flushQueue();
|
|
|
|
|
|
|
|
TaskManager.IMP.task(whenDone);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@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(() -> {
|
2020-05-14 15:20:17 +00:00
|
|
|
synchronized (FaweRegionManager.class) {
|
2020-02-12 21:18:36 +00:00
|
|
|
//todo because of the following code this should proably be in the Bukkit module
|
|
|
|
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
|
|
|
|
World pos3World = BukkitAdapter.adapt(getWorld(pos3.getWorld()));
|
|
|
|
WorldEdit.getInstance().getEditSessionFactory().getEditSession(
|
|
|
|
pos1World,-1);
|
|
|
|
EditSession sessionA = new EditSessionBuilder(pos1World).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
|
|
|
EditSession sessionB = new EditSessionBuilder(pos3World).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
2019-06-04 15:48:30 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-05-14 15:20:17 +00:00
|
|
|
@Override
|
|
|
|
public void setBiome(CuboidRegion region, int extendBiome, BiomeType biome, String world, Runnable whenDone) {
|
|
|
|
region.expand(BlockVector3.at(extendBiome, 0, extendBiome));
|
|
|
|
region.expand(BlockVector3.at(-extendBiome, 0, -extendBiome));
|
|
|
|
TaskManager.IMP.async(() -> {
|
|
|
|
synchronized (FaweRegionManager.class) {
|
|
|
|
EditSession editSession = new EditSessionBuilder(BukkitAdapter.adapt(getWorld(world))).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
|
|
|
FlatRegionFunction replace = new BiomeReplace(editSession, biome);
|
|
|
|
FlatRegionVisitor visitor = new FlatRegionVisitor(region, replace);
|
|
|
|
try {
|
|
|
|
Operations.completeLegacy(visitor);
|
|
|
|
editSession.flushQueue();
|
|
|
|
} catch (MaxChangedBlocksException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
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(() -> {
|
2020-05-14 15:20:17 +00:00
|
|
|
synchronized (FaweRegionManager.class) {
|
2020-02-12 21:18:36 +00:00
|
|
|
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
|
|
|
|
World pos3World = BukkitAdapter.adapt(getWorld(pos3.getWorld()));
|
|
|
|
EditSession from = new EditSessionBuilder(pos1World).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
|
|
|
EditSession to = new EditSessionBuilder(pos3World).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
|
2019-06-04 15:48:30 +00:00
|
|
|
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(() -> {
|
2020-05-14 15:20:17 +00:00
|
|
|
synchronized (FaweRegionManager.class) {
|
2020-02-12 21:18:36 +00:00
|
|
|
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
|
|
|
|
try (EditSession editSession = new EditSessionBuilder(pos1World).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()));
|
|
|
|
editSession.regenerate(region);
|
|
|
|
editSession.flushQueue();
|
|
|
|
}
|
2019-06-04 15:48:30 +00:00
|
|
|
TaskManager.IMP.task(whenDone);
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|