LunaChat v2.4.0 : Added mute and unmute command feature. (Issue #46)

このコミットが含まれているのは:
ucchyocean committed 2013-09-11 03:37:44 +09:00
1 親 5d0eec6876
コミット 820cea92cc
11ファイル変更
+445 -18

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

+115 -11
ファイルの表示
@@ -42,6 +42,9 @@ public class Channel implements ConfigurationSerializable {
private static final String INFO_PASSWORD = Resources.get("channelInfoPassword");
private static final String INFO_WORLDCHAT = Resources.get("channelInfoWorldChat");
private static final String INFO_RANGECHAT = Resources.get("channelInfoRangeChat");
private static final String INFO_FORMAT = Resources.get("channelInfoFormat");
private static final String INFO_BANNED = Resources.get("channelInfoBanned");
private static final String INFO_MUTED = Resources.get("channelInfoMuted");
private static final String LIST_ENDLINE = Resources.get("listEndLine");
private static final String LIST_FORMAT = Resources.get("listFormat");
@@ -53,17 +56,23 @@ public class Channel implements ConfigurationSerializable {
private static final String MSG_QUIT = Resources.get("quitMessage");
private static final String PREINFO = Resources.get("infoPrefix");
private static final String PREERR = Resources.get("errorPrefix");
private static final String NGWORD_PREFIX = Resources.get("ngwordPrefix");
private static final String MSG_KICKED = Resources.get("cmdmsgKicked");
private static final String MSG_BANNED = Resources.get("cmdmsgBanned");
private static final String MSG_MUTED = Resources.get("cmdmsgMuted");
private static final String MSG_NO_RECIPIENT = Resources.get("noRecipientMessage");
private static final String ERRMSG_MUTED = Resources.get("errmsgMuted");
private static final String KEY_NAME = "name";
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_MUTED = "muted";
private static final String KEY_MODERATOR = "moderator";
private static final String KEY_PASSWORD = "password";
private static final String KEY_VISIBLE = "visible";
@@ -80,6 +89,9 @@ public class Channel implements ConfigurationSerializable {
/** BANされたプレイヤー */
private List<String> banned;
/** Muteされたプレイヤー */
private List<String> muted;
/** チャンネルの名称 */
private String name;
@@ -128,6 +140,7 @@ public class Channel implements ConfigurationSerializable {
this.description = "";
this.members = new ArrayList<String>();
this.banned = new ArrayList<String>();
this.muted = new ArrayList<String>();
this.moderator = new ArrayList<String>();
this.password = "";
this.visible = true;
@@ -179,6 +192,13 @@ public class Channel implements ConfigurationSerializable {
*/
public void chat(Player player, String message) {
// Muteされているかどうかを確認する
if ( player != null && muted.contains(player.getName()) ) {
player.sendMessage( PREERR + ERRMSG_MUTED );
return;
}
String preReplaceMessage = message;
// 一時的にJapanizeスキップ設定かどうかを確認する
@@ -261,17 +281,29 @@ public class Channel implements ConfigurationSerializable {
if ( LunaChat.config.getNgwordAction() == NGWordAction.BAN ) {
// BANする
banned.add(player.getName());
removeMember(player.getName());
String temp = PREINFO + NGWORD_PREFIX + MSG_BANNED;
String m = String.format(temp, name);
player.sendMessage(m);
if ( !isBroadcastChannel() ) {
banned.add(player.getName());
removeMember(player.getName());
String temp = PREINFO + NGWORD_PREFIX + MSG_BANNED;
String m = String.format(temp, name);
player.sendMessage(m);
}
} else if ( LunaChat.config.getNgwordAction() == NGWordAction.KICK ) {
// キックする
removeMember(player.getName());
String temp = PREINFO + NGWORD_PREFIX + MSG_KICKED;
if ( !isBroadcastChannel() ) {
removeMember(player.getName());
String temp = PREINFO + NGWORD_PREFIX + MSG_KICKED;
String m = String.format(temp, name);
player.sendMessage(m);
}
} else if ( LunaChat.config.getNgwordAction() == NGWordAction.MUTE ) {
// Muteする
muted.add(player.getName());
String temp = PREINFO + NGWORD_PREFIX + MSG_MUTED;
String m = String.format(temp, name);
player.sendMessage(m);
}
@@ -459,16 +491,19 @@ public class Channel implements ConfigurationSerializable {
/**
* チャンネル情報を返す
* @param forModerator モデレータ向けの情報を含めるかどうか
* @return チャンネル情報
*/
public ArrayList<String> getInfo() {
public ArrayList<String> getInfo(boolean forModerator) {
ArrayList<String> info = new ArrayList<String>();
info.add(INFO_FIRSTLINE);
// チャンネル名、参加人数、総人数、チャンネル説明文
info.add( String.format(
LIST_FORMAT, name, getOnlineNum(), getTotalNum(), description) );
// 参加メンバー一覧
if ( isGlobalChannel() ) {
info.add(INFO_GLOBAL);
} else if ( isBroadcastChannel() ) {
@@ -502,20 +537,67 @@ public class Channel implements ConfigurationSerializable {
info.add(buf.toString());
}
// シークレットチャンネルかどうか
if ( !visible ) {
info.add(INFO_SECRET);
}
// パスワード設定があるかどうか
if ( password.length() > 0 ) {
info.add(INFO_PASSWORD);
if ( !forModerator ) {
info.add(INFO_PASSWORD);
} else {
info.add(INFO_PASSWORD + " " + password);
}
}
// 範囲チャット、ワールドチャット
if ( isWorldRange && chatRange > 0 ) {
info.add(String.format(INFO_RANGECHAT, chatRange));
} else if ( isWorldRange ) {
info.add(INFO_WORLDCHAT);
}
if ( forModerator ) {
// フォーマット情報
info.add(INFO_FORMAT + format);
// Muteリスト情報、5人ごとに表示する
info.add(INFO_MUTED);
StringBuffer buf = new StringBuffer();
for ( int i=0; i<muted.size(); i++ ) {
if ( i%5 == 0 ) {
if ( i != 0 ) {
info.add(buf.toString());
buf = new StringBuffer();
}
buf.append(INFO_PREFIX + ChatColor.WHITE);
}
buf.append(muted.get(i) + ",");
}
info.add(buf.toString());
// BANリスト情報、5人ごとに表示する
info.add(INFO_BANNED);
buf = new StringBuffer();
for ( int i=0; i<banned.size(); i++ ) {
if ( i%5 == 0 ) {
if ( i != 0 ) {
info.add(buf.toString());
buf = new StringBuffer();
}
buf.append(INFO_PREFIX + ChatColor.WHITE);
}
buf.append(banned.get(i) + ",");
}
info.add(buf.toString());
}
info.add(LIST_ENDLINE);
return info;
@@ -580,7 +662,7 @@ public class Channel implements ConfigurationSerializable {
*/
public int getOnlineNum() {
// グローバルチャンネルならサーバー接続人数を返す
// ブロードキャストチャンネルならサーバー接続人数を返す
if ( isBroadcastChannel() ) {
return Bukkit.getOnlinePlayers().length;
}
@@ -601,7 +683,7 @@ public class Channel implements ConfigurationSerializable {
*/
public int getTotalNum() {
// グローバルチャンネルならサーバー接続人数を返す
// ブロードキャストチャンネルならサーバー接続人数を返す
if ( isBroadcastChannel() ) {
return Bukkit.getOnlinePlayers().length;
}
@@ -623,6 +705,7 @@ public class Channel implements ConfigurationSerializable {
map.put(KEY_FORMAT, format);
map.put(KEY_MEMBERS, members);
map.put(KEY_BANNED, banned);
map.put(KEY_MUTED, muted);
map.put(KEY_MODERATOR, moderator);
map.put(KEY_PASSWORD, password);
map.put(KEY_VISIBLE, visible);
@@ -650,6 +733,7 @@ public class Channel implements ConfigurationSerializable {
channel.format =
castWithDefault(data.get(KEY_FORMAT), DEFAULT_FORMAT);
channel.banned = castToStringList(data.get(KEY_BANNED));
channel.muted = castToStringList(data.get(KEY_MUTED));
channel.moderator = castToStringList(data.get(KEY_MODERATOR));
channel.password = castWithDefault(data.get(KEY_PASSWORD), "");
channel.visible = castWithDefault(data.get(KEY_VISIBLE), true);
@@ -761,6 +845,18 @@ public class Channel implements ConfigurationSerializable {
* @return チャンネルのメンバー
*/
public List<String> getMembers() {
// ブロードキャストチャンネルなら、
// 現在サーバーに接続している全プレイヤーをメンバーとして返す
if ( isBroadcastChannel() ) {
Player[] players = Bukkit.getOnlinePlayers();
List<String> mem = new ArrayList<String>();
for ( Player p : players ) {
mem.add(p.getName());
}
return mem;
}
return members;
}
@@ -780,6 +876,14 @@ public class Channel implements ConfigurationSerializable {
return banned;
}
/**
* チャンネルのMuteリストを返す
* @return チャンネルのMuteリスト
*/
public List<String> getMuted() {
return muted;
}
/**
* チャンネル名を返す
* @return チャンネル名
+3
ファイルの表示
@@ -14,6 +14,9 @@ public enum NGWordAction {
/** マスクするのみ */
MASK("mask"),
/** マスクしつつ、チャンネルからMuteする */
MUTE("mute"),
/** マスクしつつ、チャンネルからキックする */
KICK("kick"),
+6
ファイルの表示
@@ -105,6 +105,12 @@ public class BanCommand extends SubCommandAbst {
sendResourceMessage(sender, PREERR, "errmsgNomemberOther");
return true;
}
// 既にBANされているかどうかチェックする
if (!channel.getBanned().contains(kickedName)) {
sendResourceMessage(sender, PREERR, "errmsgAlreadyBanned");
return true;
}
// BAN実行
Player kicked = Bukkit.getPlayerExact(kickedName);
+5 -1
ファイルの表示
@@ -98,9 +98,13 @@ public class InfoCommand extends SubCommandAbst {
sendResourceMessage(sender, PREERR, "errmsgBanned");
return true;
}
// チャンネルモデレーターかどうか確認する
boolean isModerator = sender.isOp() ||
(player != null && channel.getModerator().contains(player.getName()));
// 情報を取得して表示する
ArrayList<String> list = channel.getInfo();
ArrayList<String> list = channel.getInfo(isModerator);
for (String msg : list) {
sender.sendMessage(msg);
}
+3
ファイルの表示
@@ -40,11 +40,14 @@ public class LunaChatCommand implements CommandExecutor {
commands.add(new KickCommand());
commands.add(new BanCommand());
commands.add(new PardonCommand());
commands.add(new MuteCommand());
commands.add(new UnmuteCommand());
commands.add(new InfoCommand());
commands.add(new CreateCommand());
commands.add(new RemoveCommand());
commands.add(new FormatCommand());
commands.add(new ModeratorCommand());
commands.add(new ModCommand());
commands.add(new OptionCommand());
commands.add(new TemplateCommand());
commands.add(new ReloadCommand());
+25
ファイルの表示
@@ -0,0 +1,25 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc.command;
/**
* moderatorコマンドのエイリアス実行クラス、名前のみが異なるが、他は全て一緒。
* @author ucchy
*/
public class ModCommand extends ModeratorCommand {
private static final String COMMAND_NAME = "mod";
/**
* コマンドを取得します。
* @return コマンド
* @see com.github.ucchyocean.lc.command.SubCommandAbst#getCommandName()
*/
@Override
public String getCommandName() {
return COMMAND_NAME;
}
}
+122
ファイルの表示
@@ -0,0 +1,122 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc.command;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.github.ucchyocean.lc.Channel;
/**
* muteコマンドの実行クラス
* @author ucchy
*/
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";
/**
* コマンドを取得します。
* @return コマンド
* @see com.github.ucchyocean.lc.command.SubCommandAbst#getCommandName()
*/
@Override
public String getCommandName() {
return COMMAND_NAME;
}
/**
* パーミッションノードを取得します。
* @return パーミッションノード
* @see com.github.ucchyocean.lc.command.SubCommandAbst#getPermissionNode()
*/
@Override
public String getPermissionNode() {
return PERMISSION_NODE;
}
/**
* 使用方法に関するメッセージをsenderに送信します。
* @param sender コマンド実行者
* @param label 実行ラベル
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
*/
@Override
public void sendUsageMessage(
CommandSender sender, String label) {
sendResourceMessage(sender, "", USAGE_KEY, label);
}
/**
* コマンドを実行します。
* @param sender コマンド実行者
* @param label 実行ラベル
* @param args 実行時の引数
* @return コマンドが実行されたかどうか
* @see com.github.ucchyocean.lc.command.SubCommandAbst#runCommand(java.lang.String[])
*/
@Override
public boolean runCommand(
CommandSender sender, String label, String[] args) {
// プレイヤーでなければ終了する
if (!(sender instanceof Player)) {
sendResourceMessage(sender, PREERR, "errmsgIngame");
return true;
}
// 実行引数から、Muteするユーザーを取得する
String kickedName = "";
if (args.length >= 2) {
kickedName = args[1];
} else {
sendResourceMessage(sender, PREERR, "errmsgCommand");
return true;
}
// デフォルト参加チャンネルを取得、取得できない場合はエラー表示して終了する
Player kicker = (Player) sender;
Channel channel = api.getDefaultChannel(kicker.getName());
if (channel == null) {
sendResourceMessage(sender, PREERR, "errmsgNoJoin");
return true;
}
// モデレーターかどうか確認する
if (!channel.getModerator().contains(kicker.getName()) && !kicker.isOp()) {
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
return true;
}
// Muteされるプレイヤーがメンバーかどうかチェックする
if (!channel.getMembers().contains(kickedName)) {
sendResourceMessage(sender, PREERR, "errmsgNomemberOther");
return true;
}
// 既にMuteされているかどうかチェックする
if (!channel.getMuted().contains(kickedName)) {
sendResourceMessage(sender, PREERR, "errmsgAlreadyMuted");
return true;
}
// Mute実行
Player kicked = Bukkit.getPlayerExact(kickedName);
channel.getMuted().add(kickedName);
sendResourceMessage(sender, PREINFO,
"cmdmsgMute", kickedName, channel.getName());
if (kicked != null) {
sendResourceMessage(kicked, PREINFO,
"cmdmsgMuted", channel.getName());
}
return true;
}
}
+117
ファイルの表示
@@ -0,0 +1,117 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc.command;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.github.ucchyocean.lc.Channel;
/**
* unmuteコマンドの実行クラス
* @author ucchy
*/
public class UnmuteCommand extends SubCommandAbst {
private static final String COMMAND_NAME = "unmute";
private static final String PERMISSION_NODE = "lunachat." + COMMAND_NAME;
private static final String USAGE_KEY = "usageUnmute";
/**
* コマンドを取得します。
* @return コマンド
* @see com.github.ucchyocean.lc.command.SubCommandAbst#getCommandName()
*/
@Override
public String getCommandName() {
return COMMAND_NAME;
}
/**
* パーミッションノードを取得します。
* @return パーミッションノード
* @see com.github.ucchyocean.lc.command.SubCommandAbst#getPermissionNode()
*/
@Override
public String getPermissionNode() {
return PERMISSION_NODE;
}
/**
* 使用方法に関するメッセージをsenderに送信します。
* @param sender コマンド実行者
* @param label 実行ラベル
* @see com.github.ucchyocean.lc.command.SubCommandAbst#sendUsageMessage()
*/
@Override
public void sendUsageMessage(
CommandSender sender, String label) {
sendResourceMessage(sender, "", USAGE_KEY, label);
}
/**
* コマンドを実行します。
* @param sender コマンド実行者
* @param label 実行ラベル
* @param args 実行時の引数
* @return コマンドが実行されたかどうか
* @see com.github.ucchyocean.lc.command.SubCommandAbst#runCommand(java.lang.String[])
*/
@Override
public boolean runCommand(
CommandSender sender, String label, String[] args) {
// プレイヤーでなければ終了する
if (!(sender instanceof Player)) {
sendResourceMessage(sender, PREERR, "errmsgIngame");
return true;
}
// 実行引数から、Mute解除するユーザーを取得する
String kickedName = "";
if (args.length >= 2) {
kickedName = args[1];
} else {
sendResourceMessage(sender, PREERR, "errmsgCommand");
return true;
}
// デフォルト参加チャンネルを取得、取得できない場合はエラー表示して終了する
Player kicker = (Player) sender;
Channel channel = api.getDefaultChannel(kicker.getName());
if (channel == null) {
sendResourceMessage(sender, PREERR, "errmsgNoJoin");
return true;
}
// モデレーターかどうか確認する
if (!channel.getModerator().contains(kicker.getName()) && !kicker.isOp()) {
sendResourceMessage(sender, PREERR, "errmsgNotModerator");
return true;
}
// Mute解除されるプレイヤーがMuteされているかどうかチェックする
if (!channel.getMuted().contains(kickedName)) {
sendResourceMessage(sender, PREERR, "errmsgNotMuted");
return true;
}
// BAN解除実行
Player kicked = Bukkit.getPlayerExact(kickedName);
channel.getMuted().remove(kickedName);
channel.save();
sendResourceMessage(sender, PREINFO,
"cmdmsgUnmute", kickedName, channel.getName());
if (kicked != null) {
sendResourceMessage(kicked, PREINFO,
"cmdmsgUnmuted", channel.getName());
}
return true;
}
}