mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Implemented internal Chunk generators. Now multiverse can have its own custom chunk generators. Implemented the void generator (very useful). Added world type "VOID" in environments list. When create or import a world with type VOID the world will be added as a NORMAL world with "multiverse:void" generator
This commit is contained in:
parent
38f97a81c8
commit
cd30254090
@ -78,6 +78,7 @@ import com.onarandombox.MultiverseCore.destination.PlayerDestination;
|
||||
import com.onarandombox.MultiverseCore.destination.WorldDestination;
|
||||
import com.onarandombox.MultiverseCore.event.MVDebugModeEvent;
|
||||
import com.onarandombox.MultiverseCore.event.MVVersionEvent;
|
||||
import com.onarandombox.MultiverseCore.generators.InternalChunkGeneratorManager;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVAsyncPlayerChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVChatListener;
|
||||
import com.onarandombox.MultiverseCore.listeners.MVEntityListener;
|
||||
@ -281,6 +282,11 @@ public class MultiverseCore extends JavaPlugin implements MVPlugin, Core {
|
||||
|
||||
this.messaging = new MVMessaging();
|
||||
this.economist = new MVEconomist(this);
|
||||
//VoidGen start
|
||||
// Initialize internal chunk generator manager
|
||||
InternalChunkGeneratorManager.init();
|
||||
//VoidGen end
|
||||
|
||||
// Load the defaultWorldGenerators
|
||||
this.worldManager.getDefaultWorldGenerators();
|
||||
|
||||
|
@ -90,6 +90,12 @@ public class CreateCommand extends MultiverseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
//VoidGen start
|
||||
if(env.equalsIgnoreCase("VOID")) {
|
||||
env = "NORMAL";
|
||||
generator = "multiverse:void";
|
||||
}
|
||||
//VoidGen end
|
||||
Environment environment = EnvironmentCommand.getEnvFromString(env);
|
||||
if (environment == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid environment.");
|
||||
@ -100,7 +106,12 @@ public class CreateCommand extends MultiverseCommand {
|
||||
// If they didn't specify a type, default to NORMAL
|
||||
if (typeString == null) {
|
||||
typeString = "NORMAL";
|
||||
//VoidGen start
|
||||
} else if(typeString.equalsIgnoreCase("VOID")) {
|
||||
typeString = "NORMAL";
|
||||
generator = "multiverse:void";
|
||||
}
|
||||
//VoidGen end
|
||||
WorldType type = EnvironmentCommand.getWorldTypeFromString(typeString);
|
||||
if (type == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid World Type.");
|
||||
@ -108,6 +119,7 @@ public class CreateCommand extends MultiverseCommand {
|
||||
return;
|
||||
}
|
||||
// Determine if the generator is valid. #918
|
||||
|
||||
if (generator != null) {
|
||||
List<String> genarray = new ArrayList<String>(Arrays.asList(generator.split(":")));
|
||||
if (genarray.size() < 2) {
|
||||
|
@ -45,6 +45,9 @@ public class EnvironmentCommand extends MultiverseCommand {
|
||||
sender.sendMessage(ChatColor.GREEN + "NORMAL");
|
||||
sender.sendMessage(ChatColor.RED + "NETHER");
|
||||
sender.sendMessage(ChatColor.AQUA + "END");
|
||||
//VoidGen start
|
||||
sender.sendMessage(ChatColor.WHITE + "VOID");
|
||||
//VoidGen end
|
||||
}
|
||||
/**
|
||||
* Shows all valid known world types to a {@link CommandSender}.
|
||||
|
@ -106,6 +106,12 @@ public class ImportCommand extends MultiverseCommand {
|
||||
}
|
||||
|
||||
String env = args.get(1);
|
||||
//VoidGen start
|
||||
if(env.equalsIgnoreCase("VOID")){
|
||||
env = "NORMAL";
|
||||
generator = "multiverse:void";
|
||||
}
|
||||
//VoidGen end
|
||||
Environment environment = EnvironmentCommand.getEnvFromString(env);
|
||||
if (environment == null) {
|
||||
sender.sendMessage(ChatColor.RED + "That is not a valid environment.");
|
||||
@ -113,6 +119,7 @@ public class ImportCommand extends MultiverseCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!worldFile.exists()) {
|
||||
sender.sendMessage(ChatColor.RED + "FAILED.");
|
||||
String worldList = this.getPotentialWorldStrings();
|
||||
|
@ -0,0 +1,43 @@
|
||||
package com.onarandombox.MultiverseCore.generators;
|
||||
|
||||
import com.onarandombox.MultiverseCore.generators.impl.MultiverseVoidGenerator;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
//VoidGen start
|
||||
public class InternalChunkGeneratorManager {
|
||||
|
||||
private final Map<String, ChunkGenerator> generators;
|
||||
|
||||
private static InternalChunkGeneratorManager instance;
|
||||
|
||||
public static InternalChunkGeneratorManager get() {
|
||||
if (instance == null) {
|
||||
throw new IllegalStateException("InternalChunkGeneratorManager has not been initialized yet.");
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void init(){
|
||||
new InternalChunkGeneratorManager();
|
||||
}
|
||||
|
||||
public InternalChunkGeneratorManager() {
|
||||
instance = this;
|
||||
//register internal generators instances (singleton)
|
||||
generators = Map.of(
|
||||
"VOID", new MultiverseVoidGenerator()
|
||||
);
|
||||
}
|
||||
|
||||
public boolean exists(String generator){
|
||||
return generators.containsKey(generator);
|
||||
}
|
||||
|
||||
public ChunkGenerator getGenerator(String generator){
|
||||
return generators.getOrDefault(generator.toUpperCase(), null);
|
||||
}
|
||||
|
||||
}
|
||||
//VoidGen end
|
@ -0,0 +1,22 @@
|
||||
package com.onarandombox.MultiverseCore.generators.impl;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class MultiverseVoidGenerator extends ChunkGenerator {
|
||||
|
||||
@Override
|
||||
public @NotNull ChunkData generateChunkData(@NotNull World world, @NotNull Random random, int x, int z, @NotNull ChunkGenerator.BiomeGrid biome) {
|
||||
return createChunkData(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Location getFixedSpawnLocation(@NotNull World world, @NotNull Random random) {
|
||||
return new Location(world,0, 64, 0);
|
||||
}
|
||||
}
|
@ -17,6 +17,7 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld;
|
||||
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
|
||||
import com.onarandombox.MultiverseCore.api.WorldPurger;
|
||||
import com.onarandombox.MultiverseCore.event.MVWorldDeleteEvent;
|
||||
import com.onarandombox.MultiverseCore.generators.InternalChunkGeneratorManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameRule;
|
||||
import org.bukkit.Location;
|
||||
@ -257,7 +258,12 @@ public class WorldManager implements MVWorldManager {
|
||||
|
||||
// TODO: Use the fancy kind with the commandSender
|
||||
if (generator != null && generator.length() != 0) {
|
||||
c.generator(generator);
|
||||
//VoidGen start
|
||||
if(generator.startsWith("multiverse:"))
|
||||
c.generator(InternalChunkGeneratorManager.get().getGenerator(generator.split(":")[1]));
|
||||
else
|
||||
c.generator(generator);
|
||||
//VoidGen end
|
||||
}
|
||||
c.environment(env);
|
||||
if (type != null) {
|
||||
@ -305,7 +311,11 @@ public class WorldManager implements MVWorldManager {
|
||||
if (generator == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//VoidGen start
|
||||
if(generator.equalsIgnoreCase("multiverse")){
|
||||
return InternalChunkGeneratorManager.get().getGenerator(generatorID);
|
||||
}
|
||||
//VoidGen end
|
||||
final Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin(generator);
|
||||
if (myPlugin == null) {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user