Search in sources :

Example 1 with HybridPlotManager

use of com.plotsquared.core.generator.HybridPlotManager in project FastAsyncWorldEdit by IntellectualSites.

the class FaweDelegateRegionManager method handleClear.

public boolean handleClear(@Nonnull Plot plot, @Nullable Runnable whenDone, @Nonnull PlotManager manager) {
    TaskManager.taskManager().async(() -> {
        synchronized (FaweDelegateRegionManager.class) {
            final HybridPlotWorld hybridPlotWorld = ((HybridPlotManager) manager).getHybridPlotWorld();
            World world = BukkitAdapter.adapt(getWorld(hybridPlotWorld.getWorldName()));
            EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(world).checkMemory(false).fastMode(true).limitUnlimited().changeSetNull().build();
            if (!hybridPlotWorld.PLOT_SCHEMATIC || !Settings.Schematics.PASTE_ON_TOP) {
                final BlockType bedrock;
                final BlockType air = BlockTypes.AIR;
                if (hybridPlotWorld.PLOT_BEDROCK) {
                    bedrock = BlockTypes.BEDROCK;
                } else {
                    bedrock = air;
                }
                final Pattern filling = hybridPlotWorld.MAIN_BLOCK.toPattern();
                final Pattern plotfloor = hybridPlotWorld.TOP_BLOCK.toPattern();
                final BiomeType biome = hybridPlotWorld.getPlotBiome();
                BlockVector3 pos1 = plot.getBottomAbs().getBlockVector3();
                BlockVector3 pos2 = pos1.add(BlockVector3.at(hybridPlotWorld.PLOT_WIDTH - 1, hybridPlotWorld.getMaxGenHeight(), hybridPlotWorld.PLOT_WIDTH - 1));
                if (hybridPlotWorld.PLOT_BEDROCK) {
                    Region bedrockRegion = new CuboidRegion(pos1, pos2.withY(hybridPlotWorld.getMinGenHeight()));
                    editSession.setBlocks(bedrockRegion, bedrock);
                }
                Region fillingRegion = new CuboidRegion(pos1.withY(hybridPlotWorld.getMinGenHeight() + 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(hybridPlotWorld.getMaxGenHeight()));
                editSession.setBlocks(fillingRegion, filling);
                editSession.setBlocks(floorRegion, plotfloor);
                editSession.setBlocks(airRegion, air);
            }
            if (hybridPlotWorld.PLOT_SCHEMATIC) {
                // We cannot reuse the editsession
                EditSession scheditsession = !Settings.Schematics.PASTE_ON_TOP ? editSession : WorldEdit.getInstance().newEditSessionBuilder().world(world).checkMemory(false).fastMode(true).limitUnlimited().changeSetNull().build();
                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 : hybridPlotWorld.getMinBuildHeight());
                try {
                    Clipboard clip = ClipboardFormats.findByFile(schematicFile).getReader(new FileInputStream(schematicFile)).read();
                    clip.paste(scheditsession, to, true, true, true);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                // Be verbose in editsession flushing
                scheditsession.flushQueue();
            }
            editSession.flushQueue();
            FaweAPI.fixLighting(world, new CuboidRegion(plot.getBottomAbs().getBlockVector3(), plot.getTopAbs().getBlockVector3()), null, RelightMode.valueOf(com.fastasyncworldedit.core.configuration.Settings.settings().LIGHTING.MODE));
            if (whenDone != null) {
                TaskManager.taskManager().task(whenDone);
            }
        }
    });
    return true;
}
Also used : Pattern(com.sk89q.worldedit.function.pattern.Pattern) HybridPlotWorld(com.plotsquared.core.generator.HybridPlotWorld) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) IOException(java.io.IOException) World(com.sk89q.worldedit.world.World) Bukkit.getWorld(org.bukkit.Bukkit.getWorld) HybridPlotWorld(com.plotsquared.core.generator.HybridPlotWorld) BlockVector3(com.sk89q.worldedit.math.BlockVector3) FileInputStream(java.io.FileInputStream) BiomeType(com.sk89q.worldedit.world.biome.BiomeType) BlockType(com.sk89q.worldedit.world.block.BlockType) HybridPlotManager(com.plotsquared.core.generator.HybridPlotManager) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) Region(com.sk89q.worldedit.regions.Region) EditSession(com.sk89q.worldedit.EditSession) Clipboard(com.sk89q.worldedit.extent.clipboard.Clipboard) File(java.io.File)

Aggregations

HybridPlotManager (com.plotsquared.core.generator.HybridPlotManager)1 HybridPlotWorld (com.plotsquared.core.generator.HybridPlotWorld)1 EditSession (com.sk89q.worldedit.EditSession)1 Clipboard (com.sk89q.worldedit.extent.clipboard.Clipboard)1 Pattern (com.sk89q.worldedit.function.pattern.Pattern)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 Region (com.sk89q.worldedit.regions.Region)1 World (com.sk89q.worldedit.world.World)1 BiomeType (com.sk89q.worldedit.world.biome.BiomeType)1 BlockType (com.sk89q.worldedit.world.block.BlockType)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Bukkit.getWorld (org.bukkit.Bukkit.getWorld)1