diff --git a/pom.xml b/pom.xml index b3573caf..c437f883 100644 --- a/pom.xml +++ b/pom.xml @@ -92,5 +92,10 @@ 24.1.0 compile + + org.apache.maven + maven-model + 3.9.7 + diff --git a/src/main/java/net/jeqo/bloons/configuration/PluginConfiguration.java b/src/main/java/net/jeqo/bloons/configuration/PluginConfiguration.java new file mode 100644 index 00000000..4fd7835a --- /dev/null +++ b/src/main/java/net/jeqo/bloons/configuration/PluginConfiguration.java @@ -0,0 +1,64 @@ +package net.jeqo.bloons.configuration; + +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.FileReader; +import java.io.IOException; + +/** + * A class that contains configurations and information regarding the plugin + */ +public class PluginConfiguration { + // The developer credits for the plugin, displayed on startup + public static final String DEVELOPER_CREDITS = "Jeqo and Gucci Fox"; + + /** + * Get the version of the plugin from the pom.xml file + * @return The version of the plugin + * @throws IOException If the file cannot be read + * @throws XmlPullParserException If the file cannot be parsed + */ + public static String getVersion() throws IOException, XmlPullParserException { + MavenXpp3Reader reader = new MavenXpp3Reader(); + Model model = reader.read(new FileReader("pom.xml")); + return model.getVersion(); + } + + /** + * Get the name of the plugin from the pom.xml file + * @return The name of the plugin + * @throws IOException If the file cannot be read + * @throws XmlPullParserException If the file cannot be parsed + */ + public static String getName() throws IOException, XmlPullParserException { + MavenXpp3Reader reader = new MavenXpp3Reader(); + Model model = reader.read(new FileReader("pom.xml")); + return model.getName(); + } + + /** + * Get the description of the plugin from the pom.xml file + * @return The description of the plugin + * @throws IOException If the file cannot be read + * @throws XmlPullParserException If the file cannot be parsed + */ + public static String getDescription() throws IOException, XmlPullParserException { + MavenXpp3Reader reader = new MavenXpp3Reader(); + Model model = reader.read(new FileReader("pom.xml")); + return model.getDescription(); + } + + /** + * Gets the website URL of the plugin from the pom.xml file + * @return The website URL of the plugin + * @throws IOException If the file cannot be read + * @throws XmlPullParserException If the file cannot be parsed + */ + public static String getURL() throws IOException, XmlPullParserException { + MavenXpp3Reader reader = new MavenXpp3Reader(); + Model model = reader.read(new FileReader("pom.xml")); + return model.getUrl(); + } +} diff --git a/src/main/java/net/jeqo/bloons/logger/Logger.java b/src/main/java/net/jeqo/bloons/logger/Logger.java new file mode 100644 index 00000000..340efe27 --- /dev/null +++ b/src/main/java/net/jeqo/bloons/logger/Logger.java @@ -0,0 +1,84 @@ +package net.jeqo.bloons.logger; + +import net.jeqo.bloons.configuration.PluginConfiguration; +import org.bukkit.Bukkit; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +import java.io.IOException; + +/** + * A utility class intended to log messages easily to the Bukkit console + */ +public class Logger { + /** + * Log a message to the console with STDOUT + * @param message The message to log + */ + public static void logWithSTDOUT(String message) { + System.out.println(message); + } + + /** + * Log a message to the console + * @param level The logging level + * @param message The message to log + */ + public static void log(LoggingLevel level, String message) { + Bukkit.getServer().getConsoleSender().sendMessage(level.getColor() + "[" + level.getName() + "] " + message); + } + + /** + * Logs a message to the console with the WARNING level + * @param message The message to log + */ + public static void logWarning(String message) { + log(LoggingLevel.WARNING, message); + } + + /** + * Logs a message to the console with the INFO level + * @param message The message to log + */ + public static void logInfo(String message) { + log(LoggingLevel.INFO, message); + } + + /** + * Logs a message to the console with the ERROR level + * @param message The message to log + */ + public static void logError(String message) { + log(LoggingLevel.ERROR, message); + } + + /** + * Logs a message to the console with the DEBUG level + * @param message The message to log + */ + public static void logDebug(String message) { + log(LoggingLevel.DEBUG, message); + } + + /** + * Logs an initialization message to the Bukkit console + */ + public static void logInitialization() throws XmlPullParserException, IOException { + log(LoggingLevel.INFO, "Initializing" + PluginConfiguration.getName() + " plugin..."); + } + + /** + * Logs a startup message to the Bukkit console containing plugin information + */ + public static void logStartup() throws XmlPullParserException, IOException { + log(LoggingLevel.INFO, PluginConfiguration.getName() + "plugin has initialized"); + log(LoggingLevel.INFO, "Version: " + PluginConfiguration.getVersion()); + log(LoggingLevel.INFO, "Developers: " + PluginConfiguration.DEVELOPER_CREDITS); + } + + /** + * Logs a shutdown message to the Bukkit console + */ + public static void logShutdown() throws XmlPullParserException, IOException { + log(LoggingLevel.INFO, PluginConfiguration.getName() + "plugin has been shutdown gracefully"); + } +} diff --git a/src/main/java/net/jeqo/bloons/logger/LoggingLevel.java b/src/main/java/net/jeqo/bloons/logger/LoggingLevel.java new file mode 100644 index 00000000..e7c93f52 --- /dev/null +++ b/src/main/java/net/jeqo/bloons/logger/LoggingLevel.java @@ -0,0 +1,29 @@ +package net.jeqo.bloons.logger; + +import lombok.Getter; +import net.kyori.adventure.text.format.NamedTextColor; + +/** + * The different levels of logging that can be used in the plugin + * Contains the name and color of the logging level to use in the Bukkit console + */ +@Getter +public enum LoggingLevel { + WARNING("WARNING", NamedTextColor.RED), + INFO("INFO", NamedTextColor.YELLOW), + ERROR("ERROR", NamedTextColor.DARK_RED), + DEBUG("DEBUG", NamedTextColor.WHITE); + + private final String name; + private final NamedTextColor color; + + /** + * Create a new logging level + * @param name The name of the logging level to use in the console + * @param color The Minecraft chat color of the logging level + */ + LoggingLevel(String name, NamedTextColor color) { + this.name = name; + this.color = color; + } +} \ No newline at end of file diff --git a/src/main/java/net/jeqo/bloons/logger/README.md b/src/main/java/net/jeqo/bloons/logger/README.md new file mode 100644 index 00000000..0f30e3db --- /dev/null +++ b/src/main/java/net/jeqo/bloons/logger/README.md @@ -0,0 +1,5 @@ +# Logger +This module is a custom logger designed to easily log messages to both STDOUT +and to the Bukkit server that is currently running this plugin. It efficiently and easily +works by allowing you to select a logging level and the text you want to push +to the source of the logging. \ No newline at end of file