Compare commits

...

5 commits

Author SHA1 Message Date
65b8d79ada
Fix engine initialization crash
All checks were successful
push-build-apidoc / build (push) Successful in 1m4s
push-build-apidoc / generate-javadoc (push) Successful in 1m5s
2024-11-10 14:23:33 +01:00
156b027ff2
Add crash operation to command
All checks were successful
push-build-apidoc / build (push) Successful in 1m42s
push-build-apidoc / generate-javadoc (push) Successful in 1m52s
2024-11-09 22:46:20 +01:00
5c4b4beedf
Update sos!engine to v1-alpha8 2024-11-09 22:45:58 +01:00
c78af0e80e
Update sos!engine to v1-alpha7
All checks were successful
push-build-apidoc / build (push) Successful in 54s
push-build-apidoc / generate-javadoc (push) Successful in 52s
2024-10-16 13:39:28 +02:00
78b025fbed
Bump version
All checks were successful
push-build-apidoc / build (push) Successful in 41s
push-build-apidoc / generate-javadoc (push) Successful in 52s
2024-10-16 02:15:40 +02:00
6 changed files with 63 additions and 114 deletions

View file

@ -24,7 +24,6 @@ import de.staropensource.engine.base.EngineInternals;
import de.staropensource.engine.base.implementable.LoggingAdapter; import de.staropensource.engine.base.implementable.LoggingAdapter;
import de.staropensource.engine.base.implementable.ShutdownHandler; import de.staropensource.engine.base.implementable.ShutdownHandler;
import de.staropensource.engine.base.logging.Logger; import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.logging.LoggerInstance;
import de.staropensource.engine.base.type.InternalAccessArea; import de.staropensource.engine.base.type.InternalAccessArea;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -34,14 +33,6 @@ import org.jetbrains.annotations.NotNull;
* @since v1-alpha0 * @since v1-alpha0
*/ */
public final class EngineBootstrapper { public final class EngineBootstrapper {
/**
* Contains the {@link LoggerInstance} for this instance.
*
* @see LoggerInstance
* @since v1-alpha0
*/
private static final LoggerInstance logger = new LoggerInstance.Builder().setClazz(EngineBootstrapper.class).setOrigin("ENGINEMC").build();
/** /**
* Constructs this class. * Constructs this class.
* *
@ -62,11 +53,7 @@ public final class EngineBootstrapper {
public static void initialize(boolean disableMultithreading, boolean disableClasspathScanning, @NotNull ShutdownHandler shutdownHandler, @NotNull LoggingAdapter loggingAdapter) throws Exception { public static void initialize(boolean disableMultithreading, boolean disableClasspathScanning, @NotNull ShutdownHandler shutdownHandler, @NotNull LoggingAdapter loggingAdapter) throws Exception {
overwriteSystemProperties(disableMultithreading, disableClasspathScanning); // Overwrites certain system properties to overwrite the engine configuration overwriteSystemProperties(disableMultithreading, disableClasspathScanning); // Overwrites certain system properties to overwrite the engine configuration
Logger.setLoggingAdapter(loggingAdapter); // Install logging adapter Logger.setLoggingAdapter(loggingAdapter); // Install logging adapter
try { Engine.initialize(); // Initialize engine
Engine.initialize(); // Initialize engine
} catch (Exception exception) {
throw exception;
}
configureEngineShutdown(shutdownHandler); // Configures how the engine shuts itself down configureEngineShutdown(shutdownHandler); // Configures how the engine shuts itself down
EngineInternals.getInstance().restrictAccess(InternalAccessArea.ALL_WRITE); // Restrict internal engine access to read-only EngineInternals.getInstance().restrictAccess(InternalAccessArea.ALL_WRITE); // Restrict internal engine access to read-only
initializeSubystems(); // Initialize subsystems initializeSubystems(); // Initialize subsystems
@ -80,13 +67,12 @@ public final class EngineBootstrapper {
* @since v1-alpha0 * @since v1-alpha0
*/ */
private static void overwriteSystemProperties(boolean disableMultithreading, boolean disableClasspathScanning) { private static void overwriteSystemProperties(boolean disableMultithreading, boolean disableClasspathScanning) {
System.getProperties().setProperty("sosengine.base.loggerTemplate", "[%log_level% %log_path%%log_metadata%] %log_message_prefix%%log_message%"); System.getProperties().setProperty("sosengine.base.logFeatures", "methodName,lineNumber");
System.getProperties().setProperty("sosengine.base.optimizeLogging", "true"); System.getProperties().setProperty("sosengine.base.optimizeLogging", "true");
System.getProperties().setProperty("sosengine.base.loggerImmediateShutdown", "false");
if (disableMultithreading) if (disableMultithreading)
System.getProperties().setProperty("sosengine.base.optimizeEvents", "false"); System.getProperties().setProperty("sosengine.base.optimizeEvents", "false");
if (disableClasspathScanning) if (disableClasspathScanning)
System.getProperties().setProperty("sosengine.base.initialForceDisableClasspathScanning", "true"); System.getProperties().setProperty("sosengine.base.considerEnvironmentUnfriendlyToClasspathScanning", "true");
} }
/** /**
@ -97,11 +83,11 @@ public final class EngineBootstrapper {
*/ */
private static void configureEngineShutdown(@NotNull ShutdownHandler shutdownHandler) { private static void configureEngineShutdown(@NotNull ShutdownHandler shutdownHandler) {
EngineInternals.getInstance().setShutdownHandler(exitcode -> { EngineInternals.getInstance().setShutdownHandler(exitcode -> {
logger.diag("Invoking shutdown handler"); Logger.diag("Invoking shutdown handler");
try { try {
shutdownHandler.shutdown(exitcode); shutdownHandler.shutdown(exitcode);
} catch (Exception exception) { } catch (Exception exception) {
logger.crash("Unable to shutdown server! Shutdown handler threw an exception. Hanging thread", exception, true); Logger.crash("Unable to shutdown server (Shutdown handler threw an exception)! Hanging thread", exception, true);
//noinspection InfiniteLoopStatement // we want an infinite loop //noinspection InfiniteLoopStatement // we want an infinite loop
while (true) while (true)
Thread.onSpinWait(); Thread.onSpinWait();
@ -111,7 +97,7 @@ public final class EngineBootstrapper {
} }
/** /**
* Initializes all subsystems bundled with this subsystem. * Initializes all subsystems bundled with EngineMC.
* *
* @since v1-alpha0 * @since v1-alpha0
*/ */

View file

@ -20,13 +20,12 @@
package de.staropensource.engine.minecraft; package de.staropensource.engine.minecraft;
import de.staropensource.engine.base.Engine; import de.staropensource.engine.base.Engine;
import de.staropensource.engine.base.logging.LoggerInstance; import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.type.VersionType; import de.staropensource.engine.base.type.VersionType;
import de.staropensource.engine.base.utility.Miscellaneous; import de.staropensource.engine.base.utility.Miscellaneous;
import de.staropensource.engine.base.utility.PropertiesReader; import de.staropensource.engine.base.utility.PropertiesReader;
import de.staropensource.engine.base.utility.information.EngineInformation; import de.staropensource.engine.base.utility.information.EngineInformation;
import lombok.Getter; import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -45,14 +44,6 @@ import java.util.Properties;
*/ */
@SuppressWarnings({ "JavadocDeclaration" }) @SuppressWarnings({ "JavadocDeclaration" })
public final class SubsystemInformation { public final class SubsystemInformation {
/**
* Contains the {@link LoggerInstance} for this instance.
*
* @see LoggerInstance
* @since v1-alpha0
*/
private static final @NotNull LoggerInstance logger = new LoggerInstance.Builder().setClazz(SubsystemInformation.class).setOrigin("ENGINEMC").build();
/** /**
* Contains the subsystem's version codename. * Contains the subsystem's version codename.
* *
@ -297,14 +288,14 @@ public final class SubsystemInformation {
* @since v1-alpha0 * @since v1-alpha0
*/ */
public static synchronized void update() { public static synchronized void update() {
logger.diag("Updating subsystem information"); Logger.diag("Updating subsystem information");
// Load properties from bundled gradle.properties // Load properties from bundled gradle.properties
Properties gradleProperties = new Properties(); Properties gradleProperties = new Properties();
InputStream gradleStream = EngineInformation.class.getClassLoader().getResourceAsStream("sosenginemc-gradle.properties"); InputStream gradleStream = EngineInformation.class.getClassLoader().getResourceAsStream("sosenginemc-gradle.properties");
if (gradleStream == null) { if (gradleStream == null) {
logger.crash("Unable to load build information: The bundled gradle.properties file could not be found."); Logger.crash("Unable to load build information: The bundled gradle.properties file could not be found.");
return; return;
} }
@ -312,7 +303,7 @@ public final class SubsystemInformation {
gradleProperties.load(gradleStream); gradleProperties.load(gradleStream);
gradleStream.close(); gradleStream.close();
} catch (IOException exception) { } catch (IOException exception) {
logger.crash("Unable to load build information: InputStream 'gradleStream' failed", exception); Logger.crash("Unable to load build information: InputStream 'gradleStream' failed", exception);
return; return;
} }
@ -321,7 +312,7 @@ public final class SubsystemInformation {
Properties gitProperties = new Properties(); Properties gitProperties = new Properties();
InputStream gitStream = EngineInformation.class.getClassLoader().getResourceAsStream("sosenginemc-git.properties"); InputStream gitStream = EngineInformation.class.getClassLoader().getResourceAsStream("sosenginemc-git.properties");
if (gitStream == null) { if (gitStream == null) {
logger.error("Unable to load build information: The bundled git.properties file could not be found. Did you download a tarball?"); Logger.error("Unable to load build information: The bundled git.properties file could not be found. Did you download a tarball?");
// Fake information // Fake information
gitProperties.setProperty("git.total.commit.count", "0"); gitProperties.setProperty("git.total.commit.count", "0");
@ -339,7 +330,7 @@ public final class SubsystemInformation {
gitProperties.load(gitStream); gitProperties.load(gitStream);
gitStream.close(); gitStream.close();
} catch (IOException exception) { } catch (IOException exception) {
logger.crash("Unable to load build information: InputStream 'gitStream' failed", exception); Logger.crash("Unable to load build information: InputStream 'gitStream' failed", exception);
return; return;
} }
} }

View file

@ -20,6 +20,7 @@
package de.staropensource.engine.minecraft.command; package de.staropensource.engine.minecraft.command;
import de.staropensource.engine.base.EngineConfiguration; import de.staropensource.engine.base.EngineConfiguration;
import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.utility.ListFormatter; import de.staropensource.engine.base.utility.ListFormatter;
import de.staropensource.engine.base.utility.Miscellaneous; import de.staropensource.engine.base.utility.Miscellaneous;
import de.staropensource.engine.base.utility.PlaceholderEngine; import de.staropensource.engine.base.utility.PlaceholderEngine;
@ -67,30 +68,34 @@ public final class Command {
message(player, Strings.errorTooFewArguments); message(player, Strings.errorTooFewArguments);
else if (arguments.length == 2) { else if (arguments.length == 2) {
// Return configuration setting // Return configuration setting
String value = switch (arguments[1]) { String value = null;
case "debug" -> String.valueOf(EngineConfiguration.getInstance().isDebug());
case "debugEvents" -> String.valueOf(EngineConfiguration.getInstance().isDebugEvents());
case "initialPerformSubsystemInitialization" -> String.valueOf(EngineConfiguration.getInstance().isInitialPerformSubsystemInitialization()); switch (arguments[1]) {
case "initialForceDisableClasspathScanning" -> String.valueOf(EngineConfiguration.getInstance().isInitialForceDisableClasspathScanning()); case "debug" -> value = String.valueOf(EngineConfiguration.getInstance().isDebug());
case "initialIncludeSubsystemClasses" -> ListFormatter.formatSet(EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses()); case "debugEvents" -> value = String.valueOf(EngineConfiguration.getInstance().isDebugEvents());
case "errorShortcodeParser" -> String.valueOf(EngineConfiguration.getInstance().isErrorShortcodeParser()); case "initialPerformSubsystemInitialization" -> value = String.valueOf(EngineConfiguration.getInstance().isInitialPerformSubsystemInitialization());
case "initialIncludeSubsystemClasses" -> value = ListFormatter.formatSet(EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses());
case "optimizeLogging" -> String.valueOf(EngineConfiguration.getInstance().isOptimizeLogging()); case "errorShortcodeParser" -> value = String.valueOf(EngineConfiguration.getInstance().isErrorShortcodeParser());
case "optimizeEvents" -> String.valueOf(EngineConfiguration.getInstance().isOptimizeEvents());
case "loggerLevel" -> "LogLevel." + EngineConfiguration.getInstance().getLoggerLevel().name(); case "optimizeLogging" -> value = String.valueOf(EngineConfiguration.getInstance().isOptimizeLogging());
case "loggerTemplate" -> "\"" + EngineConfiguration.getInstance().getLoggerTemplate() + "\""; case "optimizeEvents" -> value = String.valueOf(EngineConfiguration.getInstance().isOptimizeEvents());
case "loggerPollingSpeed" -> String.valueOf(EngineConfiguration.getInstance().getLoggerPollingSpeed());
case "loggerForceStandardOutput" -> String.valueOf(EngineConfiguration.getInstance().isLoggerForceStandardOutput());
case "loggerEnableNewlineSupport" -> String.valueOf(EngineConfiguration.getInstance().isLoggerEnableNewlineSupport());
case "loggerImmediateShutdown" -> String.valueOf(EngineConfiguration.getInstance().isLoggerImmediateShutdown());
case "hideFullTypePath" -> String.valueOf(EngineConfiguration.getInstance().isHideFullTypePath()); case "logLevel" -> value = "LogLevel." + EngineConfiguration.getInstance().getLogLevel().name();
case "logFeatures" -> {
StringBuilder features = new StringBuilder();
default -> null; for (String feature : EngineConfiguration.getInstance().getLogFeatures())
}; features.append(feature);
value = features.toString();
}
case "logPollingSpeed" -> value = String.valueOf(EngineConfiguration.getInstance().getLogPollingSpeed());
case "logForceStandardOutput" -> value = String.valueOf(EngineConfiguration.getInstance().isLogForceStandardOutput());
case "hideFullTypePath" -> value = String.valueOf(EngineConfiguration.getInstance().isHideFullTypePath());
}
if (value == null) if (value == null)
message(player, Strings.errorInvalidSetting.replace("%key%", arguments[1])); message(player, Strings.errorInvalidSetting.replace("%key%", arguments[1]));
@ -109,10 +114,8 @@ public final class Command {
switch (arguments[1]) { switch (arguments[1]) {
case "debug" -> System.getProperties().setProperty("sosengine.base.debug", String.valueOf(newValue)); case "debug" -> System.getProperties().setProperty("sosengine.base.debug", String.valueOf(newValue));
case "debugEvents" -> System.getProperties().setProperty("sosengine.base.debugEvents", String.valueOf(newValue)); case "debugEvents" -> System.getProperties().setProperty("sosengine.base.debugEvents", String.valueOf(newValue));
case "debugShortcodeConverter" -> System.getProperties().setProperty("sosengine.base.debugShortcodeConverter", String.valueOf(newValue));
case "initialPerformSubsystemInitialization" -> System.getProperties().setProperty("sosengine.base.initialPerformSubsystemInitialization", String.valueOf(newValue)); case "initialPerformSubsystemInitialization" -> System.getProperties().setProperty("sosengine.base.initialPerformSubsystemInitialization", String.valueOf(newValue));
case "initialForceDisableClasspathScanning" -> System.getProperties().setProperty("sosengine.base.initialForceDisableClasspathScanning", String.valueOf(newValue));
case "initialIncludeSubsystemClasses" -> System.getProperties().setProperty("sosengine.base.initialIncludeSubsystemClasses", String.valueOf(newValue)); case "initialIncludeSubsystemClasses" -> System.getProperties().setProperty("sosengine.base.initialIncludeSubsystemClasses", String.valueOf(newValue));
case "errorShortcodeConverter" -> System.getProperties().setProperty("sosengine.base.errorShortcodeConverter", String.valueOf(newValue)); case "errorShortcodeConverter" -> System.getProperties().setProperty("sosengine.base.errorShortcodeConverter", String.valueOf(newValue));
@ -120,12 +123,10 @@ public final class Command {
case "optimizeLogging" -> System.getProperties().setProperty("sosengine.base.optimizeLogging", String.valueOf(newValue)); case "optimizeLogging" -> System.getProperties().setProperty("sosengine.base.optimizeLogging", String.valueOf(newValue));
case "optimizeEvents" -> System.getProperties().setProperty("sosengine.base.optimizeEvents", String.valueOf(newValue)); case "optimizeEvents" -> System.getProperties().setProperty("sosengine.base.optimizeEvents", String.valueOf(newValue));
case "loggerLevel" -> System.getProperties().setProperty("sosengine.base.loggerLevel", String.valueOf(newValue)); case "logLevel" -> System.getProperties().setProperty("sosengine.base.logLevel", String.valueOf(newValue));
case "loggerTemplate" -> System.getProperties().setProperty("sosengine.base.loggerTemplate", String.valueOf(newValue)); case "logFeatures" -> System.getProperties().setProperty("sosengine.base.logFeatures", String.valueOf(newValue));
case "loggerPollingSpeed" -> System.getProperties().setProperty("sosengine.base.loggerPollingSpeed", String.valueOf(newValue)); case "logPollingSpeed" -> System.getProperties().setProperty("sosengine.base.logPollingSpeed", String.valueOf(newValue));
case "loggerForceStandardOutput" -> System.getProperties().setProperty("sosengine.base.loggerForceStandardOutput", String.valueOf(newValue)); case "logForceStandardOutput" -> System.getProperties().setProperty("sosengine.base.logForceStandardOutput", String.valueOf(newValue));
case "loggerEnableNewlineSupport" -> System.getProperties().setProperty("sosengine.base.loggerEnableNewlineSupport", String.valueOf(newValue));
case "loggerImmediateShutdown" -> System.getProperties().setProperty("sosengine.base.loggerImmediateShutdown", String.valueOf(newValue));
case "hideFullTypePath" -> System.getProperties().setProperty("sosengine.base.hideFullTypePath", String.valueOf(newValue)); case "hideFullTypePath" -> System.getProperties().setProperty("sosengine.base.hideFullTypePath", String.valueOf(newValue));
@ -223,6 +224,7 @@ public final class Command {
message(player, message); message(player, message);
} }
case "crash" -> Logger.crash("Manually initiated crash (/enginemc crash)");
default -> message(player, Strings.errorInvalidArgument); default -> message(player, Strings.errorInvalidArgument);
} }
} }
@ -269,7 +271,8 @@ public final class Command {
<red><bold>config</bold> \\<key> [value]: Displays the value of a setting if <italic>value</italic> is unset, or sets it if it isn't <red><bold>config</bold> \\<key> [value]: Displays the value of a setting if <italic>value</italic> is unset, or sets it if it isn't
<red><bold>placeholder</bold> \\<message>: Runs the specified message through sos!engine's PlaceholderEngine and returns it's result <red><bold>placeholder</bold> \\<message>: Runs the specified message through sos!engine's PlaceholderEngine and returns it's result
<red><bold>gc</bold>: Forcefully invokes the garbage collector <red><bold>gc</bold>: Forcefully invokes the garbage collector
<red><bold>jvminfo</bold>: Displays information about the Java Virtual Machine"""; <red><bold>jvminfo</bold>: Displays information about the Java Virtual Machine
<red><bold>crash</bold>: Crashes the StarOpenSource Engine""";
// Configuration // Configuration
public static final String configGet = "<red>The configuration setting \"%key%\" is set to '%value%'"; public static final String configGet = "<red>The configuration setting \"%key%\" is set to '%value%'";

View file

@ -21,11 +21,11 @@
versioningCodename=Sugarcane versioningCodename=Sugarcane
versioningVersion=1 versioningVersion=1
versioningType=release versioningType=release
versioningTyperelease=0 versioningTyperelease=3
versioningFork= versioningFork=
# Java # Java
javaSource=22 javaSource=21
javaTarget=21 javaTarget=21
# Minecraft # Minecraft
@ -34,15 +34,15 @@ minecraftMinor=.1
paperSnapshot=R0.1 paperSnapshot=R0.1
# Plugins # Plugins
pluginShadow=8.1.7 pluginShadow=8.1.8
pluginLombok=8.6 pluginLombok=8.10.2
pluginGitProperties=2.4.2 pluginGitProperties=2.4.2
pluginRunTask=2.3.1 pluginRunTask=2.3.1
# Dependencies # Dependencies
dependencyLombok=1.18.32 dependencyLombok=1.18.34
dependencyJetbrainsAnnotations=24.1.0 dependencyJetbrainsAnnotations=26.0.1
dependencyStarOpenSourceEngine=1-alpha6 dependencyStarOpenSourceEngine=1-alpha8
dependencyAdventure=4.17.0 dependencyAdventure=4.17.0
# etc # etc

View file

@ -21,10 +21,9 @@ package de.staropensource.engine.minecraft.bukkit;
import de.staropensource.engine.base.EngineConfiguration; import de.staropensource.engine.base.EngineConfiguration;
import de.staropensource.engine.base.implementable.LoggingAdapter; import de.staropensource.engine.base.implementable.LoggingAdapter;
import de.staropensource.engine.base.implementation.shortcode.EmptyShortcodeConverter; import de.staropensource.engine.base.implementation.shortcode.EmptyShortcodeParser;
import de.staropensource.engine.base.type.logging.LogLevel; import de.staropensource.engine.base.type.logging.LogLevel;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/** /**
* A {@link LoggingAdapter} for the Bukkit API. * A {@link LoggingAdapter} for the Bukkit API.
@ -39,34 +38,14 @@ public final class BukkitLoggingAdapter implements LoggingAdapter {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public @Nullable String prePlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) { public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {
return null;
}
/** {@inheritDoc} */
@Override
public @NotNull String postPlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
return format;
}
/** {@inheritDoc} */
@Override
public void print(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @NotNull String message, @NotNull String format) {
// Remove any tags // Remove any tags
format = new EmptyShortcodeConverter(format, true).getClean(); if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().getLogFeatures().contains("formatting"))
format = new EmptyShortcodeParser(format, true).getClean();
// Fix newlines
if (EngineConfiguration.getInstance().isLoggerEnableNewlineSupport()) {
String spaces = " ";
if (level == LogLevel.ERROR || level == LogLevel.CRASH)
spaces += " ";
format = format.replace("\n", "\n" + spaces);
}
switch (level) { switch (level) {
case DIAGNOSTIC, VERBOSE, SILENT_WARNING, INFORMATIONAL, WARNING -> PlatformInitializer.getInstance().getLogger().info(format); case DIAGNOSTIC, VERBOSE, SILENT_WARNING, INFORMATIONAL, WARNING -> PlatformInitializer.getInstance().getLogger().info(format.replace("\n", "\n "));
case ERROR, CRASH -> PlatformInitializer.getInstance().getLogger().severe(format); case ERROR, CRASH -> PlatformInitializer.getInstance().getLogger().severe(format.replace("\n", "\n "));
} }
} }
} }

View file

@ -21,7 +21,6 @@ package de.staropensource.engine.minecraft.bukkit;
import de.staropensource.engine.base.Engine; import de.staropensource.engine.base.Engine;
import de.staropensource.engine.base.logging.Logger; import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.logging.LoggerInstance;
import de.staropensource.engine.minecraft.EngineBootstrapper; import de.staropensource.engine.minecraft.EngineBootstrapper;
import de.staropensource.engine.minecraft.bukkit.command.BukkitCommand; import de.staropensource.engine.minecraft.bukkit.command.BukkitCommand;
import lombok.Getter; import lombok.Getter;
@ -31,7 +30,6 @@ import org.bukkit.World;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.Objects; import java.util.Objects;
@ -54,15 +52,7 @@ public final class PlatformInitializer extends JavaPlugin {
*/ */
@Getter @Getter
private static PlatformInitializer instance; private static PlatformInitializer instance;
/**
* Contains the {@link LoggerInstance} for this instance.
*
* @see LoggerInstance
* @since v1-alpha0
*/
private static final @NotNull LoggerInstance logger = new LoggerInstance.Builder().setClazz(PlatformInitializer.class).setOrigin("ENGINEMC").build();
/** /**
* Constructs this class. * Constructs this class.
* *
@ -90,7 +80,7 @@ public final class PlatformInitializer extends JavaPlugin {
true, true,
exitcode -> { exitcode -> {
if (Bukkit.getWorlds().isEmpty()) { if (Bukkit.getWorlds().isEmpty()) {
logger.info("No worlds are loaded, halting JVM"); Logger.info("No worlds are loaded, halting JVM");
Runtime.getRuntime().halt(exitcode); Runtime.getRuntime().halt(exitcode);
} else if (!Bukkit.isStopping()) } else if (!Bukkit.isStopping())
Bukkit.shutdown(); Bukkit.shutdown();
@ -122,7 +112,7 @@ public final class PlatformInitializer extends JavaPlugin {
PluginCommand command = Objects.requireNonNull(Bukkit.getPluginCommand("enginemc")); PluginCommand command = Objects.requireNonNull(Bukkit.getPluginCommand("enginemc"));
command.setExecutor(new BukkitCommand()); command.setExecutor(new BukkitCommand());
} catch (NullPointerException exception) { } catch (NullPointerException exception) {
logger.crash("Failed to register the /enginemc command", exception); Logger.crash("Failed to register the /enginemc command", exception);
} }
} }
@ -135,7 +125,7 @@ public final class PlatformInitializer extends JavaPlugin {
public void onDisable() { public void onDisable() {
if (!Bukkit.isStopping()) { if (!Bukkit.isStopping()) {
// Server is reloading, print warning and shutdown server // Server is reloading, print warning and shutdown server
logger.error(""" Logger.error("""
__ ___ _ _ _____ _ ____ _____ __ _____ _ _ ____ ___ ___ _ _ ____ ___ ___ __ ___ _ _ _____ _ ____ _____ __ _____ _ _ ____ ___ ___ _ _ ____ ___ ___
\\ \\ / / | | | / \\|_ _| / \\ | _ \\| ____| \\ \\ / / _ \\| | | | | _ \\ / _ \\_ _| \\ | |/ ___|__ \\__ \\ \\ \\ / / | | | / \\|_ _| / \\ | _ \\| ____| \\ \\ / / _ \\| | | | | _ \\ / _ \\_ _| \\ | |/ ___|__ \\__ \\
\\ \\ /\\ / /| |_| | / _ \\ | | / _ \\ | |_) | _| \\ V / | | | | | | | | | | | | | || \\| | | _ / / / / \\ \\ /\\ / /| |_| | / _ \\ | | / _ \\ | |_) | _| \\ V / | | | | | | | | | | | | | || \\| | | _ / / / /
@ -152,7 +142,7 @@ For safety, EngineMC will now save player and world data and forcefully shutdown
// Save and kick players // Save and kick players
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
logger.info("Saving data for player \"" + player.getName() + "\" [" + player.getUniqueId() + "]"); Logger.info("Saving data for player \"" + player.getName() + "\" [" + player.getUniqueId() + "]");
player.saveData(); player.saveData();
if (player.isOp()) if (player.isOp())
player.kick(MiniMessage.miniMessage().deserialize("The server has been forcefully shut down as the server has been reloaded,\nwhich is known to be unsafe. Check your server console for more information.")); player.kick(MiniMessage.miniMessage().deserialize("The server has been forcefully shut down as the server has been reloaded,\nwhich is known to be unsafe. Check your server console for more information."));
@ -162,13 +152,13 @@ For safety, EngineMC will now save player and world data and forcefully shutdown
// Save worlds // Save worlds
for (World world : Bukkit.getWorlds()) { for (World world : Bukkit.getWorlds()) {
logger.info("Saving data for world \"" + world.getName() + "\""); Logger.info("Saving data for world \"" + world.getName() + "\"");
world.save(); world.save();
} }
// Halt JVM // Halt JVM
logger.info("Halting JVM"); Logger.info("Halting JVM");
Logger.flushLogMessages(); // flush remaining log messages Logger.flush(); // flush remaining log messages
Runtime.getRuntime().halt(0); Runtime.getRuntime().halt(0);
} }