Skip to content

Commit

Permalink
Added protection around no WorldGeneratorAPI plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Mar 4, 2021
1 parent 9c714e1 commit d33f932
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 24 deletions.
46 changes: 27 additions & 19 deletions src/main/java/world/bentobox/boxed/Boxed.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collections;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
Expand All @@ -10,9 +11,6 @@
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;
Expand All @@ -22,8 +20,7 @@
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;
Expand All @@ -49,6 +46,7 @@ public class Boxed extends GameModeAddon {
private Config<Settings> configObject = new Config<>(this, Settings.class);
private AdvancementsManager advManager;
private DeleteGen delChunks;
private boolean disabled;

@Override
public void onLoad() {
Expand All @@ -58,21 +56,15 @@ public void onLoad() {
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) {};

Expand All @@ -83,6 +75,10 @@ public void onLoad() {
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();
Expand All @@ -97,6 +93,18 @@ private boolean loadSettings() {

@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
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/world/bentobox/boxed/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -1638,28 +1638,28 @@ public boolean isCheckForBlocks() {
/**
* @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;
}
}
Original file line number Diff line number Diff line change
@@ -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));
});
}

}

0 comments on commit d33f932

Please sign in to comment.