IrisSafeguard Prototype idea

This commit is contained in:
RePixelatedMC
2023-10-04 14:12:53 +02:00
parent 15e6750e11
commit 46ee7a5983
5 changed files with 186 additions and 6 deletions

View File

@@ -38,6 +38,8 @@ 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.engine.safeguard.IrisSafeguard;
import com.volmit.iris.engine.safeguard.ServerBoot;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.exceptions.IrisException;
@@ -85,10 +87,15 @@ import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.lang.annotation.Annotation;
import java.lang.management.ManagementFactory;
import java.lang.management.OperatingSystemMXBean;
import java.net.URL;
import java.util.Date;
import java.util.Map;
import static com.volmit.iris.engine.safeguard.IrisSafeguard.unstablemode;
import static com.volmit.iris.engine.safeguard.ServerBoot.passedserversoftware;
@SuppressWarnings("CanBeFinal")
public class Iris extends VolmitPlugin implements Listener {
public static final String OVERWORLD_TAG = "3620";
@@ -308,6 +315,9 @@ public class Iris extends VolmitPlugin implements Listener {
public static void info(String format, Object... args) {
msg(C.WHITE + String.format(format, args));
}
public static void safeguard(String format, Object... args) {
msg(C.RESET + String.format(format, args));
}
@SuppressWarnings("deprecation")
public static void later(NastyRunnable object) {
@@ -455,6 +465,9 @@ public class Iris extends VolmitPlugin implements Listener {
J.s(this::setupPapi);
J.a(ServerConfigurator::configure, 20);
splash();
ServerBoot.unstablemode();
ServerBoot.supportedserversoftware();
ServerBoot.incompatiblepluginset();
autoStartStudio();
checkForBukkitWorlds();
IrisToolbelt.retainMantleDataForSlice(String.class.getCanonicalName());
@@ -542,6 +555,7 @@ public class Iris extends VolmitPlugin implements Listener {
enable();
super.onEnable();
Bukkit.getPluginManager().registerEvents(this, this);
IrisSafeguard.IrisSafeguardSystem();
setupChecks();
}
@@ -714,12 +728,10 @@ public class Iris extends VolmitPlugin implements Listener {
return;
}
// @NoArgsConstructor
String padd = Form.repeat(" ", 8);
String padd2 = Form.repeat(" ", 4);
String[] info = {"", "", "", "", "", padd2 + C.IRIS + " Iris", padd2 + C.GRAY + " by " + "<rainbow>Volmit Software", padd2 + C.GRAY + " v" + C.IRIS + getDescription().getVersion(),
};
String[] splash = {
String[] info = {"", "", "", "", "", padd2 + C.IRIS + " Iris", padd2 + C.GRAY + " by " + "<rainbow>Volmit Software", padd2 + C.GRAY + " v" + C.IRIS + getDescription().getVersion()};
String[] splashstable = {
padd + C.GRAY + " @@@@@@@@@@@@@@" + C.DARK_GRAY + "@@@",
padd + C.GRAY + " @@&&&&&&&&&" + C.DARK_GRAY + "&&&&&&" + C.IRIS + " .(((()))). ",
padd + C.GRAY + "@@@&&&&&&&&" + C.DARK_GRAY + "&&&&&" + C.IRIS + " .((((((())))))). ",
@@ -732,8 +744,37 @@ public class Iris extends VolmitPlugin implements Listener {
padd + C.GRAY + "" + C.IRIS + " '(((())))' " + C.DARK_GRAY + "&&&&&&&&" + C.GRAY + "&&&&&&&@@",
padd + C.GRAY + " " + C.DARK_GRAY + "@@@" + C.GRAY + "@@@@@@@@@@@@@@"
};
//@done
Iris.info("Server type & version: " + Bukkit.getVersion());
String[] splashunstable = {
padd + C.GRAY + " @@@@@@@@@@@@@@" + C.DARK_GRAY + "@@@",
padd + C.GRAY + " @@&&&&&&&&&" + C.DARK_GRAY + "&&&&&&" + C.RED + " .(((()))). ",
padd + C.GRAY + "@@@&&&&&&&&" + C.DARK_GRAY + "&&&&&" + C.RED + " .((((((())))))). ",
padd + C.GRAY + "@@@&&&&&" + C.DARK_GRAY + "&&&&&&&" + C.RED + " ((((((((())))))))) " + C.GRAY + " @",
padd + C.GRAY + "@@@&&&&" + C.DARK_GRAY + "@@@@@&" + C.RED + " ((((((((-))))))))) " + C.GRAY + " @@",
padd + C.GRAY + "@@@&&" + C.RED + " ((((((({ })))))))) " + C.GRAY + " &&@@@",
padd + C.GRAY + "@@" + C.RED + " ((((((((-))))))))) " + C.DARK_GRAY + "&@@@@@" + C.GRAY + "&&&&@@@",
padd + C.GRAY + "@" + C.RED + " ((((((((())))))))) " + C.DARK_GRAY + "&&&&&" + C.GRAY + "&&&&&&&@@@",
padd + C.GRAY + "" + C.RED + " '((((((()))))))' " + C.DARK_GRAY + "&&&&&" + C.GRAY + "&&&&&&&&@@@",
padd + C.GRAY + "" + C.RED + " '(((())))' " + C.DARK_GRAY + "&&&&&&&&" + C.GRAY + "&&&&&&&@@",
padd + C.GRAY + " " + C.DARK_GRAY + "@@@" + C.GRAY + "@@@@@@@@@@@@@@"
};
String[] splash = unstablemode ? splashunstable : splashstable; // Choose the appropriate splash array based on unstablemode
long maxMemory = Runtime.getRuntime().maxMemory() / (1024 * 1024);
OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
String osArch = osBean.getArch();
String osName = osBean.getName();
if (!passedserversoftware) {
Iris.info("Server type & version: " + C.RED + Bukkit.getVersion());
} else { Iris.info("Server type & version: " + Bukkit.getVersion()); }
Iris.info("Server OS: " + osName + " (" + osArch + ")");
Iris.info("Process Memory: " + maxMemory + " MB");
if (maxMemory < 5999) {
Iris.warn("6GB+ Ram is recommended");
}
Iris.info("Bukkit version: " + Bukkit.getBukkitVersion());
Iris.info("Java version: " + getJavaVersion());
Iris.info("Custom Biomes: " + INMS.get().countCustomBiomes());

View File

@@ -25,6 +25,7 @@ import com.volmit.iris.core.tools.IrisToolbelt;
import com.volmit.iris.engine.framework.Engine;
import com.volmit.iris.engine.object.IrisDimension;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.engine.safeguard.ServerBoot;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.decree.DecreeContext;
import com.volmit.iris.util.decree.DecreeExecutor;
@@ -47,6 +48,8 @@ import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import static com.volmit.iris.engine.safeguard.ServerBoot.multiverse;
@Decree(name = "iris", aliases = {"ir", "irs"}, description = "Basic Command")
public class CommandIris implements DecreeExecutor {
private CommandStudio studio;
@@ -67,6 +70,14 @@ public class CommandIris implements DecreeExecutor {
@Param(description = "The seed to generate the world with", defaultValue = "1337")
long seed
) {
if (multiverse){
sender().sendMessage(C.RED + "Your server has a incompatibility that may corrupt all worlds on the server if not handled properly.");
sender().sendMessage(C.RED + "its heavily advised for you to take action. see log for full detail");
Iris.safeguard(C.RED + "----------------------------------------------------------------");
Iris.safeguard(C.RED + "Command ran: /iris create");
ServerBoot.incompatiblepluginset();
Iris.safeguard(C.RED + "----------------------------------------------------------------");
}
if (name.equals("iris")) {
sender().sendMessage(C.RED + "You cannot use the world name \"iris\" for creating worlds as Iris uses this directory for studio worlds.");
sender().sendMessage(C.RED + "May we suggest the name \"IrisWorld\" instead?");

View File

@@ -0,0 +1,13 @@
package com.volmit.iris.engine.safeguard;
import com.volmit.iris.Iris;
public class IrisSafeguard {
// more planned and WIP
public static boolean unstablemode = false;
public static void IrisSafeguardSystem() {
Iris.info("Enabled Iris SafeGuard");
ServerBoot.bootcheck();
}
}

View File

@@ -0,0 +1,7 @@
package com.volmit.iris.engine.safeguard;
public class SafeguardUtils {
public static void resetdatapacks(){
}
}

View File

@@ -0,0 +1,108 @@
package com.volmit.iris.engine.safeguard;
import com.volmit.iris.Iris;
import com.volmit.iris.util.format.C;
import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import static com.volmit.iris.Iris.instance;
import static com.volmit.iris.engine.safeguard.IrisSafeguard.unstablemode;
public class ServerBoot {
public static boolean multiverse = false;
public static boolean dynmap = false;
public static boolean terraform = false;
public static boolean stratos = false;
protected static boolean safeguardPassed;
public static boolean passedserversoftware = true;
protected static byte count;
public static void bootcheck() {
Iris.info("Checking for possible conflicts..");
org.bukkit.plugin.PluginManager pluginManager = Bukkit.getPluginManager();
Plugin[] plugins = pluginManager.getPlugins();
StringBuilder pluginList = new StringBuilder("Plugin list: ");
count = 0;
for (Plugin plugin : plugins) {
String pluginName = plugin.getName();
if (pluginName.equalsIgnoreCase("Multiverse-Core")) {
multiverse = true;
count++;
}
if (pluginName.equalsIgnoreCase("Dynmap")) {
dynmap = true;
count++;
}
if (pluginName.equalsIgnoreCase("TerraformGenerator")) {
terraform = true;
count++;
}
if (pluginName.equalsIgnoreCase("Stratos")) {
stratos = true;
count++;
}
pluginList.append(pluginName).append(", ");
}
if (
!instance.getServer().getVersion().contains("Purpur") &&
!instance.getServer().getVersion().contains("Paper") &&
!instance.getServer().getVersion().contains("Spigot") &&
!instance.getServer().getVersion().contains("Pufferfish") &&
!instance.getServer().getVersion().contains("Bukkit"))
{
unstablemode = true;
passedserversoftware = false;
}
safeguardPassed = (count == 0);
if(!safeguardPassed){
unstablemode = true;
}
if (unstablemode){
Iris.safeguard("Unstable mode has been activated.");
}
Iris.safeguard(pluginList.toString());
}
public static void unstablemode(){
if (unstablemode) {
Iris.safeguard(C.DARK_RED + "Iris is running in Unstable Mode");
} else {
Iris.safeguard(C.BLUE + "Iris is running Stable");
}
}
public static void supportedserversoftware(){
if (!passedserversoftware) {
Iris.safeguard(C.DARK_RED + "Server is running unsupported server software");
Iris.safeguard(C.RED + "Supported: Purpur, Pufferfish, Paper, Spigot, Bukkit");
}
}
public static void incompatiblepluginset(){
if (safeguardPassed) {
Iris.safeguard(C.BLUE + "0 Conflicts found");
} else {
Iris.safeguard(C.DARK_RED + "" + count + " Conflicts found");
unstablemode = true;
if (multiverse) {
Iris.safeguard(C.RED + "Multiverse");
Iris.safeguard(C.RED + "- The plugin Multiverse is not compatible with the server.");
Iris.safeguard(C.RED + "- If you want to have a world manager, consider using PhantomWorlds or MyWorlds instead.");
}
if (dynmap) {
Iris.safeguard(C.RED + "Dynmap");
Iris.safeguard(C.RED + "- The plugin Dynmap is not compatible with the server.");
Iris.safeguard(C.RED + "- If you want to have a map plugin like Dynmap, consider Bluemap or LiveAtlas.");
}
if (terraform || stratos) {
Iris.safeguard(C.YELLOW + "Terraform Generator / Stratos");
Iris.safeguard(C.YELLOW + "- Iris is not compatible with other worldgen plugins.");
}
}
}
}