LunaChat v2.5.8 : Fixed issue #66

このコミットが含まれているのは:
ucchyocean committed 2014-01-13 21:23:09 +09:00
1 親 cad998945d
コミット a49eb3dea7
7ファイル変更
+222 -10

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

+105
ファイルの表示
@@ -55,6 +55,10 @@ public class Channel implements ConfigurationSerializable {
Resources.get("defaultFormatForPersonalChat");
private static final String MSG_JOIN = Resources.get("joinMessage");
private static final String MSG_QUIT = Resources.get("quitMessage");
private static final String MSG_BAN_EXPIRED = Resources.get("expiredBan");
private static final String MSG_MUTE_EXPIRED = Resources.get("expiredMute");
private static final String MSG_BAN_EXPIRED_PLAYER = Resources.get("cmdmsgPardoned");
private static final String MSG_MUTE_EXPIRED_PLAYER = Resources.get("cmdmsgUnmuted");
private static final String PREINFO = Resources.get("infoPrefix");
private static final String PREERR = Resources.get("errorPrefix");
@@ -82,6 +86,8 @@ public class Channel implements ConfigurationSerializable {
private static final String KEY_BROADCAST = "broadcast";
private static final String KEY_WORLD = "world";
private static final String KEY_RANGE = "range";
private static final String KEY_BAN_EXPIRES = "ban_expires";
private static final String KEY_MUTE_EXPIRES = "mute_expires";
/** 参加者 */
private List<String> members;
@@ -133,6 +139,12 @@ public class Channel implements ConfigurationSerializable {
/** チャットの可聴範囲 0は無制限 */
private int chatRange;
/** 期限付きBANの期限(key=プレイヤー名、value=期日(ミリ秒)) */
private Map<String, Long> banExpires;
/** 期限付きMuteの期限(key=プレイヤー名、value=期日(ミリ秒)) */
private Map<String, Long> muteExpires;
/** ロガー */
private LunaChatLogger logger;
@@ -154,6 +166,8 @@ public class Channel implements ConfigurationSerializable {
this.broadcastChannel = false;
this.isWorldRange = false;
this.chatRange = 0;
this.banExpires = new HashMap<String, Long>();
this.muteExpires = new HashMap<String, Long>();
if ( isPersonalChat() ) {
this.format = DEFAULT_FORMAT_FOR_PERSONAL;
@@ -769,6 +783,60 @@ public class Channel implements ConfigurationSerializable {
return members.size();
}
/**
* 期限付きBanや期限付きMuteをチェックし、期限が切れていたら解除を行う
*/
public void checkExpires() {
long now = System.currentTimeMillis();
// 期限付きBANのチェック
for ( String name : banExpires.keySet() ) {
if ( banExpires.get(name) <= now ) {
// 期限マップから削除し、BANを解除
banExpires.remove(name);
if ( banned.contains(name) ) {
banned.remove(name);
save();
// メッセージ通知を流す
String msg = String.format(MSG_BAN_EXPIRED, this.name, name);
sendMessage(null, msg, null, false);
Player player = Bukkit.getPlayerExact(name);
if ( player != null ) {
msg = PREINFO + String.format(MSG_BAN_EXPIRED_PLAYER, this.name);
player.sendMessage(msg);
}
}
}
}
// 期限付きMuteのチェック
for ( String name : muteExpires.keySet() ) {
if ( muteExpires.get(name) <= now ) {
// 期限マップから削除し、Muteを解除
muteExpires.remove(name);
if ( muted.contains(name) ) {
muted.remove(name);
save();
// メッセージ通知を流す
String msg = String.format(MSG_MUTE_EXPIRED, this.name, name);
sendMessage(null, msg, null, false);
Player player = Bukkit.getPlayerExact(name);
if ( player != null ) {
msg = PREINFO + String.format(MSG_MUTE_EXPIRED_PLAYER, this.name);
player.sendMessage(msg);
}
}
}
}
}
/**
* シリアライズ<br>
@@ -793,6 +861,8 @@ public class Channel implements ConfigurationSerializable {
map.put(KEY_BROADCAST, broadcastChannel);
map.put(KEY_WORLD, isWorldRange);
map.put(KEY_RANGE, chatRange);
map.put(KEY_BAN_EXPIRES, banExpires);
map.put(KEY_MUTE_EXPIRES, muteExpires);
return map;
}
@@ -822,6 +892,8 @@ public class Channel implements ConfigurationSerializable {
channel.broadcastChannel = castWithDefault(data.get(KEY_BROADCAST), false);
channel.isWorldRange = castWithDefault(data.get(KEY_WORLD), false);
channel.chatRange = castWithDefault(data.get(KEY_RANGE), 0);
channel.banExpires = castToStringLongMap(data.get(KEY_BAN_EXPIRES));
channel.muteExpires = castToStringLongMap(data.get(KEY_MUTE_EXPIRES));
return channel;
}
@@ -857,6 +929,23 @@ public class Channel implements ConfigurationSerializable {
return (List<String>)obj;
}
/**
* Objectを、Map&lt;String, Long&gt;に変換する。nullなら空のリストを返す。
* @param obj 変換元
* @return 変換後
*/
@SuppressWarnings("unchecked")
private static Map<String, Long> castToStringLongMap(Object obj) {
if ( obj == null ) {
return new HashMap<String, Long>();
}
if ( !(obj instanceof HashMap<?, ?>) ) {
return new HashMap<String, Long>();
}
return (Map<String, Long>)obj;
}
/**
* チャンネルの説明文を返す
* @return チャンネルの説明文
@@ -965,6 +1054,22 @@ public class Channel implements ConfigurationSerializable {
return muted;
}
/**
* 期限付きBANの期限マップを返す(key=プレイヤー名、value=期日(ミリ秒))
* @return banExpires
*/
public Map<String, Long> getBanExpires() {
return banExpires;
}
/**
* 期限付きMuteの期限マップを返す(key=プレイヤー名、value=期日(ミリ秒))
* @return muteExpires
*/
public Map<String, Long> getMuteExpires() {
return muteExpires;
}
/**
* 非表示プレイヤーの一覧を返す
* @return チャンネルの非表示プレイヤーの一覧
+26
ファイルの表示
@@ -0,0 +1,26 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2014
*/
package com.github.ucchyocean.lc;
import org.bukkit.scheduler.BukkitRunnable;
/**
* 各チャンネルの期限付きBANや期限付きMuteを、1分間隔で確認しに行くタスク
* @author ucchy
*/
public class ExpireCheckTask extends BukkitRunnable {
/**
* 1分ごとに呼び出されるメソッド
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
for ( Channel channel : LunaChat.instance.getLunaChatAPI().getChannels() ) {
channel.checkExpires();
}
}
}
+21
ファイルの表示
@@ -10,6 +10,7 @@ import java.io.File;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import com.github.ucchyocean.lc.bridge.DynmapBridge;
import com.github.ucchyocean.lc.bridge.VaultChatBridge;
@@ -30,6 +31,8 @@ public class LunaChat extends JavaPlugin {
protected static VaultChatBridge vaultchat;
protected static DynmapBridge dynmap;
private static BukkitTask expireCheckerTask;
/**
* プラグインが有効化されたときに呼び出されるメソッド
@@ -69,6 +72,24 @@ public class LunaChat extends JavaPlugin {
// シリアル化可能オブジェクトの登録
ConfigurationSerialization.registerClass(Channel.class, "Channel");
// 期限チェッカータスクの起動
expireCheckerTask =
getServer().getScheduler().runTaskTimer(
this, new ExpireCheckTask(), 100, 1200);
}
/**
* プラグインが無効化されたときに呼び出されるメソッド
* @see org.bukkit.plugin.java.JavaPlugin#onDisable()
*/
@Override
public void onDisable() {
// 期限チェッカータスクの停止
if ( expireCheckerTask != null ) {
getServer().getScheduler().cancelTask(expireCheckerTask.getTaskId());
}
}
/**
+30 -5
ファイルの表示
@@ -19,7 +19,8 @@ public class BanCommand extends SubCommandAbst {
private static final String COMMAND_NAME = "ban";
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
private static final String USAGE_KEY = "usageBan";
private static final String USAGE_KEY1 = "usageBan";
private static final String USAGE_KEY2 = "usageBan2";
/**
* コマンドを取得します。
@@ -60,7 +61,8 @@ public class BanCommand extends SubCommandAbst {
@Override
public void sendUsageMessage(
CommandSender sender, String label) {
sendResourceMessage(sender, "", USAGE_KEY, label);
sendResourceMessage(sender, "", USAGE_KEY1, label);
sendResourceMessage(sender, "", USAGE_KEY2, label);
}
/**
@@ -115,20 +117,43 @@ public class BanCommand extends SubCommandAbst {
sendResourceMessage(sender, PREERR, "errmsgNomemberOther");
return true;
}
// 既にBANされているかどうかチェックする
if (channel.getBanned().contains(kickedName)) {
sendResourceMessage(sender, PREERR, "errmsgAlreadyBanned");
return true;
}
// 期限付きBANの場合、期限の指定が正しいかどうかをチェックする
int expireMinutes = -1;
if (args.length >= 3) {
if ( !args[2].matches("[0-9]+") ) {
sendResourceMessage(sender, PREERR, "errmsgInvalidBanExpireParameter");
return true;
}
expireMinutes = Integer.parseInt(args[2]);
if ( expireMinutes < 1 || 43200 < expireMinutes ) {
sendResourceMessage(sender, PREERR, "errmsgInvalidBanExpireParameter");
return true;
}
}
// BAN実行
Player kicked = Bukkit.getPlayerExact(kickedName);
channel.getBanned().add(kickedName);
if ( expireMinutes != -1 ) {
long expire = System.currentTimeMillis() + expireMinutes * 60 * 1000;
channel.getBanExpires().put(kickedName, expire);
}
channel.removeMember(kickedName);
sendResourceMessage(sender, PREINFO,
"cmdmsgBan", kickedName, channel.getName());
if ( expireMinutes != -1 ) {
sendResourceMessage(sender, PREINFO,
"cmdmsgBanWithExpire", kickedName, channel.getName(), expireMinutes);
} else {
sendResourceMessage(sender, PREINFO,
"cmdmsgBan", kickedName, channel.getName());
}
if (kicked != null) {
sendResourceMessage(kicked, PREINFO,
"cmdmsgBanned", channel.getName());
+30 -5
ファイルの表示
@@ -19,7 +19,8 @@ public class MuteCommand extends SubCommandAbst {
private static final String COMMAND_NAME = "mute";
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
private static final String USAGE_KEY = "usageMute";
private static final String USAGE_KEY1 = "usageMute";
private static final String USAGE_KEY2 = "usageMute2";
/**
* コマンドを取得します。
@@ -60,7 +61,8 @@ public class MuteCommand extends SubCommandAbst {
@Override
public void sendUsageMessage(
CommandSender sender, String label) {
sendResourceMessage(sender, "", USAGE_KEY, label);
sendResourceMessage(sender, "", USAGE_KEY1, label);
sendResourceMessage(sender, "", USAGE_KEY2, label);
}
/**
@@ -109,20 +111,43 @@ public class MuteCommand extends SubCommandAbst {
sendResourceMessage(sender, PREERR, "errmsgNomemberOther");
return true;
}
// 既にMuteされているかどうかチェックする
if (channel.getMuted().contains(kickedName)) {
sendResourceMessage(sender, PREERR, "errmsgAlreadyMuted");
return true;
}
// 期限付きMuteの場合、期限の指定が正しいかどうかをチェックする
int expireMinutes = -1;
if (args.length >= 3) {
if ( !args[2].matches("[0-9]+") ) {
sendResourceMessage(sender, PREERR, "errmsgInvalidMuteExpireParameter");
return true;
}
expireMinutes = Integer.parseInt(args[2]);
if ( expireMinutes < 1 || 43200 < expireMinutes ) {
sendResourceMessage(sender, PREERR, "errmsgInvalidMuteExpireParameter");
return true;
}
}
// Mute実行
Player kicked = Bukkit.getPlayerExact(kickedName);
channel.getMuted().add(kickedName);
if ( expireMinutes != -1 ) {
long expire = System.currentTimeMillis() + expireMinutes * 60 * 1000;
channel.getMuteExpires().put(kickedName, expire);
}
channel.save();
sendResourceMessage(sender, PREINFO,
"cmdmsgMute", kickedName, channel.getName());
if ( expireMinutes != -1 ) {
sendResourceMessage(sender, PREINFO,
"cmdmsgMuteWithExpire", kickedName, channel.getName(), expireMinutes);
} else {
sendResourceMessage(sender, PREINFO,
"cmdmsgMute", kickedName, channel.getName());
}
if (kicked != null) {
sendResourceMessage(kicked, PREINFO,
"cmdmsgMuted", channel.getName());