LunaChat v2.0.0 : Issue #23 (wip. There are still compile errors.)
このコミットが含まれているのは:
1 親
b4ef7c0733
コミット
c8f33a7cd5
5ファイル変更
+164
-5
検索条件に一致するファイルはありません
@@ -25,6 +25,7 @@ import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
|
||||
import com.github.ucchyocean.lc.event.LunaChatChannelChatEvent;
|
||||
import com.github.ucchyocean.lc.event.LunaChatChannelMemberChangedEvent;
|
||||
import com.github.ucchyocean.lc.japanize.KanaConverter;
|
||||
|
||||
/**
|
||||
* @author ucchy
|
||||
|
||||
@@ -15,6 +15,8 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import com.github.ucchyocean.lc.japanize.KanaConverter;
|
||||
|
||||
/**
|
||||
* @author ucchy
|
||||
* プレイヤーの行動を監視するリスナ
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license GPLv3
|
||||
* @copyright Copyright ucchy 2013
|
||||
*/
|
||||
package com.github.ucchyocean.lc.japanize;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* @author ucchy
|
||||
*/
|
||||
public class IMEConverter {
|
||||
|
||||
private static final String SOCIAL_IME_URL =
|
||||
"http://www.social-ime.com/api/?string=";
|
||||
private static final String GOOGLE_IME_URL =
|
||||
"http://www.google.com/transliterate?langpair=ja-Hira|ja&text=";
|
||||
|
||||
protected static String convByGoogleIME(String org) {
|
||||
return conv(org, true);
|
||||
}
|
||||
|
||||
protected static String convBySocialIME(String org) {
|
||||
return conv(org, false);
|
||||
}
|
||||
|
||||
private static String conv(String org, boolean isGoogleIME) {
|
||||
|
||||
HttpURLConnection urlconn = null;
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
String baseurl;
|
||||
String encode;
|
||||
if ( isGoogleIME ) {
|
||||
baseurl = GOOGLE_IME_URL + org;
|
||||
encode = "UTF8";
|
||||
} else {
|
||||
baseurl = SOCIAL_IME_URL + org;
|
||||
encode = "EUC_JP";
|
||||
}
|
||||
URL url = new URL(baseurl);
|
||||
|
||||
urlconn = (HttpURLConnection)url.openConnection();
|
||||
urlconn.setRequestMethod("GET");
|
||||
urlconn.setInstanceFollowRedirects(false);
|
||||
urlconn.connect();
|
||||
|
||||
reader = new BufferedReader(
|
||||
new InputStreamReader(urlconn.getInputStream(), encode));
|
||||
String line = "";
|
||||
StringBuilder result = new StringBuilder();
|
||||
while ( (line = reader.readLine()) != null ) {
|
||||
if ( isGoogleIME ) {
|
||||
result.append(parseGoogleIMEResult(line));
|
||||
} else {
|
||||
result.append(pickFirstElement(line));
|
||||
}
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ProtocolException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if ( urlconn != null ) {
|
||||
urlconn.disconnect();
|
||||
}
|
||||
if ( reader != null ) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) { // do nothing.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String pickFirstElement(String org) {
|
||||
int index = org.indexOf("\t");
|
||||
if ( index == -1 ) {
|
||||
return org;
|
||||
} else {
|
||||
return org.substring(0, index);
|
||||
}
|
||||
}
|
||||
|
||||
private static String parseGoogleIMEResult(String result) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
int level = 0;
|
||||
int index = 0;
|
||||
while ( index < result.length() ) {
|
||||
if ( level < 3 ) {
|
||||
int nextStart = result.indexOf("[", index);
|
||||
int nextEnd = result.indexOf("]", index);
|
||||
if ( nextStart == -1 ) {
|
||||
return buf.toString();
|
||||
} else {
|
||||
if ( nextStart < nextEnd ) {
|
||||
level++;
|
||||
index = nextStart+1;
|
||||
} else {
|
||||
level--;
|
||||
index = nextEnd+1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int start = result.indexOf("\"", index);
|
||||
int end = result.indexOf("\"", start+1);
|
||||
if ( start == -1 || end == -1 ) {
|
||||
return buf.toString();
|
||||
}
|
||||
buf.append(result.substring(start+1, end));
|
||||
int next = result.indexOf("]", end);
|
||||
if ( next == -1 ) {
|
||||
return buf.toString();
|
||||
} else {
|
||||
level--;
|
||||
index = next+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.github.ucchyocean.lc.japanize;
|
||||
|
||||
public enum JapanizeType {
|
||||
|
||||
NONE,
|
||||
|
||||
KANA,
|
||||
|
||||
GOOGLE_IME,
|
||||
|
||||
SOCIAL_IME;
|
||||
}
|
||||
+13
-5
@@ -3,7 +3,7 @@
|
||||
* @license GPLv3
|
||||
* @copyright Copyright ucchy 2013
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
package com.github.ucchyocean.lc.japanize;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -103,16 +103,24 @@ public class KanaConverter {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ( java.lang.Character.isLetter(tmp.charAt(0)) ) {
|
||||
if ( last.equals(tmp) ) {
|
||||
if ( Character.isLetter(tmp.charAt(0)) ) {
|
||||
if ( Character.isUpperCase(tmp.charAt(0)) ) {
|
||||
line.append(last + tmp);
|
||||
last = "";
|
||||
} else if ( last.equals(tmp) ) {
|
||||
line.append("っ");
|
||||
last = tmp;
|
||||
} else {
|
||||
last = last + tmp;
|
||||
}
|
||||
} else {
|
||||
line.append(last + tmp);
|
||||
last = "";
|
||||
if ( tmp.equals("-") ) {
|
||||
line.append(last + "ー");
|
||||
last = "";
|
||||
} else {
|
||||
line.append(last + tmp);
|
||||
last = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする