From d33f932c5dda18cb3b5982b6bdd7adca3cd19515 Mon Sep 17 00:00:00 2001 From: tastybento Date: Thu, 4 Mar 2021 08:17:40 -0800 Subject: [PATCH] Added protection around no WorldGeneratorAPI plugin --- src/main/java/world/bentobox/boxed/Boxed.java | 46 +++++++++++-------- .../java/world/bentobox/boxed/Settings.java | 10 ++-- .../boxed/generators/BoxedChunkGenerator.java | 40 ++++++++++++++++ 3 files changed, 72 insertions(+), 24 deletions(-) create mode 100644 src/main/java/world/bentobox/boxed/generators/BoxedChunkGenerator.java diff --git a/src/main/java/world/bentobox/boxed/Boxed.java b/src/main/java/world/bentobox/boxed/Boxed.java index 17df340..e1bb779 100644 --- a/src/main/java/world/bentobox/boxed/Boxed.java +++ b/src/main/java/world/bentobox/boxed/Boxed.java @@ -2,6 +2,7 @@ package world.bentobox.boxed; import java.util.Collections; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.World.Environment; @@ -10,9 +11,6 @@ import org.bukkit.WorldType; import org.bukkit.generator.ChunkGenerator; import org.eclipse.jdt.annotation.Nullable; -import nl.rutgerkok.worldgeneratorapi.WorldGeneratorApi; -import nl.rutgerkok.worldgeneratorapi.WorldRef; -import nl.rutgerkok.worldgeneratorapi.decoration.DecorationType; import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.api.commands.admin.DefaultAdminCommand; import world.bentobox.bentobox.api.commands.island.DefaultPlayerCommand; @@ -22,8 +20,7 @@ import world.bentobox.bentobox.api.flags.Flag; import world.bentobox.bentobox.api.flags.Flag.Mode; import world.bentobox.bentobox.api.flags.Flag.Type; import world.bentobox.bentobox.managers.RanksManager; -import world.bentobox.boxed.generators.BasicWorldGenerator; -import world.bentobox.boxed.generators.BoxedBiomeGenerator; +import world.bentobox.boxed.generators.BoxedChunkGenerator; import world.bentobox.boxed.generators.DeleteGen; import world.bentobox.boxed.listeners.AdvancementListener; import world.bentobox.boxed.listeners.EnderPearlListener; @@ -49,6 +46,7 @@ public class Boxed extends GameModeAddon { private Config configObject = new Config<>(this, Settings.class); private AdvancementsManager advManager; private DeleteGen delChunks; + private boolean disabled; @Override public void onLoad() { @@ -58,21 +56,15 @@ public class Boxed extends GameModeAddon { loadSettings(); // Save biomes this.saveResource("biomes.yml", false); + // Check for WGAPI + if (isNoWGAPI()) { + logError("WorldGeneratorAPI plugin is required."); + logError("Download the correct one for your server from https://github.com/rutgerkok/WorldGeneratorApi/releases"); + disabled = true; + return; + } // Chunk generator - WorldRef wordRef = WorldRef.ofName(getSettings().getWorldName()); - chunkGenerator = WorldGeneratorApi - .getInstance(getPlugin(), 0, 5) - .createCustomGenerator(wordRef, generator -> { - // Set the noise generator - generator.setBaseNoiseGenerator(new BasicWorldGenerator(this, getSettings().getSeed())); - if (getSettings().isAllowStructures()) { - generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.SURFACE_STRUCTURES); - } - if (getSettings().isAllowStrongholds()) { - generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.STRONGHOLDS); - } - generator.setBiomeGenerator(new BoxedBiomeGenerator(this)); - }); + chunkGenerator = new BoxedChunkGenerator(this).getGenerator(); // Register commands playerCommand = new DefaultPlayerCommand(this) {}; @@ -83,6 +75,10 @@ public class Boxed extends GameModeAddon { this.registerListener(new EnderPearlListener(this)); } + private boolean isNoWGAPI() { + return Bukkit.getPluginManager().getPlugin("WorldGeneratorAPI") == null; + } + private boolean loadSettings() { // Load settings again to get worlds settings = configObject.loadConfigObject(); @@ -97,6 +93,18 @@ public class Boxed extends GameModeAddon { @Override public void onEnable(){ + // Disable in onEnable + if (disabled) { + this.setState(State.DISABLED); + return; + } + // Check for recommended addons + if (!this.getPlugin().getAddonsManager().getAddonByName("Border").isPresent()) { + this.logWarning("Boxed normally requires the Border addon."); + } + if (!this.getPlugin().getAddonsManager().getAddonByName("InvSwitcher").isPresent()) { + this.logWarning("Boxed normally requires the InvSwitcher addon for per-world Advancements."); + } // Advancements manager advManager = new AdvancementsManager(this); // Get delete chunk generator diff --git a/src/main/java/world/bentobox/boxed/Settings.java b/src/main/java/world/bentobox/boxed/Settings.java index 5c66768..acac6e9 100644 --- a/src/main/java/world/bentobox/boxed/Settings.java +++ b/src/main/java/world/bentobox/boxed/Settings.java @@ -166,7 +166,7 @@ public class Settings implements WorldSettings { private boolean netherGenerate = true; @ConfigComment("Nether spawn protection radius - this is the distance around the nether spawn") - @ConfigComment("that will be protected from player interaction (breaking blocks, pouring lava etc.)") + @ConfigComment("that will be public from player interaction (breaking blocks, pouring lava etc.)") @ConfigComment("Minimum is 0 (not recommended), maximum is 100. Default is 25.") @ConfigComment("Only applies to vanilla nether") @ConfigEntry(path = "world.nether.spawn-radius") @@ -1638,28 +1638,28 @@ public class Settings implements WorldSettings { /** * @return the allowStructures */ - protected boolean isAllowStructures() { + public boolean isAllowStructures() { return allowStructures; } /** * @param allowStructures the allowStructures to set */ - protected void setAllowStructures(boolean allowStructures) { + public void setAllowStructures(boolean allowStructures) { this.allowStructures = allowStructures; } /** * @return the allowStrongholds */ - protected boolean isAllowStrongholds() { + public boolean isAllowStrongholds() { return allowStrongholds; } /** * @param allowStrongholds the allowStrongholds to set */ - protected void setAllowStrongholds(boolean allowStrongholds) { + public void setAllowStrongholds(boolean allowStrongholds) { this.allowStrongholds = allowStrongholds; } } diff --git a/src/main/java/world/bentobox/boxed/generators/BoxedChunkGenerator.java b/src/main/java/world/bentobox/boxed/generators/BoxedChunkGenerator.java new file mode 100644 index 0000000..9a719b6 --- /dev/null +++ b/src/main/java/world/bentobox/boxed/generators/BoxedChunkGenerator.java @@ -0,0 +1,40 @@ +package world.bentobox.boxed.generators; + +import org.bukkit.generator.ChunkGenerator; + +import nl.rutgerkok.worldgeneratorapi.WorldGeneratorApi; +import nl.rutgerkok.worldgeneratorapi.WorldRef; +import nl.rutgerkok.worldgeneratorapi.decoration.DecorationType; +import world.bentobox.boxed.Boxed; + +/** + * @author tastybento + * + */ +public class BoxedChunkGenerator { + + private final WorldRef wordRef; + private final Boxed addon; + + public BoxedChunkGenerator(Boxed addon) { + this.addon = addon; + wordRef = WorldRef.ofName(addon.getSettings().getWorldName()); + } + + public ChunkGenerator getGenerator() { + return WorldGeneratorApi + .getInstance(addon.getPlugin(), 0, 5) + .createCustomGenerator(wordRef, generator -> { + // Set the noise generator + generator.setBaseNoiseGenerator(new BasicWorldGenerator(addon, addon.getSettings().getSeed())); + if (addon.getSettings().isAllowStructures()) { + generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.SURFACE_STRUCTURES); + } + if (addon.getSettings().isAllowStrongholds()) { + generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.STRONGHOLDS); + } + generator.setBiomeGenerator(new BoxedBiomeGenerator(addon)); + }); + } + +}