Skip to content

Commit

Permalink
Merge pull request #1049 from RePixelatedMC/Pixeldev
Browse files Browse the repository at this point in the history
[ Ready ] SAFEGUARD
  • Loading branch information
NextdoorPsycho authored Nov 6, 2023
2 parents 68a4eee + ffcd2b4 commit f6b51c2
Show file tree
Hide file tree
Showing 23 changed files with 933 additions and 268 deletions.
47 changes: 36 additions & 11 deletions core/src/main/java/com/volmit/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.volmit.iris.core.nms.INMS;
import com.volmit.iris.core.nms.v1X.NMSBinding1X;
import com.volmit.iris.core.pregenerator.LazyPregenerator;
import com.volmit.iris.core.service.ChunkHandlerSVC;
import com.volmit.iris.core.service.StudioSVC;
import com.volmit.iris.core.tools.IrisToolbelt;
import com.volmit.iris.engine.EnginePanic;
Expand All @@ -39,7 +40,7 @@
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.engine.safeguard.UtilsSFG;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.collection.KMap;
import com.volmit.iris.util.exceptions.IrisException;
Expand All @@ -52,6 +53,7 @@
import com.volmit.iris.util.io.JarScanner;
import com.volmit.iris.util.math.M;
import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.misc.getHardware;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.plugin.IrisService;
import com.volmit.iris.util.plugin.Metrics;
Expand Down Expand Up @@ -94,7 +96,9 @@
import java.util.Map;

import static com.volmit.iris.engine.safeguard.IrisSafeguard.unstablemode;
import static com.volmit.iris.engine.safeguard.ServerBoot.passedserversoftware;
import static com.volmit.iris.engine.safeguard.ServerBootSFG.passedserversoftware;
import static com.volmit.iris.util.misc.getHardware.getCPUModel;
import static com.volmit.iris.util.misc.getHardware.getCPUThreads;

@SuppressWarnings("CanBeFinal")
public class Iris extends VolmitPlugin implements Listener {
Expand Down Expand Up @@ -438,14 +442,15 @@ public static void addPanic(String s, String v) {
private static void fixShading() {
ShadeFix.fix(ComponentSerializer.class);
}

private ChunkHandlerSVC chunkHandlerSVC;
private void enable() {
instance = this;
services = new KMap<>();
initialize("com.volmit.iris.core.service").forEach((i) -> services.put((Class<? extends IrisService>) i.getClass(), (IrisService) i));
INMS.get();
IO.delete(new File("iris"));
setupAudience();
IrisSafeguard.IrisSafeguardSystem();
sender = new VolmitSender(Bukkit.getConsoleSender());
sender.setTag(getTag());
instance = this;
Expand All @@ -465,9 +470,14 @@ private void enable() {
J.s(this::setupPapi);
J.a(ServerConfigurator::configure, 20);
splash();
ServerBoot.UnstableMode();
ServerBoot.SupportedServerSoftware();
ServerBoot.printincompatiblepluginWarnings();
UtilsSFG.UnstableMode();
UtilsSFG.SupportedServerSoftware();
UtilsSFG.printIncompatibleWarnings();
UtilsSFG.unstablePrompt();
if(IrisSettings.get().getGeneral().useIntegratedChunkHandler) {
chunkHandlerSVC = new ChunkHandlerSVC(this);
Iris.info(C.LIGHT_PURPLE + "Started Intergrated ChunkHandlerSVC");
}
autoStartStudio();
checkForBukkitWorlds();
IrisToolbelt.retainMantleDataForSlice(String.class.getCanonicalName());
Expand Down Expand Up @@ -555,7 +565,6 @@ public void onEnable() {
enable();
super.onEnable();
Bukkit.getPluginManager().registerEvents(this, this);
IrisSafeguard.IrisSafeguardSystem();
setupChecks();
}

Expand Down Expand Up @@ -587,7 +596,12 @@ public void stop() {

@Override
public String getTag(String subTag) {
return C.BOLD + "" + C.DARK_GRAY + "[" + C.BOLD + "" + C.IRIS + "Iris" + C.BOLD + C.DARK_GRAY + "]" + C.RESET + "" + C.GRAY + ": ";
if (unstablemode) {
return C.BOLD + "" + C.DARK_GRAY + "[" + C.BOLD + "" + C.RED + "Iris" + C.BOLD + C.DARK_GRAY + "]" + C.RESET + "" + C.GRAY + ": ";
}
else {
return C.BOLD + "" + C.DARK_GRAY + "[" + C.BOLD + "" + C.IRIS + "Iris" + C.BOLD + C.DARK_GRAY + "]" + C.RESET + "" + C.GRAY + ": ";
}
}

private boolean setupChecks() {
Expand Down Expand Up @@ -731,6 +745,10 @@ public void splash() {
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()};
if (unstablemode) {
info = new String[]{"", "", "", "", "", padd2 + C.RED + " Iris", padd2 + C.GRAY + " by " + C.DARK_RED + "Volmit Software", padd2 + C.GRAY + " v" + C.RED + getDescription().getVersion()};
}

String[] splashstable = {
padd + C.GRAY + " @@@@@@@@@@@@@@" + C.DARK_GRAY + "@@@",
padd + C.GRAY + " @@&&&&&&&&&" + C.DARK_GRAY + "&&&&&&" + C.IRIS + " .(((()))). ",
Expand Down Expand Up @@ -761,7 +779,6 @@ public void splash() {
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();
Expand All @@ -771,8 +788,16 @@ public void splash() {
} else { Iris.info("Server type & version: " + Bukkit.getVersion()); }

Iris.info("Server OS: " + osName + " (" + osArch + ")");
Iris.info("Process Memory: " + maxMemory + " MB");
if (maxMemory < 5999) {

if(unstablemode) Iris.info("Server Cpu: " + C.DARK_RED + getCPUModel());

if(getCPUModel().contains("Intel")) Iris.info("Server Cpu: " + C.BLUE + getCPUModel());
if(getCPUModel().contains("Ryzen")) Iris.info("Server Cpu: " + C.RED + getCPUModel());
if(!getCPUModel().contains("Intel") && !getCPUModel().contains("Ryzen")) Iris.info("Server Cpu: " + C.DARK_GRAY + getCPUModel());

Iris.info("Process Threads: " + getCPUThreads());
Iris.info("Process Memory: " + getHardware.getProcessMemory() + " MB");
if (getHardware.getProcessMemory() < 5999) {
Iris.warn("6GB+ Ram is recommended");
}
Iris.info("Bukkit version: " + Bukkit.getBukkitVersion());
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/com/volmit/iris/core/IrisSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public static class IrisSettingsPerformance {

@Data
public static class IrisSettingsGeneral {
public boolean bootUnstable = false;
public boolean useIntegratedChunkHandler = false;
public boolean commandSounds = true;
public boolean debug = false;
public boolean disableNMS = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,20 @@ private static void increaseKeepAliveSpigot() throws IOException, InvalidConfigu
long tt = f.getLong("settings.timeout-time");

if (tt < TimeUnit.MINUTES.toSeconds(5)) {
Iris.warn("Updating spigot.yml timeout-time: " + tt + " -> " + TimeUnit.MINUTES.toSeconds(5) + " (5 minutes)");
Iris.warn("Updating spigot.yml timeout-time: " + tt + " -> " + TimeUnit.MINUTES.toSeconds(20) + " (5 minutes)");
Iris.warn("You can disable this change (autoconfigureServer) in Iris settings, then change back the value.");
f.set("settings.timeout-time", TimeUnit.MINUTES.toSeconds(5));
f.save(spigotConfig);
}
}

private static void increasePaperWatchdog() throws IOException, InvalidConfigurationException {
File spigotConfig = new File("config/paper-global.yml");
FileConfiguration f = new YamlConfiguration();
f.load(spigotConfig);
long tt = f.getLong("watchdog.early-warning-delay");

if (tt < TimeUnit.MINUTES.toMillis(3)) {
Iris.warn("Updating paper.yml watchdog early-warning-delay: " + tt + " -> " + TimeUnit.MINUTES.toMillis(3) + " (3 minutes)");
Iris.warn("Updating paper.yml watchdog early-warning-delay: " + tt + " -> " + TimeUnit.MINUTES.toMillis(15) + " (3 minutes)");
Iris.warn("You can disable this change (autoconfigureServer) in Iris settings, then change back the value.");
f.set("watchdog.early-warning-delay", TimeUnit.MINUTES.toMillis(3));
f.save(spigotConfig);
Expand Down
145 changes: 130 additions & 15 deletions core/src/main/java/com/volmit/iris/core/commands/CommandIris.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import com.volmit.iris.core.IrisSettings;
import com.volmit.iris.core.service.StudioSVC;
import com.volmit.iris.core.tools.IrisBenchmarking;
import com.volmit.iris.core.tools.IrisCreator;
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.object.IrisWorld;
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
import com.volmit.iris.engine.safeguard.ServerBoot;
import com.volmit.iris.engine.safeguard.UtilsSFG;
import com.volmit.iris.util.collection.KList;
import com.volmit.iris.util.decree.DecreeContext;
import com.volmit.iris.util.decree.DecreeExecutor;
Expand All @@ -36,23 +38,28 @@
import com.volmit.iris.util.decree.specialhandlers.NullablePlayerHandler;
import com.volmit.iris.util.format.C;
import com.volmit.iris.util.format.Form;
import com.volmit.iris.util.mantle.MantleChunk;
import com.volmit.iris.util.parallel.BurstExecutor;
import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.plugin.VolmitSender;
import com.volmit.iris.util.scheduling.J;
import com.volmit.iris.util.scheduling.jobs.QueueJob;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import static com.volmit.iris.core.service.EditSVC.deletingWorld;
import static com.volmit.iris.core.tools.IrisBenchmarking.inProgress;
import static com.volmit.iris.engine.safeguard.ServerBoot.multiverse;
import static com.volmit.iris.engine.safeguard.IrisSafeguard.unstablemode;
import static com.volmit.iris.engine.safeguard.ServerBootSFG.incompatiblePlugins;

@Decree(name = "iris", aliases = {"ir", "irs"}, description = "Basic Command")
public class CommandIris implements DecreeExecutor {
Expand All @@ -66,6 +73,8 @@ public class CommandIris implements DecreeExecutor {
private CommandFind find;
private CommandWorldManager manager;

public static @Getter String BenchDimension;

@Decree(description = "Create a new world", aliases = {"+", "c"})
public void create(
@Param(aliases = "world-name", description = "The name of the world to create")
Expand All @@ -75,19 +84,34 @@ public void create(
@Param(description = "The seed to generate the world with", defaultValue = "1337")
long seed
) {
if (multiverse){
sender().sendMessage(C.RED + "Your server has an incompatibility that may corrupt all worlds on the server if not handled properly.");
sender().sendMessage(C.RED + "it is strongly advised for you to take action. see log for full detail");
Iris.safeguard(C.RED + "----------------------------------------------------------------");
Iris.safeguard(C.RED + "Command ran: /iris create");
ServerBoot.printincompatiblepluginWarnings();
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?");
return;
if(sender() instanceof Player) {
if (incompatiblePlugins.get("Multiverse-Core")) {
sender().sendMessage(C.RED + "Your server has an incompatibility that may corrupt all worlds on the server if not handled properly.");
sender().sendMessage(C.RED + "it is strongly advised for you to take action. see log for full detail");
sender().sendMessage(C.RED + "----------------------------------------------------------------");
sender().sendMessage(C.RED + "Command ran: /iris create");
sender().sendMessage(C.RED + UtilsSFG.MSGIncompatibleWarnings());
sender().sendMessage(C.RED + "----------------------------------------------------------------");
}
if (unstablemode && !incompatiblePlugins.get("Multiverse-Core")) {
sender().sendMessage(C.RED + "Your server is experiencing an incompatibility with the Iris plugin.");
sender().sendMessage(C.RED + "Please rectify this problem to avoid further complications.");
sender().sendMessage(C.RED + "----------------------------------------------------------------");
sender().sendMessage(C.RED + "Command ran: /iris create");
sender().sendMessage(C.RED + UtilsSFG.MSGIncompatibleWarnings());
sender().sendMessage(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?");
return;
}
if (name.equals("Benchmark")) {
sender().sendMessage(C.RED + "You cannot use the world name \"Benchmark\" for creating worlds as Iris uses this directory for Benchmarking Packs.");
sender().sendMessage(C.RED + "May we suggest the name \"IrisWorld\" instead?");
return;
}

if (new File(Bukkit.getWorldContainer(), name).exists()) {
sender().sendMessage(C.RED + "That folder already exists!");
Expand Down Expand Up @@ -142,13 +166,43 @@ public void version() {
sender().sendMessage(C.GREEN + "Iris v" + Iris.instance.getDescription().getVersion() + " by Volmit Software");
}
@Decree(description = "Benchmark your server", origin = DecreeOrigin.CONSOLE)
public void benchmark() throws InterruptedException {
public void serverbenchmark() throws InterruptedException {
if(!inProgress) {
IrisBenchmarking.runBenchmark();
} else {
Iris.info(C.RED + "Benchmark already is in progress.");
}
}
/*
/todo Fix PREGEN
@Decree(description = "Benchmark a pack", origin = DecreeOrigin.CONSOLE)
public void packbenchmark(
@Param(description = "Dimension to benchmark")
IrisDimension type
) throws InterruptedException {
BenchDimension = type.getLoadKey();
IrisPackBenchmarking.runBenchmark();
} */

/* /todo Different approach this feels useless atm
@Decree(description = "Check for instabilities", origin = DecreeOrigin.CONSOLE)
public void fixunstable() throws InterruptedException {
if (unstablemode){
sender().sendMessage(C.RED + "Incompatibilities are posted in console..");
Iris.info(C.RED + "Your server is experiencing an incompatibility with the Iris plugin.");
Iris.info(C.RED + "Please rectify this problem to avoid further complications.");
Iris.info(C.RED + "----------------------------------------------------------------");
Iris.info(C.RED + "Command ran: /iris fixunstable");
UtilsSFG.printIncompatibleWarnings();
Iris.info(C.RED + "----------------------------------------------------------------");
} else {
Iris.info(C.BLUE + "Iris is running stable..");
sender().sendMessage("Iris is running stable..");
}
} */

@Decree(description = "Print world height information", origin = DecreeOrigin.PLAYER)
public void height() {
Expand All @@ -162,6 +216,67 @@ public void so() {
Iris.service(StudioSVC.class).open(sender(), 1337, "overworld");
}

@Decree(description = "Remove an Iris world", aliases = {"del", "rm", "delete"}, sync = true)
public void remove(
@Param(description = "The world to remove")
World world,
@Param(description = "Whether to also remove the folder (if set to false, just does not load the world)", defaultValue = "true")
boolean delete
) {
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 + "Removing world: " + world.getName());
try {
if (IrisToolbelt.removeWorld(world)) {
sender().sendMessage(C.GREEN + "Successfully removed " + world.getName() + " from bukkit.yml");
} else {
sender().sendMessage(C.YELLOW + "Looks like the world was already removed from bukkit.yml");
}
} catch (IOException e) {
sender().sendMessage(C.RED + "Failed to save bukkit.yml because of " + e.getMessage());
e.printStackTrace();
}
IrisToolbelt.evacuate(world, "Deleting world");
deletingWorld = true;
Bukkit.unloadWorld(world, false);
int retries = 10;
if (delete) {
if (deleteDirectory(world.getWorldFolder())) {
sender().sendMessage(C.GREEN + "Successfully removed world folder");
} else {
while(true){
if (deleteDirectory(world.getWorldFolder())){
sender().sendMessage(C.GREEN + "Successfully removed world folder");
break;
}
sender().sendMessage(C.GREEN + "DEBUG1");
retries--;
if (retries == 0){
sender().sendMessage(C.RED + "Failed to remove world folder");
break;
}
J.sleep(2000);
}
}
}
deletingWorld = false;
}

public static boolean deleteDirectory(File dir) {
if (dir.isDirectory()) {
File[] children = dir.listFiles();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDirectory(children[i]);
if (!success) {
return false;
}
}
}
return dir.delete();
}

@Decree(description = "Set aura spins")
public void aura(
@Param(description = "The h color value", defaultValue = "-20")
Expand Down
Loading

0 comments on commit f6b51c2

Please sign in to comment.