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());
|
player.spigot().sendMessage(chatRoom.getInfoComponent());
|
||||||
} else { // join room
|
} else { // join room
|
||||||
String id = args[0];
|
String id = args[0];
|
||||||
|
|
||||||
|
if (id.equals(chatRoom.id)) {
|
||||||
|
sender.spigot().sendMessage(Language.getComponent("chatAlreadyHere", ChatColor.GRAY));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String password = null;
|
String password = null;
|
||||||
if (args.length > 1) {
|
if (args.length > 1) {
|
||||||
password = Arrays.stream(args).skip(1).collect(Collectors.joining(" "));
|
password = Arrays.stream(args).skip(1).collect(Collectors.joining(" "));
|
||||||
|
|
|
@ -86,6 +86,9 @@ public class ChatManager {
|
||||||
*/
|
*/
|
||||||
public void setPlayerChatRoom(ChatRoom chatRoom, Player player) {
|
public void setPlayerChatRoom(ChatRoom chatRoom, Player player) {
|
||||||
ChatRoom oldRoom = getPlayerChatRoom(player);
|
ChatRoom oldRoom = getPlayerChatRoom(player);
|
||||||
|
|
||||||
|
if (chatRoom.equals(oldRoom)) return; // no change if changing to the same room
|
||||||
|
|
||||||
oldRoom.players.remove(player);
|
oldRoom.players.remove(player);
|
||||||
|
|
||||||
player.getPersistentDataContainer().set(chatRoomKey, PersistentDataType.STRING, chatRoom.id);
|
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
|
chatPasswordProtected = This room is password protected
|
||||||
chatWrongPassword = Wrong password
|
chatWrongPassword = Wrong password
|
||||||
chatNoSuchRoom = No room named %s
|
chatNoSuchRoom = No room named %s
|
||||||
|
chatAlreadyHere = You're already in this room
|
||||||
# Room name is added at end
|
# Room name is added at end
|
||||||
chatJoined = Joined chat room:
|
chatJoined = Joined chat room:
|
||||||
chatPlayers = %d other players are here
|
chatPlayers = %d other players are here
|
Loading…
Reference in a new issue