Update sos!engine to v1-alpha8

This commit is contained in:
JeremyStar™ 2024-11-09 22:45:58 +01:00
parent c78af0e80e
commit 5c4b4beedf
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
6 changed files with 59 additions and 113 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.ShutdownHandler;
import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.logging.LoggerInstance;
import de.staropensource.engine.base.type.InternalAccessArea;
import org.jetbrains.annotations.NotNull;
@ -34,14 +33,6 @@ import org.jetbrains.annotations.NotNull;
* @since v1-alpha0
*/
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.
*
@ -62,11 +53,7 @@ public final class EngineBootstrapper {
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
Logger.setLoggingAdapter(loggingAdapter); // Install logging adapter
try {
Engine.initialize(); // Initialize engine
} catch (Exception exception) {
throw exception;
}
configureEngineShutdown(shutdownHandler); // Configures how the engine shuts itself down
EngineInternals.getInstance().restrictAccess(InternalAccessArea.ALL_WRITE); // Restrict internal engine access to read-only
initializeSubystems(); // Initialize subsystems
@ -80,13 +67,12 @@ public final class EngineBootstrapper {
* @since v1-alpha0
*/
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.loggerImmediateShutdown", "false");
if (disableMultithreading)
System.getProperties().setProperty("sosengine.base.optimizeEvents", "false");
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) {
EngineInternals.getInstance().setShutdownHandler(exitcode -> {
logger.diag("Invoking shutdown handler");
Logger.diag("Invoking shutdown handler");
try {
shutdownHandler.shutdown(exitcode);
} 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
while (true)
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
*/

View file

@ -20,13 +20,12 @@
package de.staropensource.engine.minecraft;
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.utility.Miscellaneous;
import de.staropensource.engine.base.utility.PropertiesReader;
import de.staropensource.engine.base.utility.information.EngineInformation;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.InputStream;
@ -45,14 +44,6 @@ import java.util.Properties;
*/
@SuppressWarnings({ "JavadocDeclaration" })
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.
*
@ -297,14 +288,14 @@ public final class SubsystemInformation {
* @since v1-alpha0
*/
public static synchronized void update() {
logger.diag("Updating subsystem information");
Logger.diag("Updating subsystem information");
// Load properties from bundled gradle.properties
Properties gradleProperties = new Properties();
InputStream gradleStream = EngineInformation.class.getClassLoader().getResourceAsStream("sosenginemc-gradle.properties");
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;
}
@ -312,7 +303,7 @@ public final class SubsystemInformation {
gradleProperties.load(gradleStream);
gradleStream.close();
} 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;
}
@ -321,7 +312,7 @@ public final class SubsystemInformation {
Properties gitProperties = new Properties();
InputStream gitStream = EngineInformation.class.getClassLoader().getResourceAsStream("sosenginemc-git.properties");
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
gitProperties.setProperty("git.total.commit.count", "0");
@ -339,7 +330,7 @@ public final class SubsystemInformation {
gitProperties.load(gitStream);
gitStream.close();
} 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;
}
}

View file

@ -67,30 +67,34 @@ public final class Command {
message(player, Strings.errorTooFewArguments);
else if (arguments.length == 2) {
// Return configuration setting
String value = switch (arguments[1]) {
case "debug" -> String.valueOf(EngineConfiguration.getInstance().isDebug());
case "debugEvents" -> String.valueOf(EngineConfiguration.getInstance().isDebugEvents());
String value = null;
case "initialPerformSubsystemInitialization" -> String.valueOf(EngineConfiguration.getInstance().isInitialPerformSubsystemInitialization());
case "initialForceDisableClasspathScanning" -> String.valueOf(EngineConfiguration.getInstance().isInitialForceDisableClasspathScanning());
case "initialIncludeSubsystemClasses" -> ListFormatter.formatSet(EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses());
switch (arguments[1]) {
case "debug" -> value = String.valueOf(EngineConfiguration.getInstance().isDebug());
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 "optimizeEvents" -> String.valueOf(EngineConfiguration.getInstance().isOptimizeEvents());
case "errorShortcodeParser" -> value = String.valueOf(EngineConfiguration.getInstance().isErrorShortcodeParser());
case "loggerLevel" -> "LogLevel." + EngineConfiguration.getInstance().getLoggerLevel().name();
case "loggerTemplate" -> "\"" + EngineConfiguration.getInstance().getLoggerTemplate() + "\"";
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 "optimizeLogging" -> value = String.valueOf(EngineConfiguration.getInstance().isOptimizeLogging());
case "optimizeEvents" -> value = String.valueOf(EngineConfiguration.getInstance().isOptimizeEvents());
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)
message(player, Strings.errorInvalidSetting.replace("%key%", arguments[1]));
@ -109,10 +113,8 @@ public final class Command {
switch (arguments[1]) {
case "debug" -> System.getProperties().setProperty("sosengine.base.debug", 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 "initialForceDisableClasspathScanning" -> System.getProperties().setProperty("sosengine.base.initialForceDisableClasspathScanning", 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));
@ -120,12 +122,10 @@ public final class Command {
case "optimizeLogging" -> System.getProperties().setProperty("sosengine.base.optimizeLogging", 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 "loggerTemplate" -> System.getProperties().setProperty("sosengine.base.loggerTemplate", String.valueOf(newValue));
case "loggerPollingSpeed" -> System.getProperties().setProperty("sosengine.base.loggerPollingSpeed", String.valueOf(newValue));
case "loggerForceStandardOutput" -> System.getProperties().setProperty("sosengine.base.loggerForceStandardOutput", 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 "logLevel" -> System.getProperties().setProperty("sosengine.base.logLevel", String.valueOf(newValue));
case "logFeatures" -> System.getProperties().setProperty("sosengine.base.logFeatures", String.valueOf(newValue));
case "logPollingSpeed" -> System.getProperties().setProperty("sosengine.base.logPollingSpeed", String.valueOf(newValue));
case "logForceStandardOutput" -> System.getProperties().setProperty("sosengine.base.logForceStandardOutput", String.valueOf(newValue));
case "hideFullTypePath" -> System.getProperties().setProperty("sosengine.base.hideFullTypePath", String.valueOf(newValue));

View file

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

View file

@ -21,10 +21,9 @@ package de.staropensource.engine.minecraft.bukkit;
import de.staropensource.engine.base.EngineConfiguration;
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 org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* A {@link LoggingAdapter} for the Bukkit API.
@ -39,34 +38,14 @@ public final class BukkitLoggingAdapter implements LoggingAdapter {
/** {@inheritDoc} */
@Override
public @Nullable String prePlaceholder(@NotNull LogLevel level, @NotNull Class<?> issuerClass, @NotNull String issuerOrigin, @Nullable String issuerMetadata, @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) {
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {
// Remove any tags
format = new EmptyShortcodeConverter(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);
}
if (EngineConfiguration.getInstance().getLogFeatures().contains("formatting"))
format = new EmptyShortcodeParser(format, true).getClean();
switch (level) {
case DIAGNOSTIC, VERBOSE, SILENT_WARNING, INFORMATIONAL, WARNING -> PlatformInitializer.getInstance().getLogger().info(format);
case ERROR, CRASH -> PlatformInitializer.getInstance().getLogger().severe(format);
case DIAGNOSTIC, VERBOSE, SILENT_WARNING, INFORMATIONAL, WARNING -> PlatformInitializer.getInstance().getLogger().info(format.replace("\n", "\n "));
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.logging.Logger;
import de.staropensource.engine.base.logging.LoggerInstance;
import de.staropensource.engine.minecraft.EngineBootstrapper;
import de.staropensource.engine.minecraft.bukkit.command.BukkitCommand;
import lombok.Getter;
@ -31,7 +30,6 @@ import org.bukkit.World;
import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
@ -55,14 +53,6 @@ public final class PlatformInitializer extends JavaPlugin {
@Getter
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.
*
@ -90,7 +80,7 @@ public final class PlatformInitializer extends JavaPlugin {
true,
exitcode -> {
if (Bukkit.getWorlds().isEmpty()) {
logger.info("No worlds are loaded, halting JVM");
Logger.info("No worlds are loaded, halting JVM");
Runtime.getRuntime().halt(exitcode);
} else if (!Bukkit.isStopping())
Bukkit.shutdown();
@ -122,7 +112,7 @@ public final class PlatformInitializer extends JavaPlugin {
PluginCommand command = Objects.requireNonNull(Bukkit.getPluginCommand("enginemc"));
command.setExecutor(new BukkitCommand());
} 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() {
if (!Bukkit.isStopping()) {
// Server is reloading, print warning and shutdown server
logger.error("""
Logger.error("""
__ ___ _ _ _____ _ ____ _____ __ _____ _ _ ____ ___ ___ _ _ ____ ___ ___
\\ \\ / / | | | / \\|_ _| / \\ | _ \\| ____| \\ \\ / / _ \\| | | | | _ \\ / _ \\_ _| \\ | |/ ___|__ \\__ \\
\\ \\ /\\ / /| |_| | / _ \\ | | / _ \\ | |_) | _| \\ V / | | | | | | | | | | | | | || \\| | | _ / / / /
@ -152,7 +142,7 @@ For safety, EngineMC will now save player and world data and forcefully shutdown
// Save and kick players
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();
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."));
@ -162,13 +152,13 @@ For safety, EngineMC will now save player and world data and forcefully shutdown
// Save worlds
for (World world : Bukkit.getWorlds()) {
logger.info("Saving data for world \"" + world.getName() + "\"");
Logger.info("Saving data for world \"" + world.getName() + "\"");
world.save();
}
// Halt JVM
logger.info("Halting JVM");
Logger.flushLogMessages(); // flush remaining log messages
Logger.info("Halting JVM");
Logger.flush(); // flush remaining log messages
Runtime.getRuntime().halt(0);
}