parent
ddd100f493
commit
282bebdcdb
22 changed files with 706 additions and 192 deletions
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue