Skip to content

Commit

Permalink
Optimization Overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
NextdoorPsycho committed Nov 12, 2022
1 parent 85fbbec commit af1a03c
Show file tree
Hide file tree
Showing 505 changed files with 21,083 additions and 22,791 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ plugins {
id "de.undercouch.download" version "5.0.1"
}

version '2.3.7-1.19.2' // Needs to be version specific
version '2.3.8-1.19.2' // Needs to be version specific
def nmsVersion = "1.19.2" //[NMS]
def apiVersion = '1.19'
def specialSourceVersion = '1.11.0' //[NMS]
Expand Down
242 changes: 121 additions & 121 deletions src/main/java/com/volmit/iris/Iris.java

Large diffs are not rendered by default.

104 changes: 52 additions & 52 deletions src/main/java/com/volmit/iris/core/IrisSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,64 @@ public class IrisSettings {
private IrisSettingsPerformance performance = new IrisSettingsPerformance();

public static int getThreadCount(int c) {
return switch(c) {
return switch (c) {
case -1, -2, -4 -> Runtime.getRuntime().availableProcessors() / -c;
case 0, 1, 2 -> 1;
default -> Math.max(c, 2);
};
}

public static IrisSettings get() {
if (settings != null) {
return settings;
}

settings = new IrisSettings();

File s = Iris.instance.getDataFile("settings.json");

if (!s.exists()) {
try {
IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4));
} catch (JSONException | IOException e) {
e.printStackTrace();
Iris.reportError(e);
}
} else {
try {
String ss = IO.readAll(s);
settings = new Gson().fromJson(ss, IrisSettings.class);
try {
IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4));
} catch (IOException e) {
e.printStackTrace();
}
} catch (Throwable ee) {
// Iris.reportError(ee); causes a self-reference & stackoverflow
Iris.error("Configuration Error in settings.json! " + ee.getClass().getSimpleName() + ": " + ee.getMessage());
}
}

return settings;
}

public static void invalidate() {
synchronized (settings) {
settings = null;
}
}

public void forceSave() {
File s = Iris.instance.getDataFile("settings.json");

try {
IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4));
} catch (JSONException | IOException e) {
e.printStackTrace();
Iris.reportError(e);
}
}

@Data
public static class IrisSettingsAutoconfiguration {
public boolean configureSpigotTimeoutTime = true;
Expand Down Expand Up @@ -132,55 +183,4 @@ public static class IrisSettingsStudio {
public boolean disableTimeAndWeather = true;
public boolean autoStartDefaultStudio = false;
}

public static IrisSettings get() {
if(settings != null) {
return settings;
}

settings = new IrisSettings();

File s = Iris.instance.getDataFile("settings.json");

if(!s.exists()) {
try {
IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4));
} catch(JSONException | IOException e) {
e.printStackTrace();
Iris.reportError(e);
}
} else {
try {
String ss = IO.readAll(s);
settings = new Gson().fromJson(ss, IrisSettings.class);
try {
IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4));
} catch(IOException e) {
e.printStackTrace();
}
} catch(Throwable ee) {
// Iris.reportError(ee); causes a self-reference & stackoverflow
Iris.error("Configuration Error in settings.json! " + ee.getClass().getSimpleName() + ": " + ee.getMessage());
}
}

return settings;
}

public static void invalidate() {
synchronized(settings) {
settings = null;
}
}

public void forceSave() {
File s = Iris.instance.getDataFile("settings.json");

try {
IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4));
} catch(JSONException | IOException e) {
e.printStackTrace();
Iris.reportError(e);
}
}
}
70 changes: 35 additions & 35 deletions src/main/java/com/volmit/iris/core/ServerConfigurator.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
public class ServerConfigurator {
public static void configure() {
IrisSettings.IrisSettingsAutoconfiguration s = IrisSettings.get().getAutoConfiguration();
if(s.isConfigureSpigotTimeoutTime()) {
if (s.isConfigureSpigotTimeoutTime()) {
J.attempt(ServerConfigurator::increaseKeepAliveSpigot);
}

if(s.isConfigurePaperWatchdogDelay()) {
if (s.isConfigurePaperWatchdogDelay()) {
J.attempt(ServerConfigurator::increasePaperWatchdog);
}

Expand All @@ -60,7 +60,7 @@ private static void increaseKeepAliveSpigot() throws IOException, InvalidConfigu
f.load(spigotConfig);
long tt = f.getLong("settings.timeout-time");

if(tt < TimeUnit.MINUTES.toSeconds(5)) {
if (tt < TimeUnit.MINUTES.toSeconds(5)) {
Iris.warn("Updating spigot.yml timeout-time: " + tt + " -> " + TimeUnit.MINUTES.toSeconds(5) + " (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));
Expand All @@ -74,7 +74,7 @@ private static void increasePaperWatchdog() throws IOException, InvalidConfigura
f.load(spigotConfig);
long tt = f.getLong("watchdog.early-warning-delay");

if(tt < TimeUnit.MINUTES.toMillis(3)) {
if (tt < TimeUnit.MINUTES.toMillis(3)) {
Iris.warn("Updating paper.yml watchdog early-warning-delay: " + tt + " -> " + TimeUnit.MINUTES.toMillis(3) + " (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));
Expand All @@ -83,7 +83,7 @@ private static void increasePaperWatchdog() throws IOException, InvalidConfigura
}

private static List<File> getDatapacksFolder() {
if(!IrisSettings.get().getGeneral().forceMainWorld.isEmpty()) {
if (!IrisSettings.get().getGeneral().forceMainWorld.isEmpty()) {
return new KList<File>().qadd(new File(IrisSettings.get().getGeneral().forceMainWorld + "/datapacks"));
}
KList<File> worlds = new KList<>();
Expand All @@ -96,24 +96,24 @@ public static void installDataPacks(boolean fullInstall) {
Iris.info("Checking Data Packs...");
File packs = new File("plugins/Iris/packs");

if(packs.exists()) {
for(File i : packs.listFiles()) {
if(i.isDirectory()) {
if (packs.exists()) {
for (File i : packs.listFiles()) {
if (i.isDirectory()) {
Iris.verbose("Checking Pack: " + i.getPath());
IrisData data = IrisData.get(i);
File dims = new File(i, "dimensions");

if(dims.exists()) {
for(File j : dims.listFiles()) {
if(j.getName().endsWith(".json")) {
if (dims.exists()) {
for (File j : dims.listFiles()) {
if (j.getName().endsWith(".json")) {
IrisDimension dim = data.getDimensionLoader().load(j.getName().split("\\Q.\\E")[0]);

if(dim == null) {
if (dim == null) {
continue;
}

Iris.verbose(" Checking Dimension " + dim.getLoadFile().getPath());
for(File dpack : getDatapacksFolder()) {
for (File dpack : getDatapacksFolder()) {
dim.installDataPack(() -> data, dpack);
}
}
Expand All @@ -125,32 +125,32 @@ public static void installDataPacks(boolean fullInstall) {

Iris.info("Data Packs Setup!");

if(fullInstall)
if (fullInstall)
verifyDataPacksPost(IrisSettings.get().getAutoConfiguration().isAutoRestartOnCustomBiomeInstall());
}

private static void verifyDataPacksPost(boolean allowRestarting) {
File packs = new File("plugins/Iris/packs");

boolean bad = false;
if(packs.exists()) {
for(File i : packs.listFiles()) {
if(i.isDirectory()) {
if (packs.exists()) {
for (File i : packs.listFiles()) {
if (i.isDirectory()) {
Iris.verbose("Checking Pack: " + i.getPath());
IrisData data = IrisData.get(i);
File dims = new File(i, "dimensions");

if(dims.exists()) {
for(File j : dims.listFiles()) {
if(j.getName().endsWith(".json")) {
if (dims.exists()) {
for (File j : dims.listFiles()) {
if (j.getName().endsWith(".json")) {
IrisDimension dim = data.getDimensionLoader().load(j.getName().split("\\Q.\\E")[0]);

if(dim == null) {
if (dim == null) {
Iris.error("Failed to load " + j.getPath() + " ");
continue;
}

if(!verifyDataPackInstalled(dim)) {
if (!verifyDataPackInstalled(dim)) {
bad = true;
}
}
Expand All @@ -160,19 +160,19 @@ private static void verifyDataPacksPost(boolean allowRestarting) {
}
}

if(bad) {
if(allowRestarting) {
if (bad) {
if (allowRestarting) {
restart();
} else if(INMS.get().supportsDataPacks()) {
} else if (INMS.get().supportsDataPacks()) {
Iris.error("============================================================================");
Iris.error(C.ITALIC + "You need to restart your server to properly generate custom biomes.");
Iris.error(C.ITALIC + "By continuing, Iris will use backup biomes in place of the custom biomes.");
Iris.error("----------------------------------------------------------------------------");
Iris.error(C.UNDERLINE + "IT IS HIGHLY RECOMMENDED YOU RESTART THE SERVER BEFORE GENERATING!");
Iris.error("============================================================================");

for(Player i : Bukkit.getOnlinePlayers()) {
if(i.isOp() || i.hasPermission("iris.all")) {
for (Player i : Bukkit.getOnlinePlayers()) {
if (i.isOp() || i.hasPermission("iris.all")) {
VolmitSender sender = new VolmitSender(i, Iris.instance.getTag("WARNING"));
sender.sendMessage("There are some Iris Packs that have custom biomes in them");
sender.sendMessage("You need to restart your server to use these packs.");
Expand Down Expand Up @@ -202,16 +202,16 @@ public static boolean verifyDataPackInstalled(IrisDimension dimension) {
KSet<String> keys = new KSet<>();
boolean warn = false;

for(IrisBiome i : dimension.getAllBiomes(() -> idm)) {
if(i.isCustom()) {
for(IrisBiomeCustom j : i.getCustomDerivitives()) {
for (IrisBiome i : dimension.getAllBiomes(() -> idm)) {
if (i.isCustom()) {
for (IrisBiomeCustom j : i.getCustomDerivitives()) {
keys.add(dimension.getLoadKey() + ":" + j.getId());
}
}
}

if(!INMS.get().supportsDataPacks()) {
if(!keys.isEmpty()) {
if (!INMS.get().supportsDataPacks()) {
if (!keys.isEmpty()) {
Iris.warn("===================================================================================");
Iris.warn("Pack " + dimension.getLoadKey() + " has " + keys.size() + " custom biome(s). ");
Iris.warn("Your server version does not yet support datapacks for iris.");
Expand All @@ -222,16 +222,16 @@ public static boolean verifyDataPackInstalled(IrisDimension dimension) {
return true;
}

for(String i : keys) {
for (String i : keys) {
Object o = INMS.get().getCustomBiomeBaseFor(i);

if(o == null) {
if (o == null) {
Iris.warn("The Biome " + i + " is not registered on the server.");
warn = true;
}
}

if(warn) {
if (warn) {
Iris.error("The Pack " + dimension.getLoadKey() + " is INCAPABLE of generating custom biomes");
Iris.error("If not done automatically, restart your server before generating with this pack!");
}
Expand Down
Loading

0 comments on commit af1a03c

Please sign in to comment.