Skip to content

Commit 7af8d7c

Browse files
BarofiosoBarofioso
authored andcommitted
Fixed the Umlauts problem
1 parent bf94d2e commit 7af8d7c

9 files changed

Lines changed: 79 additions & 13 deletions

File tree

.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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void run() {
5555
&& ts3.getIn() != null && !stop) {
5656
try {
5757
if (ts3.getIn().ready()) {
58-
final String line = ts3.getIn().readLine();
58+
final String line = StringUtil.convertFromUTF8(ts3.getIn().readLine());
5959
if (!line.isEmpty()) {
6060
final Command c = ts3.getCommandList().peek();
6161
if (line.startsWith("notify")) {

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ 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) {
5150
final Command c = ts3.getCommandList().peek();
5251
if (c != null && !c.isSent()) {
5352
final String msg = c.toString();
54-
TS3Query.log.info("> " + msg);
55-
ts3.getOut().println(msg);
53+
TS3Query.log.info("> " + StringUtil.convertToUTF8(msg));
54+
ts3.getOut().println(StringUtil.convertToUTF8(msg));
5655
lastCommand = System.currentTimeMillis();
5756
c.setSent();
5857
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,12 @@ public static int getInt(String str) {
102102
}
103103
return Integer.parseInt(str);
104104
}
105+
106+
public static String convertToUTF8(String str){
107+
return str.replace("ä", "ä").replace("ö", "ö").replace("ü", "ü").replace("Ä", "Ä").replace("Ö", "Ö").replace("Ü", "Ü").trim();
108+
}
109+
public static String convertFromUTF8(String str){
110+
return str.replace("ä", "ä").replace("ö", "ö").replace("ü", "ü").replace("Ä", "Ä").replace("Ö", "Ö").replace("Ü", "Ü").trim();
111+
}
105112

106113
}

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,13 @@ public boolean selectVirtualServerByPort(int port) {
11731173
public boolean selectVirtualServer(VirtualServer server) {
11741174
return selectVirtualServerById(server.getId());
11751175
}
1176-
1176+
/**
1177+
* Sends an offline message to a Client
1178+
* @param clientUId The Unique string
1179+
* @param subject header
1180+
* @param message your message to send
1181+
* @return true if the message was send
1182+
*/
11771183
public boolean sendOfflineMessage(String clientUId, String subject,
11781184
String message) {
11791185
final CMessageAdd add = new CMessageAdd(clientUId, subject, message);
@@ -1182,7 +1188,13 @@ public boolean sendOfflineMessage(String clientUId, String subject,
11821188
}
11831189
return false;
11841190
}
1185-
1191+
/**
1192+
* Sends a TextMessage
1193+
* @param targetMode The targetmode (Server, channel or private)
1194+
* @param targetId The recipient of this message
1195+
* @param message Yout text message to send
1196+
* @return true if the message was send
1197+
*/
11861198
public boolean sendTextMessage(TextMessageTargetMode targetMode,
11871199
int targetId, String message) {
11881200
final CSendTextMessage msg = new CSendTextMessage(
@@ -1192,7 +1204,12 @@ public boolean sendTextMessage(TextMessageTargetMode targetMode,
11921204
}
11931205
return false;
11941206
}
1195-
1207+
/**
1208+
* Sends a ChannelMessage
1209+
* @param channelId The channelID which receive your message
1210+
* @param message Your message which you would send
1211+
* @return true if the message was succesfully send
1212+
*/
11961213
public boolean sendChannelMessage(int channelId, String message) {
11971214
return sendTextMessage(TextMessageTargetMode.CHANNEL, channelId,
11981215
message);

src/main/java/com/github/theholywaffle/teamspeak3/api/event/ChannelPasswordChangedEvent.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,31 @@
1-
package com.github.theholywaffle.teamspeak3.api.event;
1+
package com.github.theholywaffle.teamspeak3.api.event;
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+
229

330
import java.util.HashMap;
431

src/main/java/com/github/theholywaffle/teamspeak3/commands/Command.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,7 @@ public void setAnswered() {
105105
public void setSent() {
106106
sent = true;
107107
}
108-
109-
@Override
108+
110109
public String toString() {
111110
String str = command;
112111
for (final Parameter p : params) {

src/main/java/com/github/theholywaffle/teamspeak3/commands/response/DefaultArrayResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public List<HashMap<String, String>> getArray() {
6767
return array;
6868
}
6969

70-
@Override
7170
public String toString() {
7271
String str = "";
7372
for (final HashMap<String, String> opt : array) {

src/main/java/com/github/theholywaffle/teamspeak3/example/ChatBotExample.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
* #L%
3737
*/
3838

39+
import java.nio.ByteBuffer;
40+
import java.nio.charset.Charset;
3941
import java.util.logging.Level;
4042

4143
import com.github.theholywaffle.teamspeak3.TS3Api;
@@ -63,9 +65,9 @@ public static void main(String[] args) {
6365

6466
public ChatBotExample() {
6567
final TS3Config config = new TS3Config();
66-
config.setHost("77.77.77.77");
68+
config.setHost("188.40.60.18");
6769
config.setDebugLevel(Level.ALL);
68-
config.setLoginCredentials("serveradmin", "serveradminpassword");
70+
config.setLoginCredentials("chronicbot", "phdaHBBD");
6971

7072
final TS3Query query = new TS3Query(config);
7173
query.connect();
@@ -86,6 +88,21 @@ public void onTextMessage(TextMessageEvent e) {
8688
if(e.getMessage().toLowerCase().contains("hello")){
8789
api.sendChannelMessage("Hello "+e.getInvokerName());
8890
}
91+
if(e.getMessage().toLowerCase().contains("!test")){
92+
char a = 'ä';
93+
char o = 'ö';
94+
char u = 'ü';
95+
api.sendChannelMessage("Umlaute: \u00e4 \u00f6 \u00fc \u00c4 \u00d6 \u00dc \u00df");
96+
api.sendChannelMessage("Umlaute: ä ö ü Ä Ö Ü");
97+
api.sendChannelMessage("Umlaute: " + a + " " + o + " " + u);
98+
api.sendChannelMessage(new String("Umlaute: ä ö ü Ä Ö Ü".getBytes(), Charset.forName("UTF8")));
99+
byte[] m = "Umlaute: ä ö ü Ä Ö Ü".getBytes(Charset.forName("UTF8"));
100+
api.sendChannelMessage(m.toString());
101+
//Hallo\s& #228;\s& #246;\s& #252;\s& #223;
102+
api.sendChannelMessage("Umlaute: &#228; &#246; &#252; &#223");
103+
api.sendChannelMessage(Charset.forName("UTF8").decode(ByteBuffer.wrap(m)).toString());
104+
api.sendChannelMessage("äöüÄÖÜ");
105+
}
89106
}
90107
}
91108

0 commit comments

Comments
 (0)