|
1 | | -package com.github.theholywaffle.teamspeak3; |
2 | | - |
3 | | -/* |
4 | | - * #%L |
5 | | - * TeamSpeak 3 Java API |
6 | | - * %% |
7 | | - * Copyright (C) 2014 Bert De Geyter |
8 | | - * %% |
9 | | - * Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | - * of this software and associated documentation files (the "Software"), to deal |
11 | | - * in the Software without restriction, including without limitation the rights |
12 | | - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | - * copies of the Software, and to permit persons to whom the Software is |
14 | | - * furnished to do so, subject to the following conditions: |
15 | | - * |
16 | | - * The above copyright notice and this permission notice shall be included in |
17 | | - * all copies or substantial portions of the Software. |
18 | | - * |
19 | | - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | - * THE SOFTWARE. |
26 | | - * #L% |
27 | | - */ |
28 | | - |
29 | | -import java.util.ArrayList; |
30 | | -import java.util.HashMap; |
31 | | -import java.util.List; |
32 | | -import java.util.Map; |
33 | | - |
34 | | -import com.github.theholywaffle.teamspeak3.api.event.ChannelDescriptionEditedEvent; |
35 | | -import com.github.theholywaffle.teamspeak3.api.event.ChannelEditedEvent; |
36 | | -import com.github.theholywaffle.teamspeak3.api.event.ClientJoinEvent; |
37 | | -import com.github.theholywaffle.teamspeak3.api.event.ClientLeaveEvent; |
38 | | -import com.github.theholywaffle.teamspeak3.api.event.ClientMovedEvent; |
39 | | -import com.github.theholywaffle.teamspeak3.api.event.ServerEditedEvent; |
40 | | -import com.github.theholywaffle.teamspeak3.api.event.TS3EventEmitter; |
41 | | -import com.github.theholywaffle.teamspeak3.api.event.TS3Listener; |
42 | | -import com.github.theholywaffle.teamspeak3.api.event.TextMessageEvent; |
43 | | -import com.github.theholywaffle.teamspeak3.api.exception.TS3UnknownEventException; |
44 | | -import com.github.theholywaffle.teamspeak3.commands.response.DefaultArrayResponse; |
45 | | - |
46 | | -public class EventManager { |
47 | | - |
48 | | - private final Map<String, TS3EventEmitter> map = new HashMap<>(); |
49 | | - |
50 | | - private final List<TS3Listener> listeners = new ArrayList<>(); |
51 | | - |
52 | | - public EventManager() { |
53 | | - map.put("notifytextmessage", new TextMessageEvent()); |
54 | | - map.put("notifycliententerview", new ClientJoinEvent()); |
55 | | - map.put("notifyclientleftview", new ClientLeaveEvent()); |
56 | | - map.put("notifyserveredited", new ServerEditedEvent()); |
57 | | - map.put("notifychanneledited", new ChannelEditedEvent()); |
58 | | - map.put("notifychanneldescriptionchanged", |
59 | | - new ChannelDescriptionEditedEvent()); |
60 | | - map.put("notifyclientmoved", new ClientMovedEvent()); |
61 | | - } |
62 | | - |
63 | | - public void addListeners(TS3Listener... listeners) { |
64 | | - for (final TS3Listener l : listeners) { |
65 | | - this.listeners.add(l); |
66 | | - } |
67 | | - } |
68 | | - |
69 | | - public void removeListeners(TS3Listener... listeners) { |
70 | | - for (final TS3Listener l : listeners) { |
71 | | - this.listeners.remove(l); |
72 | | - } |
73 | | - } |
74 | | - |
75 | | - public void fireEvent(String notifyName, String notifyBody) { |
76 | | - final TS3EventEmitter emitter = map.get(notifyName); |
77 | | - if (emitter != null) { |
78 | | - for (final TS3Listener l : listeners) { |
79 | | - emitter.fire(l, new DefaultArrayResponse(notifyBody).getArray() |
80 | | - .get(0)); |
81 | | - } |
82 | | - } else { |
83 | | - throw new TS3UnknownEventException(notifyName + " " + notifyBody); |
84 | | - } |
85 | | - |
86 | | - } |
87 | | - |
88 | | -} |
| 1 | +package com.github.theholywaffle.teamspeak3; |
| 2 | + |
| 3 | +/* |
| 4 | + * #%L |
| 5 | + * TeamSpeak 3 Java API |
| 6 | + * %% |
| 7 | + * Copyright (C) 2014 Bert De Geyter |
| 8 | + * %% |
| 9 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 10 | + * of this software and associated documentation files (the "Software"), to deal |
| 11 | + * in the Software without restriction, including without limitation the rights |
| 12 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 13 | + * copies of the Software, and to permit persons to whom the Software is |
| 14 | + * furnished to do so, subject to the following conditions: |
| 15 | + * |
| 16 | + * The above copyright notice and this permission notice shall be included in |
| 17 | + * all copies or substantial portions of the Software. |
| 18 | + * |
| 19 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 20 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 22 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 23 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 24 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 25 | + * THE SOFTWARE. |
| 26 | + * #L% |
| 27 | + */ |
| 28 | + |
| 29 | +import java.util.ArrayList; |
| 30 | +import java.util.HashMap; |
| 31 | +import java.util.List; |
| 32 | +import java.util.Map; |
| 33 | + |
| 34 | +import com.github.theholywaffle.teamspeak3.api.event.ChannelCreateEvent; |
| 35 | +import com.github.theholywaffle.teamspeak3.api.event.ChannelDeletedEvent; |
| 36 | +import com.github.theholywaffle.teamspeak3.api.event.ChannelDescriptionEditedEvent; |
| 37 | +import com.github.theholywaffle.teamspeak3.api.event.ChannelEditedEvent; |
| 38 | +import com.github.theholywaffle.teamspeak3.api.event.ChannelMovedEvent; |
| 39 | +import com.github.theholywaffle.teamspeak3.api.event.ChannelPasswordChangedEvent; |
| 40 | +import com.github.theholywaffle.teamspeak3.api.event.ClientJoinEvent; |
| 41 | +import com.github.theholywaffle.teamspeak3.api.event.ClientLeaveEvent; |
| 42 | +import com.github.theholywaffle.teamspeak3.api.event.ClientMovedEvent; |
| 43 | +import com.github.theholywaffle.teamspeak3.api.event.ServerEditedEvent; |
| 44 | +import com.github.theholywaffle.teamspeak3.api.event.TS3EventEmitter; |
| 45 | +import com.github.theholywaffle.teamspeak3.api.event.TS3Listener; |
| 46 | +import com.github.theholywaffle.teamspeak3.api.event.TextMessageEvent; |
| 47 | +import com.github.theholywaffle.teamspeak3.api.exception.TS3UnknownEventException; |
| 48 | +import com.github.theholywaffle.teamspeak3.commands.response.DefaultArrayResponse; |
| 49 | + |
| 50 | +public class EventManager { |
| 51 | + |
| 52 | + private final Map<String, TS3EventEmitter> map = new HashMap<>(); |
| 53 | + |
| 54 | + private final List<TS3Listener> listeners = new ArrayList<>(); |
| 55 | + |
| 56 | + public EventManager() { |
| 57 | + map.put("notifytextmessage", new TextMessageEvent()); |
| 58 | + map.put("notifycliententerview", new ClientJoinEvent()); |
| 59 | + map.put("notifyclientleftview", new ClientLeaveEvent()); |
| 60 | + map.put("notifyserveredited", new ServerEditedEvent()); |
| 61 | + map.put("notifychanneledited", new ChannelEditedEvent()); |
| 62 | + map.put("notifychanneldescriptionchanged", new ChannelDescriptionEditedEvent()); |
| 63 | + map.put("notifyclientmoved", new ClientMovedEvent()); |
| 64 | + map.put("notifychannelcreated", new ChannelCreateEvent()); |
| 65 | + map.put("notifychanneldeleted", new ChannelDeletedEvent()); |
| 66 | + map.put("notifychannelmoved", new ChannelMovedEvent()); |
| 67 | + map.put("notifychannelpasswordchanged", new ChannelPasswordChangedEvent()); |
| 68 | + } |
| 69 | + |
| 70 | + public void addListeners(TS3Listener... listeners) { |
| 71 | + for (final TS3Listener l : listeners) { |
| 72 | + this.listeners.add(l); |
| 73 | + } |
| 74 | + } |
| 75 | + |
| 76 | + public void removeListeners(TS3Listener... listeners) { |
| 77 | + for (final TS3Listener l : listeners) { |
| 78 | + this.listeners.remove(l); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + public void fireEvent(String notifyName, String notifyBody) { |
| 83 | + final TS3EventEmitter emitter = map.get(notifyName); |
| 84 | + if (emitter != null) { |
| 85 | + for (final TS3Listener l : listeners) { |
| 86 | + emitter.fire(l, new DefaultArrayResponse(notifyBody).getArray() |
| 87 | + .get(0)); |
| 88 | + } |
| 89 | + } else { |
| 90 | + throw new TS3UnknownEventException(notifyName + " " + notifyBody); |
| 91 | + } |
| 92 | + |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments