Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal Chunk Generators and multiverse:void generator as first custom gen. VOID as Environment type when creating or importing worlds. #3110

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public void runCommand(CommandSender sender, List<String> 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.");
Expand All @@ -100,14 +106,20 @@ public void runCommand(CommandSender sender, List<String> 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.");
EnvironmentCommand.showWorldTypes(sender);
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,20 @@ public void runCommand(CommandSender sender, List<String> 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.");
EnvironmentCommand.showEnvironments(sender);
return;
}


if (!worldFile.exists()) {
sender.sendMessage(ChatColor.RED + "FAILED.");
String worldList = this.getPotentialWorldStrings();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<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);
}

}
//CustomGenerators end
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down