diff --git a/src/main/java/eu/m724/tweaks/chat/ChatCommands.java b/src/main/java/eu/m724/tweaks/chat/ChatCommands.java index f2ecad1..a99719b 100644 --- a/src/main/java/eu/m724/tweaks/chat/ChatCommands.java +++ b/src/main/java/eu/m724/tweaks/chat/ChatCommands.java @@ -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(" ")); diff --git a/src/main/java/eu/m724/tweaks/chat/ChatManager.java b/src/main/java/eu/m724/tweaks/chat/ChatManager.java index 99885f8..960d896 100644 --- a/src/main/java/eu/m724/tweaks/chat/ChatManager.java +++ b/src/main/java/eu/m724/tweaks/chat/ChatManager.java @@ -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); diff --git a/src/main/resources/strings.properties b/src/main/resources/strings.properties index f7a4b90..4b67662 100644 --- a/src/main/resources/strings.properties +++ b/src/main/resources/strings.properties @@ -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 \ No newline at end of file