LunaChat v2.1.0 : Fixed issue #29.

このコミットが含まれているのは:
ucchyocean committed 2013-07-05 13:16:43 +09:00
1 親 bd3ab14283
コミット 22a73dd02d
7ファイル変更
+183 -38

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

+30 -18
ファイルの表示
@@ -33,8 +33,8 @@ import com.github.ucchyocean.lc.japanize.ConvertTask;
import com.github.ucchyocean.lc.japanize.JapanizeType;
/**
* @author ucchy
* チャンネル
* @author ucchy
*/
@SerializableAs("Channel")
public class Channel implements ConfigurationSerializable {
@@ -60,7 +60,7 @@ public class Channel implements ConfigurationSerializable {
private static final String MSG_BANNED = Resources.get("cmdmsgBanned");
private static final String MSG_NO_RECIPIENT = Resources.get("messageNoRecipient");
private static final String KEY_NAME = "name";
private static final String KEY_DESC = "desc";
private static final String KEY_FORMAT = "format";
@@ -228,7 +228,7 @@ public class Channel implements ConfigurationSerializable {
if ( !chated ) {
// メッセージの送信
String msg = msgFormat.replace("%msg", maskedMessage);
sendMessage(player, msg);
}
@@ -346,6 +346,9 @@ public class Channel implements ConfigurationSerializable {
}
/**
* TODO: このメソッドはprivateに変更したい
* ※本メソッドはLunaChat内部での呼び出し用です。
* ※イベントが発生しないため、APIからは呼び出ししないでください。
* 情報をチャンネルメンバーに流します。
* @param message メッセージ
*/
@@ -371,14 +374,17 @@ public class Channel implements ConfigurationSerializable {
// ロギング
log(message);
}
/**
* TODO: このメソッドはprivateに変更したい
* ※本メソッドはLunaChat内部での呼び出し用です。
* ※イベントが発生しないため、APIからは呼び出ししないでください。
* メッセージを表示します。指定したプレイヤーの発言として処理されます。
* @param player プレイヤー(ワールドチャット、範囲チャットの場合は必須です)
* @param message メッセージ
*/
public void sendMessage(Player player, String message) {
// 受信者を設定する
ArrayList<Player> recipients = new ArrayList<Player>();
if ( isBroadcastChannel() ) {
@@ -386,38 +392,44 @@ public class Channel implements ConfigurationSerializable {
if ( isWorldRange ) {
World w = player.getWorld();
if ( chatRange > 0 ) {
// 範囲チャット
for ( Player p : Bukkit.getOnlinePlayers() ) {
if ( p.getWorld().equals(w) &&
if ( p.getWorld().equals(w) &&
player.getLocation().distance(p.getLocation()) <= chatRange ) {
recipients.add(p);
}
}
} else {
// ワールドチャット
for ( Player p : Bukkit.getOnlinePlayers() ) {
if ( p.getWorld().equals(w) ) {
recipients.add(p);
}
}
}
} else {
// 通常ブロードキャスト(全員へ送信)
for ( Player p : Bukkit.getOnlinePlayers() ) {
recipients.add(p);
}
// 通常ブロードキャストなら、設定に応じてdynmapへ送信する
if ( LunaChat.config.sendBroadcastChannelChatToDynmap &&
LunaChat.dynmap != null ) {
LunaChat.dynmap.chat(player, message);
}
}
} else {
// 通常チャンネル
for ( String name : members ) {
Player p = Bukkit.getPlayerExact(name);
if ( p != null ) {
@@ -431,8 +443,8 @@ public class Channel implements ConfigurationSerializable {
p.sendMessage(message);
}
// 受信者が自分以外いない場合は、メッセージを表示する
if ( recipients.size() == 0 ||
(recipients.size() == 1 &&
if ( recipients.size() == 0 ||
(recipients.size() == 1 &&
recipients.get(0).getName().equals(player.getName()) ) ) {
player.sendMessage(MSG_NO_RECIPIENT);
}
@@ -532,9 +544,9 @@ public class Channel implements ConfigurationSerializable {
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
String prefix = "";
String suffix = "";
if ( LunaChat.chatPlugin != null ) {
prefix = LunaChat.chatPlugin.getPlayerPrefix(player);
suffix = LunaChat.chatPlugin.getPlayerSuffix(player);
if ( LunaChat.vaultchat != null ) {
prefix = LunaChat.vaultchat.getPlayerPrefix(player);
suffix = LunaChat.vaultchat.getPlayerSuffix(player);
}
msg = msg.replace("%prefix", prefix);
msg = msg.replace("%suffix", suffix);
+1 -1
ファイルの表示
@@ -22,8 +22,8 @@ import com.github.ucchyocean.lc.japanize.ConvertTask;
import com.github.ucchyocean.lc.japanize.JapanizeType;
/**
* @author ucchy
* チャンネルマネージャー
* @author ucchy
*/
public class ChannelManager implements LunaChatAPI {
+11 -17
ファイルの表示
@@ -8,19 +8,17 @@ package com.github.ucchyocean.lc;
import java.io.File;
import java.util.HashMap;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.chat.Chat;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import org.dynmap.bukkit.DynmapPlugin;
import com.github.ucchyocean.lc.bridge.DynmapBridge;
import com.github.ucchyocean.lc.bridge.VaultChatBridge;
/**
* @author ucchy
* LunaChat プラグイン
* @author ucchy
*/
public class LunaChat extends JavaPlugin {
@@ -31,8 +29,8 @@ public class LunaChat extends JavaPlugin {
protected static HashMap<String, String> inviterMap;
protected static HashMap<String, String> privateMessageMap;
protected static Chat chatPlugin;
protected static DynmapPlugin dynmap;
protected static VaultChatBridge vaultchat;
protected static DynmapBridge dynmap;
/**
* プラグインが有効化されたときに呼び出されるメソッド
@@ -51,18 +49,14 @@ public class LunaChat extends JavaPlugin {
// Chat Plugin のロード
Plugin temp = getServer().getPluginManager().getPlugin("Vault");
if ( temp != null && temp instanceof Vault ) {
RegisteredServiceProvider<Chat> chatProvider =
getServer().getServicesManager().getRegistration(Chat.class);
if ( chatProvider != null ) {
chatPlugin = chatProvider.getProvider();
}
if ( temp != null ) {
vaultchat = VaultChatBridge.load(temp);
}
// Dynmap のロード
temp = getServer().getPluginManager().getPlugin("dynmap");
if ( temp != null && temp instanceof DynmapPlugin ) {
dynmap = (DynmapPlugin)temp;
if ( temp != null ) {
dynmap = DynmapBridge.load(temp);
}
// リスナーの登録
+23 -2
ファイルの表示
@@ -13,8 +13,8 @@ import org.bukkit.configuration.file.FileConfiguration;
import com.github.ucchyocean.lc.japanize.JapanizeType;
/**
* @author ucchy
* LunaChatのコンフィグクラス
* @author ucchy
*/
public class LunaChatConfig {
@@ -43,6 +43,10 @@ public class LunaChatConfig {
* 参加させない場合は、から文字列 "" を指定すること。 */
protected String globalChannel;
/** ブロードキャストチャンネルの発言内容を、dynmapに送信するかどうか。
* dynmapがロードされていない場合は、この設定は無視されます(false扱い)。 */
protected boolean sendBroadcastChannelChatToDynmap;
/** NGワードの設定 */
protected List<String> ngword;
@@ -97,8 +101,10 @@ public class LunaChatConfig {
zeroMemberRemove = config.getBoolean("zeroMemberRemove", false);
showListOnJoin = config.getBoolean("showListOnJoin", false);
createChannelOnJoinCommand =
config.getBoolean("createChannelOnJoinCommand", true);
config.getBoolean("createChannelOnJoinCommand", true);
globalChannel = config.getString("globalChannel", "");
sendBroadcastChannelChatToDynmap =
config.getBoolean("sendBroadcastChannelChatToDynmap", true);
ngword = config.getStringList("ngword");
ngwordAction = NGWordAction.fromID(config.getString("ngwordAction", "mask"));
japanizeType = JapanizeType.fromID(config.getString("japanizeType", "kana"));
@@ -313,4 +319,19 @@ public class LunaChatConfig {
public void setJapanizeLine2Format(String japanizeLine2Format) {
this.japanizeLine2Format = japanizeLine2Format;
}
/**
* @return sendBroadcastChannelChatToDynmapを返す
*/
public boolean isSendBroadcastChannelChatToDynmap() {
return sendBroadcastChannelChatToDynmap;
}
/**
* @param sendBroadcastChannelChatToDynmap sendBroadcastChannelChatToDynmapを設定する
*/
public void setSendBroadcastChannelChatToDynmap(
boolean sendBroadcastChannelChatToDynmap) {
this.sendBroadcastChannelChatToDynmap = sendBroadcastChannelChatToDynmap;
}
}
+50
ファイルの表示
@@ -0,0 +1,50 @@
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc.bridge;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.dynmap.DynmapAPI;
/**
* dynmap連携クラス
* @author ucchy
*/
public class DynmapBridge {
/** dynmap-apiクラス */
private DynmapAPI dynmap;
/** コンストラクタは使用不可 */
private DynmapBridge() {
}
/**
* dynmap-apiをロードする
* @param plugin dynmap-apiのプラグインインスタンス
* @param ロードしたかどうか
*/
public static DynmapBridge load(Plugin plugin) {
if ( plugin instanceof DynmapAPI ) {
DynmapBridge bridge = new DynmapBridge();
bridge.dynmap = (DynmapAPI)plugin;
return bridge;
} else {
return null;
}
}
/**
* dynmapにプレイヤーのチャットを流す
* @param player プレイヤー
* @param message 発言内容
*/
public void chat(Player player, String message) {
dynmap.postPlayerMessageToWeb(player, message);
}
}
+66
ファイルの表示
@@ -0,0 +1,66 @@
/*
* @author ucchy
* @license GPLv3
* @copyright Copyright ucchy 2013
*/
package com.github.ucchyocean.lc.bridge;
import net.milkbowl.vault.Vault;
import net.milkbowl.vault.chat.Chat;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
/**
* Vault-Chat連携クラス
* @author ucchy
*/
public class VaultChatBridge {
/** vault-chatクラス */
private Chat chatPlugin;
/** コンストラクタは使用不可 */
private VaultChatBridge() {
}
/**
* vault-chatをロードする
* @param plugin vaultのプラグインインスタンス
* @param ロードしたかどうか
*/
public static VaultChatBridge load(Plugin plugin) {
if ( plugin instanceof Vault ) {
RegisteredServiceProvider<Chat> chatProvider =
Bukkit.getServicesManager().getRegistration(Chat.class);
if ( chatProvider != null ) {
VaultChatBridge bridge = new VaultChatBridge();
bridge.chatPlugin = chatProvider.getProvider();
return bridge;
}
}
return null;
}
/**
* プレイヤーのprefixを取得します。
* @param player プレイヤー
* @return プレイヤーのprefix
*/
public String getPlayerPrefix(Player player) {
return chatPlugin.getPlayerPrefix(player);
}
/**
* プレイヤーのsuffixを取得します。
* @param player プレイヤー
* @return プレイヤーのsuffix
*/
public String getPlayerSuffix(Player player) {
return chatPlugin.getPlayerSuffix(player);
}
}