From cd30254090fa52bc14221b7bfbdb58b9fef0e6aa Mon Sep 17 00:00:00 2001 From: MarcoLvr Date: Sun, 22 Sep 2024 01:08:08 +0200 Subject: [PATCH 1/2] 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 --- .../MultiverseCore/MultiverseCore.java | 6 +++ .../commands/CreateCommand.java | 12 ++++++ .../commands/EnvironmentCommand.java | 3 ++ .../commands/ImportCommand.java | 7 +++ .../InternalChunkGeneratorManager.java | 43 +++++++++++++++++++ .../impl/MultiverseVoidGenerator.java | 22 ++++++++++ .../MultiverseCore/utils/WorldManager.java | 14 +++++- 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/generators/InternalChunkGeneratorManager.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/generators/impl/MultiverseVoidGenerator.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 6fda9ae95..d215843b0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -78,6 +78,7 @@ 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 void onEnable() { 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(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java index 6d8f3833b..700353015 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java @@ -90,6 +90,12 @@ public void runCommand(CommandSender sender, List args) { 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 void runCommand(CommandSender sender, List args) { // 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 void runCommand(CommandSender sender, List args) { return; } // Determine if the generator is valid. #918 + if (generator != null) { List genarray = new ArrayList(Arrays.asList(generator.split(":"))); if (genarray.size() < 2) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java index f9ac88600..66f32dd48 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java @@ -45,6 +45,9 @@ public static void showEnvironments(CommandSender sender) { 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}. diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java index 7a52d5a15..57a578797 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java @@ -106,6 +106,12 @@ public void runCommand(CommandSender sender, List args) { } 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 void runCommand(CommandSender sender, List args) { return; } + if (!worldFile.exists()) { sender.sendMessage(ChatColor.RED + "FAILED."); String worldList = this.getPotentialWorldStrings(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/generators/InternalChunkGeneratorManager.java b/src/main/java/com/onarandombox/MultiverseCore/generators/InternalChunkGeneratorManager.java new file mode 100644 index 000000000..85d2fb943 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/generators/InternalChunkGeneratorManager.java @@ -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 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 diff --git a/src/main/java/com/onarandombox/MultiverseCore/generators/impl/MultiverseVoidGenerator.java b/src/main/java/com/onarandombox/MultiverseCore/generators/impl/MultiverseVoidGenerator.java new file mode 100644 index 000000000..91aa7cac9 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/generators/impl/MultiverseVoidGenerator.java @@ -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); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index 0b2ab0701..bed415b9a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -17,6 +17,7 @@ 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 boolean addWorld(String name, Environment env, String seedString, WorldTy // 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 ChunkGenerator getChunkGenerator(String generator, final String generator 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; From 4052be9e1b31eb13436ec16c21149282761acf54 Mon Sep 17 00:00:00 2001 From: MarcoLvr Date: Sun, 22 Sep 2024 01:08:08 +0200 Subject: [PATCH 2/2] 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 --- .../MultiverseCore/MultiverseCore.java | 6 +++ .../commands/CreateCommand.java | 12 ++++++ .../commands/EnvironmentCommand.java | 3 ++ .../commands/ImportCommand.java | 7 +++ .../InternalChunkGeneratorManager.java | 43 +++++++++++++++++++ .../impl/MultiverseVoidGenerator.java | 22 ++++++++++ .../MultiverseCore/utils/WorldManager.java | 14 +++++- 7 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/generators/InternalChunkGeneratorManager.java create mode 100644 src/main/java/com/onarandombox/MultiverseCore/generators/impl/MultiverseVoidGenerator.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 6fda9ae95..697bbf6ee 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -78,6 +78,7 @@ 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 void onEnable() { this.messaging = new MVMessaging(); this.economist = new MVEconomist(this); + //CustomGenerators start + // Initialize internal chunk generator manager + InternalChunkGeneratorManager.init(); + //CustomGenerators end + // Load the defaultWorldGenerators this.worldManager.getDefaultWorldGenerators(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java index 6d8f3833b..b6fe362ec 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java @@ -90,6 +90,12 @@ public void runCommand(CommandSender sender, List args) { return; } + //CustomGenerators start + if(env.equalsIgnoreCase("VOID")) { + env = "NORMAL"; + generator = "multiverse:void"; + } + //CustomGenerators end Environment environment = EnvironmentCommand.getEnvFromString(env); if (environment == null) { sender.sendMessage(ChatColor.RED + "That is not a valid environment."); @@ -100,7 +106,12 @@ public void runCommand(CommandSender sender, List args) { // If they didn't specify a type, default to NORMAL if (typeString == null) { typeString = "NORMAL"; + //CustomGenerators start + } else if(typeString.equalsIgnoreCase("VOID")) { + typeString = "NORMAL"; + generator = "multiverse:void"; } + //CustomGenerators 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 void runCommand(CommandSender sender, List args) { return; } // Determine if the generator is valid. #918 + if (generator != null) { List genarray = new ArrayList(Arrays.asList(generator.split(":"))); if (genarray.size() < 2) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java index f9ac88600..87dda60d4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java @@ -45,6 +45,9 @@ public static void showEnvironments(CommandSender sender) { sender.sendMessage(ChatColor.GREEN + "NORMAL"); sender.sendMessage(ChatColor.RED + "NETHER"); sender.sendMessage(ChatColor.AQUA + "END"); + //CustomGenerators start + sender.sendMessage(ChatColor.WHITE + "VOID"); + //CustomGenerators end } /** * Shows all valid known world types to a {@link CommandSender}. diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java index 7a52d5a15..2cb6bbf4f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java @@ -106,6 +106,12 @@ public void runCommand(CommandSender sender, List args) { } String env = args.get(1); + //CustomGenerators start + if(env.equalsIgnoreCase("VOID")){ + env = "NORMAL"; + generator = "multiverse:void"; + } + //CustomGenerators end Environment environment = EnvironmentCommand.getEnvFromString(env); if (environment == null) { sender.sendMessage(ChatColor.RED + "That is not a valid environment."); @@ -113,6 +119,7 @@ public void runCommand(CommandSender sender, List args) { return; } + if (!worldFile.exists()) { sender.sendMessage(ChatColor.RED + "FAILED."); String worldList = this.getPotentialWorldStrings(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/generators/InternalChunkGeneratorManager.java b/src/main/java/com/onarandombox/MultiverseCore/generators/InternalChunkGeneratorManager.java new file mode 100644 index 000000000..b211e851b --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/generators/InternalChunkGeneratorManager.java @@ -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; + +//CustomGenerators start +public class InternalChunkGeneratorManager { + + private final Map 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); + } + +} +//CustomGenerators end diff --git a/src/main/java/com/onarandombox/MultiverseCore/generators/impl/MultiverseVoidGenerator.java b/src/main/java/com/onarandombox/MultiverseCore/generators/impl/MultiverseVoidGenerator.java new file mode 100644 index 000000000..91aa7cac9 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/generators/impl/MultiverseVoidGenerator.java @@ -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); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java index 0b2ab0701..e6c982c8d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/utils/WorldManager.java @@ -17,6 +17,7 @@ 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 boolean addWorld(String name, Environment env, String seedString, WorldTy // TODO: Use the fancy kind with the commandSender if (generator != null && generator.length() != 0) { - c.generator(generator); + //CustomGenerators start + if(generator.startsWith("multiverse:")) + c.generator(InternalChunkGeneratorManager.get().getGenerator(generator.split(":")[1])); + else + c.generator(generator); + //CustomGenerators end } c.environment(env); if (type != null) { @@ -305,7 +311,11 @@ public ChunkGenerator getChunkGenerator(String generator, final String generator if (generator == null) { return null; } - + //CustomGenerators start + if(generator.equalsIgnoreCase("multiverse")){ + return InternalChunkGeneratorManager.get().getGenerator(generatorID); + } + //CustomGenerators end final Plugin myPlugin = this.plugin.getServer().getPluginManager().getPlugin(generator); if (myPlugin == null) { return null;