by robscherer123 » January 8th, 2019, 6:02 pm
by Henrik » January 15th, 2019, 6:44 am
private Dictionary<string, List<Action<Player, Message>>> handlers = new Dictionary<string, List<Action<Player, Message>>>();
public void AddHandler(string type, Action<Player, Message> action) {
if (!handlers.ContainsKey(type)) { handlers[type] = new List<Action<Player, Message>>(); }
handlers[type].Add(action);
}
public void RemoveHandler(string type, Action<Player, Message> action) {
if (handlers.ContainsKey(type)) {
handlers[type].Remove(action);
}
}
public override void GotMessage(Player player, Message message) {
if (handlers.ContainsKey(message.Type)) {
foreach (var action in handlers[message.Type]) {
action(player, message);
}
}
//...the rest of your original GotMessage continues here...
}