Allow chat error messages to be disabled

Fixes #1549
This commit is contained in:
Dan Mulloy 2022-03-26 10:32:03 -04:00
parent d361526371
commit b4eff32213
No known key found for this signature in database
GPG Key ID: BFACD592A5F0DFD6
3 changed files with 17 additions and 98 deletions

View File

@ -46,7 +46,7 @@ public class ProtocolConfig {
private static final String DEBUG_MODE_ENABLED = "debug";
private static final String DETAILED_ERROR = "detailed error";
private static final String INJECTION_METHOD = "injection method";
private static final String CHAT_WARNINGS = "chat warnings";
private static final String SCRIPT_ENGINE_NAME = "script engine";
private static final String SUPPRESSED_REPORTS = "suppressed reports";
@ -225,12 +225,11 @@ public class ProtocolConfig {
}
/**
* Set whether or not detailed error reporting is enabled.
*
* @param value - TRUE if it is enabled, FALSE otherwise.
* Print warnings to players with protocol.info
* @return true if enabled, false if not
*/
public void setDetailedErrorReporting(boolean value) {
global.set(DETAILED_ERROR, value);
public boolean isChatWarnings() {
return getGlobalValue(CHAT_WARNINGS, true);
}
/**
@ -242,16 +241,6 @@ public class ProtocolConfig {
return getUpdaterValue(UPDATER_NOTIFY, true);
}
/**
* Set whether or not ProtocolLib should determine if a new version has been released.
*
* @param value - TRUE to do this automatically, FALSE otherwise.
*/
public void setAutoNotify(boolean value) {
setConfig(updater, UPDATER_NOTIFY, value);
modCount++;
}
/**
* Retrieve whether or not ProtocolLib should automatically download the new version.
*
@ -261,16 +250,6 @@ public class ProtocolConfig {
return updater != null && getUpdaterValue(UPDATER_DOWNLAD, false);
}
/**
* Set whether or not ProtocolLib should automatically download the new version.
*
* @param value - TRUE if it should. FALSE otherwise.
*/
public void setAutoDownload(boolean value) {
setConfig(updater, UPDATER_DOWNLAD, value);
modCount++;
}
/**
* Determine whether or not debug mode is enabled.
* <p>
@ -301,16 +280,6 @@ public class ProtocolConfig {
return ImmutableList.copyOf(getGlobalValue(SUPPRESSED_REPORTS, new ArrayList<String>()));
}
/**
* Set the list of suppressed report types,
*
* @param reports - suppressed report types.
*/
public void setSuppressedReports(List<String> reports) {
global.set(SUPPRESSED_REPORTS, Lists.newArrayList(reports));
modCount++;
}
/**
* Retrieve the amount of time to wait until checking for a new update.
*
@ -321,22 +290,6 @@ public class ProtocolConfig {
return Math.max(getUpdaterValue(UPDATER_DELAY, 0), DEFAULT_UPDATER_DELAY);
}
/**
* Set the amount of time to wait until checking for a new update.
* <p>
* This time must be greater than 59 seconds.
*
* @param delaySeconds - the amount of time to wait.
*/
public void setAutoDelay(long delaySeconds) {
// Silently fix the delay
if (delaySeconds < DEFAULT_UPDATER_DELAY) {
delaySeconds = DEFAULT_UPDATER_DELAY;
}
setConfig(updater, UPDATER_DELAY, delaySeconds);
modCount++;
}
/**
* The version of Minecraft to ignore the built-in safety feature.
*
@ -346,18 +299,6 @@ public class ProtocolConfig {
return getGlobalValue(IGNORE_VERSION_CHECK, "");
}
/**
* Sets under which version of Minecraft the version safety feature will be ignored.
* <p>
* This is useful if a server operator has tested and verified that a version of ProtocolLib works, but doesn't want or can't upgrade to a newer version.
*
* @param ignoreVersion - the version of Minecraft where the satefy will be disabled.
*/
public void setIgnoreVersionCheck(String ignoreVersion) {
setConfig(global, IGNORE_VERSION_CHECK, ignoreVersion);
modCount++;
}
/**
* Retrieve whether or not metrics is enabled.
*
@ -367,18 +308,6 @@ public class ProtocolConfig {
return getGlobalValue(METRICS_ENABLED, true);
}
/**
* Set whether or not metrics is enabled.
* <p>
* This setting will take effect next time ProtocolLib is started.
*
* @param enabled - whether or not metrics is enabled.
*/
public void setMetricsEnabled(boolean enabled) {
setConfig(global, METRICS_ENABLED, enabled);
modCount++;
}
/**
* Retrieve whether or not the background compiler for structure modifiers is enabled or not.
*
@ -388,18 +317,6 @@ public class ProtocolConfig {
return getGlobalValue(BACKGROUND_COMPILER_ENABLED, true);
}
/**
* Set whether or not the background compiler for structure modifiers is enabled or not.
* <p>
* This setting will take effect next time ProtocolLib is started.
*
* @param enabled - TRUE if is enabled/running, FALSE otherwise.
*/
public void setBackgroundCompilerEnabled(boolean enabled) {
setConfig(global, BACKGROUND_COMPILER_ENABLED, enabled);
modCount++;
}
/**
* Retrieve the last time we updated, in seconds since 1970.01.01 00:00.
*

View File

@ -30,6 +30,8 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.comphenix.protocol.ProtocolConfig;
import com.comphenix.protocol.ProtocolLibrary;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.bukkit.Bukkit;
@ -89,7 +91,7 @@ public class DetailedErrorReporter implements ErrorReporter {
// Reports to ignore
private ExpireHashMap<Report, Boolean> rateLimited = new ExpireHashMap<Report, Boolean>();
private Object rateLock = new Object();
private final Object rateLock = new Object();
/**
* Create a default error reporting system.
@ -202,14 +204,14 @@ public class DetailedErrorReporter implements ErrorReporter {
// See if we should print the full error
if (errorCount < getMaxErrorCount()) {
logger.log(Level.SEVERE, "[" + pluginName + "] Unhandled exception occured in " +
logger.log(Level.SEVERE, "[" + pluginName + "] Unhandled exception occurred in " +
methodName + " for " + pluginName, error);
return true;
} else {
// Nope - only print the error count occationally
// Nope - only print the error count occasionally
if (isPowerOfTwo(errorCount)) {
logger.log(Level.SEVERE, "[" + pluginName + "] Unhandled exception number " + errorCount + " occured in " +
logger.log(Level.SEVERE, "[" + pluginName + "] Unhandled exception number " + errorCount + " occurred in " +
methodName + " for " + pluginName, error);
}
return false;
@ -390,9 +392,9 @@ public class DetailedErrorReporter implements ErrorReporter {
writer.println(addPrefix(Bukkit.getServer().getVersion(), SECOND_LEVEL_PREFIX));
// Inform of this occurrence
if (ERROR_PERMISSION != null) {
if (ERROR_PERMISSION != null && ProtocolLibrary.getConfig().isChatWarnings()) {
Bukkit.getServer().broadcast(
String.format("Error %s (%s) occured in %s.", report.getReportMessage(), report.getException(), sender),
String.format("Error %s (%s) occurred in %s.", report.getReportMessage(), report.getException(), sender),
ERROR_PERMISSION
);
}

View File

@ -8,16 +8,16 @@ global:
delay: 43200 # 12 hours
metrics: true
# Prints certain warnings to players with the protocol.info permission
chat warnings: true
# Automatically compile structure modifiers
background compiler: true
# Disable version checking for the given Minecraft version. Backup your world first!
ignore version check:
# Override the starting injecting method
injection method:
# Whether or not to enable the filter command
debug: false