From 6aa4d7a9a028a6b3f9cc78d7e4593d7a19dc63a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o?= Date: Thu, 23 May 2024 22:01:40 +0100 Subject: [PATCH] Fixed server crash when reward commands are empty or wrong --- .../src/main/java/org/pokesplash/hunt/util/Utils.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/org/pokesplash/hunt/util/Utils.java b/common/src/main/java/org/pokesplash/hunt/util/Utils.java index 9a3f28c..b183deb 100644 --- a/common/src/main/java/org/pokesplash/hunt/util/Utils.java +++ b/common/src/main/java/org/pokesplash/hunt/util/Utils.java @@ -309,6 +309,11 @@ public static void removeAllHunts() { } public static void runCommands(ArrayList commands, ServerPlayer player, Pokemon pokemon, double price) { + if (commands == null) { + Hunt.LOGGER.error("Commands are null"); + return; + } + // Run commands CommandDispatcher dispatcher = Hunt.server.getCommands().getDispatcher(); @@ -317,8 +322,9 @@ public static void runCommands(ArrayList commands, ServerPlayer player, dispatcher.execute( Utils.formatPlaceholders(command, player, pokemon, price), Hunt.server.createCommandSourceStack()); - } catch (CommandSyntaxException ex) { - throw new RuntimeException(ex); + } catch (Exception ex) { + Hunt.LOGGER.error("Error running command: " + command); + Hunt.LOGGER.error(ex.getMessage()); } } }