LunaChat v2.0.0 : Fixed issue #21.
このコミットが含まれているのは:
1 親
b4ef7c0733
コミット
1ce3ec5e64
7ファイル変更
+175
-7
検索条件に一致するファイルはありません
@@ -373,7 +373,20 @@ public class Channel implements ConfigurationSerializable {
|
||||
*/
|
||||
private String replaceKeywords(String format, Player player, String message) {
|
||||
|
||||
String msg = format.replace("%ch", name);
|
||||
String msg = format;
|
||||
|
||||
// テンプレートのキーワードを、まず最初に置き換える
|
||||
for ( int i=0; i<=9; i++ ) {
|
||||
String key = "%" + i;
|
||||
if ( msg.contains(key) ) {
|
||||
if ( LunaChat.manager.getTemplate("" + i) != null ) {
|
||||
msg = msg.replace(key, LunaChat.manager.getTemplate("" + i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg = msg.replace("%ch", name);
|
||||
msg = msg.replace("%msg", message);
|
||||
msg = msg.replace("%chcolor", colorCode);
|
||||
|
||||
|
||||
@@ -33,10 +33,13 @@ public class ChannelManager implements LunaChatAPI {
|
||||
private static final String MOTD_FIRSTLINE = Resources.get("motdFirstLine");
|
||||
|
||||
private static final String FILE_NAME_DCHANNELS = "defaults.yml";
|
||||
private static final String FILE_NAME_TEMPLATES = "templates.yml";
|
||||
|
||||
private File fileDefaults;
|
||||
private File fileTemplates;
|
||||
private HashMap<String, Channel> channels;
|
||||
private HashMap<String, String> defaultChannels;
|
||||
private HashMap<String, String> templates;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
@@ -73,6 +76,28 @@ public class ChannelManager implements LunaChatAPI {
|
||||
defaultChannels.put(key, config.getString(key));
|
||||
}
|
||||
|
||||
// テンプレート設定のロード
|
||||
fileTemplates = new File(
|
||||
LunaChat.instance.getDataFolder() +
|
||||
File.separator + FILE_NAME_TEMPLATES);
|
||||
|
||||
if ( !fileTemplates.exists() ) {
|
||||
YamlConfiguration conf = new YamlConfiguration();
|
||||
try {
|
||||
conf.save(fileTemplates);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
YamlConfiguration configTemplates =
|
||||
YamlConfiguration.loadConfiguration(fileTemplates);
|
||||
|
||||
templates = new HashMap<String, String>();
|
||||
for ( String key : configTemplates.getValues(false).keySet() ) {
|
||||
templates.put(key, configTemplates.getString(key));
|
||||
}
|
||||
|
||||
// チャンネル設定のロード
|
||||
channels = Channel.loadAllChannels();
|
||||
}
|
||||
@@ -91,6 +116,7 @@ public class ChannelManager implements LunaChatAPI {
|
||||
|
||||
/**
|
||||
* デフォルトチャンネル設定を保存する
|
||||
* @return 保存したかどうか
|
||||
*/
|
||||
public boolean saveDefaults() {
|
||||
|
||||
@@ -105,6 +131,23 @@ public class ChannelManager implements LunaChatAPI {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* テンプレート設定を保存する
|
||||
* @return 保存したかどうか
|
||||
*/
|
||||
public boolean saveTemplates() {
|
||||
|
||||
try {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
config.set("", templates);
|
||||
config.save(fileTemplates);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* リスト表示用のリストを返す
|
||||
* @param player プレイヤー、指定しない場合はnullにする
|
||||
@@ -349,6 +392,38 @@ public class ChannelManager implements LunaChatAPI {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* テンプレートを取得する
|
||||
* @param id テンプレートID
|
||||
* @return テンプレート
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#getTemplate(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public String getTemplate(String id) {
|
||||
return templates.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* テンプレートを登録する
|
||||
* @param id テンプレートID
|
||||
* @param template テンプレート
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#setTemplate(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void setTemplate(String id, String template) {
|
||||
templates.put(id, template);
|
||||
}
|
||||
|
||||
/**
|
||||
* テンプレートを削除する
|
||||
* @param id テンプレートID
|
||||
* @see com.github.ucchyocean.lc.LunaChatAPI#removeTemplate(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void removeTemplate(String id) {
|
||||
templates.remove(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された名前がチャンネル名として使用可能かどうかを判定する
|
||||
* @param name 名前
|
||||
|
||||
@@ -73,4 +73,24 @@ public interface LunaChatAPI {
|
||||
* @return 削除したかどうか
|
||||
*/
|
||||
public boolean removeChannel(String channelName);
|
||||
|
||||
/**
|
||||
* テンプレートを取得する
|
||||
* @param id テンプレートID
|
||||
* @return テンプレート
|
||||
*/
|
||||
public String getTemplate(String id);
|
||||
|
||||
/**
|
||||
* テンプレートを登録する
|
||||
* @param id テンプレートID
|
||||
* @param template テンプレート
|
||||
*/
|
||||
public void setTemplate(String id, String template);
|
||||
|
||||
/**
|
||||
* テンプレートを削除する
|
||||
* @param id テンプレートID
|
||||
*/
|
||||
public void removeTemplate(String id);
|
||||
}
|
||||
@@ -30,7 +30,8 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
private static final String[] COMMANDS = {
|
||||
"join", "leave", "list", "invite", "accept",
|
||||
"deny", "kick", "ban", "pardon", "create",
|
||||
"remove", "format", "moderator", "option", "reload",
|
||||
"remove", "format", "moderator", "option",
|
||||
"template", "reload",
|
||||
};
|
||||
|
||||
private static final String[] USAGE_KEYS = {
|
||||
@@ -85,6 +86,8 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
return doModerator(sender, args);
|
||||
} else if (args[0].equalsIgnoreCase("option")) {
|
||||
return doOption(sender, args);
|
||||
} else if (args[0].equalsIgnoreCase("template")) {
|
||||
return doTemplate(sender, args);
|
||||
} else if (args[0].equalsIgnoreCase("reload")) {
|
||||
return doReload(sender, args);
|
||||
} else {
|
||||
@@ -1023,6 +1026,8 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
}
|
||||
if ( !LunaChat.config.globalChannel.equals(channel.getName()) ) {
|
||||
if ( options.containsKey("password") ) {
|
||||
// パスワード
|
||||
// TODO: パスワードは10文字制限をした方がいい。
|
||||
channel.setPassword(options.get("password"));
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgOption", "password", options.get("password"));
|
||||
@@ -1053,6 +1058,53 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* テンプレートの登録を行う
|
||||
*
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doTemplate(CommandSender sender, String[] args) {
|
||||
|
||||
// 引数チェック
|
||||
// このコマンドは、コンソールでも実行できる
|
||||
if ( args.length <= 1 ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( !args[1].matches("[0-9]") ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgInvalidTemplateNumber");
|
||||
sendResourceMessage(sender, PREERR, "usageTemplate");
|
||||
return true;
|
||||
}
|
||||
|
||||
String id = args[1];
|
||||
StringBuilder buf = new StringBuilder();
|
||||
if ( args.length >= 3 ) {
|
||||
for (int i = 2; i < args.length; i++) {
|
||||
buf.append(args[i] + " ");
|
||||
}
|
||||
}
|
||||
String format = buf.toString().trim();
|
||||
|
||||
// 登録を実行
|
||||
if ( format.equals("") ) {
|
||||
LunaChat.manager.removeTemplate(id);
|
||||
LunaChat.manager.saveTemplates();
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgTemplateRemove", id);
|
||||
} else {
|
||||
LunaChat.manager.setTemplate(id, format);
|
||||
LunaChat.manager.saveTemplates();
|
||||
sendResourceMessage(sender, PREINFO,
|
||||
"cmdmsgTemplate", id, format);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* sender がパーミッションを持っているかどうかを確認する。<br>
|
||||
* 持っていなければ、エラーメッセージを表示する。
|
||||
|
||||
@@ -37,7 +37,7 @@ public class Resources {
|
||||
|
||||
if ( !file.exists() ) {
|
||||
Utility.copyFileFromJar(LunaChat.getPluginJarFile(),
|
||||
file, "messages.yml", false);
|
||||
file, FILE_NAME, false);
|
||||
}
|
||||
|
||||
defaultMessages = loadDefaultMessages();
|
||||
@@ -68,7 +68,7 @@ public class Resources {
|
||||
JarFile jarFile = null;
|
||||
try {
|
||||
jarFile = new JarFile(LunaChat.getPluginJarFile());
|
||||
ZipEntry zipEntry = jarFile.getEntry("messages.yml");
|
||||
ZipEntry zipEntry = jarFile.getEntry(FILE_NAME);
|
||||
InputStream inputStream = jarFile.getInputStream(zipEntry);
|
||||
BufferedReader reader =
|
||||
new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする