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:
parent
541f095075
commit
6ff6ec9d6b
1 changed files with 8 additions and 8 deletions
|
@ -99,8 +99,8 @@ public class ChatCommands implements CommandExecutor {
|
||||||
} catch (ChatModule.ChatRoomExistsException e) {
|
} catch (ChatModule.ChatRoomExistsException e) {
|
||||||
sender.sendMessage("Room %s already exists".formatted(argument));
|
sender.sendMessage("Room %s already exists".formatted(argument));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
sender.sendMessage("Failed to create room");
|
sender.sendMessage("Error creating room");
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "delete" -> {
|
case "delete" -> {
|
||||||
|
@ -124,8 +124,8 @@ public class ChatCommands implements CommandExecutor {
|
||||||
manager.saveChatRoom(chatRoom);
|
manager.saveChatRoom(chatRoom);
|
||||||
sender.sendMessage("Owner changed to " + newOwner.getName());
|
sender.sendMessage("Owner changed to " + newOwner.getName());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
sender.sendMessage("Failed to change owner");
|
sender.sendMessage("Error changing owner");
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Player must be online");
|
sender.sendMessage("Player must be online");
|
||||||
|
@ -141,8 +141,8 @@ public class ChatCommands implements CommandExecutor {
|
||||||
manager.saveChatRoom(chatRoom);
|
manager.saveChatRoom(chatRoom);
|
||||||
sender.sendMessage("Password changed");
|
sender.sendMessage("Password changed");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
sender.sendMessage("Failed to change password");
|
sender.sendMessage("Error changing password");
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("You're not the owner of %s, please enter the room you want to make changes in".formatted(chatRoom.id));
|
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);
|
manager.saveChatRoom(chatRoom);
|
||||||
sender.sendMessage("Message color changed to " + newColor.getName());
|
sender.sendMessage("Message color changed to " + newColor.getName());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
sender.sendMessage("Failed to change color");
|
sender.sendMessage("Error changing color");
|
||||||
e.printStackTrace();
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("Invalid color");
|
sender.sendMessage("Invalid color");
|
||||||
|
|
Loading…
Add table
Reference in a new issue