From 962eb7aabac7b14a794549d06d5f0c70d86a4950 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Sun, 31 May 2020 21:12:47 +0200 Subject: [PATCH] Improve config-file errors from `/ma setting`. Catches ConfigError and prints its message rather than letting it bubble up to the command handler as an uncaught exception. This means that instead of seeing "An internal error occurred...", command senders now see the underlying error message, as well as a short message telling them to fix the error in the config-file and reload. Closes #599 --- changelog.md | 1 + .../MobArena/commands/setup/SettingCommand.java | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 6bddabc..999ea81 100644 --- a/changelog.md +++ b/changelog.md @@ -18,6 +18,7 @@ These changes will (most likely) be included in the next version. - The Root Target ability now uses potion effects (slowness, slow falling, and negative jump boost) instead of repeated teleports. This should make for a smoother root experience. - Config-files with missing `pet-items` nodes no longer errors. A missing `pet-items` node in `global-settings` is treated as empty, i.e. no pet items will be registered. - The `player-time-in-arena` setting has been fixed. +- Config-file errors imposed by incorrect usage of `/ma setting` no longer cause "internal errors". Instead, the errors are properly communicated in the command output similar to how the `/ma reload` command works. ## [0.104.2] - 2020-01-03 - The region overlap check now works across both arena and lobby regions, i.e. all four combinations of intersections between two regions (arena-arena, arena-lobby, lobby-arena, and lobby-lobby) are evaluated. diff --git a/src/main/java/com/garbagemule/MobArena/commands/setup/SettingCommand.java b/src/main/java/com/garbagemule/MobArena/commands/setup/SettingCommand.java index 37104e5..84d81b3 100644 --- a/src/main/java/com/garbagemule/MobArena/commands/setup/SettingCommand.java +++ b/src/main/java/com/garbagemule/MobArena/commands/setup/SettingCommand.java @@ -1,5 +1,6 @@ package com.garbagemule.MobArena.commands.setup; +import com.garbagemule.MobArena.ConfigError; import com.garbagemule.MobArena.commands.Command; import com.garbagemule.MobArena.commands.CommandInfo; import com.garbagemule.MobArena.framework.Arena; @@ -89,7 +90,13 @@ public class SettingCommand implements Command { // Save config-file and reload arena am.saveConfig(); - am.reloadArena(args[0]); + try { + am.reloadArena(args[0]); + } catch (ConfigError e) { + am.getGlobalMessenger().tell(sender, "Failed to reload arena after changing setting, reason:\n" + ChatColor.RED + e.getMessage()); + am.getGlobalMessenger().tell(sender, "Fix the error in your config-file, then run " + ChatColor.YELLOW + "/ma reload"); + return true; + } // Notify the sender StringBuilder buffy = new StringBuilder();