fix: improve error handling in ChatCommands

Updated error handling to throw RuntimeException instead of printing stack traces. Enhanced user feedback by standardizing error messages across various chat command operations.

Signed-off-by: Minecon724 <git@m724.eu>
This commit is contained in:
Minecon724 2025-02-03 10:52:04 +01:00
parent 541f095075
commit 6ff6ec9d6b
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8

View file

@ -99,8 +99,8 @@ public class ChatCommands implements CommandExecutor {
} catch (ChatModule.ChatRoomExistsException e) {
sender.sendMessage("Room %s already exists".formatted(argument));
} catch (IOException e) {
sender.sendMessage("Failed to create room");
e.printStackTrace();
sender.sendMessage("Error creating room");
throw new RuntimeException(e);
}
}
case "delete" -> {
@ -124,8 +124,8 @@ public class ChatCommands implements CommandExecutor {
manager.saveChatRoom(chatRoom);
sender.sendMessage("Owner changed to " + newOwner.getName());
} catch (IOException e) {
sender.sendMessage("Failed to change owner");
e.printStackTrace();
sender.sendMessage("Error changing owner");
throw new RuntimeException(e);
}
} else {
sender.sendMessage("Player must be online");
@ -141,8 +141,8 @@ public class ChatCommands implements CommandExecutor {
manager.saveChatRoom(chatRoom);
sender.sendMessage("Password changed");
} catch (IOException e) {
sender.sendMessage("Failed to change password");
e.printStackTrace();
sender.sendMessage("Error changing password");
throw new RuntimeException(e);
}
} else {
sender.sendMessage("You're not the owner of %s, please enter the room you want to make changes in".formatted(chatRoom.id));
@ -157,8 +157,8 @@ public class ChatCommands implements CommandExecutor {
manager.saveChatRoom(chatRoom);
sender.sendMessage("Message color changed to " + newColor.getName());
} catch (IOException e) {
sender.sendMessage("Failed to change color");
e.printStackTrace();
sender.sendMessage("Error changing color");
throw new RuntimeException(e);
}
} else {
sender.sendMessage("Invalid color");