LunaChat v1.2.0 : Refactored.

Removed strip following whitespace from each lines.
Changed encoding UTF8 -> UTF8N.
このコミットが含まれているのは:
ucchyocean committed 2013-04-24 11:30:04 +09:00
1 親 71db840611
コミット 8492e6e486
10ファイル変更
+2349 -2348

検索条件に一致するファイルはありません

+268 -268
ファイルの表示
@@ -1,268 +1,268 @@
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
/**
* @author ucchy
* チャンネル
*/
public class Channel {
private static final String INFO_FIRSTLINE = Resources.get("channelInfoFirstLine");
private static final String INFO_PREFIX = Resources.get("channelInfoPrefix");
private static final String LIST_ENDLINE = Resources.get("listEndLine");
private static final String LIST_FORMAT = Resources.get("listFormat");
private static final String DEFAULT_FORMAT = Resources.get("defaultFormat");
private static final String MSG_JOIN = Resources.get("joinMessage");
private static final String MSG_QUIT = Resources.get("quitMessage");
/** 参加者 */
protected List<String> members;
/** チャンネルモデレータ */
protected List<String> moderator;
/** BANされたプレイヤー */
protected List<String> banned;
/** チャンネルの名称 */
protected String name;
/** チャンネルの説明文 */
protected String description;
/** チャンネルのパスワード */
protected String password;
/** チャンネルリストに表示されるかどうか */
protected boolean visible;
/** メッセージフォーマット<br>
* 指定可能なキーワードは下記のとおり<br>
* %ch - チャンネル名<br>
* %username - ユーザー名<br>
* %msg - メッセージ
* */
protected String format;
/**
* コンストラクタ
* @param name チャンネルの名称
* @param description チャンネルの説明文
*/
protected Channel(String name, String description) {
this(name, description, new ArrayList<String>());
}
/**
* コンストラクタ
* @param name チャンネルの名称
* @param description チャンネルの説明文
* @param members 参加者
*/
protected Channel(String name, String description, List<String> members) {
this.name = name;
this.description = description;
this.members = members;
this.format = DEFAULT_FORMAT;
this.banned = new ArrayList<String>();
this.moderator = new ArrayList<String>();
this.password = "";
this.visible = true;
}
/**
* このチャットに発言をする
* @param player 発言をするプレイヤー
* @param message 発言をするメッセージ
*/
protected void chat(Player player, String message) {
// Japanize変換
if ( LunaChat.config.displayJapanize ) {
// 2byteコードを含まない場合にのみ、処理を行う
if ( message.getBytes().length == message.length() ) {
String kana = KanaConverter.conv(message);
message = message + "(" + kana + ")";
}
}
String msg = format.replace("%ch", name);
msg = msg.replace("%username", player.getDisplayName());
msg = msg.replace("%msg", message);
msg = Utility.replaceColorCode(msg);
// オンラインのプレイヤーに送信する
for ( String member : members ) {
Player p = LunaChat.getPlayerExact(member);
if ( p != null ) {
p.sendMessage(msg);
}
}
// ロギング
if ( LunaChat.config.loggingChat ) {
LunaChat.log(msg);
}
}
/**
* メンバーを追加する
* @param name 追加するメンバー名
*/
protected void addMember(String name) {
if ( members.size() == 0 ) {
moderator.add(name);
}
if ( !members.contains(name) ) {
members.add(name);
sendJoinQuitMessage(true, name);
LunaChat.manager.save();
}
}
/**
* メンバーを削除する
* @param name 削除するメンバー名
*/
protected void removeMember(String name) {
// デフォルト発言先が退出するチャンネルと一致する場合、
// デフォルト発言先を削除する
String def = LunaChat.manager.getDefault(name);
if ( def != null && def.equals(this.name) ) {
LunaChat.manager.removeDefault(name);
}
// 実際にメンバーから削除する
if ( members.contains(name) ) {
members.remove(name);
sendJoinQuitMessage(false, name);
if ( LunaChat.config.zeroMemberRemove && members.size() <= 0 ) {
LunaChat.manager.removeChannel(this.name);
return;
} else {
LunaChat.manager.save();
}
}
// モデレーターだった場合は、モデレーターから除去する
if ( moderator.contains(name) ) {
moderator.remove(name);
}
}
/**
* 入退室メッセージを流す
* @param isJoin 入室かどうか(falseなら退室)
* @param player 入退室したプレイヤー名
*/
protected void sendJoinQuitMessage(boolean isJoin, String player) {
String msg;
if ( isJoin ) {
msg = MSG_JOIN;
} else {
msg = MSG_QUIT;
}
msg = msg.replace("%ch", name);
msg = msg.replace("%username", player);
msg = Utility.replaceColorCode(msg);
sendInformation(msg);
}
/**
* 情報をチャンネルメンバーに流します。
* @param message メッセージ
*/
private void sendInformation(String message) {
// オンラインのプレイヤーに送信する
for ( String member : members ) {
Player p = LunaChat.getPlayerExact(member);
if ( p != null ) {
p.sendMessage(message);
}
}
// ロギング
if ( LunaChat.config.loggingChat ) {
LunaChat.log(message);
}
}
/**
* チャンネル情報を返す
* @return チャンネル情報
*/
protected ArrayList<String> getInfo() {
ArrayList<String> info = new ArrayList<String>();
info.add(Utility.replaceColorCode(INFO_FIRSTLINE));
// メンバーの人数を数える
int onlineNum = 0;
for ( String pname : members ) {
if ( isOnline(pname) ) {
onlineNum++;
}
}
int memberNum = members.size();
info.add( String.format(
Utility.replaceColorCode(LIST_FORMAT),
name, onlineNum, memberNum, description) );
// メンバーを、5人ごとに表示する
StringBuffer buf = new StringBuffer();
for ( int i=0; i<members.size(); i++ ) {
if ( i%5 == 0 ) {
if ( i != 0 ) {
info.add(buf.toString());
buf = new StringBuffer();
}
buf.append(Utility.replaceColorCode(INFO_PREFIX));
}
String name = members.get(i);
String disp;
if ( moderator.contains(name) ) {
name = "@" + name;
}
if ( isOnline(members.get(i)) ) {
disp = ChatColor.WHITE + name;
} else {
disp = ChatColor.GRAY + name;
}
buf.append(disp + ",");
}
info.add(buf.toString());
info.add(Utility.replaceColorCode(LIST_ENDLINE));
return info;
}
/**
* 指定された名前のプレイヤーがオンラインかどうかを確認する
* @param name プレイヤー名
* @return オンラインかどうか
*/
private boolean isOnline(String name) {
Player p = LunaChat.getPlayerExact(name);
return ( p != null && p.isOnline() );
}
}
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
/**
* @author ucchy
* チャンネル
*/
public class Channel {
private static final String INFO_FIRSTLINE = Resources.get("channelInfoFirstLine");
private static final String INFO_PREFIX = Resources.get("channelInfoPrefix");
private static final String LIST_ENDLINE = Resources.get("listEndLine");
private static final String LIST_FORMAT = Resources.get("listFormat");
private static final String DEFAULT_FORMAT = Resources.get("defaultFormat");
private static final String MSG_JOIN = Resources.get("joinMessage");
private static final String MSG_QUIT = Resources.get("quitMessage");
/** 参加者 */
protected List<String> members;
/** チャンネルモデレータ */
protected List<String> moderator;
/** BANされたプレイヤー */
protected List<String> banned;
/** チャンネルの名称 */
protected String name;
/** チャンネルの説明文 */
protected String description;
/** チャンネルのパスワード */
protected String password;
/** チャンネルリストに表示されるかどうか */
protected boolean visible;
/** メッセージフォーマット<br>
* 指定可能なキーワードは下記のとおり<br>
* %ch - チャンネル名<br>
* %username - ユーザー名<br>
* %msg - メッセージ
* */
protected String format;
/**
* コンストラクタ
* @param name チャンネルの名称
* @param description チャンネルの説明文
*/
protected Channel(String name, String description) {
this(name, description, new ArrayList<String>());
}
/**
* コンストラクタ
* @param name チャンネルの名称
* @param description チャンネルの説明文
* @param members 参加者
*/
protected Channel(String name, String description, List<String> members) {
this.name = name;
this.description = description;
this.members = members;
this.format = DEFAULT_FORMAT;
this.banned = new ArrayList<String>();
this.moderator = new ArrayList<String>();
this.password = "";
this.visible = true;
}
/**
* このチャットに発言をする
* @param player 発言をするプレイヤー
* @param message 発言をするメッセージ
*/
protected void chat(Player player, String message) {
// Japanize変換
if ( LunaChat.config.displayJapanize ) {
// 2byteコードを含まない場合にのみ、処理を行う
if ( message.getBytes().length == message.length() ) {
String kana = KanaConverter.conv(message);
message = message + "(" + kana + ")";
}
}
String msg = format.replace("%ch", name);
msg = msg.replace("%username", player.getDisplayName());
msg = msg.replace("%msg", message);
msg = Utility.replaceColorCode(msg);
// オンラインのプレイヤーに送信する
for ( String member : members ) {
Player p = LunaChat.getPlayerExact(member);
if ( p != null ) {
p.sendMessage(msg);
}
}
// ロギング
if ( LunaChat.config.loggingChat ) {
LunaChat.log(msg);
}
}
/**
* メンバーを追加する
* @param name 追加するメンバー名
*/
protected void addMember(String name) {
if ( members.size() == 0 ) {
moderator.add(name);
}
if ( !members.contains(name) ) {
members.add(name);
sendJoinQuitMessage(true, name);
LunaChat.manager.save();
}
}
/**
* メンバーを削除する
* @param name 削除するメンバー名
*/
protected void removeMember(String name) {
// デフォルト発言先が退出するチャンネルと一致する場合、
// デフォルト発言先を削除する
String def = LunaChat.manager.getDefault(name);
if ( def != null && def.equals(this.name) ) {
LunaChat.manager.removeDefault(name);
}
// 実際にメンバーから削除する
if ( members.contains(name) ) {
members.remove(name);
sendJoinQuitMessage(false, name);
if ( LunaChat.config.zeroMemberRemove && members.size() <= 0 ) {
LunaChat.manager.removeChannel(this.name);
return;
} else {
LunaChat.manager.save();
}
}
// モデレーターだった場合は、モデレーターから除去する
if ( moderator.contains(name) ) {
moderator.remove(name);
}
}
/**
* 入退室メッセージを流す
* @param isJoin 入室かどうか(falseなら退室)
* @param player 入退室したプレイヤー名
*/
protected void sendJoinQuitMessage(boolean isJoin, String player) {
String msg;
if ( isJoin ) {
msg = MSG_JOIN;
} else {
msg = MSG_QUIT;
}
msg = msg.replace("%ch", name);
msg = msg.replace("%username", player);
msg = Utility.replaceColorCode(msg);
sendInformation(msg);
}
/**
* 情報をチャンネルメンバーに流します。
* @param message メッセージ
*/
private void sendInformation(String message) {
// オンラインのプレイヤーに送信する
for ( String member : members ) {
Player p = LunaChat.getPlayerExact(member);
if ( p != null ) {
p.sendMessage(message);
}
}
// ロギング
if ( LunaChat.config.loggingChat ) {
LunaChat.log(message);
}
}
/**
* チャンネル情報を返す
* @return チャンネル情報
*/
protected ArrayList<String> getInfo() {
ArrayList<String> info = new ArrayList<String>();
info.add(Utility.replaceColorCode(INFO_FIRSTLINE));
// メンバーの人数を数える
int onlineNum = 0;
for ( String pname : members ) {
if ( isOnline(pname) ) {
onlineNum++;
}
}
int memberNum = members.size();
info.add( String.format(
Utility.replaceColorCode(LIST_FORMAT),
name, onlineNum, memberNum, description) );
// メンバーを、5人ごとに表示する
StringBuffer buf = new StringBuffer();
for ( int i=0; i<members.size(); i++ ) {
if ( i%5 == 0 ) {
if ( i != 0 ) {
info.add(buf.toString());
buf = new StringBuffer();
}
buf.append(Utility.replaceColorCode(INFO_PREFIX));
}
String name = members.get(i);
String disp;
if ( moderator.contains(name) ) {
name = "@" + name;
}
if ( isOnline(members.get(i)) ) {
disp = ChatColor.WHITE + name;
} else {
disp = ChatColor.GRAY + name;
}
buf.append(disp + ",");
}
info.add(buf.toString());
info.add(Utility.replaceColorCode(LIST_ENDLINE));
return info;
}
/**
* 指定された名前のプレイヤーがオンラインかどうかを確認する
* @param name プレイヤー名
* @return オンラインかどうか
*/
private boolean isOnline(String name) {
Player p = LunaChat.getPlayerExact(name);
return ( p != null && p.isOnline() );
}
}
+399 -399
ファイルの表示
@@ -1,399 +1,399 @@
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
/**
* @author ucchy
* チャンネルマネージャー
*/
public class ChannelManager {
private static final String LIST_FIRSTLINE = Resources.get("listFirstLine");
private static final String LIST_ENDLINE = Resources.get("listEndLine");
private static final String LIST_FORMAT = Resources.get("listFormat");
private static final String MOTD_FIRSTLINE = Resources.get("motdFirstLine");
private static final String DEFAULT_FORMAT = Resources.get("defaultFormat");
private static final String FILE_NAME = "channels.yml";
private static final String KEY_DESC = "desc";
private static final String KEY_FORMAT = "format";
private static final String KEY_MEMBERS = "members";
private static final String KEY_BANNED = "banned";
private static final String KEY_MODERATOR = "moderator";
private static final String KEY_PASSWORD = "password";
private static final String KEY_VISIBLE = "visible";
private File file;
private HashMap<String, Channel> channels;
private HashMap<String, String> defaultChannels;
/**
* コンストラクタ
*/
public ChannelManager() {
load();
}
/**
* 読み込みする
*/
private void load() {
file = new File(
LunaChat.instance.getDataFolder() +
File.separator + FILE_NAME);
if ( !file.exists() ) {
YamlConfiguration conf = new YamlConfiguration();
try {
conf.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
YamlConfiguration config =
YamlConfiguration.loadConfiguration(file);
// チャンネル設定のロード
if ( channels == null ) {
channels = new HashMap<String, Channel>();
} else {
channels.clear();
}
if ( config.contains("channels") ) {
ConfigurationSection section = config.getConfigurationSection("channels");
Set<String> keyset = section.getValues(false).keySet();
for ( String key : keyset ) {
ConfigurationSection sec = section.getConfigurationSection(key);
Channel channel = getChannelFromSection(sec);
channels.put(key, channel);
}
}
// デフォルト設定のロード
if ( defaultChannels == null ) {
defaultChannels = new HashMap<String, String>();
} else {
defaultChannels.clear();
}
if ( config.contains("defaults") ) {
ConfigurationSection section = config.getConfigurationSection("defaults");
Set<String> keyset = section.getValues(false).keySet();
for ( String key : keyset ) {
defaultChannels.put(key, section.getString(key));
}
}
}
/**
* セクションからChannelクラスを生成して返す
* @param section セクション
* @return Channel
*/
private Channel getChannelFromSection(ConfigurationSection section) {
String name = section.getName();
String desc = section.getString(KEY_DESC, "");
String format = section.getString(KEY_FORMAT, DEFAULT_FORMAT);
List<String> members = section.getStringList(KEY_MEMBERS);
List<String> banned = section.getStringList(KEY_BANNED);
List<String> moderator = section.getStringList(KEY_MODERATOR);
String password = section.getString(KEY_PASSWORD, "");
boolean visible = section.getBoolean(KEY_VISIBLE, true);
if ( members == null ) {
members = new ArrayList<String>();
}
Channel channel = new Channel(name, desc, members);
channel.format = format;
channel.banned = banned;
channel.moderator = moderator;
channel.password = password;
channel.visible = visible;
return channel;
}
/**
* 保存する
*/
protected boolean save() {
try {
YamlConfiguration config =
YamlConfiguration.loadConfiguration(file);
for ( String key : channels.keySet() ) {
Channel channel = channels.get(key);
config.set("channels." + key + "." + KEY_DESC, channel.description);
config.set("channels." + key + "." + KEY_FORMAT, channel.format);
config.set("channels." + key + "." + KEY_MEMBERS, channel.members);
config.set("channels." + key + "." + KEY_BANNED, channel.banned);
config.set("channels." + key + "." + KEY_MODERATOR, channel.moderator);
config.set("channels." + key + "." + KEY_PASSWORD, channel.password);
config.set("channels." + key + "." + KEY_VISIBLE, channel.visible);
}
for ( String key : defaultChannels.keySet() ) {
config.set("defaults." + key, defaultChannels.get(key));
}
config.save(file);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
/**
* チャンネルをアップデートする
* @param channel
*/
protected void updateChannel(Channel channel) {
String key = channel.name;
channels.put(key, channel);
save();
}
/**
* チャンネルの名前リストを返す
* @return チャンネルの名前
*/
protected ArrayList<String> getNames() {
ArrayList<String> names = new ArrayList<String>();
for ( String k : channels.keySet() ) {
names.add(k);
}
return names;
}
/**
* リスト表示用のリストを返す
* @param player プレイヤー、指定しない場合はnullにする
* @return リスト
*/
protected ArrayList<String> getList(Player player) {
ArrayList<String> items = new ArrayList<String>();
String dchannel = "";
String playerName = "";
if ( player != null ) {
playerName = player.getName();
dchannel = defaultChannels.get(player.getName());
if ( dchannel == null ) {
dchannel = "";
}
}
items.add(Utility.replaceColorCode(LIST_FIRSTLINE));
for ( String key : channels.keySet() ) {
Channel channel = channels.get(key);
// BANされているチャンネルは表示しない
if ( channel.banned.contains(playerName) ) {
continue;
}
// visible=false のチャンネルは表示しない
if ( !channel.visible ) {
continue;
}
String disp = ChatColor.WHITE + key;
if ( key.equals(dchannel) ) {
disp = ChatColor.RED + key;
}
if ( player != null && !channel.members.contains(playerName) ) {
disp = ChatColor.GRAY + key;
}
String desc = channel.description;
int onlineNum = 0;
for ( String pname : channel.members ) {
Player p = LunaChat.getPlayerExact(pname);
if ( p != null && p.isOnline() ) {
onlineNum++;
}
}
int memberNum = channel.members.size();
String item = String.format(
Utility.replaceColorCode(LIST_FORMAT),
disp, onlineNum, memberNum, desc);
items.add(item);
}
items.add(Utility.replaceColorCode(LIST_ENDLINE));
return items;
}
/**
* プレイヤーのサーバー参加時用の参加チャンネルリストを返す
* @param player プレイヤー
* @return リスト
*/
protected ArrayList<String> getListForMotd(Player player) {
ArrayList<String> items = new ArrayList<String>();
String playerName = player.getName();
String dchannel = defaultChannels.get(player.getName());
if ( dchannel == null ) {
dchannel = "";
}
items.add(Utility.replaceColorCode(MOTD_FIRSTLINE));
for ( String key : channels.keySet() ) {
Channel channel = channels.get(key);
if ( !channel.members.contains(playerName) ) {
continue;
}
String disp = ChatColor.WHITE + key;
if ( key.equals(dchannel) ) {
disp = ChatColor.RED + key;
}
String desc = channel.description;
int onlineNum = 0;
for ( String pname : channel.members ) {
Player p = LunaChat.getPlayerExact(pname);
if ( p != null && p.isOnline() ) {
onlineNum++;
}
}
int memberNum = channel.members.size();
String item = String.format(
Utility.replaceColorCode(LIST_FORMAT),
disp, onlineNum, memberNum, desc);
items.add(item);
}
items.add(Utility.replaceColorCode(LIST_ENDLINE));
return items;
}
/**
* プレイヤーが参加しているチャンネルを返す
* @param player プレイヤー
* @return チャンネル
*/
protected ArrayList<Channel> getChannelByPlayer(Player player) {
ArrayList<Channel> result = new ArrayList<Channel>();
String name = player.getName();
for ( String key : channels.keySet() ) {
Channel channel = channels.get(key);
if ( channel.members.contains(name) ) {
result.add(channel);
}
}
return result;
}
/**
* プレイヤーが参加しているデフォルトのチャンネルを返す
* @param player プレイヤー
* @return チャンネル
*/
protected Channel getDefaultChannelByPlayer(String name) {
String cname = defaultChannels.get(name);
if ( cname == null || !channels.containsKey(cname) ) {
return null;
}
return channels.get(cname);
}
/**
* 指定した名前のプレイヤーに設定されている、デフォルトチャンネル名を取得する
* @param name プレイヤー名
* @return デフォルトチャンネル名
*/
protected String getDefault(String name) {
return defaultChannels.get(name);
}
/**
* 指定した名前のプレイヤーに設定されている、デフォルトチャンネルを削除する
* @param name プレイヤー名
*/
protected void removeDefault(String name) {
if ( defaultChannels.containsKey(name) ) {
defaultChannels.remove(name);
}
}
/**
* プレイヤーのデフォルトチャンネルを設定する
* @param player プレイヤー
* @param cname チャンネル名
*/
protected void setDefaultChannel(String name, String cname) {
defaultChannels.put(name, cname);
save();
}
/**
* チャンネルを取得する
* @param name チャンネル名
* @return チャンネル
*/
protected Channel getChannel(String name) {
return channels.get(name);
}
/**
* 新しいチャンネルを作成する
* @param name チャンネル名
* @param desc チャンネルの説明文
* @return 作成されたチャンネル
*/
protected Channel createChannel(String name, String desc) {
Channel channel = new Channel(name, desc);
channels.put(name, channel);
save();
return channel;
}
/**
* チャンネルを削除する
* @param name 削除するチャンネル名
*/
protected void removeChannel(String name) {
if ( channels.containsKey(name) ) {
channels.remove(name);
}
Channel channel = getChannel(name);
if ( channel != null ) {
// チャンネルのメンバーを強制解散させる
String message = String.format(Utility.replaceColorCode(
Resources.get("breakupMessage")), name);
for ( String pname : channel.members ) {
Player player = LunaChat.getPlayerExact(pname);
if ( player != null ) {
player.sendMessage(message);
}
}
}
save();
}
}
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
/**
* @author ucchy
* チャンネルマネージャー
*/
public class ChannelManager {
private static final String LIST_FIRSTLINE = Resources.get("listFirstLine");
private static final String LIST_ENDLINE = Resources.get("listEndLine");
private static final String LIST_FORMAT = Resources.get("listFormat");
private static final String MOTD_FIRSTLINE = Resources.get("motdFirstLine");
private static final String DEFAULT_FORMAT = Resources.get("defaultFormat");
private static final String FILE_NAME = "channels.yml";
private static final String KEY_DESC = "desc";
private static final String KEY_FORMAT = "format";
private static final String KEY_MEMBERS = "members";
private static final String KEY_BANNED = "banned";
private static final String KEY_MODERATOR = "moderator";
private static final String KEY_PASSWORD = "password";
private static final String KEY_VISIBLE = "visible";
private File file;
private HashMap<String, Channel> channels;
private HashMap<String, String> defaultChannels;
/**
* コンストラクタ
*/
public ChannelManager() {
load();
}
/**
* 読み込みする
*/
private void load() {
file = new File(
LunaChat.instance.getDataFolder() +
File.separator + FILE_NAME);
if ( !file.exists() ) {
YamlConfiguration conf = new YamlConfiguration();
try {
conf.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
YamlConfiguration config =
YamlConfiguration.loadConfiguration(file);
// チャンネル設定のロード
if ( channels == null ) {
channels = new HashMap<String, Channel>();
} else {
channels.clear();
}
if ( config.contains("channels") ) {
ConfigurationSection section = config.getConfigurationSection("channels");
Set<String> keyset = section.getValues(false).keySet();
for ( String key : keyset ) {
ConfigurationSection sec = section.getConfigurationSection(key);
Channel channel = getChannelFromSection(sec);
channels.put(key, channel);
}
}
// デフォルト設定のロード
if ( defaultChannels == null ) {
defaultChannels = new HashMap<String, String>();
} else {
defaultChannels.clear();
}
if ( config.contains("defaults") ) {
ConfigurationSection section = config.getConfigurationSection("defaults");
Set<String> keyset = section.getValues(false).keySet();
for ( String key : keyset ) {
defaultChannels.put(key, section.getString(key));
}
}
}
/**
* セクションからChannelクラスを生成して返す
* @param section セクション
* @return Channel
*/
private Channel getChannelFromSection(ConfigurationSection section) {
String name = section.getName();
String desc = section.getString(KEY_DESC, "");
String format = section.getString(KEY_FORMAT, DEFAULT_FORMAT);
List<String> members = section.getStringList(KEY_MEMBERS);
List<String> banned = section.getStringList(KEY_BANNED);
List<String> moderator = section.getStringList(KEY_MODERATOR);
String password = section.getString(KEY_PASSWORD, "");
boolean visible = section.getBoolean(KEY_VISIBLE, true);
if ( members == null ) {
members = new ArrayList<String>();
}
Channel channel = new Channel(name, desc, members);
channel.format = format;
channel.banned = banned;
channel.moderator = moderator;
channel.password = password;
channel.visible = visible;
return channel;
}
/**
* 保存する
*/
protected boolean save() {
try {
YamlConfiguration config =
YamlConfiguration.loadConfiguration(file);
for ( String key : channels.keySet() ) {
Channel channel = channels.get(key);
config.set("channels." + key + "." + KEY_DESC, channel.description);
config.set("channels." + key + "." + KEY_FORMAT, channel.format);
config.set("channels." + key + "." + KEY_MEMBERS, channel.members);
config.set("channels." + key + "." + KEY_BANNED, channel.banned);
config.set("channels." + key + "." + KEY_MODERATOR, channel.moderator);
config.set("channels." + key + "." + KEY_PASSWORD, channel.password);
config.set("channels." + key + "." + KEY_VISIBLE, channel.visible);
}
for ( String key : defaultChannels.keySet() ) {
config.set("defaults." + key, defaultChannels.get(key));
}
config.save(file);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
/**
* チャンネルをアップデートする
* @param channel
*/
protected void updateChannel(Channel channel) {
String key = channel.name;
channels.put(key, channel);
save();
}
/**
* チャンネルの名前リストを返す
* @return チャンネルの名前
*/
protected ArrayList<String> getNames() {
ArrayList<String> names = new ArrayList<String>();
for ( String k : channels.keySet() ) {
names.add(k);
}
return names;
}
/**
* リスト表示用のリストを返す
* @param player プレイヤー、指定しない場合はnullにする
* @return リスト
*/
protected ArrayList<String> getList(Player player) {
ArrayList<String> items = new ArrayList<String>();
String dchannel = "";
String playerName = "";
if ( player != null ) {
playerName = player.getName();
dchannel = defaultChannels.get(player.getName());
if ( dchannel == null ) {
dchannel = "";
}
}
items.add(Utility.replaceColorCode(LIST_FIRSTLINE));
for ( String key : channels.keySet() ) {
Channel channel = channels.get(key);
// BANされているチャンネルは表示しない
if ( channel.banned.contains(playerName) ) {
continue;
}
// visible=false のチャンネルは表示しない
if ( !channel.visible ) {
continue;
}
String disp = ChatColor.WHITE + key;
if ( key.equals(dchannel) ) {
disp = ChatColor.RED + key;
}
if ( player != null && !channel.members.contains(playerName) ) {
disp = ChatColor.GRAY + key;
}
String desc = channel.description;
int onlineNum = 0;
for ( String pname : channel.members ) {
Player p = LunaChat.getPlayerExact(pname);
if ( p != null && p.isOnline() ) {
onlineNum++;
}
}
int memberNum = channel.members.size();
String item = String.format(
Utility.replaceColorCode(LIST_FORMAT),
disp, onlineNum, memberNum, desc);
items.add(item);
}
items.add(Utility.replaceColorCode(LIST_ENDLINE));
return items;
}
/**
* プレイヤーのサーバー参加時用の参加チャンネルリストを返す
* @param player プレイヤー
* @return リスト
*/
protected ArrayList<String> getListForMotd(Player player) {
ArrayList<String> items = new ArrayList<String>();
String playerName = player.getName();
String dchannel = defaultChannels.get(player.getName());
if ( dchannel == null ) {
dchannel = "";
}
items.add(Utility.replaceColorCode(MOTD_FIRSTLINE));
for ( String key : channels.keySet() ) {
Channel channel = channels.get(key);
if ( !channel.members.contains(playerName) ) {
continue;
}
String disp = ChatColor.WHITE + key;
if ( key.equals(dchannel) ) {
disp = ChatColor.RED + key;
}
String desc = channel.description;
int onlineNum = 0;
for ( String pname : channel.members ) {
Player p = LunaChat.getPlayerExact(pname);
if ( p != null && p.isOnline() ) {
onlineNum++;
}
}
int memberNum = channel.members.size();
String item = String.format(
Utility.replaceColorCode(LIST_FORMAT),
disp, onlineNum, memberNum, desc);
items.add(item);
}
items.add(Utility.replaceColorCode(LIST_ENDLINE));
return items;
}
/**
* プレイヤーが参加しているチャンネルを返す
* @param player プレイヤー
* @return チャンネル
*/
protected ArrayList<Channel> getChannelByPlayer(Player player) {
ArrayList<Channel> result = new ArrayList<Channel>();
String name = player.getName();
for ( String key : channels.keySet() ) {
Channel channel = channels.get(key);
if ( channel.members.contains(name) ) {
result.add(channel);
}
}
return result;
}
/**
* プレイヤーが参加しているデフォルトのチャンネルを返す
* @param player プレイヤー
* @return チャンネル
*/
protected Channel getDefaultChannelByPlayer(String name) {
String cname = defaultChannels.get(name);
if ( cname == null || !channels.containsKey(cname) ) {
return null;
}
return channels.get(cname);
}
/**
* 指定した名前のプレイヤーに設定されている、デフォルトチャンネル名を取得する
* @param name プレイヤー名
* @return デフォルトチャンネル名
*/
protected String getDefault(String name) {
return defaultChannels.get(name);
}
/**
* 指定した名前のプレイヤーに設定されている、デフォルトチャンネルを削除する
* @param name プレイヤー名
*/
protected void removeDefault(String name) {
if ( defaultChannels.containsKey(name) ) {
defaultChannels.remove(name);
}
}
/**
* プレイヤーのデフォルトチャンネルを設定する
* @param player プレイヤー
* @param cname チャンネル名
*/
protected void setDefaultChannel(String name, String cname) {
defaultChannels.put(name, cname);
save();
}
/**
* チャンネルを取得する
* @param name チャンネル名
* @return チャンネル
*/
protected Channel getChannel(String name) {
return channels.get(name);
}
/**
* 新しいチャンネルを作成する
* @param name チャンネル名
* @param desc チャンネルの説明文
* @return 作成されたチャンネル
*/
protected Channel createChannel(String name, String desc) {
Channel channel = new Channel(name, desc);
channels.put(name, channel);
save();
return channel;
}
/**
* チャンネルを削除する
* @param name 削除するチャンネル名
*/
protected void removeChannel(String name) {
if ( channels.containsKey(name) ) {
channels.remove(name);
}
Channel channel = getChannel(name);
if ( channel != null ) {
// チャンネルのメンバーを強制解散させる
String message = String.format(Utility.replaceColorCode(
Resources.get("breakupMessage")), name);
for ( String pname : channel.members ) {
Player player = LunaChat.getPlayerExact(pname);
if ( player != null ) {
player.sendMessage(message);
}
}
}
save();
}
}
+123 -123
ファイルの表示
@@ -1,123 +1,123 @@
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.util.HashMap;
/**
* @author ucchy
* ローマ字からかな文字へ変換するクラス
*/
public class KanaConverter {
private static final HashMap<String, String[]> TABLE;
static {
TABLE = new HashMap<String, String[]>();
TABLE.put( "", new String[]{"あ","い","う","え","お"});
TABLE.put( "k", new String[]{"か","き","く","け","こ"});
TABLE.put( "s", new String[]{"さ","し","す","せ","そ"});
TABLE.put( "t", new String[]{"た","ち","つ","て","と"});
TABLE.put( "n", new String[]{"な","に","ぬ","ね","の"});
TABLE.put( "h", new String[]{"は","ひ","ふ","へ","ほ"});
TABLE.put( "m", new String[]{"ま","み","む","め","も"});
TABLE.put( "y", new String[]{"や","い","ゆ","いぇ","よ"});
TABLE.put( "r", new String[]{"ら","り","る","れ","ろ"});
TABLE.put( "w", new String[]{"わ","うぃ","う","うぇ","を"});
TABLE.put( "g", new String[]{"が","ぎ","ぐ","げ","ご"});
TABLE.put( "z", new String[]{"ざ","じ","ず","ぜ","ぞ"});
TABLE.put( "j", new String[]{"じゃ","じ","じゅ","じぇ","じょ"});
TABLE.put( "d", new String[]{"だ","ぢ","づ","で","ど"});
TABLE.put( "b", new String[]{"ば","び","ぶ","べ","ぼ"});
TABLE.put( "p", new String[]{"ぱ","ぴ","ぷ","ぺ","ぽ"});
TABLE.put("gy", new String[]{"ぎゃ","ぎぃ","ぎゅ","ぎぇ","ぎょ"});
TABLE.put("zy", new String[]{"じゃ","じぃ","じゅ","じぇ","じょ"});
TABLE.put("jy", new String[]{"じゃ","じぃ","じゅ","じぇ","じょ"});
TABLE.put("dy", new String[]{"ぢゃ","ぢぃ","ぢゅ","ぢぇ","ぢょ"});
TABLE.put("by", new String[]{"びゃ","びぃ","びゅ","びぇ","びょ"});
TABLE.put("py", new String[]{"ぴゃ","ぴぃ","ぴゅ","ぴぇ","ぴょ"});
TABLE.put( "l", new String[]{"ぁ","ぃ","ぅ","ぇ","ぉ"});
TABLE.put( "v", new String[]{"ヴぁ","ヴぃ","ヴ","ヴぇ","ヴぉ"});
TABLE.put("sh", new String[]{"しゃ","し","しゅ","しぇ","しょ"});
TABLE.put("sy", new String[]{"しゃ","し","しゅ","しぇ","しょ"});
TABLE.put("ch", new String[]{"ちゃ","ち","ちゅ","ちぇ","ちょ"});
TABLE.put("cy", new String[]{"ちゃ","ち","ちゅ","ちぇ","ちょ"});
TABLE.put( "f", new String[]{"ふぁ","ふぃ","ふ","ふぇ","ふぉ"});
TABLE.put( "q", new String[]{"くぁ","くぃ","く","くぇ","くぉ"});
TABLE.put("ky", new String[]{"きゃ","きぃ","きゅ","きぇ","きょ"});
TABLE.put("ty", new String[]{"ちゃ","ちぃ","ちゅ","ちぇ","ちょ"});
TABLE.put("ny", new String[]{"にゃ","にぃ","にゅ","にぇ","にょ"});
TABLE.put("hy", new String[]{"ひゃ","ひぃ","ひゅ","ひぇ","ひょ"});
TABLE.put("my", new String[]{"みゃ","みぃ","みゅ","みぇ","みょ"});
TABLE.put("ry", new String[]{"りゃ","りぃ","りゅ","りぇ","りょ"});
TABLE.put("ly", new String[]{"ゃ","ぃ","ゅ","ぇ","ょ"});
TABLE.put("lt", new String[]{"た","ち","っ","て","と"});
TABLE.put("xy", new String[]{"ゃ","ぃ","ゅ","ぇ","ょ"});
TABLE.put("xt", new String[]{"た","ち","っ","て","と"});
TABLE.put( "x", new String[]{"ぁ","ぃ","ぅ","ぇ","ぉ"});
};
private static String getKanaFromTable(String s, int n) {
if ( TABLE.containsKey(s) ) {
return TABLE.get(s)[n];
}
return s + TABLE.get("")[n];
}
/**
* ローマ字をかな文字へ変換する
* @param org 変換元文字列
* @return 変換後の文字列
*/
protected static String conv(String org) {
String last = "";
StringBuilder line = new StringBuilder();
for ( int i=0; i<org.length(); i++ ) {
String tmp = org.substring(i,i+1);
if ( tmp.equals("a") ) {
line.append( getKanaFromTable(last, 0) );
last = "";
} else if ( tmp.equals("i") ) {
line.append( getKanaFromTable(last, 1) );
last = "";
} else if ( tmp.equals("u") ) {
line.append( getKanaFromTable(last, 2) );
last = "";
} else if ( tmp.equals("e") ) {
line.append( getKanaFromTable(last, 3) );
last = "";
} else if ( tmp.equals("o") ) {
line.append( getKanaFromTable(last, 4) );
last = "";
} else {
if ( last.equals("n") && !(tmp.equals("y")) ) {
line.append("ん");
last = "";
if ( tmp.equals("n") ) {
continue;
}
}
if ( java.lang.Character.isLetter(tmp.charAt(0)) ) {
if ( last.equals(tmp) ) {
line.append("っ");
last = tmp;
} else {
last = last + tmp;
}
} else {
line.append(last + tmp);
last = "";
}
}
}
line.append(last);
return line.toString();
}
}
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.util.HashMap;
/**
* @author ucchy
* ローマ字からかな文字へ変換するクラス
*/
public class KanaConverter {
private static final HashMap<String, String[]> TABLE;
static {
TABLE = new HashMap<String, String[]>();
TABLE.put( "", new String[]{"あ","い","う","え","お"});
TABLE.put( "k", new String[]{"か","き","く","け","こ"});
TABLE.put( "s", new String[]{"さ","し","す","せ","そ"});
TABLE.put( "t", new String[]{"た","ち","つ","て","と"});
TABLE.put( "n", new String[]{"な","に","ぬ","ね","の"});
TABLE.put( "h", new String[]{"は","ひ","ふ","へ","ほ"});
TABLE.put( "m", new String[]{"ま","み","む","め","も"});
TABLE.put( "y", new String[]{"や","い","ゆ","いぇ","よ"});
TABLE.put( "r", new String[]{"ら","り","る","れ","ろ"});
TABLE.put( "w", new String[]{"わ","うぃ","う","うぇ","を"});
TABLE.put( "g", new String[]{"が","ぎ","ぐ","げ","ご"});
TABLE.put( "z", new String[]{"ざ","じ","ず","ぜ","ぞ"});
TABLE.put( "j", new String[]{"じゃ","じ","じゅ","じぇ","じょ"});
TABLE.put( "d", new String[]{"だ","ぢ","づ","で","ど"});
TABLE.put( "b", new String[]{"ば","び","ぶ","べ","ぼ"});
TABLE.put( "p", new String[]{"ぱ","ぴ","ぷ","ぺ","ぽ"});
TABLE.put("gy", new String[]{"ぎゃ","ぎぃ","ぎゅ","ぎぇ","ぎょ"});
TABLE.put("zy", new String[]{"じゃ","じぃ","じゅ","じぇ","じょ"});
TABLE.put("jy", new String[]{"じゃ","じぃ","じゅ","じぇ","じょ"});
TABLE.put("dy", new String[]{"ぢゃ","ぢぃ","ぢゅ","ぢぇ","ぢょ"});
TABLE.put("by", new String[]{"びゃ","びぃ","びゅ","びぇ","びょ"});
TABLE.put("py", new String[]{"ぴゃ","ぴぃ","ぴゅ","ぴぇ","ぴょ"});
TABLE.put( "l", new String[]{"ぁ","ぃ","ぅ","ぇ","ぉ"});
TABLE.put( "v", new String[]{"ヴぁ","ヴぃ","ヴ","ヴぇ","ヴぉ"});
TABLE.put("sh", new String[]{"しゃ","し","しゅ","しぇ","しょ"});
TABLE.put("sy", new String[]{"しゃ","し","しゅ","しぇ","しょ"});
TABLE.put("ch", new String[]{"ちゃ","ち","ちゅ","ちぇ","ちょ"});
TABLE.put("cy", new String[]{"ちゃ","ち","ちゅ","ちぇ","ちょ"});
TABLE.put( "f", new String[]{"ふぁ","ふぃ","ふ","ふぇ","ふぉ"});
TABLE.put( "q", new String[]{"くぁ","くぃ","く","くぇ","くぉ"});
TABLE.put("ky", new String[]{"きゃ","きぃ","きゅ","きぇ","きょ"});
TABLE.put("ty", new String[]{"ちゃ","ちぃ","ちゅ","ちぇ","ちょ"});
TABLE.put("ny", new String[]{"にゃ","にぃ","にゅ","にぇ","にょ"});
TABLE.put("hy", new String[]{"ひゃ","ひぃ","ひゅ","ひぇ","ひょ"});
TABLE.put("my", new String[]{"みゃ","みぃ","みゅ","みぇ","みょ"});
TABLE.put("ry", new String[]{"りゃ","りぃ","りゅ","りぇ","りょ"});
TABLE.put("ly", new String[]{"ゃ","ぃ","ゅ","ぇ","ょ"});
TABLE.put("lt", new String[]{"た","ち","っ","て","と"});
TABLE.put("xy", new String[]{"ゃ","ぃ","ゅ","ぇ","ょ"});
TABLE.put("xt", new String[]{"た","ち","っ","て","と"});
TABLE.put( "x", new String[]{"ぁ","ぃ","ぅ","ぇ","ぉ"});
};
private static String getKanaFromTable(String s, int n) {
if ( TABLE.containsKey(s) ) {
return TABLE.get(s)[n];
}
return s + TABLE.get("")[n];
}
/**
* ローマ字をかな文字へ変換する
* @param org 変換元文字列
* @return 変換後の文字列
*/
protected static String conv(String org) {
String last = "";
StringBuilder line = new StringBuilder();
for ( int i=0; i<org.length(); i++ ) {
String tmp = org.substring(i,i+1);
if ( tmp.equals("a") ) {
line.append( getKanaFromTable(last, 0) );
last = "";
} else if ( tmp.equals("i") ) {
line.append( getKanaFromTable(last, 1) );
last = "";
} else if ( tmp.equals("u") ) {
line.append( getKanaFromTable(last, 2) );
last = "";
} else if ( tmp.equals("e") ) {
line.append( getKanaFromTable(last, 3) );
last = "";
} else if ( tmp.equals("o") ) {
line.append( getKanaFromTable(last, 4) );
last = "";
} else {
if ( last.equals("n") && !(tmp.equals("y")) ) {
line.append("ん");
last = "";
if ( tmp.equals("n") ) {
continue;
}
}
if ( java.lang.Character.isLetter(tmp.charAt(0)) ) {
if ( last.equals(tmp) ) {
line.append("っ");
last = tmp;
} else {
last = last + tmp;
}
} else {
line.append(last + tmp);
last = "";
}
}
}
line.append(last);
return line.toString();
}
}
+72 -72
ファイルの表示
@@ -1,72 +1,72 @@
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.io.File;
import java.util.HashMap;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
/**
* @author ucchy
* LunaChat プラグイン
*/
public class LunaChat extends JavaPlugin {
protected static LunaChat instance;
protected static LunaChatConfig config;
protected static ChannelManager manager;
protected static HashMap<String, String> inviteMap;
protected static HashMap<String, String> inviterMap;
/**
* プラグインが有効化されたときに呼び出されるメソッド
* @see org.bukkit.plugin.java.JavaPlugin#onEnable()
*/
@Override
public void onEnable() {
// 変数などの初期化
instance = this;
config = new LunaChatConfig();
manager = new ChannelManager();
inviteMap = new HashMap<String, String>();
inviterMap = new HashMap<String, String>();
// リスナーの登録
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
// コマンドの登録
getCommand("lunachat").setExecutor(new LunaChatCommand());
}
/**
* このプラグインのJarファイル自身を示すFileクラスを返す。
* @return
*/
protected static File getPluginJarFile() {
return instance.getFile();
}
/**
* ログにメッセージを出力する
* @param message メッセージ
*/
protected static void log(String message) {
instance.getLogger().info(ChatColor.stripColor(message));
}
/**
* Playerを取得する
* @param name プレイヤー名
* @return Player
*/
protected static Player getPlayerExact(String name) {
return instance.getServer().getPlayerExact(name);
}
}
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.io.File;
import java.util.HashMap;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
/**
* @author ucchy
* LunaChat プラグイン
*/
public class LunaChat extends JavaPlugin {
protected static LunaChat instance;
protected static LunaChatConfig config;
protected static ChannelManager manager;
protected static HashMap<String, String> inviteMap;
protected static HashMap<String, String> inviterMap;
/**
* プラグインが有効化されたときに呼び出されるメソッド
* @see org.bukkit.plugin.java.JavaPlugin#onEnable()
*/
@Override
public void onEnable() {
// 変数などの初期化
instance = this;
config = new LunaChatConfig();
manager = new ChannelManager();
inviteMap = new HashMap<String, String>();
inviterMap = new HashMap<String, String>();
// リスナーの登録
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
// コマンドの登録
getCommand("lunachat").setExecutor(new LunaChatCommand());
}
/**
* このプラグインのJarファイル自身を示すFileクラスを返す。
* @return
*/
protected static File getPluginJarFile() {
return instance.getFile();
}
/**
* ログにメッセージを出力する
* @param message メッセージ
*/
protected static void log(String message) {
instance.getLogger().info(ChatColor.stripColor(message));
}
/**
* Playerを取得する
* @param name プレイヤー名
* @return Player
*/
protected static Player getPlayerExact(String name) {
return instance.getServer().getPlayerExact(name);
}
}
ファイル差分が大きすぎるため表示されません。 差分を読み込み
+93 -93
ファイルの表示
@@ -1,93 +1,93 @@
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.io.File;
import org.bukkit.configuration.file.FileConfiguration;
/**
* @author ucchy
* LunaChatのコンフィグクラス
*/
public class LunaChatConfig {
/** Japanize変換をおこなうかどうか */
protected boolean displayJapanize;
/** チャンネルチャットに入っていない人の発言を、グローバルとして扱うかどうか */
protected boolean noJoinAsGlobal;
/** チャンネルチャットの発言内容を、ログに残すかどうか */
protected boolean loggingChat;
/** グローバルマーカー これが発言の頭に入っている場合は、強制的にグローバル発言になる */
protected String globalMarker;
/** 発言先移動時に、移動元のチャンネルから退出するかどうか */
protected boolean autoLeavingOnMove;
/** サーバーから退出したときに、全ての参加チャンネルから退出するかどうか */
protected boolean autoLeavingOnQuit;
/** 全てのメンバーが退出したときに、チャンネルを削除するかどうか */
protected boolean zeroMemberRemove;
/** ログイン時に、参加中チャンネルを表示するかどうか */
protected boolean showListOnJoin;
/** /ch join コマンドで存在しないチャンネルを指定したときに、チャンネルを新規作成して入室するかどうか */
protected boolean createChannelOnJoinCommand;
/** サーバーに初参加したユーザーを参加させる、既定のチャンネル。
* 参加させない場合は、から文字列 "" を指定すること。 */
protected String globalChannel;
/**
* コンストラクタ
*/
protected LunaChatConfig() {
reloadConfig();
}
/**
* config.yml を再読み込みする
*/
protected void reloadConfig() {
File configFile = new File(LunaChat.instance.getDataFolder(), "config.yml");
if ( !configFile.exists() ) {
LunaChat.instance.saveDefaultConfig();
}
LunaChat.instance.reloadConfig();
FileConfiguration config = LunaChat.instance.getConfig();
displayJapanize = config.getBoolean("displayJapanize", true);
noJoinAsGlobal = config.getBoolean("noJoinAsGlobal", true);
loggingChat = config.getBoolean("loggingChat", true);
globalMarker = config.getString("globalMarker", "!");
autoLeavingOnMove = config.getBoolean("autoLeavingOnMove", false);
autoLeavingOnQuit = config.getBoolean("autoLeavingOnQuit", false);
zeroMemberRemove = config.getBoolean("zeroMemberRemove", false);
showListOnJoin = config.getBoolean("showListOnJoin", false);
createChannelOnJoinCommand =
config.getBoolean("createChannelOnJoinCommand", true);
globalChannel = config.getString("globalChannel", "");
}
/**
* config.yml に、設定値を保存する
* @param key 設定値のキー
* @param value 設定値の値
*/
public static void setConfigValue(String key, Object value) {
FileConfiguration config = LunaChat.instance.getConfig();
config.set(key, value);
LunaChat.instance.saveConfig();
}
}
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.io.File;
import org.bukkit.configuration.file.FileConfiguration;
/**
* @author ucchy
* LunaChatのコンフィグクラス
*/
public class LunaChatConfig {
/** Japanize変換をおこなうかどうか */
protected boolean displayJapanize;
/** チャンネルチャットに入っていない人の発言を、グローバルとして扱うかどうか */
protected boolean noJoinAsGlobal;
/** チャンネルチャットの発言内容を、ログに残すかどうか */
protected boolean loggingChat;
/** グローバルマーカー これが発言の頭に入っている場合は、強制的にグローバル発言になる */
protected String globalMarker;
/** 発言先移動時に、移動元のチャンネルから退出するかどうか */
protected boolean autoLeavingOnMove;
/** サーバーから退出したときに、全ての参加チャンネルから退出するかどうか */
protected boolean autoLeavingOnQuit;
/** 全てのメンバーが退出したときに、チャンネルを削除するかどうか */
protected boolean zeroMemberRemove;
/** ログイン時に、参加中チャンネルを表示するかどうか */
protected boolean showListOnJoin;
/** /ch join コマンドで存在しないチャンネルを指定したときに、チャンネルを新規作成して入室するかどうか */
protected boolean createChannelOnJoinCommand;
/** サーバーに初参加したユーザーを参加させる、既定のチャンネル。
* 参加させない場合は、から文字列 "" を指定すること。 */
protected String globalChannel;
/**
* コンストラクタ
*/
protected LunaChatConfig() {
reloadConfig();
}
/**
* config.yml を再読み込みする
*/
protected void reloadConfig() {
File configFile = new File(LunaChat.instance.getDataFolder(), "config.yml");
if ( !configFile.exists() ) {
LunaChat.instance.saveDefaultConfig();
}
LunaChat.instance.reloadConfig();
FileConfiguration config = LunaChat.instance.getConfig();
displayJapanize = config.getBoolean("displayJapanize", true);
noJoinAsGlobal = config.getBoolean("noJoinAsGlobal", true);
loggingChat = config.getBoolean("loggingChat", true);
globalMarker = config.getString("globalMarker", "!");
autoLeavingOnMove = config.getBoolean("autoLeavingOnMove", false);
autoLeavingOnQuit = config.getBoolean("autoLeavingOnQuit", false);
zeroMemberRemove = config.getBoolean("zeroMemberRemove", false);
showListOnJoin = config.getBoolean("showListOnJoin", false);
createChannelOnJoinCommand =
config.getBoolean("createChannelOnJoinCommand", true);
globalChannel = config.getString("globalChannel", "");
}
/**
* config.yml に、設定値を保存する
* @param key 設定値のキー
* @param value 設定値の値
*/
public static void setConfigValue(String key, Object value) {
FileConfiguration config = LunaChat.instance.getConfig();
config.set(key, value);
LunaChat.instance.saveConfig();
}
}
+201 -201
ファイルの表示
@@ -1,201 +1,201 @@
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.util.ArrayList;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
/**
* @author ucchy
* プレイヤーの行動を監視するリスナ
*/
public class PlayerListener implements Listener {
private static final String PREINFO = Resources.get("infoPrefix");
private static final String PREERR = Resources.get("errorPrefix");
/**
* プレイヤーのチャットごとに呼び出されるメソッド
* @param event チャットイベント
*/
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
// 頭にglobalMarkerが付いている場合は、グローバル発言にする
if ( LunaChat.config.globalMarker != null &&
!LunaChat.config.globalMarker.equals("") &&
event.getMessage().startsWith(LunaChat.config.globalMarker) ) {
int offset = LunaChat.config.globalMarker.length();
String message = event.getMessage().substring(offset);
// Japanize変換
if ( LunaChat.config.displayJapanize ) {
message = addJapanize(message);
}
event.setMessage(message);
return;
}
Player player = event.getPlayer();
Channel channel = LunaChat.manager.getDefaultChannelByPlayer(player.getName());
// デフォルトの発言先が無い場合
if ( channel == null ) {
if ( LunaChat.config.noJoinAsGlobal ) {
// グローバル発言にする
if ( !LunaChat.config.globalChannel.equals("") &&
LunaChat.manager.getChannel(LunaChat.config.globalChannel) != null ) {
Channel global = LunaChat.manager.getChannel(LunaChat.config.globalChannel);
// もしグローバルのメンバーでなければ、まず参加させる
if ( global.members.contains(player.getName()) ) {
global.addMember(player.getName());
}
// チャンネルチャット発言
global.chat(player, event.getMessage());
// もとのイベントをキャンセル
event.setCancelled(true);
return;
} else {
// Japanize変換
if ( LunaChat.config.displayJapanize ) {
event.setMessage( addJapanize(event.getMessage()) );
}
// 通常チャット発言(つまり、何もしないで終了)
return;
}
} else {
// 発言をキャンセルして終了する
event.setCancelled(true);
return;
}
}
// チャンネルチャット発言
channel.chat(player, event.getMessage());
// もとのイベントをキャンセル
event.setCancelled(true);
}
/**
* プレイヤーのサーバー参加ごとに呼び出されるメソッド
* @param event プレイヤー参加イベント
*/
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
// どのチャンネルにも所属していないプレイヤーを、既定のチャンネルへ参加させる
if ( LunaChat.manager.getChannelByPlayer(player).size() == 0 &&
!LunaChat.config.globalChannel.equals("") ) {
tryJoinToDefaultChannel(player);
}
// チャンネルチャット情報を表示する
if ( LunaChat.config.showListOnJoin ) {
ArrayList<String> list = LunaChat.manager.getListForMotd(player);
for ( String msg : list ) {
player.sendMessage(msg);
}
}
}
/**
* 既定のチャンネルへの参加を試みる。
* @param player プレイヤー
* @return 参加できたかどうか
*/
private boolean tryJoinToDefaultChannel(Player player) {
String channelName = LunaChat.config.globalChannel;
// チャンネルが存在するかどうかをチェックする
ArrayList<String> channels = LunaChat.manager.getNames();
if (!channels.contains(channelName)) {
if (LunaChat.config.createChannelOnJoinCommand) {
// 存在しないチャットには、チャンネルを作って入る設定の場合
// チャンネル作成
Channel c = LunaChat.manager.createChannel(channelName, "");
c.addMember(player.getName());
sendResourceMessage(player, PREINFO, "cmdmsgCreate", channelName);
return false;
} else {
// 存在しないチャットには入れない設定の場合
sendResourceMessage(player, PREERR, "errmsgNotExist");
return false;
}
}
// デフォルト発言先をチェックする
Channel channel = LunaChat.manager.getChannel(channelName);
// BANされていないか確認する
if (channel.banned.contains(player.getName())) {
sendResourceMessage(player, PREERR, "errmsgBanned");
return false;
}
// チャンネルに参加し、デフォルトの発言先に設定する
channel.addMember(player.getName());
sendResourceMessage(player, PREINFO, "cmdmsgJoin", channelName);
LunaChat.manager.setDefaultChannel(player.getName(), channelName);
sendResourceMessage(player, PREINFO, "cmdmsgSet", channelName);
return true;
}
/**
* メッセージリソースのメッセージを、カラーコード置き換えしつつ、senderに送信する
*
* @param sender メッセージの送り先
* @param pre プレフィックス
* @param key リソースキー
* @param args リソース内の置き換え対象キーワード
*/
private void sendResourceMessage(CommandSender sender, String pre,
String key, Object... args) {
String msg = String.format(
Utility.replaceColorCode(pre + Resources.get(key)), args);
sender.sendMessage(msg);
}
/**
* メッセージに2バイトコードが含まれていない場合に、かな文字を付加する
* @param message メッセージ
* @return かな文字付きのメッセージ
*/
private String addJapanize(String message) {
// 2byteコードを含まない場合にのみ、処理を行う
if ( message.getBytes().length == message.length() ) {
String kana = KanaConverter.conv(message);
message = message + "(" + kana + ")";
}
return message;
}
}
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.util.ArrayList;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerJoinEvent;
/**
* @author ucchy
* プレイヤーの行動を監視するリスナ
*/
public class PlayerListener implements Listener {
private static final String PREINFO = Resources.get("infoPrefix");
private static final String PREERR = Resources.get("errorPrefix");
/**
* プレイヤーのチャットごとに呼び出されるメソッド
* @param event チャットイベント
*/
@EventHandler
public void onChat(AsyncPlayerChatEvent event) {
// 頭にglobalMarkerが付いている場合は、グローバル発言にする
if ( LunaChat.config.globalMarker != null &&
!LunaChat.config.globalMarker.equals("") &&
event.getMessage().startsWith(LunaChat.config.globalMarker) ) {
int offset = LunaChat.config.globalMarker.length();
String message = event.getMessage().substring(offset);
// Japanize変換
if ( LunaChat.config.displayJapanize ) {
message = addJapanize(message);
}
event.setMessage(message);
return;
}
Player player = event.getPlayer();
Channel channel = LunaChat.manager.getDefaultChannelByPlayer(player.getName());
// デフォルトの発言先が無い場合
if ( channel == null ) {
if ( LunaChat.config.noJoinAsGlobal ) {
// グローバル発言にする
if ( !LunaChat.config.globalChannel.equals("") &&
LunaChat.manager.getChannel(LunaChat.config.globalChannel) != null ) {
Channel global = LunaChat.manager.getChannel(LunaChat.config.globalChannel);
// もしグローバルのメンバーでなければ、まず参加させる
if ( global.members.contains(player.getName()) ) {
global.addMember(player.getName());
}
// チャンネルチャット発言
global.chat(player, event.getMessage());
// もとのイベントをキャンセル
event.setCancelled(true);
return;
} else {
// Japanize変換
if ( LunaChat.config.displayJapanize ) {
event.setMessage( addJapanize(event.getMessage()) );
}
// 通常チャット発言(つまり、何もしないで終了)
return;
}
} else {
// 発言をキャンセルして終了する
event.setCancelled(true);
return;
}
}
// チャンネルチャット発言
channel.chat(player, event.getMessage());
// もとのイベントをキャンセル
event.setCancelled(true);
}
/**
* プレイヤーのサーバー参加ごとに呼び出されるメソッド
* @param event プレイヤー参加イベント
*/
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
// どのチャンネルにも所属していないプレイヤーを、既定のチャンネルへ参加させる
if ( LunaChat.manager.getChannelByPlayer(player).size() == 0 &&
!LunaChat.config.globalChannel.equals("") ) {
tryJoinToDefaultChannel(player);
}
// チャンネルチャット情報を表示する
if ( LunaChat.config.showListOnJoin ) {
ArrayList<String> list = LunaChat.manager.getListForMotd(player);
for ( String msg : list ) {
player.sendMessage(msg);
}
}
}
/**
* 既定のチャンネルへの参加を試みる。
* @param player プレイヤー
* @return 参加できたかどうか
*/
private boolean tryJoinToDefaultChannel(Player player) {
String channelName = LunaChat.config.globalChannel;
// チャンネルが存在するかどうかをチェックする
ArrayList<String> channels = LunaChat.manager.getNames();
if (!channels.contains(channelName)) {
if (LunaChat.config.createChannelOnJoinCommand) {
// 存在しないチャットには、チャンネルを作って入る設定の場合
// チャンネル作成
Channel c = LunaChat.manager.createChannel(channelName, "");
c.addMember(player.getName());
sendResourceMessage(player, PREINFO, "cmdmsgCreate", channelName);
return false;
} else {
// 存在しないチャットには入れない設定の場合
sendResourceMessage(player, PREERR, "errmsgNotExist");
return false;
}
}
// デフォルト発言先をチェックする
Channel channel = LunaChat.manager.getChannel(channelName);
// BANされていないか確認する
if (channel.banned.contains(player.getName())) {
sendResourceMessage(player, PREERR, "errmsgBanned");
return false;
}
// チャンネルに参加し、デフォルトの発言先に設定する
channel.addMember(player.getName());
sendResourceMessage(player, PREINFO, "cmdmsgJoin", channelName);
LunaChat.manager.setDefaultChannel(player.getName(), channelName);
sendResourceMessage(player, PREINFO, "cmdmsgSet", channelName);
return true;
}
/**
* メッセージリソースのメッセージを、カラーコード置き換えしつつ、senderに送信する
*
* @param sender メッセージの送り先
* @param pre プレフィックス
* @param key リソースキー
* @param args リソース内の置き換え対象キーワード
*/
private void sendResourceMessage(CommandSender sender, String pre,
String key, Object... args) {
String msg = String.format(
Utility.replaceColorCode(pre + Resources.get(key)), args);
sender.sendMessage(msg);
}
/**
* メッセージに2バイトコードが含まれていない場合に、かな文字を付加する
* @param message メッセージ
* @return かな文字付きのメッセージ
*/
private String addJapanize(String message) {
// 2byteコードを含まない場合にのみ、処理を行う
if ( message.getBytes().length == message.length() ) {
String kana = KanaConverter.conv(message);
message = message + "(" + kana + ")";
}
return message;
}
}
+99 -99
ファイルの表示
@@ -1,99 +1,99 @@
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import org.bukkit.configuration.file.YamlConfiguration;
/**
* プラグインのリソース管理クラス
* @author ucchy
*/
public class Resources {
private static final String FILE_NAME = "messages.yml";
private static YamlConfiguration defaultMessages;
private static YamlConfiguration resources;
/**
* 初期化する
*/
protected static void initialize() {
File file = new File(
LunaChat.instance.getDataFolder() +
File.separator + FILE_NAME);
if ( !file.exists() ) {
Utility.copyFileFromJar(LunaChat.getPluginJarFile(),
file, "messages.yml", false);
}
defaultMessages = loadDefaultMessages();
resources = YamlConfiguration.loadConfiguration(file);
}
/**
* リソースを取得する
* @param key リソースキー
* @return リソース
*/
protected static String get(String key) {
if ( resources == null ) {
initialize();
}
String def = defaultMessages.getString(key, "");
return resources.getString(key, def);
}
/**
* Jarファイル内から直接 messages.yml を読み込み、YamlConfigurationにして返すメソッド
* @return
*/
private static YamlConfiguration loadDefaultMessages() {
YamlConfiguration messages = new YamlConfiguration();
JarFile jarFile = null;
try {
jarFile = new JarFile(LunaChat.getPluginJarFile());
ZipEntry zipEntry = jarFile.getEntry("messages.yml");
InputStream inputStream = jarFile.getInputStream(zipEntry);
BufferedReader reader =
new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
String line;
while ( (line = reader.readLine()) != null ) {
if ( line.contains(":") && !line.startsWith("#") ) {
String key = line.substring(0, line.indexOf(":")).trim();
String value = line.substring(line.indexOf(":") + 1).trim();
if ( value.startsWith("'") && value.endsWith("'") )
value = value.substring(1, value.length()-1);
messages.set(key, value);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if ( jarFile != null ) {
try {
jarFile.close();
} catch (IOException e) {
// do nothing.
}
}
}
return messages;
}
}
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import org.bukkit.configuration.file.YamlConfiguration;
/**
* プラグインのリソース管理クラス
* @author ucchy
*/
public class Resources {
private static final String FILE_NAME = "messages.yml";
private static YamlConfiguration defaultMessages;
private static YamlConfiguration resources;
/**
* 初期化する
*/
protected static void initialize() {
File file = new File(
LunaChat.instance.getDataFolder() +
File.separator + FILE_NAME);
if ( !file.exists() ) {
Utility.copyFileFromJar(LunaChat.getPluginJarFile(),
file, "messages.yml", false);
}
defaultMessages = loadDefaultMessages();
resources = YamlConfiguration.loadConfiguration(file);
}
/**
* リソースを取得する
* @param key リソースキー
* @return リソース
*/
protected static String get(String key) {
if ( resources == null ) {
initialize();
}
String def = defaultMessages.getString(key, "");
return resources.getString(key, def);
}
/**
* Jarファイル内から直接 messages.yml を読み込み、YamlConfigurationにして返すメソッド
* @return
*/
private static YamlConfiguration loadDefaultMessages() {
YamlConfiguration messages = new YamlConfiguration();
JarFile jarFile = null;
try {
jarFile = new JarFile(LunaChat.getPluginJarFile());
ZipEntry zipEntry = jarFile.getEntry("messages.yml");
InputStream inputStream = jarFile.getInputStream(zipEntry);
BufferedReader reader =
new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
String line;
while ( (line = reader.readLine()) != null ) {
if ( line.contains(":") && !line.startsWith("#") ) {
String key = line.substring(0, line.indexOf(":")).trim();
String value = line.substring(line.indexOf(":") + 1).trim();
if ( value.startsWith("'") && value.endsWith("'") )
value = value.substring(1, value.length()-1);
messages.set(key, value);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if ( jarFile != null ) {
try {
jarFile.close();
} catch (IOException e) {
// do nothing.
}
}
}
return messages;
}
}
+118 -118
ファイルの表示
@@ -1,118 +1,118 @@
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
/**
* @author ucchy
* ユーティリティクラス
*/
public class Utility {
/**
* jarファイルの中に格納されているファイルを、jarファイルの外にコピーするメソッド
* @param jarFile jarファイル
* @param targetFile コピー先
* @param sourceFilePath コピー元
* @param isBinary バイナリファイルかどうか
*/
protected static void copyFileFromJar(
File jarFile, File targetFile, String sourceFilePath, boolean isBinary) {
InputStream is = null;
FileOutputStream fos = null;
BufferedReader reader = null;
BufferedWriter writer = null;
File parent = targetFile.getParentFile();
if ( !parent.exists() ) {
parent.mkdirs();
}
try {
JarFile jar = new JarFile(jarFile);
ZipEntry zipEntry = jar.getEntry(sourceFilePath);
is = jar.getInputStream(zipEntry);
fos = new FileOutputStream(targetFile);
if ( isBinary ) {
byte[] buf = new byte[8192];
int len;
while ( (len = is.read(buf)) != -1 ) {
fos.write(buf, 0, len);
}
} else {
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
writer = new BufferedWriter(new OutputStreamWriter(fos));
String line;
while ((line = reader.readLine()) != null) {
writer.write(line);
writer.newLine();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if ( writer != null ) {
try {
writer.flush();
writer.close();
} catch (IOException e) {
// do nothing.
}
}
if ( reader != null ) {
try {
reader.close();
} catch (IOException e) {
// do nothing.
}
}
if ( fos != null ) {
try {
fos.flush();
fos.close();
} catch (IOException e) {
// do nothing.
}
}
if ( is != null ) {
try {
is.close();
} catch (IOException e) {
// do nothing.
}
}
}
}
/**
* 文字列内のカラーコードを置き換えする
* @param source 置き換え元の文字列
* @return 置き換え後の文字列
*/
public static String replaceColorCode(String source) {
return source.replaceAll("&([0-9a-fk-or])", "\u00A7$1");
}
}
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
/**
* @author ucchy
* ユーティリティクラス
*/
public class Utility {
/**
* jarファイルの中に格納されているファイルを、jarファイルの外にコピーするメソッド
* @param jarFile jarファイル
* @param targetFile コピー先
* @param sourceFilePath コピー元
* @param isBinary バイナリファイルかどうか
*/
protected static void copyFileFromJar(
File jarFile, File targetFile, String sourceFilePath, boolean isBinary) {
InputStream is = null;
FileOutputStream fos = null;
BufferedReader reader = null;
BufferedWriter writer = null;
File parent = targetFile.getParentFile();
if ( !parent.exists() ) {
parent.mkdirs();
}
try {
JarFile jar = new JarFile(jarFile);
ZipEntry zipEntry = jar.getEntry(sourceFilePath);
is = jar.getInputStream(zipEntry);
fos = new FileOutputStream(targetFile);
if ( isBinary ) {
byte[] buf = new byte[8192];
int len;
while ( (len = is.read(buf)) != -1 ) {
fos.write(buf, 0, len);
}
} else {
reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
writer = new BufferedWriter(new OutputStreamWriter(fos));
String line;
while ((line = reader.readLine()) != null) {
writer.write(line);
writer.newLine();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if ( writer != null ) {
try {
writer.flush();
writer.close();
} catch (IOException e) {
// do nothing.
}
}
if ( reader != null ) {
try {
reader.close();
} catch (IOException e) {
// do nothing.
}
}
if ( fos != null ) {
try {
fos.flush();
fos.close();
} catch (IOException e) {
// do nothing.
}
}
if ( is != null ) {
try {
is.close();
} catch (IOException e) {
// do nothing.
}
}
}
}
/**
* 文字列内のカラーコードを置き換えする
* @param source 置き換え元の文字列
* @return 置き換え後の文字列
*/
public static String replaceColorCode(String source) {
return source.replaceAll("&([0-9a-fk-or])", "\u00A7$1");
}
}