001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.bukkit.util.fawe;
020
021import com.fastasyncworldedit.bukkit.regions.plotsquared.FaweDelegateRegionManager;
022import com.google.inject.Inject;
023import com.plotsquared.bukkit.util.BukkitRegionManager;
024import com.plotsquared.core.configuration.Settings;
025import com.plotsquared.core.generator.HybridPlotManager;
026import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
027import com.plotsquared.core.location.Location;
028import com.plotsquared.core.player.PlotPlayer;
029import com.plotsquared.core.plot.Plot;
030import com.plotsquared.core.plot.PlotArea;
031import com.plotsquared.core.plot.PlotManager;
032import com.plotsquared.core.queue.GlobalBlockQueue;
033import com.plotsquared.core.queue.QueueCoordinator;
034import com.plotsquared.core.util.WorldUtil;
035import com.sk89q.worldedit.function.pattern.Pattern;
036import com.sk89q.worldedit.regions.CuboidRegion;
037import com.sk89q.worldedit.world.biome.BiomeType;
038import org.checkerframework.checker.nullness.qual.NonNull;
039import org.checkerframework.checker.nullness.qual.Nullable;
040import org.jetbrains.annotations.NotNull;
041
042import java.util.Objects;
043import java.util.Set;
044
045public class FaweRegionManager extends BukkitRegionManager {
046
047    private final FaweDelegateRegionManager delegate = new FaweDelegateRegionManager();
048
049    @Inject
050    public FaweRegionManager(WorldUtil worldUtil, GlobalBlockQueue blockQueue, ProgressSubscriberFactory subscriberFactory) {
051        super(worldUtil, blockQueue, subscriberFactory);
052    }
053
054    @Override
055    public boolean setCuboids(
056            final @NonNull PlotArea area,
057            final @NonNull Set<CuboidRegion> regions,
058            final @NonNull Pattern blocks,
059            int minY,
060            int maxY,
061            @Nullable PlotPlayer<?> actor,
062            @Nullable QueueCoordinator queue
063    ) {
064        return delegate.setCuboids(
065                area, regions, blocks, minY, maxY,
066                Objects.requireNonNullElseGet(queue, area::getQueue).getCompleteTask()
067        );
068    }
069
070    @Override
071    public boolean notifyClear(PlotManager manager) {
072        if (!Settings.FAWE_Components.CLEAR || !(manager instanceof HybridPlotManager)) {
073            return false;
074        }
075        return delegate.notifyClear(manager);
076    }
077
078    @Override
079    public boolean handleClear(
080            @NonNull Plot plot,
081            @Nullable Runnable whenDone,
082            @NonNull PlotManager manager,
083            final @Nullable PlotPlayer<?> player
084    ) {
085        if (!Settings.FAWE_Components.CLEAR || !(manager instanceof HybridPlotManager)) {
086            return false;
087        }
088        return delegate.handleClear(plot, whenDone, manager);
089    }
090
091    @Override
092    public void swap(
093            Location pos1,
094            Location pos2,
095            Location swapPos,
096            final @Nullable PlotPlayer<?> player,
097            final Runnable whenDone
098    ) {
099        delegate.swap(pos1, pos2, swapPos, whenDone);
100    }
101
102    @Override
103    public void setBiome(CuboidRegion region, int extendBiome, BiomeType biome, PlotArea area, Runnable whenDone) {
104        delegate.setBiome(region, extendBiome, biome, area.getWorldName(), whenDone);
105    }
106
107    @Override
108    public boolean copyRegion(
109            final @NonNull Location pos1,
110            final @NonNull Location pos2,
111            final @NonNull Location pos3,
112            final @Nullable PlotPlayer<?> player,
113            final @NonNull Runnable whenDone
114    ) {
115        return delegate.copyRegion(pos1, pos2, pos3, whenDone);
116    }
117
118    @Override
119    public boolean regenerateRegion(final @NotNull Location pos1, final @NotNull Location pos2, boolean ignore, final Runnable whenDone) {
120        return delegate.regenerateRegion(pos1, pos2, ignore, whenDone);
121    }
122
123}