mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Changes
This commit is contained in:
parent
cea2ec194f
commit
4444fc6ec2
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user