From d79f9725bd1637d6f6ebf50bbc2976bbabf0124f Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 22 Jul 2021 23:31:48 +0200 Subject: [PATCH 1/3] Add logging options to PlaceholderExpansion --- .../expansion/PlaceholderExpansion.java | 44 ++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java b/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java index 1e71a45..8d5ec15 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java +++ b/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java @@ -22,6 +22,7 @@ package me.clip.placeholderapi.expansion; import java.util.Collections; import java.util.List; +import java.util.logging.Level; import me.clip.placeholderapi.PlaceholderAPIPlugin; import me.clip.placeholderapi.PlaceholderHook; import org.bukkit.Bukkit; @@ -275,7 +276,6 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { * @param def The default boolean to return when the ConfigurationSection is null * @return boolean from the provided path or the default one provided */ - @NotNull public final boolean getBoolean(@NotNull final String path, final boolean def) { final ConfigurationSection section = getConfigSection(); return section == null ? def : section.getBoolean(path, def); @@ -293,6 +293,48 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { final ConfigurationSection section = getConfigSection(); return section != null && section.contains(path); } + + /** + * Logs the provided message with the provided Level in the console. + *
The message will be prefixed with {@link #getName() [<expansion name>]} + * + * @param level The Level at which the message should be logged with + * @param msg The message to log + */ + public void log(Level level, String msg) { + getPlaceholderAPI().getLogger().log(level, "[" + getName() + "] " + msg); + } + + /** + * Logs the provided message with Level "info". + *
The message will be prefixed with {@link #getName() [<expansion name>]} + * + * @param msg The message to log + */ + public void info(String msg) { + log(Level.INFO, msg); + } + + /** + * Logs the provided message with Level "warning". + *
The message will be prefixed with {@link #getName() [<expansion name>]} + * + * @param msg The message to log + */ + public void warning(String msg) { + log(Level.WARNING, msg); + } + + /** + * Logs the provided message with Level "severe" (error). + *
The message will be prefixed with {@link #getName() [<expansion name>]} + * + * @param msg The message to log + */ + public void severe(String msg) { + log(Level.SEVERE, msg); + } + /** * Whether the provided Object is an instance of this PlaceholderExpansion. From 721904335d86bc0a0ad45041bb4964177a7e7f86 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Thu, 22 Jul 2021 23:56:29 +0200 Subject: [PATCH 2/3] Add overload for Throwable --- .../expansion/PlaceholderExpansion.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java b/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java index 8d5ec15..907dc61 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java +++ b/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java @@ -305,6 +305,18 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { getPlaceholderAPI().getLogger().log(level, "[" + getName() + "] " + msg); } + /** + * Logs the provided message and Throwable with the provided Level in the console. + *
The message will be prefixed with {@link #getName() [<expansion name>]} + * + * @param level The Level at which the message should be logged with + * @param msg The message to log + * @param throwable The Throwable to log + */ + public void log(Level level, String msg, Throwable throwable) { + getPlaceholderAPI().getLogger().log(level, msg, throwable); + } + /** * Logs the provided message with Level "info". *
The message will be prefixed with {@link #getName() [<expansion name>]} @@ -334,6 +346,17 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { public void severe(String msg) { log(Level.SEVERE, msg); } + + /** + * Logs the provided message and Throwable with Level "severe" (error). + *
The message will be prefixed with {@link #getName() [<expansion name>]} + * + * @param msg The message to log + * @param throwable The Throwable to log + */ + public void severe(String msg, Throwable throwable) { + log(Level.SEVERE, msg, throwable); + } /** From fe0bb12d530858eba8290742e5f4013228e68579 Mon Sep 17 00:00:00 2001 From: Andre601 <11576465+Andre601@users.noreply.github.com> Date: Sat, 31 Jul 2021 00:11:24 +0200 Subject: [PATCH 3/3] Add missing [] prefix --- .../me/clip/placeholderapi/expansion/PlaceholderExpansion.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java b/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java index 907dc61..a7ff90b 100644 --- a/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java +++ b/src/main/java/me/clip/placeholderapi/expansion/PlaceholderExpansion.java @@ -314,7 +314,7 @@ public abstract class PlaceholderExpansion extends PlaceholderHook { * @param throwable The Throwable to log */ public void log(Level level, String msg, Throwable throwable) { - getPlaceholderAPI().getLogger().log(level, msg, throwable); + getPlaceholderAPI().getLogger().log(level, "[" + getName() + "] " + msg, throwable); } /**