Skip to content

Commit

Permalink
add a debug output limiter option
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Aug 25, 2019
1 parent a9cf7d8 commit 072c23b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
Expand Up @@ -422,6 +422,7 @@ public void run() {
getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
@Override
public void run() {
Debug.outputThisTick = 0;
DenizenCore.tick(50); // Sadly, minecraft has no delta timing, so a tick is always 50ms.
}
}, 1, 1);
Expand Down
7 changes: 6 additions & 1 deletion plugin/src/main/java/com/denizenscript/denizen/Settings.java
Expand Up @@ -37,6 +37,7 @@ public static void refillCache() {
cache_allowConsoleRedirection = config.getBoolean("Debug.Allow console redirection", false);
cache_canRecordStats = config.getBoolean("Debug.Stats", true);
cache_defaultDebugMode = config.getBoolean("Debug.Container default", true);
cache_debugLimitPerTick = config.getInt("Debug.Limit per tick", 5000);
cache_scriptQueueSpeed = config.getString("Scripts.Queue speed", "instant");
cache_interactQueueSpeed = config.getString("Scripts.Interact.Queue speed", "0.5s");
cache_healthTraitEnabledByDefault = config.getBoolean("Traits.Health.Enabled", false);
Expand Down Expand Up @@ -95,7 +96,7 @@ public static void refillCache() {
cache_chatToNpcFormat, cache_chatToNpcOverheardFormat, cache_interactQueueSpeed, cache_limitPath;

private static int cache_consoleWidth = 128, cache_trimLength = 1024, cache_whileMaxLoops, cache_blockTagsMaxBlocks,
cache_chatHistoryMaxMessages, cache_tagTimeout;
cache_chatHistoryMaxMessages, cache_tagTimeout, cache_debugLimitPerTick;

private static long cache_warningRate;

Expand Down Expand Up @@ -155,6 +156,10 @@ public static boolean defaultDebugMode() {
return cache_defaultDebugMode;
}

public static int debugLimitPerTick() {
return cache_debugLimitPerTick;
}

/**
* Sets the default speed between execution of commands in queues
*/
Expand Down
Expand Up @@ -554,7 +554,16 @@ public static String cleanTextForDebugOutput(String message) {
.replace("<W>", ChatColor.WHITE.toString()));
}

public static int outputThisTick = 0;

static void finalOutputDebugText(String message, Debuggable caller, boolean reformat) {
outputThisTick++;
if (outputThisTick >= Settings.debugLimitPerTick()) {
if (outputThisTick == Settings.debugLimitPerTick()) {
ConsoleSender.sendMessage("... Debug rate limit per-tick hit, edit config.yml to adjust this limit...", true);
}
return;
}
// These colors are used a lot in the debugging of commands/etc, so having a few shortcuts is nicer
// than having a bunch of ChatColor.XXXX
message = cleanTextForDebugOutput(message);
Expand Down
4 changes: 4 additions & 0 deletions plugin/src/main/resources/config.yml
Expand Up @@ -24,6 +24,10 @@ Debug:
# The default debug mode for script containers.
# This should almost always be left at 'true'.
Container default: true
# How many debug messages can appear within the span of a single tick before they simply get blocked.
# This is available as a backup safety feature to prevent debug output from crashing a server.
# Set the value lower to better protect this, set the value higher to willfully debug a very very long script.
Limit per tick: 5000

Scripts:
World:
Expand Down

0 comments on commit 072c23b

Please sign in to comment.