1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00
This commit is contained in:
Daniel Walsh 2021-10-09 17:57:38 +01:00
parent cea2ec194f
commit 4444fc6ec2
No known key found for this signature in database
GPG Key ID: DA4CCF44247893FD
4 changed files with 26 additions and 13 deletions

View File

@ -16,7 +16,7 @@ import javax.annotation.Nonnull;
*/
public class DebugCommand extends SubCommand {
protected DebugCommand(Slimefun plugin, SlimefunCommand cmd) {
protected DebugCommand(@Nonnull Slimefun plugin, @Nonnull SlimefunCommand cmd) {
super(plugin, cmd, "debug", true);
}
@ -32,9 +32,10 @@ public class DebugCommand extends SubCommand {
return;
}
if (args.length < 2) {
Slimefun.getLocalization().sendMessage(sender, "messages.usage", true,
msg -> msg.replace("%usage%", "/sf debug <test>"));
if (args.length == 1) {
Slimefun.getLocalization().sendMessage(sender, "commands.debug.current", true,
msg -> msg.replace("%test_case%", Debug.getTestCase() != null ? Debug.getTestCase() : "None")
);
return;
}

View File

@ -4,6 +4,7 @@ import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.logging.Level;
/**
* This class is responsible for debug logging.
@ -43,28 +44,28 @@ public final class Debug {
/**
* Log a message if the test case is currently enabled.
*
* @param mode The test case to use
* @param test The test case to use
* @param msg The message to log
*/
public static void log(@Nonnull String mode, @Nonnull String msg) {
log(mode, msg, new Object[0]);
public static void log(@Nonnull String test, @Nonnull String msg) {
log(test, msg, new Object[0]);
}
/**
* Log a message if the test case is currently enabled.
*
* @param mode The test case to use
* @param test The test case to use
* @param msg The message to log
* @param vars The variables to replace, use "{}" in the message and have it replaced with a specified thing
*/
public static void log(@Nonnull String mode, @Nonnull String msg, @Nonnull Object... vars) {
if (testCase == null || !testCase.equals(mode)) return;
public static void log(@Nonnull String test, @Nonnull String msg, @Nonnull Object... vars) {
if (testCase == null || !testCase.equals(test)) return;
if (vars.length > 0) {
String formatted = formatMessage(msg, vars);
Slimefun.logger().info(formatted);
Slimefun.logger().log(Level.INFO, "[DEBUG {0}] {1}", new Object[]{ test, formatted });
} else {
Slimefun.logger().info(msg);
Slimefun.logger().log(Level.INFO, "[DEBUG {0}] {1}", new Object[]{ test, msg });
}
}
@ -103,4 +104,13 @@ public final class Debug {
public static void setTestCase(@Nullable String test) {
testCase = test;
}
/**
* Get the current test case for this server or null if disabled
*
* @return The current test case to enable or null if disabled
*/
public static @Nullable String getTestCase() {
return testCase;
}
}

View File

@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.debug;
import javax.annotation.Nonnull;
import java.util.Locale;
/**
@ -20,7 +21,7 @@ public enum TestCase {
TestCase() {}
@Override
public String toString() {
public @Nonnull String toString() {
return "slimefun_" + name().toLowerCase(Locale.ROOT);
}
}

View File

@ -34,6 +34,7 @@ commands:
debug:
description: 'Run debug logging for the developers'
current: '&7Current test case: &6%test_case%'
running: '&7Running debug mode with test: %test%'
disabled: '&7Disabled debug mode'