mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-06-17 14:21:33 +00:00
IrisSafeguard Prototype idea
WorldManager ( Not done WIP )
This commit is contained in:
@@ -57,6 +57,7 @@ public class CommandIris implements DecreeExecutor {
|
|||||||
private CommandSettings settings;
|
private CommandSettings settings;
|
||||||
private CommandObject object;
|
private CommandObject object;
|
||||||
private CommandJigsaw jigsaw;
|
private CommandJigsaw jigsaw;
|
||||||
|
private CommandWorldManager manager;
|
||||||
private CommandWhat what;
|
private CommandWhat what;
|
||||||
private CommandEdit edit;
|
private CommandEdit edit;
|
||||||
private CommandFind find;
|
private CommandFind find;
|
||||||
@@ -131,10 +132,12 @@ public class CommandIris implements DecreeExecutor {
|
|||||||
}
|
}
|
||||||
IrisToolbelt.evacuate(world, "Deleting world");
|
IrisToolbelt.evacuate(world, "Deleting world");
|
||||||
Bukkit.unloadWorld(world, false);
|
Bukkit.unloadWorld(world, false);
|
||||||
if (delete && world.getWorldFolder().delete()) {
|
if (delete) {
|
||||||
sender().sendMessage(C.GREEN + "Successfully removed world folder");
|
if (world.getWorldFolder().delete()) {
|
||||||
} else {
|
sender().sendMessage(C.GREEN + "Successfully removed world folder");
|
||||||
sender().sendMessage(C.RED + "Failed to remove world folder");
|
} else {
|
||||||
|
sender().sendMessage(C.RED + "Failed to remove world folder");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,246 @@
|
|||||||
|
/*
|
||||||
|
* Iris is a World Generator for Minecraft Bukkit Servers
|
||||||
|
* Copyright (c) 2022 Arcane Arts (Volmit Software)
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.volmit.iris.core.commands;
|
||||||
|
|
||||||
|
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.core.tools.IrisToolbelt;
|
||||||
|
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.decree.DecreeExecutor;
|
||||||
|
import com.volmit.iris.util.decree.DecreeOrigin;
|
||||||
|
import com.volmit.iris.util.decree.annotations.Decree;
|
||||||
|
import com.volmit.iris.util.decree.annotations.Param;
|
||||||
|
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 static com.volmit.iris.Iris.service;
|
||||||
|
|
||||||
|
@Decree(name = "worldmanager", origin = DecreeOrigin.PLAYER, description = "Iris World Manager")
|
||||||
|
public class CommandWorldManager implements DecreeExecutor {
|
||||||
|
String WorldToLoad;
|
||||||
|
String WorldEngine;
|
||||||
|
String worldNameToCheck = "YourWorldName";
|
||||||
|
VolmitSender sender = Iris.getSender();
|
||||||
|
@Decree(description = "Unload an Iris World", origin = DecreeOrigin.PLAYER, sync = true)
|
||||||
|
public void unloadworld(
|
||||||
|
@Param(description = "The world to unload")
|
||||||
|
World world
|
||||||
|
) {
|
||||||
|
if (!IrisToolbelt.isIrisWorld(world)) {
|
||||||
|
sender().sendMessage(C.RED + "This is not an Iris world. Iris worlds: " + String.join(", ", Bukkit.getServer().getWorlds().stream().filter(IrisToolbelt::isIrisWorld).map(World::getName).toList()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sender().sendMessage(C.GREEN + "Unloading world: " + world.getName());
|
||||||
|
try {
|
||||||
|
IrisToolbelt.evacuate(world);
|
||||||
|
Bukkit.unloadWorld(world, false);
|
||||||
|
sender().sendMessage(C.GREEN + "World unloaded successfully.");
|
||||||
|
} catch (Exception e) {
|
||||||
|
sender().sendMessage(C.RED + "Failed to unload the world: " + e.getMessage());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Decree(description = "Load an Iris World", origin = DecreeOrigin.PLAYER, sync = true)
|
||||||
|
public void loadworld(
|
||||||
|
@Param(description = "The name of the world to load")
|
||||||
|
String world
|
||||||
|
) {
|
||||||
|
World worldloaded = Bukkit.getWorld(world);
|
||||||
|
worldNameToCheck = world;
|
||||||
|
boolean worldExists = doesWorldExist(worldNameToCheck);
|
||||||
|
WorldEngine = world;
|
||||||
|
|
||||||
|
if (!worldExists) {
|
||||||
|
sender().sendMessage(C.YELLOW + world + " Doesnt exist on the server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldToLoad = world;
|
||||||
|
File BUKKIT_YML = new File("bukkit.yml");
|
||||||
|
String pathtodim = world + "\\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);
|
||||||
|
sender().sendMessage(C.BLUE + "Generator: " + dimension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sender().sendMessage(C.GOLD + world + " is not an iris world.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sender().sendMessage(C.GREEN + "Loading world: " + world);
|
||||||
|
|
||||||
|
YamlConfiguration yml = YamlConfiguration.loadConfiguration(BUKKIT_YML);
|
||||||
|
String gen = "Iris:" + dimension;
|
||||||
|
ConfigurationSection section = yml.contains("worlds") ? yml.getConfigurationSection("worlds") : yml.createSection("worlds");
|
||||||
|
if (!section.contains(world)) {
|
||||||
|
section.createSection(world).set("generator", gen);
|
||||||
|
try {
|
||||||
|
yml.save(BUKKIT_YML);
|
||||||
|
Iris.info("Registered \"" + world + "\" in bukkit.yml");
|
||||||
|
} catch (IOException e) {
|
||||||
|
Iris.error("Failed to update bukkit.yml!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
checkForBukkitWorlds();
|
||||||
|
sender().sendMessage(C.GREEN + world + " loaded successfully.");
|
||||||
|
|
||||||
|
}
|
||||||
|
public static boolean doesWorldExist(String worldName) {
|
||||||
|
File worldContainer = Bukkit.getWorldContainer();
|
||||||
|
File worldDirectory = new File(worldContainer, worldName);
|
||||||
|
return worldDirectory.exists() && worldDirectory.isDirectory();
|
||||||
|
}
|
||||||
|
private 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 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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.volmit.iris.engine.safeguard;
|
package com.volmit.iris.engine.safeguard;
|
||||||
|
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
|
import com.volmit.iris.core.nms.v20.NMSBinding1_20_1;
|
||||||
import com.volmit.iris.util.format.C;
|
import com.volmit.iris.util.format.C;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
@@ -13,6 +14,7 @@ public class ServerBoot {
|
|||||||
public static boolean dynmap = false;
|
public static boolean dynmap = false;
|
||||||
public static boolean terraform = false;
|
public static boolean terraform = false;
|
||||||
public static boolean stratos = false;
|
public static boolean stratos = false;
|
||||||
|
public static boolean correctversion = true;
|
||||||
|
|
||||||
protected static boolean safeguardPassed;
|
protected static boolean safeguardPassed;
|
||||||
public static boolean passedserversoftware = true;
|
public static boolean passedserversoftware = true;
|
||||||
@@ -22,6 +24,10 @@ public class ServerBoot {
|
|||||||
Iris.info("Checking for possible conflicts..");
|
Iris.info("Checking for possible conflicts..");
|
||||||
org.bukkit.plugin.PluginManager pluginManager = Bukkit.getPluginManager();
|
org.bukkit.plugin.PluginManager pluginManager = Bukkit.getPluginManager();
|
||||||
Plugin[] plugins = pluginManager.getPlugins();
|
Plugin[] plugins = pluginManager.getPlugins();
|
||||||
|
if (!instance.getServer().getBukkitVersion().contains(NMSBinding1_20_1.NMS_VERSION)) {
|
||||||
|
unstablemode = true;
|
||||||
|
correctversion = false;
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder pluginList = new StringBuilder("Plugin list: ");
|
StringBuilder pluginList = new StringBuilder("Plugin list: ");
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user