Skip to content

Commit

Permalink
Add option for hiding Reflections messages
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberedCake committed Jul 1, 2024
1 parent 245e02b commit 83d20e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,10 +27,12 @@ public interface CommonManager {
* <b>I would not recommend calling this method yourself, just let CyberAPI handle it!</b>
* @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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -163,23 +164,31 @@ public Builder() {
/**
* Sets the name of the plugin CyberAPI uses
* <br> <br>
* <em>Default Value:</em> *your plugin's name in the <b>plugin.yml</b>*
* <em>Default Value:</em> {@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; }

/**
* Sets the prefix of the plugin in console logging
* <br> <br>
* <em>Default Value:</em> *your plugin's prefix in the <b>plugin.yml</b>*
* <em>Default Value:</em> {@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.
* <br> <br>
* <em>Default Value:</em> {@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.
* <br> <br>
* <em>Default Value:</em> **your project's group ID**
* <em>Default Value:</em> {@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
*/
Expand All @@ -189,7 +198,7 @@ public Builder() {
/**
* Disable auto-registering for certain classes, used for commands and listeners that are registered with CyberAPI.
* <br> <br>
* <em>Default Value:</em> null
* <em>Default Value:</em> {@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; }
Expand Down Expand Up @@ -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 <em>(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)</em>>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 83d20e9

Please sign in to comment.