質問編集履歴
3
エラーを貼り付けました
test
CHANGED
File without changes
|
test
CHANGED
@@ -204,26 +204,64 @@
|
|
204
204
|
|
205
205
|
[**YukiKanaConveter.java**](https://github.com/ucchyocean/LunaChat/blob/master/src/main/java/com/github/ucchyocean/lc/japanize/YukiKanaConverter.java)
|
206
206
|
|
207
|
-
|
207
|
+
|
208
|
-
|
209
|
-
|
208
|
+
|
210
|
-
|
211
|
-
System.out.print(result); //ここでは「watasihatukareta」と出力
|
212
|
-
|
213
|
-
|
209
|
+
文字数の都合上**Chat.java**はコードのコピペです。
|
214
|
-
|
210
|
+
|
215
|
-
|
211
|
+
[**Chat.java**](https://pastebin.com/J3b3B7uH)
|
216
|
-
|
212
|
+
|
213
|
+
|
214
|
+
|
217
|
-
|
215
|
+
参考にしたもの:
|
218
|
-
|
216
|
+
|
219
|
-
|
217
|
+
[GitHub](https://github.com/ucchyocean/LunaChat/)
|
218
|
+
|
219
|
+
#エラー
|
220
220
|
|
221
221
|
```
|
222
222
|
|
223
|
-
参考にしたもの:
|
224
|
-
|
225
|
-
[
|
223
|
+
[10:53:09 ERROR]: Could not pass event AsyncPlayerChatEvent to MLSPlugin v1.0-SNAPSHOT
|
226
|
-
|
224
|
+
|
227
|
-
|
225
|
+
org.bukkit.event.EventException: null
|
226
|
+
|
228
|
-
|
227
|
+
at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:72) ~[patched_1.12.2.jar:git-Paper-1613]
|
228
|
+
|
229
|
+
at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:74) ~[patched_1.12.2.jar:git-Paper-1613]
|
230
|
+
|
231
|
+
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[patched_1.12.2.jar:git-Paper-1613]
|
232
|
+
|
233
|
+
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:513) ~[patched_1.12.2.jar:git-Paper-1613]
|
234
|
+
|
229
|
-
|
235
|
+
at net.minecraft.server.v1_12_R1.PlayerConnection.chat(PlayerConnection.java:1393) ~[patched_1.12.2.jar:git-Paper-1613]
|
236
|
+
|
237
|
+
at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1308) ~[patched_1.12.2.jar:git-Paper-1613]
|
238
|
+
|
239
|
+
at net.minecraft.server.v1_12_R1.PacketPlayInChat$1.run(PacketPlayInChat.java:39) ~[patched_1.12.2.jar:git-Paper-1613]
|
240
|
+
|
241
|
+
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_211]
|
242
|
+
|
243
|
+
at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_211]
|
244
|
+
|
245
|
+
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:1.8.0_211]
|
246
|
+
|
247
|
+
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?:1.8.0_211]
|
248
|
+
|
249
|
+
at java.lang.Thread.run(Unknown Source) [?:1.8.0_211]
|
250
|
+
|
251
|
+
Caused by: java.lang.ClassCastException: sun.net.www.protocol.https.HttpsURLConnectionImpl cannot be cast to sun.net.www.protocol.http.HttpURLConnection
|
252
|
+
|
253
|
+
at jp.dip.monsterlifeserver.mlsplugin.mlsplugin.API.honyaku.GoogleIME.conv(GoogleIME.java:41) ~[?:?]
|
254
|
+
|
255
|
+
at jp.dip.monsterlifeserver.mlsplugin.mlsplugin.API.honyaku.GoogleIME.convByGoogleIME(GoogleIME.java:23) ~[?:?]
|
256
|
+
|
257
|
+
at jp.dip.monsterlifeserver.mlsplugin.mlsplugin.Listener.Chat.onChat(Chat.java:56) ~[?:?]
|
258
|
+
|
259
|
+
at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor9.execute(Unknown Source) ~[?:?]
|
260
|
+
|
261
|
+
at org.bukkit.plugin.EventExecutor$2.execute(EventExecutor.java:70) ~[patched_1.12.2.jar:git-Paper-1613]
|
262
|
+
|
263
|
+
... 11 more
|
264
|
+
|
265
|
+
[10:53:09 INFO]: <Monster2408> test
|
266
|
+
|
267
|
+
```
|
2
#うまく動作しないところ【追記1】の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,220 +10,220 @@
|
|
10
10
|
|
11
11
|
原因がわかる方はいますか?(変換部分はMinecraft とは互換性はないと思います。
|
12
12
|
|
13
|
+
#書いたコード
|
14
|
+
|
15
|
+
**GoogleIME.java**
|
16
|
+
|
17
|
+
```Java
|
18
|
+
|
19
|
+
package jp.dip.monsterlifeserver.mlsplugin.mlsplugin.API.honyaku;
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
import com.google.common.io.CharStreams;
|
24
|
+
|
25
|
+
import com.google.gson.Gson;
|
26
|
+
|
27
|
+
import com.google.gson.JsonArray;
|
28
|
+
|
29
|
+
import com.google.gson.JsonElement;
|
30
|
+
|
31
|
+
import sun.net.www.protocol.http.HttpURLConnection;
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
import java.io.BufferedReader;
|
36
|
+
|
37
|
+
import java.io.IOException;
|
38
|
+
|
39
|
+
import java.io.InputStreamReader;
|
40
|
+
|
41
|
+
import java.net.MalformedURLException;
|
42
|
+
|
43
|
+
import java.net.ProtocolException;
|
44
|
+
|
45
|
+
import java.net.URL;
|
46
|
+
|
47
|
+
import java.net.URLEncoder;
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
public class GoogleIME {
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
private static final String GOOGLE_IME_URL =
|
56
|
+
|
57
|
+
"https://www.google.com/transliterate?langpair=ja-Hira|ja&text=";
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
public static String convByGoogleIME(String org) {
|
62
|
+
|
63
|
+
return conv(org);
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
// 変換の実行
|
70
|
+
|
71
|
+
private static String conv(String org) {
|
72
|
+
|
73
|
+
if ( org.length() == 0 ) {
|
74
|
+
|
75
|
+
return "";
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
HttpURLConnection urlconn = null;
|
82
|
+
|
83
|
+
BufferedReader reader = null;
|
84
|
+
|
85
|
+
try {
|
86
|
+
|
87
|
+
String baseurl;
|
88
|
+
|
89
|
+
String encode = "UTF-8";
|
90
|
+
|
91
|
+
baseurl = GOOGLE_IME_URL + URLEncoder.encode(org , "UTF-8");
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
URL url = new URL(baseurl);
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
urlconn = (HttpURLConnection)url.openConnection();
|
100
|
+
|
101
|
+
urlconn.setRequestMethod("GET");
|
102
|
+
|
103
|
+
urlconn.setInstanceFollowRedirects(false);
|
104
|
+
|
105
|
+
urlconn.connect();
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
reader = new BufferedReader(
|
110
|
+
|
111
|
+
new InputStreamReader(urlconn.getInputStream(), encode));
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
String json = CharStreams.toString(reader);
|
116
|
+
|
117
|
+
String parsed = GoogleIME.parseJson(json);
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
return parsed;
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
} catch (MalformedURLException e) {
|
126
|
+
|
127
|
+
e.printStackTrace();
|
128
|
+
|
129
|
+
} catch (ProtocolException e) {
|
130
|
+
|
131
|
+
e.printStackTrace();
|
132
|
+
|
133
|
+
} catch (IOException e) {
|
134
|
+
|
135
|
+
e.printStackTrace();
|
136
|
+
|
137
|
+
} finally {
|
138
|
+
|
139
|
+
if ( urlconn != null ) {
|
140
|
+
|
141
|
+
urlconn.disconnect();
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
if ( reader != null ) {
|
146
|
+
|
147
|
+
try {
|
148
|
+
|
149
|
+
reader.close();
|
150
|
+
|
151
|
+
} catch (IOException e) { // do nothing.
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
return "";
|
162
|
+
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
// デバッグ用エントリ
|
168
|
+
|
169
|
+
/**
|
170
|
+
|
171
|
+
* GoogleIMEの最初の変換候補を抽出して結合します
|
172
|
+
|
173
|
+
*
|
174
|
+
|
175
|
+
* @param json 変換元のJson形式の文字列
|
176
|
+
|
177
|
+
* @return 変換後の文字列
|
178
|
+
|
179
|
+
* @since 2.8.10
|
180
|
+
|
181
|
+
*/
|
182
|
+
|
183
|
+
public static String parseJson(String json) {
|
184
|
+
|
185
|
+
StringBuilder result = new StringBuilder();
|
186
|
+
|
187
|
+
for (JsonElement response : new Gson().fromJson(json, JsonArray.class)) {
|
188
|
+
|
189
|
+
result.append(response.getAsJsonArray().get(1).getAsJsonArray().get(0).getAsString());
|
190
|
+
|
191
|
+
}
|
192
|
+
|
193
|
+
return result.toString();
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
```
|
202
|
+
|
203
|
+
文字数の都合上**YukiKanaConveter.java**は参考にしたGitHubのリンクとする(コピペなので中身はまったく同じです)
|
204
|
+
|
205
|
+
[**YukiKanaConveter.java**](https://github.com/ucchyocean/LunaChat/blob/master/src/main/java/com/github/ucchyocean/lc/japanize/YukiKanaConverter.java)
|
206
|
+
|
207
|
+
```Java
|
208
|
+
|
209
|
+
String result = "watasihatukareta";
|
210
|
+
|
211
|
+
System.out.print(result); //ここでは「watasihatukareta」と出力
|
212
|
+
|
213
|
+
result = YukiKanaConverter.conv(result);
|
214
|
+
|
215
|
+
System.out.print(result); //ここでは「わたしはつかれた」と出力←ここまでは動作済み
|
216
|
+
|
217
|
+
result = GoogleIME.convByGoogleIME(result);
|
218
|
+
|
219
|
+
System.out.print(result); //ここでは「私は疲れた」と出力←ここが失敗
|
220
|
+
|
221
|
+
```
|
222
|
+
|
223
|
+
参考にしたもの:
|
224
|
+
|
225
|
+
[GitHub](https://github.com/ucchyocean/LunaChat/)
|
226
|
+
|
13
|
-
#うまく動作しないところ
|
227
|
+
#うまく動作しないところ【追記1】
|
14
228
|
|
15
229
|
`urlconn = (HttpURLConnection)url.openConnection();`部分でnullエラーが出て、`System.out.print(result); //ここでは「私は疲れた」と出力←ここが失敗`が出力されない。
|
16
|
-
|
17
|
-
#書いたコード
|
18
|
-
|
19
|
-
**GoogleIME.java**
|
20
|
-
|
21
|
-
```Java
|
22
|
-
|
23
|
-
package jp.dip.monsterlifeserver.mlsplugin.mlsplugin.API.honyaku;
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
import com.google.common.io.CharStreams;
|
28
|
-
|
29
|
-
import com.google.gson.Gson;
|
30
|
-
|
31
|
-
import com.google.gson.JsonArray;
|
32
|
-
|
33
|
-
import com.google.gson.JsonElement;
|
34
|
-
|
35
|
-
import sun.net.www.protocol.http.HttpURLConnection;
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
import java.io.BufferedReader;
|
40
|
-
|
41
|
-
import java.io.IOException;
|
42
|
-
|
43
|
-
import java.io.InputStreamReader;
|
44
|
-
|
45
|
-
import java.net.MalformedURLException;
|
46
|
-
|
47
|
-
import java.net.ProtocolException;
|
48
|
-
|
49
|
-
import java.net.URL;
|
50
|
-
|
51
|
-
import java.net.URLEncoder;
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
public class GoogleIME {
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
private static final String GOOGLE_IME_URL =
|
60
|
-
|
61
|
-
"https://www.google.com/transliterate?langpair=ja-Hira|ja&text=";
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
public static String convByGoogleIME(String org) {
|
66
|
-
|
67
|
-
return conv(org);
|
68
|
-
|
69
|
-
}
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
// 変換の実行
|
74
|
-
|
75
|
-
private static String conv(String org) {
|
76
|
-
|
77
|
-
if ( org.length() == 0 ) {
|
78
|
-
|
79
|
-
return "";
|
80
|
-
|
81
|
-
}
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
HttpURLConnection urlconn = null;
|
86
|
-
|
87
|
-
BufferedReader reader = null;
|
88
|
-
|
89
|
-
try {
|
90
|
-
|
91
|
-
String baseurl;
|
92
|
-
|
93
|
-
String encode = "UTF-8";
|
94
|
-
|
95
|
-
baseurl = GOOGLE_IME_URL + URLEncoder.encode(org , "UTF-8");
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
URL url = new URL(baseurl);
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
urlconn = (HttpURLConnection)url.openConnection();
|
104
|
-
|
105
|
-
urlconn.setRequestMethod("GET");
|
106
|
-
|
107
|
-
urlconn.setInstanceFollowRedirects(false);
|
108
|
-
|
109
|
-
urlconn.connect();
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
reader = new BufferedReader(
|
114
|
-
|
115
|
-
new InputStreamReader(urlconn.getInputStream(), encode));
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
String json = CharStreams.toString(reader);
|
120
|
-
|
121
|
-
String parsed = GoogleIME.parseJson(json);
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
return parsed;
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
} catch (MalformedURLException e) {
|
130
|
-
|
131
|
-
e.printStackTrace();
|
132
|
-
|
133
|
-
} catch (ProtocolException e) {
|
134
|
-
|
135
|
-
e.printStackTrace();
|
136
|
-
|
137
|
-
} catch (IOException e) {
|
138
|
-
|
139
|
-
e.printStackTrace();
|
140
|
-
|
141
|
-
} finally {
|
142
|
-
|
143
|
-
if ( urlconn != null ) {
|
144
|
-
|
145
|
-
urlconn.disconnect();
|
146
|
-
|
147
|
-
}
|
148
|
-
|
149
|
-
if ( reader != null ) {
|
150
|
-
|
151
|
-
try {
|
152
|
-
|
153
|
-
reader.close();
|
154
|
-
|
155
|
-
} catch (IOException e) { // do nothing.
|
156
|
-
|
157
|
-
}
|
158
|
-
|
159
|
-
}
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
return "";
|
166
|
-
|
167
|
-
}
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
// デバッグ用エントリ
|
172
|
-
|
173
|
-
/**
|
174
|
-
|
175
|
-
* GoogleIMEの最初の変換候補を抽出して結合します
|
176
|
-
|
177
|
-
*
|
178
|
-
|
179
|
-
* @param json 変換元のJson形式の文字列
|
180
|
-
|
181
|
-
* @return 変換後の文字列
|
182
|
-
|
183
|
-
* @since 2.8.10
|
184
|
-
|
185
|
-
*/
|
186
|
-
|
187
|
-
public static String parseJson(String json) {
|
188
|
-
|
189
|
-
StringBuilder result = new StringBuilder();
|
190
|
-
|
191
|
-
for (JsonElement response : new Gson().fromJson(json, JsonArray.class)) {
|
192
|
-
|
193
|
-
result.append(response.getAsJsonArray().get(1).getAsJsonArray().get(0).getAsString());
|
194
|
-
|
195
|
-
}
|
196
|
-
|
197
|
-
return result.toString();
|
198
|
-
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
}
|
204
|
-
|
205
|
-
```
|
206
|
-
|
207
|
-
文字数の都合上**YukiKanaConveter.java**は参考にしたGitHubのリンクとする(コピペなので中身はまったく同じです)
|
208
|
-
|
209
|
-
[**YukiKanaConveter.java**](https://github.com/ucchyocean/LunaChat/blob/master/src/main/java/com/github/ucchyocean/lc/japanize/YukiKanaConverter.java)
|
210
|
-
|
211
|
-
```Java
|
212
|
-
|
213
|
-
String result = "watasihatukareta";
|
214
|
-
|
215
|
-
System.out.print(result); //ここでは「watasihatukareta」と出力
|
216
|
-
|
217
|
-
result = YukiKanaConverter.conv(result);
|
218
|
-
|
219
|
-
System.out.print(result); //ここでは「わたしはつかれた」と出力←ここまでは動作済み
|
220
|
-
|
221
|
-
result = GoogleIME.convByGoogleIME(result);
|
222
|
-
|
223
|
-
System.out.print(result); //ここでは「私は疲れた」と出力←ここが失敗
|
224
|
-
|
225
|
-
```
|
226
|
-
|
227
|
-
参考にしたもの:
|
228
|
-
|
229
|
-
[GitHub](https://github.com/ucchyocean/LunaChat/)
|
1
うまく動作しないところの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,6 +10,10 @@
|
|
10
10
|
|
11
11
|
原因がわかる方はいますか?(変換部分はMinecraft とは互換性はないと思います。
|
12
12
|
|
13
|
+
#うまく動作しないところ
|
14
|
+
|
15
|
+
`urlconn = (HttpURLConnection)url.openConnection();`部分でnullエラーが出て、`System.out.print(result); //ここでは「私は疲れた」と出力←ここが失敗`が出力されない。
|
16
|
+
|
13
17
|
#書いたコード
|
14
18
|
|
15
19
|
**GoogleIME.java**
|