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;
040
041import java.util.Set;
042
043public class FaweRegionManager extends BukkitRegionManager {
044
045    private final FaweDelegateRegionManager delegate = new FaweDelegateRegionManager();
046
047    @Inject
048    public FaweRegionManager(WorldUtil worldUtil, GlobalBlockQueue blockQueue, ProgressSubscriberFactory subscriberFactory) {
049        super(worldUtil, blockQueue, subscriberFactory);
050    }
051
052    @Override
053    public boolean setCuboids(
054            final @NonNull PlotArea area,
055            final @NonNull Set<CuboidRegion> regions,
056            final @NonNull Pattern blocks,
057            int minY,
058            int maxY,
059            @Nullable PlotPlayer<?> actor,
060            @Nullable QueueCoordinator queue
061    ) {
062        return delegate.setCuboids(area, regions, blocks, minY, maxY, queue.getCompleteTask());
063    }
064
065    @Override
066    public boolean notifyClear(PlotManager manager) {
067        if (!Settings.FAWE_Components.CLEAR || !(manager instanceof HybridPlotManager)) {
068            return false;
069        }
070        return delegate.notifyClear(manager);
071    }
072
073    @Override
074    public boolean handleClear(
075            @NonNull Plot plot,
076            @Nullable Runnable whenDone,
077            @NonNull PlotManager manager,
078            final @Nullable PlotPlayer<?> player
079    ) {
080        if (!Settings.FAWE_Components.CLEAR || !(manager instanceof HybridPlotManager)) {
081            return false;
082        }
083        return delegate.handleClear(plot, whenDone, manager);
084    }
085
086    @Override
087    public void swap(
088            Location pos1,
089            Location pos2,
090            Location swapPos,
091            final @Nullable PlotPlayer<?> player,
092            final Runnable whenDone
093    ) {
094        delegate.swap(pos1, pos2, swapPos, whenDone);
095    }
096
097    @Override
098    public void setBiome(CuboidRegion region, int extendBiome, BiomeType biome, PlotArea area, Runnable whenDone) {
099        delegate.setBiome(region, extendBiome, biome, area.getWorldName(), whenDone);
100    }
101
102    @Override
103    public boolean copyRegion(
104            final @NonNull Location pos1,
105            final @NonNull Location pos2,
106            final @NonNull Location pos3,
107            final @Nullable PlotPlayer<?> player,
108            final @NonNull Runnable whenDone
109    ) {
110        return delegate.copyRegion(pos1, pos2, pos3, whenDone);
111    }
112
113    @Override
114    public boolean regenerateRegion(final Location pos1, final Location pos2, boolean ignore, final Runnable whenDone) {
115        return delegate.regenerateRegion(pos1, pos2, ignore, whenDone);
116    }
117
118}