commit
Some checks failed
/ deploy (push) Failing after 2m13s

This commit is contained in:
Minecon724 2024-11-23 17:51:03 +01:00
parent ddd100f493
commit 282bebdcdb
Signed by untrusted user who does not match committer: Minecon724
GPG key ID: 3CCC4D267742C8E8
22 changed files with 706 additions and 192 deletions

View file

@ -1,5 +1,6 @@
package eu.m724.tweaks.chat;
import eu.m724.tweaks.TweaksConfig;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.NamespacedKey;
@ -15,6 +16,7 @@ import java.util.Map;
public class ChatManager {
private final Plugin plugin;
private final NamespacedKey chatRoomKey;
private final String defaultRoom;
private final Map<Player, ChatRoom> playerMap = new HashMap<>();
private final Map<String, ChatRoom> roomIdMap = new HashMap<>();
@ -22,10 +24,11 @@ public class ChatManager {
public ChatManager(Plugin plugin) {
this.plugin = plugin;
this.chatRoomKey = new NamespacedKey(plugin, "chatRoom");
this.defaultRoom = TweaksConfig.getConfig().chatDefaultName();
}
public void init() {
getById("global");
getById(defaultRoom);
plugin.getServer().getPluginManager().registerEvents(new ChatListener(this), plugin);
}
@ -53,10 +56,15 @@ public class ChatManager {
ChatRoom chatRoom = roomIdMap.get(id);
if (chatRoom == null) {
chatRoom = ChatRoomLoader.load(plugin, id);
if (id.equals(defaultRoom)) {
return new ChatRoom(defaultRoom, null, null);
} else {
chatRoom = ChatRoomLoader.load(plugin, id);
}
roomIdMap.put(id, chatRoom);
}
return chatRoom;
}
@ -104,9 +112,9 @@ public class ChatManager {
if (chatRoom == null) {
String id = player.getPersistentDataContainer().get(chatRoomKey, PersistentDataType.STRING);
if (id == null) id = "global";
if (id == null) id = defaultRoom;
chatRoom = getById(id);
if (chatRoom == null) chatRoom = getById("global");
if (chatRoom == null) chatRoom = getById(defaultRoom);
chatRoom.players.add(player);
playerMap.put(player, chatRoom);
@ -157,7 +165,7 @@ public class ChatManager {
roomIdMap.remove(chatRoom.id);
ChatRoomLoader.getFile(plugin, chatRoom.id).delete();
chatRoom.players.forEach(player -> {
setPlayerChatRoom(getById("global"), player);
setPlayerChatRoom(getById(defaultRoom), player);
});
}