parent
4503f15d6c
commit
621c006590
15 changed files with 233 additions and 51 deletions
|
@ -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.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue