Disallow joining same chatroom
This commit is contained in:
parent
760f52df71
commit
6183ccd6bf
3 changed files with 10 additions and 0 deletions
|
@ -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(" "));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
Loading…
Reference in a new issue