LunaChat : initial revision.
このコミットが含まれているのは:
コミット
fbd32c522c
15ファイル変更
+1585
検索条件に一致するファイルはありません
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license GPLv3
|
||||
* @copyright Copyright ucchy 2013
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author ucchy
|
||||
* チャンネル
|
||||
*/
|
||||
public class Channel {
|
||||
|
||||
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;
|
||||
|
||||
/** BANされたプレイヤー */
|
||||
protected List<String> banned;
|
||||
|
||||
/** チャンネルの名称 */
|
||||
protected String name;
|
||||
|
||||
/** チャンネルの説明文 */
|
||||
protected String description;
|
||||
|
||||
/** メッセージフォーマット<br>
|
||||
* 指定可能なキーワードは下記のとおり<br>
|
||||
* %ch - チャンネル名<br>
|
||||
* %username - ユーザー名<br>
|
||||
* %msg - メッセージ
|
||||
* */
|
||||
protected String format;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param name チャンネルの名称
|
||||
* @param description チャンネルの説明文
|
||||
*/
|
||||
protected Channel(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.members = new ArrayList<String>();
|
||||
this.format = DEFAULT_FORMAT;
|
||||
this.banned = 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>();
|
||||
}
|
||||
|
||||
/**
|
||||
* このチャットに発言をする
|
||||
* @param player 発言をするプレイヤー
|
||||
* @param message 発言をするメッセージ
|
||||
*/
|
||||
protected void chat(Player player, String message) {
|
||||
|
||||
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.contains(name) ) {
|
||||
members.add(name);
|
||||
sendJoinQuitMessage(true, name);
|
||||
LunaChat.manager.save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* メンバーを削除する
|
||||
* @param name 削除するメンバー名
|
||||
*/
|
||||
protected void removeMember(String name) {
|
||||
|
||||
if ( !members.contains(name) ) {
|
||||
members.remove(name);
|
||||
sendJoinQuitMessage(false, name);
|
||||
LunaChat.manager.save();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 入退室メッセージを流す
|
||||
* @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);
|
||||
|
||||
// オンラインのプレイヤーに送信する
|
||||
for ( String member : members ) {
|
||||
Player p = LunaChat.getPlayerExact(member);
|
||||
if ( p != null ) {
|
||||
p.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
|
||||
// ロギング
|
||||
if ( LunaChat.config.loggingChat ) {
|
||||
LunaChat.log(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
/*
|
||||
* @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.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 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 File file;
|
||||
private HashMap<String, Channel> channels;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
Set<String> keyset = config.getValues(false).keySet();
|
||||
for ( String key : keyset ) {
|
||||
ConfigurationSection section = config.getConfigurationSection(key);
|
||||
Channel channel = getChannelFromSection(section);
|
||||
channels.put(key, channel);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存する
|
||||
*/
|
||||
protected boolean save() {
|
||||
|
||||
try {
|
||||
YamlConfiguration config =
|
||||
YamlConfiguration.loadConfiguration(file);
|
||||
|
||||
for ( String key : channels.keySet() ) {
|
||||
Channel channel = channels.get(key);
|
||||
config.set(key + "." + KEY_DESC, channel.description);
|
||||
config.set(key + "." + KEY_FORMAT, channel.format);
|
||||
config.set(key + "." + KEY_MEMBERS, channel.members);
|
||||
config.set(key + "." + KEY_BANNED, channel.banned);
|
||||
}
|
||||
|
||||
config.save(file);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルの名前リストを返す
|
||||
* @return チャンネルの名前
|
||||
*/
|
||||
protected ArrayList<String> getNames() {
|
||||
|
||||
ArrayList<String> names = new ArrayList<String>();
|
||||
for ( String k : channels.keySet() ) {
|
||||
names.add(k);
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
/**
|
||||
* リスト表示用のリストを返す
|
||||
* @return リスト
|
||||
*/
|
||||
protected ArrayList<String> getList() {
|
||||
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
items.add(Utility.replaceColorCode(LIST_FIRSTLINE));
|
||||
for ( String key : channels.keySet() ) {
|
||||
Channel channel = channels.get(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),
|
||||
key, onlineNum, memberNum, desc);
|
||||
items.add(item);
|
||||
}
|
||||
items.add(LIST_ENDLINE);
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* セクションから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);
|
||||
if ( members == null ) {
|
||||
members = new ArrayList<String>();
|
||||
}
|
||||
|
||||
Channel channel = new Channel(name, desc, members);
|
||||
channel.format = format;
|
||||
channel.banned = banned;
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーが参加しているチャンネルを返す
|
||||
* @param player プレイヤー
|
||||
* @return チャンネル
|
||||
*/
|
||||
protected Channel getChannelByPlayer(Player player) {
|
||||
|
||||
String name = player.getName();
|
||||
for ( String key : channels.keySet() ) {
|
||||
Channel channel = channels.get(key);
|
||||
if ( channel.members.contains(name) ) {
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルを取得する
|
||||
* @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;
|
||||
}
|
||||
|
||||
protected void removeChannel(String name) {
|
||||
if ( channels.containsKey(name) ) {
|
||||
channels.remove(name);
|
||||
}
|
||||
Channel channel = getChannel(name);
|
||||
if ( channel != null ) {
|
||||
// TODO チャンネルのメンバーを強制解散させる
|
||||
|
||||
}
|
||||
save();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* このプラグインの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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license GPLv3
|
||||
* @copyright Copyright ucchy 2013
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* @author ucchy
|
||||
* LunachatAdminコマンドの処理クラス
|
||||
*/
|
||||
public class LunaChatAdminCommand implements CommandExecutor {
|
||||
|
||||
private static final String PREINFO = Resources.get("infoPrefix");
|
||||
private static final String PREERR = Resources.get("errorPrefix");
|
||||
|
||||
private static final String[] USAGE_KEYS = {
|
||||
"usageReload", "usageCreate", "usageRemove"
|
||||
};
|
||||
|
||||
/**
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(
|
||||
CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if ( args.length == 0 ) {
|
||||
printUsage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( args[0].equalsIgnoreCase("reload") ) {
|
||||
return doReload(sender, args);
|
||||
} else if ( args[0].equalsIgnoreCase("create") ) {
|
||||
return doCreate(sender, args);
|
||||
} else if ( args[0].equalsIgnoreCase("remove") ) {
|
||||
return doRemove(sender, args);
|
||||
} else {
|
||||
printUsage(sender, label);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* config.yml の再読み込みを行う
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doReload(CommandSender sender, String[] args) {
|
||||
|
||||
LunaChat.config.reloadConfig();
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
Resources.get("cmdmsgReload")));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルを新規作成する
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doCreate(CommandSender sender, String[] args) {
|
||||
|
||||
// 実行引数から、作成するチャンネルを取得する
|
||||
String name = "";
|
||||
String desc = "";
|
||||
if ( args.length >= 2 ) {
|
||||
name = args[1];
|
||||
if ( args.length >= 3 ) {
|
||||
desc = args[2];
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgCommand")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
ArrayList<String> channels = LunaChat.manager.getNames();
|
||||
if ( channels.contains(name) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgExist")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネル作成
|
||||
LunaChat.manager.createChannel(name, desc);
|
||||
sender.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREINFO + Resources.get("cmdmsgCreate")),
|
||||
name));
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean doRemove(CommandSender sender, String[] args) {
|
||||
|
||||
// 実行引数から、削除するチャンネルを取得する
|
||||
String name = "";
|
||||
if ( args.length >= 2 ) {
|
||||
name = args[1];
|
||||
} else {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgCommand")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
ArrayList<String> channels = LunaChat.manager.getNames();
|
||||
if ( !channels.contains(name) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNotExist")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネル削除
|
||||
LunaChat.manager.removeChannel(name);
|
||||
sender.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREINFO + Resources.get("cmdmsgRemove")),
|
||||
name));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドの使い方を senderに送る
|
||||
* @param sender
|
||||
* @param label
|
||||
*/
|
||||
private void printUsage(CommandSender sender, String label) {
|
||||
|
||||
for ( String key : USAGE_KEYS ) {
|
||||
String msg = String.format(
|
||||
Utility.replaceColorCode(Resources.get(key)),
|
||||
label);
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,499 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license GPLv3
|
||||
* @copyright Copyright ucchy 2013
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* @author ucchy
|
||||
* Lunachatコマンドの処理クラス
|
||||
*/
|
||||
public class LunaChatCommand implements CommandExecutor {
|
||||
|
||||
private static final String PREINFO = Resources.get("infoPrefix");
|
||||
private static final String PREERR = Resources.get("errorPrefix");
|
||||
|
||||
private static final String[] USAGE_KEYS = {
|
||||
"usageJoin", "usageLeave", "usageList", "usageInvite",
|
||||
"usageAccept", "usageDeny", "usageKick", "usageBan",
|
||||
};
|
||||
|
||||
/**
|
||||
* @see org.bukkit.command.CommandExecutor#onCommand(org.bukkit.command.CommandSender, org.bukkit.command.Command, java.lang.String, java.lang.String[])
|
||||
*/
|
||||
@Override
|
||||
public boolean onCommand(
|
||||
CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
if ( args.length == 0 ) {
|
||||
printUsage(sender, label);
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( args[0].equalsIgnoreCase("join") ) {
|
||||
return doJoin(sender, args);
|
||||
} else if ( args[0].equalsIgnoreCase("leave") ) {
|
||||
return doLeave(sender, args);
|
||||
} else if ( args[0].equalsIgnoreCase("list") ) {
|
||||
return doList(sender, args);
|
||||
} else if ( args[0].equalsIgnoreCase("invite") ) {
|
||||
return doInvite(sender, args);
|
||||
} else if ( args[0].equalsIgnoreCase("accept") ) {
|
||||
return doAccept(sender, args);
|
||||
} else if ( args[0].equalsIgnoreCase("deny") ) {
|
||||
return doDeny(sender, args);
|
||||
} else if ( args[0].equalsIgnoreCase("kick") ) {
|
||||
return doKick(sender, args);
|
||||
} else if ( args[0].equalsIgnoreCase("ban") ) {
|
||||
return doBan(sender, args);
|
||||
} else {
|
||||
return doJoin(sender, args);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルへの参加をする
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doJoin(CommandSender sender, String[] args) {
|
||||
|
||||
// プレイヤーでなければ終了する
|
||||
if ( sender instanceof Player ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgIngame")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 実行引数から、参加するチャンネルを取得する
|
||||
String channel = "";
|
||||
if ( !args[0].equalsIgnoreCase("join") ) {
|
||||
channel = args[0];
|
||||
} else if ( args.length >= 2 ) {
|
||||
channel = args[1];
|
||||
} else {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgCommand")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
ArrayList<String> channels = LunaChat.manager.getNames();
|
||||
if ( !channels.contains(channel) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNotExist")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルに参加する or 発言先を変更する
|
||||
Player player = (Player)sender;
|
||||
Channel c = LunaChat.manager.getChannel(channel);
|
||||
if ( c.members.contains(player.getName()) ) {
|
||||
// TODO
|
||||
} else {
|
||||
c.addMember(player.getName());
|
||||
sender.sendMessage(String.format(
|
||||
Utility.replaceColorCode(PREINFO + Resources.get("cmdmsgJoin")),
|
||||
channel));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルから退出する
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doLeave(CommandSender sender, String[] args) {
|
||||
|
||||
// プレイヤーでなければ終了する
|
||||
if ( sender instanceof Player ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgIngame")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 実行引数から、参加するチャンネルを取得する
|
||||
String channel = "";
|
||||
if ( args.length >= 2 ) {
|
||||
channel = args[1];
|
||||
} else {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgCommand")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
ArrayList<String> channels = LunaChat.manager.getNames();
|
||||
if ( !channels.contains(channel) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNotExist")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルのメンバーかどうかを確認する
|
||||
Player player = (Player)sender;
|
||||
Channel c = LunaChat.manager.getChannel(channel);
|
||||
if ( !c.members.contains(player.getName()) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNomember")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルから退出する
|
||||
c.removeMember(player.getName());
|
||||
|
||||
sender.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREINFO + Resources.get("cmdmsgLeave")),
|
||||
channel));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルをリスト表示する
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doList(CommandSender sender, String[] args) {
|
||||
|
||||
// リストを取得して表示する
|
||||
ArrayList<String> list = LunaChat.manager.getList();
|
||||
for ( String msg : list ) {
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 招待を送信する
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doInvite(CommandSender sender, String[] args) {
|
||||
|
||||
// プレイヤーでなければ終了する
|
||||
if ( sender instanceof Player ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgIngame")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 実行引数から、参加するチャンネル、招待する人を取得する
|
||||
String channelName = "";
|
||||
String invitedName = "";
|
||||
if ( args.length >= 3 ) {
|
||||
channelName = args[1];
|
||||
invitedName = args[2];
|
||||
} else {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgCommand")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルが存在するかどうかをチェックする
|
||||
ArrayList<String> channels = LunaChat.manager.getNames();
|
||||
if ( !channels.contains(channelName) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNotExist")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルのメンバーかどうかを確認する
|
||||
Player inviter = (Player)sender;
|
||||
Channel channel = LunaChat.manager.getChannel(channelName);
|
||||
if ( !channel.members.contains(inviter.getName()) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNomember")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待相手が存在するかどうかを確認する
|
||||
Player invited = LunaChat.getPlayerExact(invitedName);
|
||||
if ( invited == null ) {
|
||||
sender.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNotfoundPlayer")),
|
||||
invitedName));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待相手が既にチャンネルに参加しているかどうかを確認する
|
||||
if ( channel.members.contains(invitedName) ) {
|
||||
sender.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgInvitedAlreadyExist")),
|
||||
invitedName));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待を送信する
|
||||
LunaChat.inviteMap.put(invitedName, channelName);
|
||||
LunaChat.inviterMap.put(invitedName, inviter.getName());
|
||||
|
||||
inviter.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREINFO + Resources.get("cmdmsgInvite")),
|
||||
invitedName, channelName));
|
||||
invited.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREINFO + Resources.get("cmdmsgInvited1")),
|
||||
inviter.getName(), channelName));
|
||||
invited.sendMessage(
|
||||
Utility.replaceColorCode(
|
||||
PREINFO + Resources.get("cmdmsgInvited2")));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 招待を受けて、チャンネルチャットへ入室する
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doAccept(CommandSender sender, String[] args) {
|
||||
|
||||
// プレイヤーでなければ終了する
|
||||
if ( sender instanceof Player ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgIngame")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待を受けていないプレイヤーなら、エラーを表示して終了する
|
||||
Player player = (Player)sender;
|
||||
if ( !LunaChat.inviteMap.containsKey(player.getName()) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNotInvited")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルを取得して、招待記録を消去する
|
||||
String channelName = LunaChat.inviteMap.get(player.getName());
|
||||
Channel channel = LunaChat.manager.getChannel(channelName);
|
||||
LunaChat.inviteMap.remove(player.getName());
|
||||
LunaChat.inviterMap.remove(player.getName());
|
||||
|
||||
// 取得できなかったらエラー終了する
|
||||
if ( channel == null ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNotfoundChannel")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 既に参加しているなら、エラーを表示して終了する
|
||||
if ( channel.members.contains(player.getName()) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgInvitedAlreadyJoin")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 参加する
|
||||
channel.addMember(player.getName());
|
||||
sender.sendMessage(String.format(
|
||||
Utility.replaceColorCode(PREINFO + Resources.get("cmdmsgJoin")),
|
||||
channel));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 招待を拒否する
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doDeny(CommandSender sender, String[] args) {
|
||||
|
||||
// プレイヤーでなければ終了する
|
||||
if ( sender instanceof Player ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgIngame")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待を受けていないプレイヤーなら、エラーを表示して終了する
|
||||
Player player = (Player)sender;
|
||||
if ( !LunaChat.inviteMap.containsKey(player.getName()) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNotInvited")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 招待者を取得して、招待記録を消去する
|
||||
String inviterName = LunaChat.inviterMap.get(player.getName());
|
||||
LunaChat.inviteMap.remove(player.getName());
|
||||
LunaChat.inviterMap.remove(player.getName());
|
||||
|
||||
// メッセージ送信
|
||||
Player inviter = LunaChat.getPlayerExact(inviterName);
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREINFO + Resources.get("cmdmsgDeny")));
|
||||
if ( inviter != null ) {
|
||||
inviter.sendMessage(Utility.replaceColorCode(
|
||||
PREINFO + Resources.get("cmdmsgDenyed")));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルから指定したユーザーをキックする
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doKick(CommandSender sender, String[] args) {
|
||||
|
||||
// プレイヤーでなければ終了する
|
||||
if ( sender instanceof Player ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgIngame")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 実行引数から、キックするユーザーを取得する
|
||||
String kickedName = "";
|
||||
if ( args.length >= 2 ) {
|
||||
kickedName = args[1];
|
||||
} else {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgCommand")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 指定されたユーザーが居ない場合は、エラーを表示して終了する
|
||||
Player kicked = LunaChat.getPlayerExact(kickedName);
|
||||
if ( kicked == null ) {
|
||||
sender.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNotfoundPlayer")),
|
||||
kicked));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 参加チャンネルを取得、取得できない場合はエラー表示して終了する
|
||||
// TODO: 複数参加可能にし、発言しているチャンネルを対象にする
|
||||
Player kicker = (Player)sender;
|
||||
Channel channel = LunaChat.manager.getChannelByPlayer(kicker);
|
||||
if ( channel == null ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNoJoin")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// キックされるプレイヤーがメンバーかどうかチェックする
|
||||
if ( !channel.members.contains(kickedName) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNomemberOther")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// キック実行
|
||||
channel.removeMember(kickedName);
|
||||
sender.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREERR + Resources.get("cmdmsgKick")),
|
||||
kickedName, channel.name));
|
||||
kicked.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREERR + Resources.get("cmdmsgKicked")),
|
||||
channel.name));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルから指定したユーザーをBANする
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doBan(CommandSender sender, String[] args) {
|
||||
|
||||
// プレイヤーでなければ終了する
|
||||
if ( sender instanceof Player ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgIngame")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 実行引数から、BANするユーザーを取得する
|
||||
String kickedName = "";
|
||||
if ( args.length >= 2 ) {
|
||||
kickedName = args[1];
|
||||
} else {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgCommand")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 指定されたユーザーが居ない場合は、エラーを表示して終了する
|
||||
Player kicked = LunaChat.getPlayerExact(kickedName);
|
||||
if ( kicked == null ) {
|
||||
sender.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNotfoundPlayer")),
|
||||
kicked));
|
||||
return true;
|
||||
}
|
||||
|
||||
// 参加チャンネルを取得、取得できない場合はエラー表示して終了する
|
||||
// TODO: 複数参加可能にし、発言しているチャンネルを対象にする
|
||||
Player kicker = (Player)sender;
|
||||
Channel channel = LunaChat.manager.getChannelByPlayer(kicker);
|
||||
if ( channel == null ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNoJoin")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// BANされるプレイヤーがメンバーかどうかチェックする
|
||||
if ( !channel.members.contains(kickedName) ) {
|
||||
sender.sendMessage(Utility.replaceColorCode(
|
||||
PREERR + Resources.get("errmsgNomemberOther")));
|
||||
return true;
|
||||
}
|
||||
|
||||
// BAN実行
|
||||
channel.banned.add(kickedName);
|
||||
channel.removeMember(kickedName);
|
||||
sender.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREERR + Resources.get("cmdmsgBan")),
|
||||
kickedName, channel.name));
|
||||
kicked.sendMessage(String.format(
|
||||
Utility.replaceColorCode(
|
||||
PREERR + Resources.get("cmdmsgBanned")),
|
||||
channel.name));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドの使い方を senderに送る
|
||||
* @param sender
|
||||
* @param label
|
||||
*/
|
||||
private void printUsage(CommandSender sender, String label) {
|
||||
|
||||
for ( String key : USAGE_KEYS ) {
|
||||
String msg = String.format(
|
||||
Utility.replaceColorCode(Resources.get(key)),
|
||||
label);
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* @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 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", false);
|
||||
noJoinAsGlobal = config.getBoolean("noJoinAsGlobal", false);
|
||||
loggingChat = config.getBoolean("loggingChat", true);
|
||||
globalMarker = config.getString("globalMarker", "!");
|
||||
autoLeavingOnMove = config.getBoolean("autoLeavingOnMove", false);
|
||||
autoLeavingOnQuit = config.getBoolean("autoLeavingOnQuit", false);
|
||||
zeroMemberRemove = config.getBoolean("zeroMemberRemove", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license GPLv3
|
||||
* @copyright Copyright ucchy 2013
|
||||
*/
|
||||
package com.github.ucchyocean.lc;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
/**
|
||||
* @author ucchy
|
||||
* プレイヤーの行動を監視するリスナ
|
||||
*/
|
||||
public class PlayerListener implements Listener {
|
||||
|
||||
/**
|
||||
* プレイヤーのチャットごとに呼び出されるメソッド
|
||||
* @param event チャットイベント
|
||||
*/
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
|
||||
// 頭にglobalMarkerが付いている場合は、グローバル発言にする
|
||||
if ( event.getMessage().startsWith(LunaChat.config.globalMarker) ) {
|
||||
int offset = LunaChat.config.globalMarker.length();
|
||||
event.setMessage(event.getMessage().substring(offset));
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Channel channel = LunaChat.manager.getChannelByPlayer(player);
|
||||
|
||||
// チャンネルに所属していない場合
|
||||
if ( channel == null ) {
|
||||
if ( LunaChat.config.noJoinAsGlobal ) {
|
||||
// グローバル発言にする(=つまり、何もしないで終了する)
|
||||
return;
|
||||
} else {
|
||||
// 発言をキャンセルして終了する
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// チャンネルチャット発言
|
||||
channel.chat(player, event.getMessage());
|
||||
|
||||
// もとのイベントをキャンセル
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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");
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする