mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-06-17 14:21:33 +00:00
Deleted leftovers
This commit is contained in:
@@ -1,179 +0,0 @@
|
|||||||
package com.volmit.iris.util.SFG;
|
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
|
||||||
import com.volmit.iris.core.IrisSettings;
|
|
||||||
import com.volmit.iris.core.loader.IrisData;
|
|
||||||
import com.volmit.iris.core.service.StudioSVC;
|
|
||||||
import com.volmit.iris.engine.object.IrisDimension;
|
|
||||||
import com.volmit.iris.engine.object.IrisWorld;
|
|
||||||
import com.volmit.iris.engine.platform.BukkitChunkGenerator;
|
|
||||||
import com.volmit.iris.engine.platform.DummyChunkGenerator;
|
|
||||||
import com.volmit.iris.util.format.C;
|
|
||||||
import com.volmit.iris.util.plugin.VolmitSender;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.WorldCreator;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
import static com.volmit.iris.Iris.service;
|
|
||||||
|
|
||||||
public class WorldHandlerSFG {
|
|
||||||
static String WorldToLoad;
|
|
||||||
static String WorldEngine;
|
|
||||||
static String worldNameToCheck = "YourWorldName";
|
|
||||||
private static VolmitSender sender;
|
|
||||||
public static void LoadWorld(String selectedWorld){
|
|
||||||
if(Objects.equals(selectedWorld, "Benchmark")){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
worldNameToCheck = selectedWorld;
|
|
||||||
boolean worldExists = doesWorldExist(worldNameToCheck);
|
|
||||||
WorldEngine = selectedWorld;
|
|
||||||
|
|
||||||
if (!worldExists) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
WorldToLoad = selectedWorld;
|
|
||||||
File BUKKIT_YML = new File("bukkit.yml");
|
|
||||||
String pathtodim = selectedWorld + "\\iris\\pack\\dimensions\\";
|
|
||||||
File directory = new File(Bukkit.getWorldContainer(), pathtodim);
|
|
||||||
|
|
||||||
String dimension = null;
|
|
||||||
if (directory.exists() && directory.isDirectory()) {
|
|
||||||
File[] files = directory.listFiles();
|
|
||||||
if (files != null) {
|
|
||||||
for (File file : files) {
|
|
||||||
if (file.isFile()) {
|
|
||||||
String fileName = file.getName();
|
|
||||||
if (fileName.endsWith(".json")) {
|
|
||||||
dimension = fileName.substring(0, fileName.length() - 5);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
YamlConfiguration yml = YamlConfiguration.loadConfiguration(BUKKIT_YML);
|
|
||||||
String gen = "Iris:" + dimension;
|
|
||||||
ConfigurationSection section = yml.contains("worlds") ? yml.getConfigurationSection("worlds") : yml.createSection("worlds");
|
|
||||||
if (!section.contains(selectedWorld)) {
|
|
||||||
section.createSection(selectedWorld).set("generator", gen);
|
|
||||||
try {
|
|
||||||
yml.save(BUKKIT_YML);
|
|
||||||
Iris.info("Registered \"" + selectedWorld + "\" in bukkit.yml");
|
|
||||||
} catch (IOException e) {
|
|
||||||
Iris.error("Failed to update bukkit.yml!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
checkForBukkitWorlds();
|
|
||||||
}
|
|
||||||
static boolean doesWorldExist(String worldName) {
|
|
||||||
File worldContainer = Bukkit.getWorldContainer();
|
|
||||||
File worldDirectory = new File(worldContainer, worldName);
|
|
||||||
return worldDirectory.exists() && worldDirectory.isDirectory();
|
|
||||||
}
|
|
||||||
private static void checkForBukkitWorlds() {
|
|
||||||
FileConfiguration fc = new YamlConfiguration();
|
|
||||||
try {
|
|
||||||
fc.load(new File("bukkit.yml"));
|
|
||||||
ConfigurationSection section = fc.getConfigurationSection("worlds");
|
|
||||||
if (section == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<String> worldsToLoad = Collections.singletonList(WorldToLoad);
|
|
||||||
|
|
||||||
for (String s : section.getKeys(false)) {
|
|
||||||
if (!worldsToLoad.contains(s)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ConfigurationSection entry = section.getConfigurationSection(s);
|
|
||||||
if (!entry.contains("generator", true)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String generator = entry.getString("generator");
|
|
||||||
if (generator.startsWith("Iris:")) {
|
|
||||||
generator = generator.split("\\Q:\\E")[1];
|
|
||||||
} else if (generator.equalsIgnoreCase("Iris")) {
|
|
||||||
generator = IrisSettings.get().getGenerator().getDefaultWorldType();
|
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Iris.info("2 World: %s | Generator: %s", s, generator);
|
|
||||||
if (Bukkit.getWorlds().stream().anyMatch(w -> w.getName().equals(s))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Iris.info(C.LIGHT_PURPLE + "Preparing Spawn for " + s + "' using Iris:" + generator + "...");
|
|
||||||
new WorldCreator(s)
|
|
||||||
.generator(getDefaultWorldGenerator(s, generator))
|
|
||||||
.environment(IrisData.loadAnyDimension(generator).getEnvironment())
|
|
||||||
.createWorld();
|
|
||||||
Iris.info(C.LIGHT_PURPLE + "Loaded " + s + "!");
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public static ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
|
|
||||||
Iris.debug("Default World Generator Called for " + worldName + " using ID: " + id);
|
|
||||||
if (worldName.equals("test")) {
|
|
||||||
try {
|
|
||||||
throw new RuntimeException();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
Iris.info(e.getStackTrace()[1].getClassName());
|
|
||||||
if (e.getStackTrace()[1].getClassName().contains("com.onarandombox.MultiverseCore")) {
|
|
||||||
Iris.debug("MVC Test detected, Quick! Send them the dummy!");
|
|
||||||
return new DummyChunkGenerator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IrisDimension dim;
|
|
||||||
if (id == null || id.isEmpty()) {
|
|
||||||
dim = IrisData.loadAnyDimension(IrisSettings.get().getGenerator().getDefaultWorldType());
|
|
||||||
} else {
|
|
||||||
dim = IrisData.loadAnyDimension(id);
|
|
||||||
}
|
|
||||||
Iris.debug("Generator ID: " + id + " requested by bukkit/plugin");
|
|
||||||
|
|
||||||
if (dim == null) {
|
|
||||||
Iris.warn("Unable to find dimension type " + id + " Looking for online packs...");
|
|
||||||
|
|
||||||
service(StudioSVC.class).downloadSearch(new VolmitSender(Bukkit.getConsoleSender()), id, true);
|
|
||||||
dim = IrisData.loadAnyDimension(id);
|
|
||||||
|
|
||||||
if (dim == null) {
|
|
||||||
throw new RuntimeException("Can't find dimension " + id + "!");
|
|
||||||
} else {
|
|
||||||
Iris.info("Resolved missing dimension, proceeding with generation.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Iris.debug("Assuming IrisDimension: " + dim.getName());
|
|
||||||
IrisWorld w = IrisWorld.builder()
|
|
||||||
.name(worldName)
|
|
||||||
.seed(1337)
|
|
||||||
.environment(dim.getEnvironment())
|
|
||||||
.worldFolder(new File(Bukkit.getWorldContainer(), worldName))
|
|
||||||
.minHeight(dim.getMinHeight())
|
|
||||||
.maxHeight(dim.getMaxHeight())
|
|
||||||
.build();
|
|
||||||
Iris.debug("Generator Config: " + w.toString());
|
|
||||||
File ff = new File(w.worldFolder(), "iris/pack");
|
|
||||||
if (!ff.exists() || ff.listFiles().length == 0) {
|
|
||||||
ff.mkdirs();
|
|
||||||
service(StudioSVC.class).installIntoWorld(sender, dim.getLoadKey(), ff.getParentFile());
|
|
||||||
}
|
|
||||||
return new BukkitChunkGenerator(w, false, ff, dim.getLoadKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user