mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-14 11:46:08 +00:00
switch to slimjar
This commit is contained in:
@@ -30,7 +30,6 @@ import com.volmit.iris.core.loader.IrisData;
|
||||
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.safeguard.ServerBootSFG;
|
||||
import com.volmit.iris.core.service.StudioSVC;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.EnginePanic;
|
||||
@@ -39,11 +38,9 @@ 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.core.safeguard.IrisSafeguard;
|
||||
import com.volmit.iris.core.safeguard.UtilsSFG;
|
||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.util.exceptions.IrisException;
|
||||
import com.volmit.iris.util.format.C;
|
||||
import com.volmit.iris.util.format.Form;
|
||||
@@ -52,30 +49,19 @@ import com.volmit.iris.util.io.FileWatcher;
|
||||
import com.volmit.iris.util.io.IO;
|
||||
import com.volmit.iris.util.io.InstanceState;
|
||||
import com.volmit.iris.util.io.JarScanner;
|
||||
import com.volmit.iris.util.json.JSONException;
|
||||
import com.volmit.iris.util.math.M;
|
||||
import com.volmit.iris.util.math.RNG;
|
||||
import com.volmit.iris.util.misc.Bindings;
|
||||
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.VolmitPlugin;
|
||||
import com.volmit.iris.util.plugin.VolmitSender;
|
||||
import com.volmit.iris.util.reflect.ShadeFix;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.scheduling.Queue;
|
||||
import com.volmit.iris.util.scheduling.ShurikenQueue;
|
||||
import com.volmit.iris.util.sentry.Attachments;
|
||||
import com.volmit.iris.util.sentry.IrisLogger;
|
||||
import com.volmit.iris.util.sentry.ServerID;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import io.sentry.Sentry;
|
||||
import io.github.slimjar.app.builder.ApplicationBuilder;
|
||||
import lombok.NonNull;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.DrilldownPie;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bstats.charts.SingleLineChart;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.command.Command;
|
||||
@@ -91,17 +77,13 @@ import org.bukkit.plugin.IllegalPluginAccessException;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import oshi.SystemInfo;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.URL;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.volmit.iris.core.safeguard.IrisSafeguard.*;
|
||||
import static com.volmit.iris.core.safeguard.ServerBootSFG.passedserversoftware;
|
||||
@@ -111,7 +93,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
private static final Queue<Runnable> syncJobs = new ShurikenQueue<>();
|
||||
|
||||
public static Iris instance;
|
||||
public static BukkitAudiences audiences;
|
||||
public static Bindings.Adventure audiences;
|
||||
public static MultiverseCoreLink linkMultiverseCore;
|
||||
public static MythicMobsLink linkMythicMobs;
|
||||
public static IrisCompat compat;
|
||||
@@ -120,7 +102,6 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
|
||||
static {
|
||||
try {
|
||||
fixShading();
|
||||
InstanceState.updateInstanceId();
|
||||
} catch (Throwable ignored) {
|
||||
|
||||
@@ -397,7 +378,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
}
|
||||
|
||||
public static void reportError(Throwable e) {
|
||||
Sentry.captureException(e);
|
||||
Bindings.capture(e);
|
||||
if (IrisSettings.get().getGeneral().isDebug()) {
|
||||
String n = e.getClass().getCanonicalName() + "-" + e.getStackTrace()[0].getClassName() + "-" + e.getStackTrace()[0].getLineNumber();
|
||||
|
||||
@@ -455,14 +436,21 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
EnginePanic.add(s, v);
|
||||
}
|
||||
|
||||
private static void fixShading() {
|
||||
ShadeFix.fix(ComponentSerializer.class);
|
||||
public Iris() {
|
||||
ApplicationBuilder.appending("Iris")
|
||||
.downloadDirectoryPath(getDataFolder("cache", "libraries").toPath())
|
||||
.logger((message, args) -> {
|
||||
if (!message.startsWith("Loaded library ")) return;
|
||||
getLogger().info(message.formatted(args));
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
private void enable() {
|
||||
instance = this;
|
||||
services = new KMap<>();
|
||||
setupAudience();
|
||||
setupSentry();
|
||||
Bindings.setupSentry();
|
||||
initialize("com.volmit.iris.core.service").forEach((i) -> services.put((Class<? extends IrisService>) i.getClass(), (IrisService) i));
|
||||
IO.delete(new File("iris"));
|
||||
compat = IrisCompat.configured(getDataFile("compat.json"));
|
||||
@@ -476,7 +464,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
services.values().forEach(IrisService::onEnable);
|
||||
services.values().forEach(this::registerListener);
|
||||
J.s(() -> {
|
||||
J.a(() -> PaperLib.suggestPaper(this));
|
||||
J.a(IrisSafeguard::suggestPaper);
|
||||
J.a(() -> IO.delete(getTemp()));
|
||||
J.a(LazyPregenerator::loadLazyGenerators, 100);
|
||||
J.a(this::bstats);
|
||||
@@ -556,7 +544,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
|
||||
private void setupAudience() {
|
||||
try {
|
||||
audiences = BukkitAudiences.create(this);
|
||||
audiences = new Bindings.Adventure(this);
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
IrisSettings.get().getGeneral().setUseConsoleCustomColors(false);
|
||||
@@ -689,50 +677,7 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
|
||||
private void bstats() {
|
||||
if (IrisSettings.get().getGeneral().isPluginMetrics()) {
|
||||
J.s(() -> {
|
||||
var metrics = new Metrics(Iris.instance, 24220);
|
||||
metrics.addCustomChart(new SingleLineChart("custom_dimensions", () -> Bukkit.getWorlds()
|
||||
.stream()
|
||||
.filter(IrisToolbelt::isIrisWorld)
|
||||
.mapToInt(w -> 1)
|
||||
.sum()));
|
||||
|
||||
metrics.addCustomChart(new DrilldownPie("used_packs", () -> Bukkit.getWorlds().stream()
|
||||
.map(IrisToolbelt::access)
|
||||
.filter(Objects::nonNull)
|
||||
.map(PlatformChunkGenerator::getEngine)
|
||||
.collect(Collectors.toMap(engine -> engine.getDimension().getLoadKey(), engine -> {
|
||||
var hash32 = engine.getHash32().getNow(null);
|
||||
if (hash32 == null) return Map.of();
|
||||
int version = engine.getDimension().getVersion();
|
||||
String checksum = Long.toHexString(hash32);
|
||||
|
||||
return Map.of("v" + version + " (" + checksum + ")", 1);
|
||||
}, (a, b) -> {
|
||||
Map<String, Integer> merged = new HashMap<>(a);
|
||||
b.forEach((k, v) -> merged.merge(k, v, Integer::sum));
|
||||
return merged;
|
||||
}))));
|
||||
|
||||
|
||||
var info = new SystemInfo().getHardware();
|
||||
var cpu = info.getProcessor().getProcessorIdentifier();
|
||||
var mem = info.getMemory();
|
||||
metrics.addCustomChart(new SimplePie("cpu_model", cpu::getName));
|
||||
|
||||
var nf = NumberFormat.getInstance(Locale.ENGLISH);
|
||||
nf.setMinimumFractionDigits(0);
|
||||
nf.setMaximumFractionDigits(2);
|
||||
nf.setRoundingMode(RoundingMode.HALF_UP);
|
||||
|
||||
metrics.addCustomChart(new DrilldownPie("memory", () -> {
|
||||
double total = mem.getTotal() * 1E-9;
|
||||
double alloc = Math.min(total, Runtime.getRuntime().maxMemory() * 1E-9);
|
||||
return Map.of(nf.format(alloc), Map.of(nf.format(total), 1));
|
||||
}));
|
||||
|
||||
postShutdown.add(metrics::shutdown);
|
||||
});
|
||||
Bindings.setupBstats(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -937,43 +882,4 @@ public class Iris extends VolmitPlugin implements Listener {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean suppress(Throwable e) {
|
||||
return (e instanceof IllegalStateException ex && "zip file closed".equals(ex.getMessage())) || e instanceof JSONException;
|
||||
}
|
||||
|
||||
private static void setupSentry() {
|
||||
var settings = IrisSettings.get().getSentry();
|
||||
if (settings.disableAutoReporting || Sentry.isEnabled() || Boolean.getBoolean("iris.suppressReporting")) return;
|
||||
Iris.info("Enabling Sentry for anonymous error reporting. You can disable this in the settings.");
|
||||
Iris.info("Your server ID is: " + ServerID.ID);
|
||||
Sentry.init(options -> {
|
||||
options.setDsn("https://b16ecc222e9c1e0c48faecacb906fd89@o4509451052646400.ingest.de.sentry.io/4509452722765904");
|
||||
if (settings.debug) {
|
||||
options.setLogger(new IrisLogger());
|
||||
options.setDebug(true);
|
||||
}
|
||||
|
||||
options.setAttachServerName(false);
|
||||
options.setEnableUncaughtExceptionHandler(false);
|
||||
options.setRelease(Iris.instance.getDescription().getVersion());
|
||||
options.setBeforeSend((event, hint) -> {
|
||||
if (suppress(event.getThrowable())) return null;
|
||||
event.setTag("iris.safeguard", IrisSafeguard.mode());
|
||||
event.setTag("iris.nms", INMS.get().getClass().getCanonicalName());
|
||||
var context = IrisContext.get();
|
||||
if (context != null) event.getContexts().set("engine", context.asContext());
|
||||
event.getContexts().set("safeguard", IrisSafeguard.asContext());
|
||||
return event;
|
||||
});
|
||||
});
|
||||
Sentry.configureScope(scope -> {
|
||||
if (settings.includeServerId) scope.setUser(ServerID.asUser());
|
||||
scope.addAttachment(Attachments.PLUGINS);
|
||||
scope.setTag("server", Bukkit.getVersion());
|
||||
scope.setTag("server.type", Bukkit.getName());
|
||||
scope.setTag("server.api", Bukkit.getBukkitVersion());
|
||||
});
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(Sentry::close));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.util.collection.KList;
|
||||
import com.volmit.iris.util.collection.KMap;
|
||||
import io.papermc.lib.PaperLib;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@@ -38,6 +39,10 @@ public class IrisSafeguard {
|
||||
}
|
||||
}
|
||||
|
||||
public static void suggestPaper() {
|
||||
PaperLib.suggestPaper(Iris.instance);
|
||||
}
|
||||
|
||||
public static KMap<String, Object> asContext() {
|
||||
KMap<String, Object> m = new KMap<>();
|
||||
m.put("diskSpace", !ServerBootSFG.hasEnoughDiskSpace);
|
||||
|
||||
146
core/src/main/java/com/volmit/iris/util/misc/Bindings.java
Normal file
146
core/src/main/java/com/volmit/iris/util/misc/Bindings.java
Normal file
@@ -0,0 +1,146 @@
|
||||
package com.volmit.iris.util.misc;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
import com.volmit.iris.core.IrisSettings;
|
||||
import com.volmit.iris.core.nms.INMS;
|
||||
import com.volmit.iris.core.safeguard.IrisSafeguard;
|
||||
import com.volmit.iris.core.tools.IrisToolbelt;
|
||||
import com.volmit.iris.engine.platform.PlatformChunkGenerator;
|
||||
import com.volmit.iris.util.context.IrisContext;
|
||||
import com.volmit.iris.util.json.JSONException;
|
||||
import com.volmit.iris.util.reflect.ShadeFix;
|
||||
import com.volmit.iris.util.scheduling.J;
|
||||
import com.volmit.iris.util.sentry.Attachments;
|
||||
import com.volmit.iris.util.sentry.IrisLogger;
|
||||
import com.volmit.iris.util.sentry.ServerID;
|
||||
import io.sentry.Sentry;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.serializer.ComponentSerializer;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.DrilldownPie;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bstats.charts.SingleLineChart;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import oshi.SystemInfo;
|
||||
|
||||
import java.math.RoundingMode;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Bindings {
|
||||
|
||||
public static void capture(Throwable throwable) {
|
||||
Sentry.captureException(throwable);
|
||||
}
|
||||
|
||||
public static void setupSentry() {
|
||||
var settings = IrisSettings.get().getSentry();
|
||||
if (settings.disableAutoReporting || Sentry.isEnabled() || Boolean.getBoolean("iris.suppressReporting")) return;
|
||||
Iris.info("Enabling Sentry for anonymous error reporting. You can disable this in the settings.");
|
||||
Iris.info("Your server ID is: " + ServerID.ID);
|
||||
Sentry.init(options -> {
|
||||
options.setDsn("https://b16ecc222e9c1e0c48faecacb906fd89@o4509451052646400.ingest.de.sentry.io/4509452722765904");
|
||||
if (settings.debug) {
|
||||
options.setLogger(new IrisLogger());
|
||||
options.setDebug(true);
|
||||
}
|
||||
|
||||
options.setAttachServerName(false);
|
||||
options.setEnableUncaughtExceptionHandler(false);
|
||||
options.setRelease(Iris.instance.getDescription().getVersion());
|
||||
options.setBeforeSend((event, hint) -> {
|
||||
if (suppress(event.getThrowable())) return null;
|
||||
event.setTag("iris.safeguard", IrisSafeguard.mode());
|
||||
event.setTag("iris.nms", INMS.get().getClass().getCanonicalName());
|
||||
var context = IrisContext.get();
|
||||
if (context != null) event.getContexts().set("engine", context.asContext());
|
||||
event.getContexts().set("safeguard", IrisSafeguard.asContext());
|
||||
return event;
|
||||
});
|
||||
});
|
||||
Sentry.configureScope(scope -> {
|
||||
if (settings.includeServerId) scope.setUser(ServerID.asUser());
|
||||
scope.addAttachment(Attachments.PLUGINS);
|
||||
scope.setTag("server", Bukkit.getVersion());
|
||||
scope.setTag("server.type", Bukkit.getName());
|
||||
scope.setTag("server.api", Bukkit.getBukkitVersion());
|
||||
});
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(Sentry::close));
|
||||
}
|
||||
|
||||
private static boolean suppress(Throwable e) {
|
||||
return (e instanceof IllegalStateException ex && "zip file closed".equals(ex.getMessage())) || e instanceof JSONException;
|
||||
}
|
||||
|
||||
|
||||
public static void setupBstats(Iris plugin) {
|
||||
J.s(() -> {
|
||||
var metrics = new Metrics(plugin, 24220);
|
||||
metrics.addCustomChart(new SingleLineChart("custom_dimensions", () -> Bukkit.getWorlds()
|
||||
.stream()
|
||||
.filter(IrisToolbelt::isIrisWorld)
|
||||
.mapToInt(w -> 1)
|
||||
.sum()));
|
||||
|
||||
metrics.addCustomChart(new DrilldownPie("used_packs", () -> Bukkit.getWorlds().stream()
|
||||
.map(IrisToolbelt::access)
|
||||
.filter(Objects::nonNull)
|
||||
.map(PlatformChunkGenerator::getEngine)
|
||||
.collect(Collectors.toMap(engine -> engine.getDimension().getLoadKey(), engine -> {
|
||||
var hash32 = engine.getHash32().getNow(null);
|
||||
if (hash32 == null) return Map.of();
|
||||
int version = engine.getDimension().getVersion();
|
||||
String checksum = Long.toHexString(hash32);
|
||||
|
||||
return Map.of("v" + version + " (" + checksum + ")", 1);
|
||||
}, (a, b) -> {
|
||||
Map<String, Integer> merged = new HashMap<>(a);
|
||||
b.forEach((k, v) -> merged.merge(k, v, Integer::sum));
|
||||
return merged;
|
||||
}))));
|
||||
|
||||
|
||||
var info = new SystemInfo().getHardware();
|
||||
var cpu = info.getProcessor().getProcessorIdentifier();
|
||||
var mem = info.getMemory();
|
||||
metrics.addCustomChart(new SimplePie("cpu_model", cpu::getName));
|
||||
|
||||
var nf = NumberFormat.getInstance(Locale.ENGLISH);
|
||||
nf.setMinimumFractionDigits(0);
|
||||
nf.setMaximumFractionDigits(2);
|
||||
nf.setRoundingMode(RoundingMode.HALF_UP);
|
||||
|
||||
metrics.addCustomChart(new DrilldownPie("memory", () -> {
|
||||
double total = mem.getTotal() * 1E-9;
|
||||
double alloc = Math.min(total, Runtime.getRuntime().maxMemory() * 1E-9);
|
||||
return Map.of(nf.format(alloc), Map.of(nf.format(total), 1));
|
||||
}));
|
||||
|
||||
plugin.postShutdown(metrics::shutdown);
|
||||
});
|
||||
}
|
||||
|
||||
public static class Adventure {
|
||||
private final BukkitAudiences audiences;
|
||||
|
||||
public Adventure(Iris plugin) {
|
||||
ShadeFix.fix(ComponentSerializer.class);
|
||||
this.audiences = BukkitAudiences.create(plugin);
|
||||
}
|
||||
|
||||
public Audience player(Player player) {
|
||||
return audiences.player(player);
|
||||
}
|
||||
|
||||
public Audience sender(CommandSender sender) {
|
||||
return audiences.sender(sender);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,12 +5,7 @@ load: STARTUP
|
||||
authors: [ cyberpwn, NextdoorPsycho, Vatuu ]
|
||||
website: volmit.com
|
||||
description: More than a Dimension!
|
||||
libraries: ${libraries}
|
||||
commands:
|
||||
iris:
|
||||
aliases: [ ir, irs ]
|
||||
api-version: '${apiVersion}'
|
||||
hotload-dependencies: false
|
||||
|
||||
paper-plugin-loader: ${loader}
|
||||
paper-skip-libraries: true
|
||||
api-version: '${apiVersion}'
|
||||
Reference in New Issue
Block a user