From 50d4353045ac05ff14f9890ecaccd2d295410781 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Tue, 8 Jun 2021 18:36:45 +0100 Subject: [PATCH] begin integration with fawe --- .../plotsquared/bukkit/BukkitPlatform.java | 22 ++- .../bukkit/inject/BukkitModule.java | 14 +- .../bukkit/util/fawe/FaweRegionManager.java | 130 ++++++++++++++++++ .../util/fawe/FaweSchematicHandler.java | 90 ++++++++++++ Core/build.gradle.kts | 2 + .../com/plotsquared/core/PlotPlatform.java | 9 ++ .../core/configuration/Settings.java | 11 ++ build.gradle.kts | 5 + gradle/libs.versions.toml | 2 + 9 files changed, 281 insertions(+), 4 deletions(-) create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweRegionManager.java create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweSchematicHandler.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index febda5dd8..2670403ef 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -186,6 +186,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl private Method methodUnloadChunk0; private boolean methodUnloadSetup = false; private boolean metricsStarted; + private boolean faweHook = false; private EconHandler econ; private Injector injector; @@ -317,14 +318,28 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl // WorldEdit if (Settings.Enabled_Components.WORLDEDIT_RESTRICTIONS) { try { - LOGGER.info("{} hooked into WorldEdit", this.pluginName()); WorldEdit.getInstance().getEventBus().register(this.injector().getInstance(WESubscriber.class)); + LOGGER.info("{} hooked into WorldEdit", this.pluginName()); } catch (Throwable e) { LOGGER.error( "Incompatible version of WorldEdit, please upgrade: https://builds.enginehub.org/job/worldedit?branch=master"); } } + // FAWE + if (Settings.FAWE_Components.FAWE_HOOK) { + Plugin fawe = getServer().getPluginManager().getPlugin("FastAsyncWorldEdit"); + if (fawe != null) { + try { + Class.forName("com.boydti.fawe.bukkit.regions.plotsquared.FaweQueueCoordinator"); + faweHook = true; + } catch (Exception ignored) { + LOGGER.error("Incompatible version of FAWE to enable hook, please upgrade: https://ci.athion" + + ".net/job/FastAsyncWorldEdit-P2-V6/"); + } + } + } + if (Settings.Enabled_Components.EVENTS) { getServer().getPluginManager().registerEvents(injector().getInstance(PlayerEventListener.class), this); getServer().getPluginManager().registerEvents(injector().getInstance(BlockEventListener.class), this); @@ -1209,4 +1224,9 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl return LegacyComponentSerializer.legacyAmpersand().serialize(component); } + @Override + public boolean isFaweHooking() { + return faweHook; + } + } diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java index 2f8025001..eec8a47dd 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java @@ -41,7 +41,10 @@ import com.plotsquared.bukkit.util.BukkitInventoryUtil; import com.plotsquared.bukkit.util.BukkitRegionManager; import com.plotsquared.bukkit.util.BukkitSetupUtils; import com.plotsquared.bukkit.util.BukkitUtil; +import com.plotsquared.bukkit.util.fawe.FaweRegionManager; +import com.plotsquared.bukkit.util.fawe.FaweSchematicHandler; import com.plotsquared.core.PlotPlatform; +import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.generator.HybridGen; import com.plotsquared.core.generator.IndependentPlotGenerator; @@ -99,10 +102,15 @@ public class BukkitModule extends AbstractModule { install(new FactoryModuleBuilder() .implement(ProgressSubscriber.class, DefaultProgressSubscriber.class) .build(ProgressSubscriberFactory.class)); - bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue(QueueProvider.of(BukkitQueueCoordinator.class))); bind(ChunkManager.class).to(BukkitChunkManager.class); - bind(RegionManager.class).to(BukkitRegionManager.class); - bind(SchematicHandler.class).to(BukkitSchematicHandler.class); + if (PlotSquared.platform().isFaweHooking()) { + bind(SchematicHandler.class).to(FaweSchematicHandler.class); + bind(RegionManager.class).to(FaweRegionManager.class); + } else { + bind(SchematicHandler.class).to(BukkitSchematicHandler.class); + bind(RegionManager.class).to(BukkitRegionManager.class); + } + bind(GlobalBlockQueue.class).toInstance(new GlobalBlockQueue(QueueProvider.of(BukkitQueueCoordinator.class))); if (Settings.Enabled_Components.WORLDS) { bind(PlotAreaManager.class).to(SinglePlotAreaManager.class); try { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweRegionManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweRegionManager.java new file mode 100644 index 000000000..c78d7c34d --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweRegionManager.java @@ -0,0 +1,130 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) ${year} IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.plotsquared.bukkit.util.fawe; + +import com.boydti.fawe.bukkit.regions.plotsquared.FaweDelegateRegionManager; +import com.google.inject.Inject; +import com.plotsquared.bukkit.util.BukkitRegionManager; +import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.generator.HybridPlotManager; +import com.plotsquared.core.inject.factory.ProgressSubscriberFactory; +import com.plotsquared.core.location.Location; +import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.plot.PlotManager; +import com.plotsquared.core.queue.GlobalBlockQueue; +import com.plotsquared.core.queue.QueueCoordinator; +import com.plotsquared.core.util.WorldUtil; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.regions.CuboidRegion; +import com.sk89q.worldedit.world.biome.BiomeType; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Set; + +public class FaweRegionManager extends BukkitRegionManager { + + private final FaweDelegateRegionManager delegate = new FaweDelegateRegionManager(); + + @Inject + public FaweRegionManager( + @NonNull WorldUtil worldUtil, @NonNull GlobalBlockQueue blockQueue, @NonNull + ProgressSubscriberFactory subscriberFactory + ) { + super(worldUtil, blockQueue, subscriberFactory); + } + + @Override + public boolean setCuboids( + final @NonNull PlotArea area, + final @NonNull Set regions, + final @NonNull Pattern blocks, + int minY, + int maxY, + @org.checkerframework.checker.nullness.qual.Nullable PlotPlayer actor, + @org.checkerframework.checker.nullness.qual.Nullable QueueCoordinator queue + ) { + return delegate.setCuboids(area, regions, blocks, minY, maxY); + } + + @Override + public boolean notifyClear(PlotManager manager) { + if (!Settings.FAWE_Components.CLEAR || !(manager instanceof HybridPlotManager)) { + return false; + } + return delegate.notifyClear(manager); + } + + @Override + public boolean handleClear( + @NotNull Plot plot, + @Nullable Runnable whenDone, + @NotNull PlotManager manager, + final @Nullable PlotPlayer player + ) { + if (!Settings.FAWE_Components.CLEAR || !(manager instanceof HybridPlotManager)) { + return false; + } + return delegate.handleClear(plot, whenDone, manager); + } + + @Override + public void swap( + Location pos1, + Location pos2, + Location swapPos, + final @Nullable PlotPlayer player, + final Runnable whenDone + ) { + delegate.swap(pos1, pos2, swapPos, whenDone); + } + + @Override + public void setBiome(CuboidRegion region, int extendBiome, BiomeType biome, String world, Runnable whenDone) { + delegate.setBiome(region, extendBiome, biome, world, whenDone); + } + + @Override + public boolean copyRegion( + final @NonNull Location pos1, + final @NonNull Location pos2, + final @NonNull Location pos3, + final @Nullable PlotPlayer player, + final @NonNull Runnable whenDone + ) { + return delegate.copyRegion(pos1, pos2, pos3, whenDone); + } + + @Override + public boolean regenerateRegion(final Location pos1, final Location pos2, boolean ignore, final Runnable whenDone) { + return delegate.regenerateRegion(pos1, pos2, ignore, whenDone); + } + +} diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweSchematicHandler.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweSchematicHandler.java new file mode 100644 index 000000000..812e68be2 --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/fawe/FaweSchematicHandler.java @@ -0,0 +1,90 @@ +/* + * _____ _ _ _____ _ + * | __ \| | | | / ____| | | + * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| | + * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` | + * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| | + * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_| + * | | + * |_| + * PlotSquared plot management system for Minecraft + * Copyright (C) ${year} IntellectualSites + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.plotsquared.bukkit.util.fawe; + +import com.boydti.fawe.bukkit.regions.plotsquared.FaweDelegateSchematicHandler; +import com.google.inject.Inject; +import com.plotsquared.core.inject.factory.ProgressSubscriberFactory; +import com.plotsquared.core.player.PlotPlayer; +import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.plot.schematic.Schematic; +import com.plotsquared.core.queue.QueueCoordinator; +import com.plotsquared.core.util.SchematicHandler; +import com.plotsquared.core.util.WorldUtil; +import com.plotsquared.core.util.task.RunnableVal; +import com.sk89q.jnbt.CompoundTag; +import org.jetbrains.annotations.NotNull; + +import java.io.InputStream; +import java.net.URL; +import java.util.UUID; + +public class FaweSchematicHandler extends SchematicHandler { + + private final FaweDelegateSchematicHandler delegate = new FaweDelegateSchematicHandler(); + + @Inject + public FaweSchematicHandler(@NotNull WorldUtil worldUtil, @NotNull ProgressSubscriberFactory subscriberFactory) { + super(worldUtil, subscriberFactory); + } + + @Override + public boolean restoreTile(QueueCoordinator queue, CompoundTag tag, int x, int y, int z) { + return false; + } + + @Override + public void paste( + final Schematic schematic, + final Plot plot, + final int xOffset, + final int yOffset, + final int zOffset, + final boolean autoHeight, + final PlotPlayer actor, + final RunnableVal whenDone + ) { + delegate.paste(schematic, plot, xOffset, yOffset, zOffset, autoHeight, whenDone); + } + + @Override + public boolean save(CompoundTag tag, String path) { + return delegate.save(tag, path); + } + + @Override + public void upload(final CompoundTag tag, final UUID uuid, final String file, final RunnableVal whenDone) { + delegate.upload(tag, uuid, file, whenDone); + } + + @Override + public Schematic getSchematic(@NotNull InputStream is) { + return delegate.getSchematic(is); + } + +} + diff --git a/Core/build.gradle.kts b/Core/build.gradle.kts index 171108e68..683a360de 100644 --- a/Core/build.gradle.kts +++ b/Core/build.gradle.kts @@ -37,6 +37,8 @@ dependencies { exclude(group = "dummypermscompat") } testImplementation(libs.worldeditCore) + compileOnlyApi(libs.fastasyncworldeditBukkit) + testImplementation(libs.fastasyncworldeditBukkit) // Logging compileOnlyApi(libs.log4j) { diff --git a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java index c1424f99d..1681d7bf4 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotPlatform.java +++ b/Core/src/main/java/com/plotsquared/core/PlotPlatform.java @@ -323,4 +323,13 @@ public interface PlotPlatform

extends LocaleHolder { */ @NonNull String toLegacyPlatformString(@NonNull Component component); + /** + * Returns if the FAWE-P2 hook is active/enabled + * + * @return status of FAWE-P2 hook + */ + default boolean isFaweHooking() { + return false; + } + } diff --git a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java index 636cc4b56..0fc83d57d 100644 --- a/Core/src/main/java/com/plotsquared/core/configuration/Settings.java +++ b/Core/src/main/java/com/plotsquared/core/configuration/Settings.java @@ -608,6 +608,17 @@ public class Settings extends Config { } + @Comment("Enable or disable all of or parts of the FAWE-P2 hook") + public static final class FAWE_Components { + + @Comment("Use FAWE for queue handling.") + public static boolean FAWE_HOOK = true; + public static boolean CUBOIDS = true; + public static boolean CLEAR = true; + public static boolean COPY_AND_SWAP = true; + public static boolean SET_BIOME = true; + + } @Comment("Enable or disable parts of the plugin specific to using Paper") public static final class Paper_Components { diff --git a/build.gradle.kts b/build.gradle.kts index 47736acbf..59cca943a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -39,6 +39,11 @@ allprojects { url = uri("https://jitpack.io") } + maven { + name = "IntellectualSites Releases Repository" + url = uri("https://mvn.intellectualsites.com/content/repositories/releases") + } + maven { name = "IntellectualSites Snapshots Repository" url = uri("https://mvn.intellectualsites.com/content/repositories/snapshots") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3d1e182f6..97a447520 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,6 +14,7 @@ guice = "5.0.1" findbugs = "3.0.1" worldedit = "7.2.5" +fawe = "p2v6-8" vault = "1.7" placeholderapi = "2.10.9" luckperms = "5.3" @@ -63,6 +64,7 @@ findbugs = { group = "com.google.code.findbugs", name = "annotations", version.r # Plugins worldeditCore = { group = "com.sk89q.worldedit", name = "worldedit-core", version.ref = "worldedit" } worldeditBukkit = { group = "com.sk89q.worldedit", name = "worldedit-bukkit", version.ref = "worldedit" } +fastasyncworldeditBukkit = { group = "com.intellectualsites.fawe", name = "FAWE-Bukkit", version.ref = "fawe" } vault = { group = "com.github.MilkBowl", name = "VaultAPI", version.ref = "vault" } placeholderapi = { group = "me.clip", name = "placeholderapi", version.ref = "placeholderapi" } luckperms = { group = "net.luckperms", name = "api", version.ref = "luckperms" }