Compare commits

..

No commits in common. "develop" and "v1-release1" have entirely different histories.

6 changed files with 114 additions and 63 deletions

View file

@ -24,6 +24,7 @@ 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;
@ -33,6 +34,14 @@ 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.
*
@ -53,7 +62,11 @@ 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
Engine.initialize(); // Initialize engine
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
@ -67,12 +80,13 @@ public final class EngineBootstrapper {
* @since v1-alpha0
*/
private static void overwriteSystemProperties(boolean disableMultithreading, boolean disableClasspathScanning) {
System.getProperties().setProperty("sosengine.base.logFeatures", "methodName,lineNumber");
System.getProperties().setProperty("sosengine.base.loggerTemplate", "[%log_level% %log_path%%log_metadata%] %log_message_prefix%%log_message%");
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.considerEnvironmentUnfriendlyToClasspathScanning", "true");
System.getProperties().setProperty("sosengine.base.initialForceDisableClasspathScanning", "true");
}
/**
@ -83,11 +97,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();
@ -97,7 +111,7 @@ public final class EngineBootstrapper {
}
/**
* Initializes all subsystems bundled with EngineMC.
* Initializes all subsystems bundled with this subsystem.
*
* @since v1-alpha0
*/

View file

@ -20,12 +20,13 @@
package de.staropensource.engine.minecraft;
import de.staropensource.engine.base.Engine;
import de.staropensource.engine.base.logging.Logger;
import de.staropensource.engine.base.logging.LoggerInstance;
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;
@ -44,6 +45,14 @@ 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.
*
@ -288,14 +297,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;
}
@ -303,7 +312,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;
}
@ -312,7 +321,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");
@ -330,7 +339,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

@ -20,7 +20,6 @@
package de.staropensource.engine.minecraft.command;
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.Miscellaneous;
import de.staropensource.engine.base.utility.PlaceholderEngine;
@ -68,34 +67,30 @@ public final class Command {
message(player, Strings.errorTooFewArguments);
else if (arguments.length == 2) {
// Return configuration setting
String value = null;
String value = switch (arguments[1]) {
case "debug" -> String.valueOf(EngineConfiguration.getInstance().isDebug());
case "debugEvents" -> String.valueOf(EngineConfiguration.getInstance().isDebugEvents());
switch (arguments[1]) {
case "debug" -> value = String.valueOf(EngineConfiguration.getInstance().isDebug());
case "debugEvents" -> value = String.valueOf(EngineConfiguration.getInstance().isDebugEvents());
case "initialPerformSubsystemInitialization" -> String.valueOf(EngineConfiguration.getInstance().isInitialPerformSubsystemInitialization());
case "initialForceDisableClasspathScanning" -> String.valueOf(EngineConfiguration.getInstance().isInitialForceDisableClasspathScanning());
case "initialIncludeSubsystemClasses" -> ListFormatter.formatSet(EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses());
case "initialPerformSubsystemInitialization" -> value = String.valueOf(EngineConfiguration.getInstance().isInitialPerformSubsystemInitialization());
case "initialIncludeSubsystemClasses" -> value = ListFormatter.formatSet(EngineConfiguration.getInstance().getInitialIncludeSubsystemClasses());
case "errorShortcodeParser" -> String.valueOf(EngineConfiguration.getInstance().isErrorShortcodeParser());
case "errorShortcodeParser" -> value = String.valueOf(EngineConfiguration.getInstance().isErrorShortcodeParser());
case "optimizeLogging" -> String.valueOf(EngineConfiguration.getInstance().isOptimizeLogging());
case "optimizeEvents" -> String.valueOf(EngineConfiguration.getInstance().isOptimizeEvents());
case "optimizeLogging" -> value = String.valueOf(EngineConfiguration.getInstance().isOptimizeLogging());
case "optimizeEvents" -> value = String.valueOf(EngineConfiguration.getInstance().isOptimizeEvents());
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 "logLevel" -> value = "LogLevel." + EngineConfiguration.getInstance().getLogLevel().name();
case "logFeatures" -> {
StringBuilder features = new StringBuilder();
case "hideFullTypePath" -> String.valueOf(EngineConfiguration.getInstance().isHideFullTypePath());
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());
}
default -> null;
};
if (value == null)
message(player, Strings.errorInvalidSetting.replace("%key%", arguments[1]));
@ -114,8 +109,10 @@ 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));
@ -123,10 +120,12 @@ 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 "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 "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 "hideFullTypePath" -> System.getProperties().setProperty("sosengine.base.hideFullTypePath", String.valueOf(newValue));
@ -224,7 +223,6 @@ public final class Command {
message(player, message);
}
case "crash" -> Logger.crash("Manually initiated crash (/enginemc crash)");
default -> message(player, Strings.errorInvalidArgument);
}
}
@ -271,8 +269,7 @@ 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>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>jvminfo</bold>: Displays information about the Java Virtual Machine
<red><bold>crash</bold>: Crashes the StarOpenSource Engine""";
<red><bold>jvminfo</bold>: Displays information about the Java Virtual Machine""";
// Configuration
public static final String configGet = "<red>The configuration setting \"%key%\" is set to '%value%'";

View file

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

View file

@ -21,9 +21,10 @@ 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.EmptyShortcodeParser;
import de.staropensource.engine.base.implementation.shortcode.EmptyShortcodeConverter;
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.
@ -38,14 +39,34 @@ public final class BukkitLoggingAdapter implements LoggingAdapter {
/** {@inheritDoc} */
@Override
public void print(@NotNull LogLevel level, @NotNull StackTraceElement issuer, @NotNull String message, @NotNull String format) {
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) {
// Remove any tags
if (EngineConfiguration.getInstance() != null && EngineConfiguration.getInstance().getLogFeatures().contains("formatting"))
format = new EmptyShortcodeParser(format, true).getClean();
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);
}
switch (level) {
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 "));
case DIAGNOSTIC, VERBOSE, SILENT_WARNING, INFORMATIONAL, WARNING -> PlatformInitializer.getInstance().getLogger().info(format);
case ERROR, CRASH -> PlatformInitializer.getInstance().getLogger().severe(format);
}
}
}

View file

@ -21,6 +21,7 @@ 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;
@ -30,6 +31,7 @@ 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;
@ -52,7 +54,15 @@ 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.
*
@ -80,7 +90,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();
@ -112,7 +122,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);
}
}
@ -125,7 +135,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 / | | | | | | | | | | | | | || \\| | | _ / / / /
@ -142,7 +152,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."));
@ -152,13 +162,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.flush(); // flush remaining log messages
logger.info("Halting JVM");
Logger.flushLogMessages(); // flush remaining log messages
Runtime.getRuntime().halt(0);
}