-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventSystem.cs
46 lines (37 loc) · 1.5 KB
/
EventSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
namespace BetterEventSystem {
public static class EventSystem {
public static void Main(string[] args) {
Console.WriteLine(
"BetterEventSystem is not intended to be run as a standalone application.\n" +
"It is meant to be used as a library.\n" +
"Please see the documentation for more information. \n \n https://bes.rtfd.io/"
);
}
public static Dictionary<String, Event> Events = new Dictionary<String, Event>();
public static Event GetEvent(string eventName, bool safe = true) {
// check if the eventName is in the dictionary
if (Events.ContainsKey(eventName)) {
return Events[eventName];
}
// if the eventName is not in the dictionary, either create it throw an exception
if (safe) {
return new Event(
name: eventName,
allowAsync: true,
register: true
); // these are the default parameters, but i want to be explicit
} else {
throw new NullReferenceException("Event \"" + eventName + "\" not found");
}
}
public static Event Register(Event e) {
Events.Add(e.Name, e);
return e;
}
public static void Unregister(Event e) {
Events.Remove(e.Name);
}
}
}