9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-22 08:39:14 +00:00

Optimization Overhaul

This commit is contained in:
Brian Neumann-Fopiano
2022-11-12 13:31:39 -08:00
parent 85fbbeca9d
commit af1a03cb67
505 changed files with 21100 additions and 22808 deletions

View File

@@ -103,7 +103,7 @@ public class Iris extends VolmitPlugin implements Listener {
try {
fixShading();
InstanceState.updateInstanceId();
} catch(Throwable ignored) {
} catch (Throwable ignored) {
}
}
@@ -121,7 +121,7 @@ public class Iris extends VolmitPlugin implements Listener {
}
public static void callEvent(Event e) {
if(!e.isAsynchronous()) {
if (!e.isAsynchronous()) {
J.s(() -> Bukkit.getPluginManager().callEvent(e));
} else {
Bukkit.getPluginManager().callEvent(e);
@@ -132,11 +132,11 @@ public class Iris extends VolmitPlugin implements Listener {
JarScanner js = new JarScanner(instance.getJarFile(), s);
KList<Object> v = new KList<>();
J.attempt(js::scan);
for(Class<?> i : js.getClasses()) {
if(slicedClass == null || i.isAnnotationPresent(slicedClass)) {
for (Class<?> i : js.getClasses()) {
if (slicedClass == null || i.isAnnotationPresent(slicedClass)) {
try {
v.add(i.getDeclaredConstructor().newInstance());
} catch(Throwable ignored) {
} catch (Throwable ignored) {
}
}
@@ -149,11 +149,11 @@ public class Iris extends VolmitPlugin implements Listener {
JarScanner js = new JarScanner(instance.getJarFile(), s);
KList<Class<?>> v = new KList<>();
J.attempt(js::scan);
for(Class<?> i : js.getClasses()) {
if(slicedClass == null || i.isAnnotationPresent(slicedClass)) {
for (Class<?> i : js.getClasses()) {
if (slicedClass == null || i.isAnnotationPresent(slicedClass)) {
try {
v.add(i);
} catch(Throwable ignored) {
} catch (Throwable ignored) {
}
}
@@ -167,7 +167,7 @@ public class Iris extends VolmitPlugin implements Listener {
}
public static void sq(Runnable r) {
synchronized(syncJobs) {
synchronized (syncJobs) {
syncJobs.queue(r);
}
}
@@ -179,27 +179,28 @@ public class Iris extends VolmitPlugin implements Listener {
public static void msg(String string) {
try {
sender.sendMessage(string);
} catch(Throwable e) {
} catch (Throwable e) {
try {
System.out.println(instance.getTag() + string.replaceAll("(<([^>]+)>)", ""));
} catch(Throwable ignored1) {
} catch (Throwable ignored1) {
}
}
}
public static File getCached(String name, String url) {
String h = IO.hash(name + "@" + url);
File f = Iris.instance.getDataFile("cache", h.substring(0, 2), h.substring(3, 5), h);
if(!f.exists()) {
try(BufferedInputStream in = new BufferedInputStream(new URL(url).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(f)) {
if (!f.exists()) {
try (BufferedInputStream in = new BufferedInputStream(new URL(url).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(f)) {
byte[] dataBuffer = new byte[1024];
int bytesRead;
while((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
fileOutputStream.write(dataBuffer, 0, bytesRead);
Iris.verbose("Aquiring " + name);
}
} catch(IOException e) {
} catch (IOException e) {
Iris.reportError(e);
}
}
@@ -211,19 +212,19 @@ public class Iris extends VolmitPlugin implements Listener {
String h = IO.hash(name + "*" + url);
File f = Iris.instance.getDataFile("cache", h.substring(0, 2), h.substring(3, 5), h);
try(BufferedInputStream in = new BufferedInputStream(new URL(url).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(f)) {
try (BufferedInputStream in = new BufferedInputStream(new URL(url).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(f)) {
byte[] dataBuffer = new byte[1024];
int bytesRead;
while((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
fileOutputStream.write(dataBuffer, 0, bytesRead);
}
} catch(IOException e) {
} catch (IOException e) {
Iris.reportError(e);
}
try {
return IO.readAll(f);
} catch(IOException e) {
} catch (IOException e) {
Iris.reportError(e);
}
@@ -234,15 +235,15 @@ public class Iris extends VolmitPlugin implements Listener {
String h = IO.hash(name + "*" + url);
File f = Iris.instance.getDataFile("cache", h.substring(0, 2), h.substring(3, 5), h);
Iris.verbose("Download " + name + " -> " + url);
try(BufferedInputStream in = new BufferedInputStream(new URL(url).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(f)) {
try (BufferedInputStream in = new BufferedInputStream(new URL(url).openStream()); FileOutputStream fileOutputStream = new FileOutputStream(f)) {
byte[] dataBuffer = new byte[1024];
int bytesRead;
while((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
fileOutputStream.write(dataBuffer, 0, bytesRead);
}
fileOutputStream.flush();
} catch(IOException e) {
} catch (IOException e) {
e.printStackTrace();
Iris.reportError(e);
}
@@ -259,32 +260,32 @@ public class Iris extends VolmitPlugin implements Listener {
}
public static void debug(String string) {
if(!IrisSettings.get().getGeneral().isDebug()) {
if (!IrisSettings.get().getGeneral().isDebug()) {
return;
}
try {
throw new RuntimeException();
} catch(Throwable e) {
} catch (Throwable e) {
try {
String[] cc = e.getStackTrace()[1].getClassName().split("\\Q.\\E");
if(cc.length > 5) {
if (cc.length > 5) {
debug(cc[3] + "/" + cc[4] + "/" + cc[cc.length - 1], e.getStackTrace()[1].getLineNumber(), string);
} else {
debug(cc[3] + "/" + cc[4], e.getStackTrace()[1].getLineNumber(), string);
}
} catch(Throwable ex) {
} catch (Throwable ex) {
debug("Origin", -1, string);
}
}
}
public static void debug(String category, int line, String string) {
if(!IrisSettings.get().getGeneral().isDebug()) {
if (!IrisSettings.get().getGeneral().isDebug()) {
return;
}
if(IrisSettings.get().getGeneral().isUseConsoleCustomColors()) {
if (IrisSettings.get().getGeneral().isUseConsoleCustomColors()) {
msg("<gradient:#095fe0:#a848db>" + category + " <#bf3b76>" + line + "<reset> " + C.LIGHT_PURPLE + string.replaceAll("\\Q<\\E", "[").replaceAll("\\Q>\\E", "]"));
} else {
msg(C.BLUE + category + ":" + C.AQUA + line + C.RESET + C.LIGHT_PURPLE + " " + string.replaceAll("\\Q<\\E", "[").replaceAll("\\Q>\\E", "]"));
@@ -311,12 +312,12 @@ public class Iris extends VolmitPlugin implements Listener {
{
try {
object.run();
} catch(Throwable e) {
} catch (Throwable e) {
e.printStackTrace();
Iris.reportError(e);
}
}, RNG.r.i(100, 1200));
} catch(IllegalPluginAccessException ignored) {
} catch (IllegalPluginAccessException ignored) {
}
}
@@ -326,18 +327,18 @@ public class Iris extends VolmitPlugin implements Listener {
}
public static void clearQueues() {
synchronized(syncJobs) {
synchronized (syncJobs) {
syncJobs.clear();
}
}
private static int getJavaVersion() {
String version = System.getProperty("java.version");
if(version.startsWith("1.")) {
if (version.startsWith("1.")) {
version = version.substring(2, 3);
} else {
int dot = version.indexOf(".");
if(dot != -1) {
if (dot != -1) {
version = version.substring(0, dot);
}
}
@@ -345,10 +346,10 @@ public class Iris extends VolmitPlugin implements Listener {
}
public static void reportErrorChunk(int x, int z, Throwable e, String extra) {
if(IrisSettings.get().getGeneral().isDebug()) {
if (IrisSettings.get().getGeneral().isDebug()) {
File f = instance.getDataFile("debug", "chunk-errors", "chunk." + x + "." + z + ".txt");
if(!f.exists()) {
if (!f.exists()) {
J.attempt(() -> {
PrintWriter pw = new PrintWriter(f);
pw.println("Thread: " + Thread.currentThread().getName());
@@ -363,16 +364,16 @@ public class Iris extends VolmitPlugin implements Listener {
}
public static void reportError(Throwable e) {
if(IrisSettings.get().getGeneral().isDebug()) {
if (IrisSettings.get().getGeneral().isDebug()) {
String n = e.getClass().getCanonicalName() + "-" + e.getStackTrace()[0].getClassName() + "-" + e.getStackTrace()[0].getLineNumber();
if(e.getCause() != null) {
if (e.getCause() != null) {
n += "-" + e.getCause().getStackTrace()[0].getClassName() + "-" + e.getCause().getStackTrace()[0].getLineNumber();
}
File f = instance.getDataFile("debug", "caught-exceptions", n + ".txt");
if(!f.exists()) {
if (!f.exists()) {
J.attempt(() -> {
PrintWriter pw = new PrintWriter(f);
pw.println("Thread: " + Thread.currentThread().getName());
@@ -386,6 +387,44 @@ public class Iris extends VolmitPlugin implements Listener {
}
}
public static void dump() {
try {
File fi = Iris.instance.getDataFile("dump", "td-" + new java.sql.Date(M.ms()) + ".txt");
FileOutputStream fos = new FileOutputStream(fi);
Map<Thread, StackTraceElement[]> f = Thread.getAllStackTraces();
PrintWriter pw = new PrintWriter(fos);
for (Thread i : f.keySet()) {
pw.println("========================================");
pw.println("Thread: '" + i.getName() + "' ID: " + i.getId() + " STATUS: " + i.getState().name());
for (StackTraceElement j : f.get(i)) {
pw.println(" @ " + j.toString());
}
pw.println("========================================");
pw.println();
pw.println();
}
pw.close();
System.out.println("DUMPED! See " + fi.getAbsolutePath());
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void panic() {
EnginePanic.panic();
}
public static void addPanic(String s, String v) {
EnginePanic.add(s, v);
}
private static void fixShading() {
ShadeFix.fix(ComponentSerializer.class);
}
private void enable() {
instance = this;
services = new KMap<>();
@@ -423,23 +462,21 @@ public class Iris extends VolmitPlugin implements Listener {
FileConfiguration fc = new YamlConfiguration();
try {
fc.load(new File("bukkit.yml"));
searching: for(String i : fc.getKeys(true))
{
if(i.startsWith("worlds.") && i.endsWith(".generator")) {
searching:
for (String i : fc.getKeys(true)) {
if (i.startsWith("worlds.") && i.endsWith(".generator")) {
String worldName = i.split("\\Q.\\E")[1];
String generator = IrisSettings.get().getGenerator().getDefaultWorldType();
if(fc.getString(i).startsWith("Iris:")) {
if (fc.getString(i).startsWith("Iris:")) {
generator = fc.getString(i).split("\\Q:\\E")[1];
} else if(fc.getString(i).equals("Iris")) {
} else if (fc.getString(i).equals("Iris")) {
generator = IrisSettings.get().getGenerator().getDefaultWorldType();
} else {
continue;
}
for(World j : Bukkit.getWorlds())
{
if(j.getName().equals(worldName))
{
for (World j : Bukkit.getWorlds()) {
if (j.getName().equals(worldName)) {
continue searching;
}
}
@@ -447,31 +484,31 @@ public class Iris extends VolmitPlugin implements Listener {
Iris.warn("Detected an Iris World in the bukkit yml '" + worldName + "' using Iris that was not loaded by bukkit. Good Guy Iris will load it up for you!");
Iris.info(C.LIGHT_PURPLE + "Preparing Spawn for " + worldName + "' using Iris:" + generator);
World world = new WorldCreator(worldName)
.generator(getDefaultWorldGenerator(worldName, generator))
.environment(IrisData.loadAnyDimension(generator).getEnvironment())
.createWorld();
.generator(getDefaultWorldGenerator(worldName, generator))
.environment(IrisData.loadAnyDimension(generator).getEnvironment())
.createWorld();
Iris.info(C.LIGHT_PURPLE + "Loaded " + worldName + "!");
}
}
} catch(Throwable e) {
} catch (Throwable e) {
e.printStackTrace();
}
}
private void autoStartStudio() {
if(IrisSettings.get().getStudio().isAutoStartDefaultStudio()) {
if (IrisSettings.get().getStudio().isAutoStartDefaultStudio()) {
Iris.info("Starting up auto Studio!");
try {
Player r = new KList<>(getServer().getOnlinePlayers()).getRandom();
Iris.service(StudioSVC.class).open(r != null ? new VolmitSender(r) : sender, 1337, IrisSettings.get().getGenerator().getDefaultWorldType(), (w) -> {
J.s(() -> {
for(Player i : getServer().getOnlinePlayers()) {
for (Player i : getServer().getOnlinePlayers()) {
i.setGameMode(GameMode.SPECTATOR);
i.teleport(new Location(w, 0, 200, 0));
}
});
});
} catch(IrisException e) {
} catch (IrisException e) {
e.printStackTrace();
}
}
@@ -480,7 +517,7 @@ public class Iris extends VolmitPlugin implements Listener {
private void setupAudience() {
try {
audiences = BukkitAudiences.create(this);
} catch(Throwable e) {
} catch (Throwable e) {
e.printStackTrace();
IrisSettings.get().getGeneral().setUseConsoleCustomColors(false);
IrisSettings.get().getGeneral().setUseCustomColorsIngame(false);
@@ -488,44 +525,10 @@ public class Iris extends VolmitPlugin implements Listener {
}
}
public static void dump() {
try {
File fi = Iris.instance.getDataFile("dump", "td-" + new java.sql.Date(M.ms()) + ".txt");
FileOutputStream fos = new FileOutputStream(fi);
Map<Thread, StackTraceElement[]> f = Thread.getAllStackTraces();
PrintWriter pw = new PrintWriter(fos);
for(Thread i : f.keySet()) {
pw.println("========================================");
pw.println("Thread: '" + i.getName() + "' ID: " + i.getId() + " STATUS: " + i.getState().name());
for(StackTraceElement j : f.get(i)) {
pw.println(" @ " + j.toString());
}
pw.println("========================================");
pw.println();
pw.println();
}
pw.close();
System.out.println("DUMPED! See " + fi.getAbsolutePath());
} catch(Throwable e) {
e.printStackTrace();
}
}
public void postShutdown(Runnable r) {
postShutdown.add(r);
}
public static void panic() {
EnginePanic.panic();
}
public static void addPanic(String s, String v) {
EnginePanic.add(s, v);
}
public void onEnable() {
enable();
super.onEnable();
@@ -542,12 +545,8 @@ public class Iris extends VolmitPlugin implements Listener {
super.onDisable();
}
private static void fixShading() {
ShadeFix.fix(ComponentSerializer.class);
}
private void setupPapi() {
if(Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
new IrisPapiExpansion().register();
}
}
@@ -568,7 +567,7 @@ public class Iris extends VolmitPlugin implements Listener {
}
private void checkConfigHotload() {
if(configWatcher.checkModified()) {
if (configWatcher.checkModified()) {
IrisSettings.invalidate();
IrisSettings.get();
configWatcher.checkModified();
@@ -577,17 +576,17 @@ public class Iris extends VolmitPlugin implements Listener {
}
private void tickQueue() {
synchronized(Iris.syncJobs) {
if(!Iris.syncJobs.hasNext()) {
synchronized (Iris.syncJobs) {
if (!Iris.syncJobs.hasNext()) {
return;
}
long ms = M.ms();
while(Iris.syncJobs.hasNext() && M.ms() - ms < 25) {
while (Iris.syncJobs.hasNext() && M.ms() - ms < 25) {
try {
Iris.syncJobs.next().run();
} catch(Throwable e) {
} catch (Throwable e) {
e.printStackTrace();
Iris.reportError(e);
}
@@ -596,7 +595,7 @@ public class Iris extends VolmitPlugin implements Listener {
}
private void bstats() {
if(IrisSettings.get().getGeneral().isPluginMetrics()) {
if (IrisSettings.get().getGeneral().isPluginMetrics()) {
J.s(() -> new Metrics(Iris.instance, 8757));
}
}
@@ -620,12 +619,12 @@ public class Iris extends VolmitPlugin implements Listener {
@Override
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
Iris.debug("Default World Generator Called for " + worldName + " using ID: " + id);
if(worldName.equals("test")) {
if (worldName.equals("test")) {
try {
throw new RuntimeException();
} catch(Throwable e) {
} catch (Throwable e) {
Iris.info(e.getStackTrace()[1].getClassName());
if(e.getStackTrace()[1].getClassName().contains("com.onarandombox.MultiverseCore")) {
if (e.getStackTrace()[1].getClassName().contains("com.onarandombox.MultiverseCore")) {
Iris.debug("MVC Test detected, Quick! Send them the dummy!");
return new DummyChunkGenerator();
}
@@ -633,20 +632,20 @@ public class Iris extends VolmitPlugin implements Listener {
}
IrisDimension dim;
if(id == null || id.isEmpty()) {
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) {
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) {
if (dim == null) {
throw new RuntimeException("Can't find dimension " + id + "!");
} else {
Iris.info("Resolved missing dimension, proceeding with generation.");
@@ -656,18 +655,18 @@ public class Iris extends VolmitPlugin implements Listener {
Iris.debug("Assuming IrisDimension: " + dim.getName());
IrisWorld w = IrisWorld.builder()
.name(worldName)
.seed(1337)
.environment(dim.getEnvironment())
.worldFolder(new File(worldName))
.minHeight(dim.getMinHeight())
.maxHeight(dim.getMaxHeight())
.build();
.name(worldName)
.seed(1337)
.environment(dim.getEnvironment())
.worldFolder(new File(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) {
if (!ff.exists() || ff.listFiles().length == 0) {
ff.mkdirs();
service(StudioSVC.class).installIntoWorld(sender, dim.getLoadKey(), ff.getParentFile());
}
@@ -676,7 +675,7 @@ public class Iris extends VolmitPlugin implements Listener {
}
public void splash() {
if(!IrisSettings.get().getGeneral().isSplashLogoStartup()) {
if (!IrisSettings.get().getGeneral().isSplashLogoStartup()) {
return;
}
@@ -705,7 +704,7 @@ public class Iris extends VolmitPlugin implements Listener {
Iris.info("Custom Biomes: " + INMS.get().countCustomBiomes());
printPacks();
for(int i = 0; i < info.length; i++) {
for (int i = 0; i < info.length; i++) {
splash[i] += info[i];
}
@@ -715,21 +714,22 @@ public class Iris extends VolmitPlugin implements Listener {
private void printPacks() {
File packFolder = Iris.service(StudioSVC.class).getWorkspaceFolder();
File[] packs = packFolder.listFiles(File::isDirectory);
if(packs == null || packs.length == 0)
if (packs == null || packs.length == 0)
return;
Iris.info("Custom Dimensions: " + packs.length);
for(File f : packs)
for (File f : packs)
printPack(f);
}
private void printPack(File pack) {
String dimName = pack.getName();
String version = "???";
try(FileReader r = new FileReader(new File(pack, "dimensions/" + dimName + ".json"))) {
try (FileReader r = new FileReader(new File(pack, "dimensions/" + dimName + ".json"))) {
JsonObject json = JsonParser.parseReader(r).getAsJsonObject();
if(json.has("version"))
if (json.has("version"))
version = json.get("version").getAsString();
} catch(IOException | JsonParseException ignored) { }
} catch (IOException | JsonParseException ignored) {
}
Iris.info(" " + dimName + " v" + version);
}
}