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
This commit is contained in:
Andreas Troelsen 2020-05-31 21:12:47 +02:00
parent 684116918a
commit 962eb7aaba
2 changed files with 9 additions and 1 deletions

View File

@ -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.

View File

@ -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();