wip
All checks were successful
/ deploy (push) Successful in 1m24s

This commit is contained in:
Minecon724 2024-11-18 16:52:57 +01:00
parent 4503f15d6c
commit 621c006590
Signed by untrusted user who does not match committer: Minecon724
GPG key ID: 3CCC4D267742C8E8
15 changed files with 233 additions and 51 deletions

View file

@ -1,5 +1,7 @@
package eu.m724.tweaks.chat;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.NamespacedKey;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@ -27,6 +29,18 @@ public class ChatManager {
plugin.getServer().getPluginManager().registerEvents(new ChatListener(this), plugin);
}
/**
* removes player from the server and their chatroom
* @param player the player
* @return the chatroom the player was removed from
*/
public ChatRoom removePlayer(Player player) {
ChatRoom chatRoom = playerMap.remove(player);
chatRoom.players.remove(player);
return chatRoom;
}
/**
* Get a chat room by id.<br>
* If the chat room is not loaded, it's loaded.
@ -59,6 +73,22 @@ public class ChatManager {
player.getPersistentDataContainer().set(chatRoomKey, PersistentDataType.STRING, chatRoom.id);
playerMap.put(player, chatRoom);
chatRoom.players.add(player);
chatRoom.broadcast(
new ComponentBuilder()
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
.append(ChatFormatUtils.formatPlayer(player))
.append(" has left the chat room").color(ChatColor.RED)
.create()
);
chatRoom.broadcast(
new ComponentBuilder()
.append(ChatFormatUtils.chatRoomPrefixShort(chatRoom))
.append(ChatFormatUtils.formatPlayer(player))
.append(" has joined the chat room").color(ChatColor.GREEN)
.create()
);
}
/**
@ -123,6 +153,14 @@ public class ChatManager {
ChatRoomLoader.save(plugin, chatRoom);
}
public void deleteChatRoom(ChatRoom chatRoom) {
roomIdMap.remove(chatRoom.id);
ChatRoomLoader.getFile(plugin, chatRoom.id).delete();
chatRoom.players.forEach(player -> {
setPlayerChatRoom(getById("global"), player);
});
}
/**
* If an ID is too short, too long, wrong composition, etc.
*/