-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3149 from Multiverse/ben/mv5/single-biome
Add support for creating worlds with single biome
- Loading branch information
Showing
22 changed files
with
254 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/org/mvplugins/multiverse/core/world/SingleBiomeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.mvplugins.multiverse.core.world; | ||
|
||
import org.bukkit.WorldCreator; | ||
import org.bukkit.block.Biome; | ||
import org.bukkit.generator.BiomeProvider; | ||
import org.bukkit.generator.WorldInfo; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Helps create a world with only 1 type of Biome specified. Used in {@link WorldCreator#biomeProvider(BiomeProvider)} | ||
*/ | ||
public class SingleBiomeProvider extends BiomeProvider { | ||
|
||
private final Biome biome; | ||
private final List<Biome> biomes; | ||
|
||
public SingleBiomeProvider(Biome biome) { | ||
this.biome = biome; | ||
this.biomes = List.of(biome); | ||
} | ||
|
||
@Override | ||
public @NotNull Biome getBiome(@NotNull WorldInfo worldInfo, int x, int y, int z) { | ||
return this.biome; | ||
} | ||
|
||
@Override | ||
public @NotNull List<Biome> getBiomes(@NotNull WorldInfo worldInfo) { | ||
return this.biomes; | ||
} | ||
|
||
public Biome getBiome() { | ||
return biome; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/org/mvplugins/multiverse/core/world/config/BiomeSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.mvplugins.multiverse.core.world.config; | ||
|
||
import org.bukkit.block.Biome; | ||
import org.mvplugins.multiverse.core.configuration.functions.NodeSerializer; | ||
|
||
public class BiomeSerializer implements NodeSerializer<Biome> { | ||
|
||
static final String VANILLA_BIOME_BEHAVIOUR = "@vanilla"; | ||
|
||
@Override | ||
public Biome deserialize(Object object, Class<Biome> type) { | ||
if (object instanceof Biome) { | ||
return (Biome) object; | ||
} | ||
try { | ||
String biomeStr = String.valueOf(object); | ||
if (biomeStr.equalsIgnoreCase(VANILLA_BIOME_BEHAVIOUR)) { | ||
return null; | ||
} | ||
return Biome.valueOf(biomeStr.toUpperCase()); | ||
} catch (IllegalArgumentException e) { | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public Object serialize(Biome biome, Class<Biome> type) { | ||
if (biome == null || biome == Biome.CUSTOM) { | ||
return VANILLA_BIOME_BEHAVIOUR; | ||
} | ||
return biome.name().toLowerCase(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.