From d3afc9c65d4fd8137d00c45cc27d269573ae20e4 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Thu, 2 Jul 2020 14:34:05 +0100 Subject: [PATCH] Update to p2 5.12.2 and implement clear pipeline --- .../plotsquared/FaweRegionManager.java | 82 +++++++++++++++++++ .../regions/plotsquared/PlotSetBiome.java | 2 +- .../plotsquared/PlotSquaredFeature.java | 3 +- worldedit-core/build.gradle.kts | 2 +- 4 files changed, 85 insertions(+), 4 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/FaweRegionManager.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/FaweRegionManager.java index 7fe036c90..78da2d18b 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/FaweRegionManager.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/FaweRegionManager.java @@ -2,14 +2,22 @@ package com.boydti.fawe.bukkit.regions.plotsquared; import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.TaskManager; +import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.generator.HybridPlotManager; +import com.plotsquared.core.generator.HybridPlotWorld; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.PlotAreaTerrainType; +import com.plotsquared.core.plot.PlotAreaType; +import com.plotsquared.core.plot.PlotManager; import com.plotsquared.core.util.RegionManager; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.function.FlatRegionFunction; import com.sk89q.worldedit.function.biome.BiomeReplace; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; @@ -21,7 +29,12 @@ 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 com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockTypes; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; import java.util.Set; import static org.bukkit.Bukkit.getWorld; @@ -65,6 +78,75 @@ public class FaweRegionManager extends RegionManager { return true; } + @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) { + final BlockState bedrock; + final BlockState air = BlockTypes.AIR.getDefaultState(); + if (hybridPlotWorld.PLOT_BEDROCK) { + bedrock = BlockTypes.BEDROCK.getDefaultState(); + } else { + bedrock = air; + } + + final Pattern filling = hybridPlotWorld.MAIN_BLOCK.toPattern(); + final Pattern plotfloor = hybridPlotWorld.TOP_BLOCK.toPattern(); + + 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())); + + editSession.setBlocks(bedrockRegion, bedrock); + editSession.setBlocks(fillingRegion, filling); + editSession.setBlocks(floorRegion, plotfloor); + editSession.setBlocks(airRegion, air); + } + + 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; + } + @Override public void swap(final Location pos1, final Location pos2, final Location pos3, final Location pos4, final Runnable whenDone) { TaskManager.IMP.async(() -> { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSetBiome.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSetBiome.java index b0374799d..30ed06ff2 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSetBiome.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSetBiome.java @@ -45,7 +45,7 @@ public class PlotSetBiome extends Command { } @Override - public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { + public CompletableFuture execute(final PlotPlayer player, String[] args, RunnableVal3 confirm, RunnableVal2 whenDone) throws CommandException { final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT); checkTrue(plot.isOwner(player.getUUID()) || Permissions .hasPermission(player, "plots.admin.command.generatebiome"), Captions.NO_PLOT_PERMS); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSquaredFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSquaredFeature.java index 02242021e..e51494aed 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSquaredFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/plotsquared/PlotSquaredFeature.java @@ -5,11 +5,11 @@ import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.FaweMaskManager; import com.boydti.fawe.regions.general.RegionFilter; +import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.command.MainCommand; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.database.DBFunc; -import com.plotsquared.core.generator.HybridPlotManager; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; @@ -18,7 +18,6 @@ import com.plotsquared.core.plot.flag.implementations.NoWorldeditFlag; import com.plotsquared.core.util.RegionManager; import com.plotsquared.core.util.SchematicHandler; import com.plotsquared.core.util.WEManager; -import com.plotsquared.core.util.uuid.UUIDHandler; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; diff --git a/worldedit-core/build.gradle.kts b/worldedit-core/build.gradle.kts index 5d965a63d..41dac87ff 100644 --- a/worldedit-core/build.gradle.kts +++ b/worldedit-core/build.gradle.kts @@ -59,7 +59,7 @@ dependencies { "compile"("com.github.intellectualsites.plotsquared:PlotSquared-API:latest") { isTransitive = false } - "compile"("com.plotsquared:PlotSquared-Core:5.11.2") { + "compile"("com.plotsquared:PlotSquared-Core:5.12.2") { isTransitive = false } implementation(kotlin("stdlib-jdk8", "1.3.61"))