From 83d20e9ca1dc68798cbf21ff8cb93f58f6e40a5d Mon Sep 17 00:00:00 2001
From: CyberedCake <61170080+CyberedCake@users.noreply.github.com>
Date: Mon, 1 Jul 2024 02:14:55 -0400
Subject: [PATCH] Add option for hiding Reflections messages
---
.../cyberapi/common/CommonManager.java | 6 ++++-
.../common/builders/settings/Settings.java | 26 +++++++++++++++----
.../common/server/ConsoleModifiers.java | 1 +
3 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/common/src/main/java/net/cybercake/cyberapi/common/CommonManager.java b/common/src/main/java/net/cybercake/cyberapi/common/CommonManager.java
index ef05f48..70ce249 100644
--- a/common/src/main/java/net/cybercake/cyberapi/common/CommonManager.java
+++ b/common/src/main/java/net/cybercake/cyberapi/common/CommonManager.java
@@ -2,11 +2,13 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import io.netty.util.internal.UnstableApi;
import net.cybercake.cyberapi.common.basic.logs.Logs;
import net.cybercake.cyberapi.common.builders.settings.Settings;
import net.cybercake.cyberapi.common.server.ConsoleModifiers;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
+import org.jetbrains.annotations.ApiStatus;
import java.io.BufferedReader;
import java.io.File;
@@ -25,10 +27,12 @@ public interface CommonManager {
* I would not recommend calling this method yourself, just let CyberAPI handle it!
* @deprecated please do not use this method, just what-so-ever, let CyberAPI handle it
*/
- @Deprecated
+ @ApiStatus.Internal
@SuppressWarnings({"all"})
default void registerLog4jModifiers() {
try {
+ if (!getSettings().shouldHideReflections()) return;
+
((Logger) LogManager.getRootLogger()).addFilter(new ConsoleModifiers());
} catch (Exception exception) {
throw new IllegalArgumentException("Failed to register Log4J modified in CyberAPI! This is CyberAPI's fault.", exception);
diff --git a/common/src/main/java/net/cybercake/cyberapi/common/builders/settings/Settings.java b/common/src/main/java/net/cybercake/cyberapi/common/builders/settings/Settings.java
index b4976a9..e436e88 100644
--- a/common/src/main/java/net/cybercake/cyberapi/common/builders/settings/Settings.java
+++ b/common/src/main/java/net/cybercake/cyberapi/common/builders/settings/Settings.java
@@ -20,7 +20,7 @@ public class Settings {
* @since 15
*/
public static class Builder {
- private boolean verbose, silenced, checkForUpdates, showPrefixInLogs, muteStartMessage;
+ private boolean verbose, silenced, checkForUpdates, showPrefixInLogs, muteStartMessage, hideReflections;
private FeatureSupport adventureSupport, miniMessageSupport, luckPermsSupport, protocolLibSupport, placeholderAPISupport, protocolizeSupport;
private String name, prefix, mainPackage;
private Class>[] disableAutoRegisterFor;
@@ -37,6 +37,7 @@ public Builder() {
this.checkForUpdates = true;
this.showPrefixInLogs = false;
this.muteStartMessage = false;
+ this.hideReflections = true;
this.adventureSupport = FeatureSupport.AUTO;
this.miniMessageSupport = FeatureSupport.AUTO;
this.luckPermsSupport = FeatureSupport.AUTO;
@@ -163,7 +164,7 @@ public Builder() {
/**
* Sets the name of the plugin CyberAPI uses
*
- * Default Value: *your plugin's name in the plugin.yml*
+ * Default Value: {@code *your plugin's name in the plugin.yml*}
* @param name set this to the name of your plugin if it's not the same as the 'plugin.yml'
*/
public Builder name(String name) { this.name = name; return this; }
@@ -171,15 +172,23 @@ public Builder() {
/**
* Sets the prefix of the plugin in console logging
*
- * Default Value: *your plugin's prefix in the plugin.yml*
+ * Default Value: {@code *your plugin's prefix in the plugin.yml*}
* @param prefix set this to the prefix to be used when you use a "Log" method of CyberAPI
*/
public Builder prefix(String prefix) { this.prefix = prefix; return this; }
+ /**
+ * Sets whether CyberAPI should hide reflections messages or not. This is the "Reflections took *ms* to complete". The default is true because CyberAPI will show this message numerous times when starting if false.
+ *
+ * Default Value: {@code true}
+ * @param hideReflections set this to true to hide the reflections message
+ */
+ public Builder hideReflections(boolean hideReflections) { this.hideReflections = hideReflections; return this; }
+
/**
* Sets the main package of the plugin to a certain path. This is for registering commands and registering listeners, and if no path is given, it will attempt to get your path for you, and it can take a while everytime your server starts if this value is not set.
*
- * Default Value: **your project's group ID**
+ * Default Value: {@code **your project's group ID**}
* @param mainPackage set this to the path where your package is located (usually like 'net.cybercake.myplugin')
* @deprecated please use {@link Builder#build(String)} to build your {@link Settings}, which is direct drop-in replacement for this
*/
@@ -189,7 +198,7 @@ public Builder() {
/**
* Disable auto-registering for certain classes, used for commands and listeners that are registered with CyberAPI.
*
- * Default Value: null
+ * Default Value: {@code null}
* @param disableAutoRegisterFor set this to classes you would like to be ignored in the package scan to be auto-registered
*/
public Builder disableAutoRegistering(Class>... disableAutoRegisterFor) { this.disableAutoRegisterFor = disableAutoRegisterFor; return this; }
@@ -325,6 +334,13 @@ public Settings(Builder builder) {
*/
public @Nullable String getPrefix() { return builder.prefix; }
+ /**
+ * Gets whether CyberAPI should hide the Reflections messages
+ * @return should hide reflections messages
+ * @since 184
+ */
+ public boolean shouldHideReflections() { return builder.hideReflections; }
+
/**
* Gets the package name where all the developer's commands are stored
* @return the commands' path (deprecated note: this will return the same thing as the main package path, so this no longer accurately reflects the plugin's command's path)>
diff --git a/common/src/main/java/net/cybercake/cyberapi/common/server/ConsoleModifiers.java b/common/src/main/java/net/cybercake/cyberapi/common/server/ConsoleModifiers.java
index ce1ccff..eb638ba 100644
--- a/common/src/main/java/net/cybercake/cyberapi/common/server/ConsoleModifiers.java
+++ b/common/src/main/java/net/cybercake/cyberapi/common/server/ConsoleModifiers.java
@@ -1,5 +1,6 @@
package net.cybercake.cyberapi.common.server;
+import net.cybercake.cyberapi.common.CommonAdapter;
import net.cybercake.cyberapi.common.CommonManager;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Marker;