Register generators early.

This commit is contained in:
tastybento 2024-03-12 22:45:58 -07:00
parent 9633a015d1
commit 1701ed3eec

View File

@ -17,6 +17,7 @@ import org.bukkit.generator.ChunkGenerator;
import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable; import org.eclipse.jdt.annotation.Nullable;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.addons.GameModeAddon; import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.commands.admin.DefaultAdminCommand; import world.bentobox.bentobox.api.commands.admin.DefaultAdminCommand;
import world.bentobox.bentobox.api.commands.island.DefaultPlayerCommand; import world.bentobox.bentobox.api.commands.island.DefaultPlayerCommand;
@ -63,11 +64,18 @@ public class Boxed extends GameModeAddon {
// Settings // Settings
private Settings settings; private Settings settings;
private AbstractBoxedChunkGenerator chunkGenerator; private AbstractBoxedChunkGenerator chunkGenerator;
private AbstractBoxedChunkGenerator seedBaseGen;
private BoxedSeedChunkGenerator seedWorldGenerator;
private AbstractBoxedChunkGenerator netherChunkGenerator;
private AbstractBoxedChunkGenerator seedBaseGenNether;
private BoxedSeedChunkGenerator seedWorldNetherGenerator;
private final Config<Settings> configObject = new Config<>(this, Settings.class); private final Config<Settings> configObject = new Config<>(this, Settings.class);
private AdvancementsManager advManager; private AdvancementsManager advManager;
private AbstractBoxedChunkGenerator netherChunkGenerator;
private World seedWorld; private World seedWorld;
private final Map<World, ChunkGenerator> generatorMap = new HashMap<>(); private final Map<World, ChunkGenerator> generatorMap = new HashMap<>();
private final Map<String, ChunkGenerator> generatorMaps = new HashMap<>();
//private World seedWorldEnd; //private World seedWorldEnd;
private BiomeProvider boxedBiomeProvider; private BiomeProvider boxedBiomeProvider;
@ -89,6 +97,7 @@ public class Boxed extends GameModeAddon {
new AdminPlaceStructureCommand(this); new AdminPlaceStructureCommand(this);
} }
}; };
BentoBox.getInstance().logDebug("On LOAD done!");
} }
private boolean loadSettings() { private boolean loadSettings() {
@ -102,12 +111,32 @@ public class Boxed extends GameModeAddon {
} }
// Initialize the Generator because createWorlds will be run after onLoad // Initialize the Generator because createWorlds will be run after onLoad
this.chunkGenerator = new BoxedChunkGenerator(this); this.chunkGenerator = new BoxedChunkGenerator(this);
generatorMaps.put(settings.getWorldName(), chunkGenerator);
seedBaseGen = new BoxedSeedChunkGenerator(this, Environment.NORMAL);
generatorMaps.put(settings.getWorldName() + "/" + SEED + BASE, seedBaseGen);
seedWorldGenerator = new BoxedSeedChunkGenerator(this, Environment.NORMAL,
new SeedBiomeGenerator(this, seedBaseGen));
generatorMaps.put(settings.getWorldName() + "/" + SEED, seedWorldGenerator);
// Nether generators
this.netherChunkGenerator = new BoxedChunkGenerator(this); this.netherChunkGenerator = new BoxedChunkGenerator(this);
generatorMaps.put(settings.getWorldName() + "/" + NETHER, netherChunkGenerator);
seedBaseGenNether = new BoxedSeedChunkGenerator(this, Environment.NETHER);
generatorMaps.put(settings.getWorldName() + "/" + NETHER + SEED + BASE, seedBaseGenNether);
seedWorldNetherGenerator = new BoxedSeedChunkGenerator(this, Environment.NETHER,
new NetherSeedBiomeGenerator(this, seedBaseGen));
generatorMaps.put(settings.getWorldName() + "/" + NETHER + SEED, seedWorldNetherGenerator);
return true; return true;
} }
@Override @Override
public void onEnable() { public void onEnable() {
BentoBox.getInstance().logDebug("On Enable started!");
// Check for recommended addons // Check for recommended addons
if (this.getPlugin().getAddonsManager().getAddonByName("Border").isEmpty()) { if (this.getPlugin().getAddonsManager().getAddonByName("Border").isEmpty()) {
this.logWarning("Boxed normally requires the Border addon."); this.logWarning("Boxed normally requires the Border addon.");
@ -162,6 +191,7 @@ public class Boxed extends GameModeAddon {
@Override @Override
public void createWorlds() { public void createWorlds() {
BentoBox.getInstance().logDebug("Create Worlds started!");
String worldName = settings.getWorldName().toLowerCase(); String worldName = settings.getWorldName().toLowerCase();
// Create overworld // Create overworld
createOverWorld(worldName); createOverWorld(worldName);
@ -180,23 +210,20 @@ public class Boxed extends GameModeAddon {
private void createNether(String worldName) { private void createNether(String worldName) {
// Create vanilla seed nether world // Create vanilla seed nether world
log("Creating Boxed Seed Nether world ..."); log("Creating Boxed Seed Nether world ...");
// This creates a vanilla base world with biomes
AbstractBoxedChunkGenerator seedBaseGen = new BoxedSeedChunkGenerator(this, Environment.NETHER);
World baseWorldNether = WorldCreator World baseWorldNether = WorldCreator
.name(worldName + "/" + SEED + NETHER + BASE) .name(worldName + "/" + SEED + NETHER + BASE)
.generator(seedBaseGen) .generator(seedBaseGenNether)
.environment(Environment.NETHER) .environment(Environment.NETHER)
.seed(getSettings().getSeed()) .seed(getSettings().getSeed())
.createWorld(); .createWorld();
baseWorldNether.setDifficulty(Difficulty.PEACEFUL); baseWorldNether.setDifficulty(Difficulty.PEACEFUL);
baseWorldNether.setSpawnLocation(settings.getSeedX(), 64, settings.getSeedZ()); baseWorldNether.setSpawnLocation(settings.getSeedX(), 64, settings.getSeedZ());
generatorMap.put(baseWorldNether, seedBaseGen); generatorMap.put(baseWorldNether, seedBaseGenNether);
getPlugin().getIWM().addWorld(baseWorldNether, this); getPlugin().getIWM().addWorld(baseWorldNether, this);
copyChunks(baseWorldNether, seedBaseGen); copyChunks(baseWorldNether, seedBaseGenNether);
// Create seed world // Create seed world
// This copies a base world with custom biomes // This copies a base world with custom biomes
log("Creating Boxed Biomed Nether world ..."); log("Creating Boxed Biomed Nether world ...");
BoxedSeedChunkGenerator seedWorldNetherGenerator = new BoxedSeedChunkGenerator(this, Environment.NETHER, new NetherSeedBiomeGenerator(this, seedBaseGen));
World seedWorldNether = WorldCreator World seedWorldNether = WorldCreator
.name(worldName + "/" + SEED + NETHER) .name(worldName + "/" + SEED + NETHER)
.generator(seedWorldNetherGenerator) .generator(seedWorldNetherGenerator)
@ -220,7 +247,6 @@ public class Boxed extends GameModeAddon {
// Create vanilla seed world // Create vanilla seed world
log("Creating Boxed Seed world ..."); log("Creating Boxed Seed world ...");
// This creates a vanilla base world with biomes // This creates a vanilla base world with biomes
AbstractBoxedChunkGenerator seedBaseGen = new BoxedSeedChunkGenerator(this, Environment.NORMAL);
World baseWorld = WorldCreator World baseWorld = WorldCreator
.name(worldName + "/" + SEED + BASE) .name(worldName + "/" + SEED + BASE)
.generator(seedBaseGen) .generator(seedBaseGen)
@ -235,7 +261,6 @@ public class Boxed extends GameModeAddon {
// Create seed world // Create seed world
// This copies a base world with custom biomes // This copies a base world with custom biomes
log("Creating Boxed Biomed world ..."); log("Creating Boxed Biomed world ...");
BoxedSeedChunkGenerator seedWorldGenerator = new BoxedSeedChunkGenerator(this, Environment.NORMAL, new SeedBiomeGenerator(this, seedBaseGen));
seedWorld = WorldCreator seedWorld = WorldCreator
.name(worldName + "/" + SEED) .name(worldName + "/" + SEED)
.generator(seedWorldGenerator) .generator(seedWorldGenerator)
@ -250,8 +275,6 @@ public class Boxed extends GameModeAddon {
getPlugin().getIWM().addWorld(seedWorld, this); getPlugin().getIWM().addWorld(seedWorld, this);
copyChunks(seedWorld, chunkGenerator); copyChunks(seedWorld, chunkGenerator);
if (getServer().getWorld(worldName) == null) { if (getServer().getWorld(worldName) == null) {
log("Creating Boxed world ..."); log("Creating Boxed world ...");
} }
@ -386,11 +409,14 @@ public class Boxed extends GameModeAddon {
@Override @Override
public @Nullable ChunkGenerator getDefaultWorldGenerator(String worldName, String id) { public @Nullable ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
for (Entry<World, ChunkGenerator> en : generatorMap.entrySet()) { BentoBox.getInstance().logDebug("Calling default chunk gen in Boxed - request is for " + worldName);
if (en.getKey().getName().equalsIgnoreCase(worldName)) { for (Entry<String, ChunkGenerator> en : generatorMaps.entrySet()) {
if (en.getKey().equalsIgnoreCase(worldName)) {
BentoBox.getInstance().logDebug("Found!");
return en.getValue(); return en.getValue();
} }
} }
BentoBox.getInstance().logDebug("Not found");
return null; return null;
} }