Disallow joining same chatroom

This commit is contained in:
Minecon724 2024-12-05 19:59:31 +01:00
parent 760f52df71
commit 6183ccd6bf
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
3 changed files with 10 additions and 0 deletions

View file

@ -40,6 +40,12 @@ public class ChatCommands implements CommandExecutor {
player.spigot().sendMessage(chatRoom.getInfoComponent());
} else { // join room
String id = args[0];
if (id.equals(chatRoom.id)) {
sender.spigot().sendMessage(Language.getComponent("chatAlreadyHere", ChatColor.GRAY));
return true;
}
String password = null;
if (args.length > 1) {
password = Arrays.stream(args).skip(1).collect(Collectors.joining(" "));

View file

@ -86,6 +86,9 @@ public class ChatManager {
*/
public void setPlayerChatRoom(ChatRoom chatRoom, Player player) {
ChatRoom oldRoom = getPlayerChatRoom(player);
if (chatRoom.equals(oldRoom)) return; // no change if changing to the same room
oldRoom.players.remove(player);
player.getPersistentDataContainer().set(chatRoomKey, PersistentDataType.STRING, chatRoom.id);

View file

@ -18,6 +18,7 @@ updatesClickToOpen = Click to open on SpigotMC "%s"
chatPasswordProtected = This room is password protected
chatWrongPassword = Wrong password
chatNoSuchRoom = No room named %s
chatAlreadyHere = You're already in this room
# Room name is added at end
chatJoined = Joined chat room:
chatPlayers = %d other players are here