Skip to content

Commit 2c06da9

Browse files
committed
Merge pull request #17 from Barofioso/b-master
New events and fix for UTF-8 characters
2 parents d034046 + c3e825b commit 2c06da9

17 files changed

Lines changed: 931 additions & 273 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212

1313
# Eclise Files
1414
.settings
15+
/.apt_generated
Lines changed: 95 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,95 @@
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+
}
Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,67 @@
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 com.github.theholywaffle.teamspeak3.commands.CWhoAmI;
30-
31-
public class KeepAliveThread extends Thread {
32-
33-
private static final int SLEEP = 60_000;
34-
35-
private final TS3Query ts3;
36-
private final SocketWriter writer;
37-
38-
private volatile boolean stop;
39-
40-
public KeepAliveThread(TS3Query ts3, SocketWriter socketWriter) {
41-
super("Keep alive");
42-
this.ts3 = ts3;
43-
this.writer = socketWriter;
44-
}
45-
46-
@Override
47-
public void run() {
48-
while (ts3.getSocket() != null && ts3.getSocket().isConnected()
49-
&& ts3.getIn() != null && !stop) {
50-
final long idleTime = writer.getIdleTime();
51-
if (idleTime >= SLEEP) {
52-
ts3.doCommand(new CWhoAmI());
53-
}
54-
try {
55-
Thread.sleep(50);
56-
} catch (final InterruptedException e) {
57-
e.printStackTrace();
58-
}
59-
}
60-
TS3Query.log.warning("KeepAlive thread has stopped!");
61-
}
62-
63-
public void finish() {
64-
stop = true;
65-
}
66-
67-
}
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 com.github.theholywaffle.teamspeak3.commands.CWhoAmI;
30+
31+
public class KeepAliveThread extends Thread {
32+
33+
private static final int SLEEP = 60_000;
34+
35+
private final TS3Query ts3;
36+
private final SocketWriter writer;
37+
38+
private volatile boolean stop;
39+
40+
public KeepAliveThread(TS3Query ts3, SocketWriter socketWriter) {
41+
super("Keep alive");
42+
this.ts3 = ts3;
43+
this.writer = socketWriter;
44+
}
45+
46+
@Override
47+
public void run() {
48+
while (ts3.getSocket() != null && ts3.getSocket().isConnected()
49+
&& ts3.getIn() != null && !stop) {
50+
final long idleTime = writer.getIdleTime();
51+
if (idleTime >= SLEEP) {
52+
ts3.doCommand(new CWhoAmI());
53+
}
54+
try {
55+
Thread.sleep(50);
56+
} catch (final InterruptedException e) {
57+
e.printStackTrace();
58+
}
59+
}
60+
TS3Query.log.warning("KeepAlive thread has stopped!");
61+
}
62+
63+
public void finish() {
64+
stop = true;
65+
}
66+
67+
}

src/main/java/com/github/theholywaffle/teamspeak3/SocketWriter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public SocketWriter(TS3Query ts3, int floodRate) {
4444
}
4545
}
4646

47-
@Override
4847
public void run() {
4948
while (ts3.getSocket() != null && ts3.getSocket().isConnected()
5049
&& ts3.getOut() != null && !stop) {

0 commit comments

Comments
 (0)