LunaChat v1.2.0 : Fixed issue #9.
このコミットが含まれているのは:
1 親
ae6975abf7
コミット
c4c9b814eb
5ファイル変更
+126
-3
検索条件に一致するファイルはありません
@@ -8,6 +8,7 @@ package com.github.ucchyocean.lc;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
@@ -16,6 +17,11 @@ import org.bukkit.entity.Player;
|
||||
*/
|
||||
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");
|
||||
@@ -202,4 +208,65 @@ public class Channel {
|
||||
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.equals(name) ) {
|
||||
disp = ChatColor.RED + name;
|
||||
} else 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() );
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public class ChannelManager {
|
||||
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("infoMotdFirstLine");
|
||||
private static final String MOTD_FIRSTLINE = Resources.get("motdFirstLine");
|
||||
|
||||
private static final String DEFAULT_FORMAT = Resources.get("defaultFormat");
|
||||
|
||||
@@ -202,6 +202,10 @@ public class ChannelManager {
|
||||
items.add(Utility.replaceColorCode(LIST_FIRSTLINE));
|
||||
for ( String key : channels.keySet() ) {
|
||||
Channel channel = channels.get(key);
|
||||
if ( channel.banned.contains(playerName) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String disp = ChatColor.WHITE + key;
|
||||
if ( key.equals(dchannel) ) {
|
||||
disp = ChatColor.RED + key;
|
||||
|
||||
@@ -56,6 +56,8 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
return doBan(sender, args);
|
||||
} else if (args[0].equalsIgnoreCase("pardon")) {
|
||||
return doPardon(sender, args);
|
||||
} else if (args[0].equalsIgnoreCase("info")) {
|
||||
return doInfo(sender, args);
|
||||
} else {
|
||||
return doJoin(sender, args);
|
||||
}
|
||||
@@ -548,6 +550,53 @@ public class LunaChatCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネル情報を表示する
|
||||
*
|
||||
* @param sender
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
private boolean doInfo(CommandSender sender, String[] args) {
|
||||
|
||||
Player player = null;
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
}
|
||||
|
||||
// 引数チェック
|
||||
// このコマンドは、コンソールでも実行できるが、その場合はチャンネル名を指定する必要がある
|
||||
String cname;
|
||||
if ( player != null && args.length <= 1 ) {
|
||||
cname = LunaChat.manager.getDefault(player.getName());
|
||||
} else if ( args.length >= 2 ) {
|
||||
cname = args[1];
|
||||
} else {
|
||||
sendResourceMessage(sender, PREERR, "errmsgCommand");
|
||||
return true;
|
||||
}
|
||||
|
||||
// チャンネルが存在するかどうか確認する
|
||||
Channel channel = LunaChat.manager.getChannel(cname);
|
||||
if ( channel == null ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgNotExist");
|
||||
return true;
|
||||
}
|
||||
|
||||
// BANされていないかどうか確認する
|
||||
if ( channel.banned.contains(player.getName()) ) {
|
||||
sendResourceMessage(sender, PREERR, "errmsgBanned");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 情報を取得して表示する
|
||||
ArrayList<String> list = channel.getInfo();
|
||||
for (String msg : list) {
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* コマンドの使い方を senderに送る
|
||||
*
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする