Roles
A static class in TavernLib, TavernLib.ModdingApi.
Players' roles from users.json, kept in memory and re-read about a second after the file changes. Server only: on a client every list is empty.
- Listed in TavernLib.ModdingApi
- Documented in Roles, TavernLib API
Fields
| Member | What it is |
|---|---|
static readonly TavernEvents.TavernEvent<RolesChange> RolesChanged | Raised on the main thread for each user whose roles change, after their new roles are sent to them. Not raised at start. |
7 private and internal fields
Methods
| Member | What it is |
|---|---|
static IReadOnlyList<string> GetRoles(Connection connection) | A player's roles, by connection or by username, without case. An empty list (never null) for anyone with none. |
static IReadOnlyList<string> GetRoles(string username) | A player's roles, by connection or by username, without case. An empty list (never null) for anyone with none. |
static bool HasRole(Connection connection, string role) | True if the connection's player has the role. Role names compare without case. |
5 private and internal methods
| Member | What it is |
|---|---|
private static void Announce(RolesChange change) | Sends the new roles to the user if online and raises RolesChanged. |
private static void Poll() | Once a second, reloads the roles if users.json changed and has stopped changing. |
private static Dictionary<string, IReadOnlyList<string>> Read() | Reads users.json and returns each user's non-blank roles. |
private static void Reload(DateTime stamp) | Rereads the roles and announces each user whose roles changed; keeps the old roles if the file can't be read. |
internal static void Start() | Internal, server: reads users.json and starts the once-a-second poll from MelonEvents.OnUpdate. |