-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create plugin configuration file to retrieve items from pom.xml
- Loading branch information
IanTapply22
committed
Jun 7, 2024
1 parent
9a73abb
commit 6087654
Showing
5 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/net/jeqo/bloons/configuration/PluginConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |