From 1237a699ba244ecfac65478df34e714afbe2366e Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 5 Jul 2024 10:07:22 +0200 Subject: [PATCH] Fix SWCommand with 0 args, Add SWException option to get ID Signed-off-by: Lixfel --- src/de/steamwar/command/AbstractSWCommand.java | 2 +- src/de/steamwar/sql/SWException.java | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/de/steamwar/command/AbstractSWCommand.java b/src/de/steamwar/command/AbstractSWCommand.java index 3a44271..65f6643 100644 --- a/src/de/steamwar/command/AbstractSWCommand.java +++ b/src/de/steamwar/command/AbstractSWCommand.java @@ -102,7 +102,7 @@ public abstract class AbstractSWCommand { protected final List tabComplete(T sender, String alias, String[] args) throws IllegalArgumentException { initialize(); - String string = args.length > 0 ? args[args.length - 1].toLowerCase() : ""; + String string = args[args.length - 1].toLowerCase(); return Stream.concat(commandList.stream(), helpCommandList.stream()) .filter(s -> !s.noTabComplete) .map(s -> s.tabComplete(sender, args)) diff --git a/src/de/steamwar/sql/SWException.java b/src/de/steamwar/sql/SWException.java index 0a8ece3..ca87a09 100644 --- a/src/de/steamwar/sql/SWException.java +++ b/src/de/steamwar/sql/SWException.java @@ -52,10 +52,17 @@ public class SWException { private final String stacktrace; public static void log(String message, String stacktrace){ + insert.update(SERVER_NAME, generateMessage(message), stacktrace); + } + + public static int logGetId(String message, String stacktrace) { + return insert.insertGetKey(SERVER_NAME, generateMessage(message), stacktrace); + } + + private static String generateMessage(String message) { StringBuilder msgBuilder = new StringBuilder(message); SQLWrapper.impl.additionalExceptionMetadata(msgBuilder); msgBuilder.append("\nCWD: ").append(CWD); - - insert.update(SERVER_NAME, msgBuilder.toString(), stacktrace); + return msgBuilder.toString(); } }