LunaChat v3.0.6 : Added bungeePassThroughMode.
このコミットが含まれているのは:
1 親
81b75f3f0f
コミット
bfd6bbbe87
13ファイル変更
+409
-116
検索条件に一致するファイルはありません
@@ -42,6 +42,9 @@ import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
*/
|
||||
public class LunaChatBukkit extends JavaPlugin implements PluginInterface {
|
||||
|
||||
/** Bukkit-BungeeCord間の送受信に使用するチャンネル名 */
|
||||
private static final String CHANNEL = "lunachat:message";
|
||||
|
||||
private static LunaChatBukkit instance;
|
||||
|
||||
private LunaChatConfig config;
|
||||
@@ -136,6 +139,9 @@ public class LunaChatBukkit extends JavaPlugin implements PluginInterface {
|
||||
|
||||
// イベント実行クラスの登録
|
||||
LunaChat.setEventSender(new BukkitEventSender());
|
||||
|
||||
// プラグインチャンネル登録
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, CHANNEL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,4 +313,12 @@ public class LunaChatBukkit extends JavaPlugin implements PluginInterface {
|
||||
public void runAsyncTask(Runnable task) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* プラグインメッセージを送信する
|
||||
* @param bytes 送信内容
|
||||
*/
|
||||
public void sendPluginMessage(byte[] bytes) {
|
||||
getServer().sendPluginMessage(this, CHANNEL, bytes);
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,9 @@ import net.md_5.bungee.api.plugin.Plugin;
|
||||
*/
|
||||
public class LunaChatBungee extends Plugin implements PluginInterface {
|
||||
|
||||
/** Bukkit-BungeeCord間の送受信に使用するチャンネル名 */
|
||||
private static final String CHANNEL = "lunachat:message";
|
||||
|
||||
private static LunaChatBungee instance;
|
||||
|
||||
private HashMap<String, String> history;
|
||||
@@ -110,6 +113,9 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
|
||||
|
||||
// イベント実行クラスの登録
|
||||
LunaChat.setEventSender(new BungeeEventSender());
|
||||
|
||||
// プラグインチャンネル登録
|
||||
getProxy().registerChannel(CHANNEL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -145,6 +145,9 @@ public class LunaChatConfig {
|
||||
|
||||
// === 以下、BungeeCord用設定 ===
|
||||
|
||||
/** Bungeeパススルーモード */
|
||||
private boolean bungeePassThroughMode;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param dataFolder コンフィグ格納フォルダ
|
||||
@@ -175,7 +178,7 @@ public class LunaChatConfig {
|
||||
lang = config.getString("lang", "en");
|
||||
enableChannelChat = config.getBoolean("enableChannelChat", true);
|
||||
playerChatEventListenerPriority
|
||||
= getEventPriority(config.getString("playerChatEventListenerPriority"), EventPriority.HIGH);
|
||||
= getEventPriority(config.getString("playerChatEventListenerPriority"), EventPriority.HIGHEST);
|
||||
noJoinAsGlobal = config.getBoolean("noJoinAsGlobal", true);
|
||||
loggingChat = config.getBoolean("loggingChat", true);
|
||||
displayChatOnConsole = config.getBoolean("displayChatOnConsole", true);
|
||||
@@ -253,6 +256,8 @@ public class LunaChatConfig {
|
||||
noneJapanizeMarker = config.getString("noneJapanizeMarker", "$");
|
||||
japanizeWait = config.getInt("japanizeWait", 1);
|
||||
|
||||
bungeePassThroughMode = config.getBoolean("bungeePassThroughMode", false);
|
||||
|
||||
// globalチャンネルが、使用可能なチャンネル名かどうかを調べる
|
||||
if ( globalChannel != null && !globalChannel.equals("") &&
|
||||
!globalChannel.matches("[0-9a-zA-Z\\-_]{1,20}") ) {
|
||||
@@ -564,6 +569,14 @@ public class LunaChatConfig {
|
||||
return enableNormalChatColorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bungeeパススルーモードかどうかを返す
|
||||
* @return bungeePassThroughMode
|
||||
*/
|
||||
public boolean isBungeePassThroughMode() {
|
||||
return bungeePassThroughMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された文字列から、対応するEventPriorityを返す。
|
||||
* @param value 文字列
|
||||
|
||||
@@ -32,6 +32,9 @@ import com.github.ucchyocean.lc3.event.EventResult;
|
||||
import com.github.ucchyocean.lc3.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberBukkit;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberOther;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberPlayer;
|
||||
import com.github.ucchyocean.lc3.messaging.BukkitChatMessage;
|
||||
import com.github.ucchyocean.lc3.util.ClickableFormat;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
|
||||
@@ -174,6 +177,18 @@ public class BukkitEventListener implements Listener {
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
// Bungeeパススルーモードなら、メッセージを返送して終了する
|
||||
if ( config.isBungeePassThroughMode() ) {
|
||||
ChannelMember player = ChannelMember.getChannelMember(event.getPlayer());
|
||||
if ( player instanceof ChannelMemberPlayer ) {
|
||||
ChannelMemberOther other = ((ChannelMemberPlayer)player).toChannelMemberOther();
|
||||
BukkitChatMessage msg = new BukkitChatMessage(other, event.getMessage());
|
||||
LunaChatBukkit.getInstance().sendPluginMessage(msg.toByteArray());
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 頭にglobalMarkerが付いている場合は、グローバル発言にする
|
||||
if ( config.getGlobalMarker() != null &&
|
||||
!config.getGlobalMarker().equals("") &&
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -23,6 +22,7 @@ import com.github.ucchyocean.lc3.channel.Channel;
|
||||
import com.github.ucchyocean.lc3.event.EventResult;
|
||||
import com.github.ucchyocean.lc3.japanize.Japanizer;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.messaging.BukkitChatMessage;
|
||||
import com.github.ucchyocean.lc3.util.ChatColor;
|
||||
import com.github.ucchyocean.lc3.util.ClickableFormat;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
@@ -34,6 +34,7 @@ import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||
import net.md_5.bungee.api.event.PluginMessageEvent;
|
||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
@@ -45,6 +46,9 @@ import net.md_5.bungee.event.EventPriority;
|
||||
*/
|
||||
public class BungeeEventListener implements Listener {
|
||||
|
||||
/** Bukkit-BungeeCord間の送受信に使用するチャンネル名 */
|
||||
private static final String CHANNEL = "lunachat:message";
|
||||
|
||||
private static final int MAX_LIST_ITEMS = 8;
|
||||
|
||||
private LunaChatBungee parent;
|
||||
@@ -180,12 +184,48 @@ public class BungeeEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* プラグインメッセージを受信したときに呼び出される
|
||||
* @param event
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPluginMessageReceived(PluginMessageEvent event) {
|
||||
|
||||
// 自分のチャンネルメッセージでない場合は無視する
|
||||
if ( !event.getTag().equals(CHANNEL) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// データをメッセージに復元する
|
||||
BukkitChatMessage msg = BukkitChatMessage.fromByteArray(event.getData());
|
||||
if ( msg == null ) return;
|
||||
|
||||
// 受信者と発言者が一致しない場合は無視する
|
||||
if ( event.getReceiver() instanceof ProxiedPlayer ) {
|
||||
ProxiedPlayer receiver = (ProxiedPlayer)event.getReceiver();
|
||||
if ( !receiver.getName().equals(msg.getMember().getName()) ) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// 発言先チャンネルを取得して発言する
|
||||
processChat(msg.getMember(), msg.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのチャットごとに呼び出されるメソッド
|
||||
* @param event チャットイベント
|
||||
*/
|
||||
private void processChatEvent(ChatEvent event) {
|
||||
|
||||
// Bungeeパススルーモードなら何もしない
|
||||
if ( config.isBungeePassThroughMode() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// コマンド実行の場合は、そのまま無視する
|
||||
if ( event.isCommand() ) {
|
||||
return;
|
||||
@@ -196,15 +236,24 @@ public class BungeeEventListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
// 発言内容を処理する
|
||||
processChat(ChannelMember.getChannelMember(event.getSender()), event.getMessage());
|
||||
|
||||
// イベントをキャンセル
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
private void processChat(ChannelMember member, String message) {
|
||||
|
||||
// 頭にglobalMarkerが付いている場合は、グローバル発言にする
|
||||
if ( config.getGlobalMarker() != null &&
|
||||
!config.getGlobalMarker().equals("") &&
|
||||
event.getMessage().startsWith(config.getGlobalMarker()) &&
|
||||
event.getMessage().length() > config.getGlobalMarker().length() ) {
|
||||
message.startsWith(config.getGlobalMarker()) &&
|
||||
message.length() > config.getGlobalMarker().length() ) {
|
||||
|
||||
int offset = config.getGlobalMarker().length();
|
||||
event.setMessage( event.getMessage().substring(offset) );
|
||||
chatGlobal(event);
|
||||
message = message.substring(offset);
|
||||
chatGlobal(member, message);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -212,8 +261,8 @@ public class BungeeEventListener implements Listener {
|
||||
// クイックチャンネルチャットとして処理する。
|
||||
if ( config.isEnableQuickChannelChat() ) {
|
||||
String separator = config.getQuickChannelChatSeparator();
|
||||
if ( event.getMessage().contains(separator) ) {
|
||||
String[] temp = event.getMessage().split(separator, 2);
|
||||
if ( message.contains(separator) ) {
|
||||
String[] temp = message.split(separator, 2);
|
||||
String name = temp[0];
|
||||
String value = "";
|
||||
if ( temp.length > 0 ) {
|
||||
@@ -221,62 +270,49 @@ public class BungeeEventListener implements Listener {
|
||||
}
|
||||
|
||||
Channel channel = api.getChannel(name);
|
||||
if ( channel != null && !channel.isPersonalChat()
|
||||
&& event.getSender() instanceof ProxiedPlayer ) {
|
||||
ChannelMember player =
|
||||
ChannelMember.getChannelMember(event.getSender());
|
||||
if ( !channel.getMembers().contains(player) ) {
|
||||
if ( channel != null ) {
|
||||
|
||||
if ( !channel.getMembers().contains(member) ) {
|
||||
// 指定されたチャンネルに参加していないなら、エラーを表示して何も発言せずに終了する。
|
||||
((ProxiedPlayer)event.getSender()).sendMessage(
|
||||
member.sendMessage(
|
||||
TextComponent.fromLegacyText(Messages.errmsgNomember()));
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// 指定されたチャンネルに発言して終了する。
|
||||
chatToChannelWithEvent(player, channel, value);
|
||||
event.setCancelled(true);
|
||||
chatToChannelWithEvent(member, channel, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ChannelMember player =
|
||||
ChannelMember.getChannelMember(event.getSender());
|
||||
Channel channel = api.getDefaultChannel(player.getName());
|
||||
Channel channel = api.getDefaultChannel(member.getName());
|
||||
|
||||
// デフォルトの発言先が無い場合
|
||||
if ( channel == null ) {
|
||||
if ( config.isNoJoinAsGlobal() ) {
|
||||
// グローバル発言にする
|
||||
chatGlobal(event);
|
||||
chatGlobal(member, message);
|
||||
return;
|
||||
|
||||
} else {
|
||||
// 発言をキャンセルして終了する
|
||||
event.setCancelled(true);
|
||||
// 何もせずに終了する
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
chatToChannelWithEvent(player, channel, event.getMessage());
|
||||
|
||||
// もとのイベントをキャンセル
|
||||
event.setCancelled(true);
|
||||
chatToChannelWithEvent(member, channel, message);
|
||||
}
|
||||
|
||||
private void chatGlobal(ChatEvent event) {
|
||||
private void chatGlobal(ChannelMember member, String message) {
|
||||
|
||||
// 発言者と発言サーバーと発言内容の取得
|
||||
final ProxiedPlayer sender = (ProxiedPlayer)event.getSender();
|
||||
String message = event.getMessage();
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
// NGワードのマスク
|
||||
message = maskNGWord(message, config.getNgwordCompiled());
|
||||
|
||||
// Japanizeをスキップするかどうかフラグ
|
||||
boolean skipJapanize = !LunaChat.getAPI().isPlayerJapanize(sender.getName());
|
||||
boolean skipJapanize = !LunaChat.getAPI().isPlayerJapanize(member.getName());
|
||||
|
||||
// 一時的なJapanizeスキップが指定されているか確認する
|
||||
String marker = config.getNoneJapanizeMarker();
|
||||
@@ -315,82 +351,32 @@ public class BungeeEventListener implements Listener {
|
||||
|
||||
String result;
|
||||
|
||||
if ( config.isEnableNormalChatMessageFormat() ) {
|
||||
// チャットフォーマット装飾を適用する場合
|
||||
String f = config.getNormalChatMessageFormat();
|
||||
ClickableFormat format = ClickableFormat.makeFormat(f, ChannelMember.getChannelMember(sender));
|
||||
format.replace("%msg", message);
|
||||
String f = config.getNormalChatMessageFormat();
|
||||
ClickableFormat format = ClickableFormat.makeFormat(f, member);
|
||||
format.replace("%msg", message);
|
||||
|
||||
// イベントをキャンセルする
|
||||
event.setCancelled(true);
|
||||
// hideされているプレイヤーを除くすべてのプレイヤーに、
|
||||
// 発言内容を送信する。
|
||||
BaseComponent[] msg = format.makeTextComponent();
|
||||
List<ChannelMember> hidelist = api.getHidelist(member);
|
||||
|
||||
// hideされているプレイヤーを除くすべてのプレイヤーに、
|
||||
// 発言内容を送信する。
|
||||
BaseComponent[] msg = format.makeTextComponent();
|
||||
List<ChannelMember> hidelist = api.getHidelist(ChannelMember.getChannelMember(sender));
|
||||
|
||||
for ( String server : parent.getProxy().getServers().keySet() ) {
|
||||
|
||||
ServerInfo info = parent.getProxy().getServerInfo(server);
|
||||
for ( ProxiedPlayer player : info.getPlayers() ) {
|
||||
if ( !containsHideList(player, hidelist) ) {
|
||||
sendMessage(player, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = format.toLegacyText();
|
||||
|
||||
} else {
|
||||
// チャットフォーマットを適用しない場合
|
||||
// NOTE: ChatEvent経由で送信する都合上、hideは適用しない(できない)仕様とする。
|
||||
|
||||
// NOTE: 改行がサポートされないので、改行を含む場合は、
|
||||
// \nで分割して前半をセットし、後半は150ミリ秒後に送信する。
|
||||
if ( !message.contains("\n") ) {
|
||||
event.setMessage(Utility.stripColorCode(message));
|
||||
} else {
|
||||
int index = message.indexOf("\n");
|
||||
String pre = message.substring(0, index);
|
||||
final String post = Utility.replaceColorCode(
|
||||
message.substring(index + "\n".length()));
|
||||
event.setMessage(Utility.stripColorCode(pre));
|
||||
|
||||
parent.getProxy().getScheduler().schedule(parent, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for ( ProxiedPlayer p : sender.getServer().getInfo().getPlayers() ) {
|
||||
sendMessage(p, post);
|
||||
}
|
||||
}
|
||||
}, 150, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
result = Utility.replaceColorCode(message);
|
||||
|
||||
// 発言したプレイヤーがいるサーバー"以外"のサーバーに、
|
||||
// 発言内容を送信する。
|
||||
for ( String server : parent.getProxy().getServers().keySet() ) {
|
||||
|
||||
String senderServer = sender.getServer().getInfo().getName();
|
||||
if ( server.equals(senderServer) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ServerInfo info = parent.getProxy().getServerInfo(server);
|
||||
for ( ProxiedPlayer player : info.getPlayers() ) {
|
||||
sendMessage(player, result);
|
||||
for ( ServerInfo info : parent.getProxy().getServers().values() ) {
|
||||
for ( ProxiedPlayer player : info.getPlayers() ) {
|
||||
if ( !containsHideList(player, hidelist) ) {
|
||||
sendMessage(player, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = format.toLegacyText();
|
||||
|
||||
// コンソールに表示設定なら、コンソールに表示する
|
||||
if ( config.isDisplayChatOnConsole() ) {
|
||||
parent.getLogger().info(result);
|
||||
}
|
||||
|
||||
// ログに記録する
|
||||
LunaChat.getNormalChatLogger().log(Utility.stripColorCode(result), sender.getName());
|
||||
LunaChat.getNormalChatLogger().log(Utility.stripColorCode(result), member.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -561,19 +547,6 @@ public class BungeeEventListener implements Listener {
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定した対象にメッセージを送信する
|
||||
* @param reciever 送信先
|
||||
* @param message メッセージ
|
||||
*/
|
||||
private void sendMessage(CommandSender reciever, String message) {
|
||||
if ( message == null ) return;
|
||||
ChannelMember cm = ChannelMember.getChannelMember(reciever);
|
||||
if ( cm != null ) {
|
||||
cm.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定した対象にメッセージを送信する
|
||||
* @param reciever 送信先
|
||||
|
||||
@@ -443,6 +443,7 @@ public abstract class Channel {
|
||||
// パーミッション lunachat-admin.listen-all-channels を持つプレイヤーを
|
||||
// 受信者に加える。
|
||||
if ( config.isOpListenAllChannel() ) {
|
||||
// TODO Bukkit参照しているのでNGなのでは
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
ChannelMember cp = ChannelMember.getChannelMember(p);
|
||||
if ( cp.hasPermission("lunachat-admin.listen-all-channels")
|
||||
@@ -470,6 +471,7 @@ public abstract class Channel {
|
||||
|
||||
// 設定に応じて、コンソールに出力する
|
||||
if ( config.isDisplayChatOnConsole() ) {
|
||||
// TODO Bukkit参照しているのでNGなのでは
|
||||
Bukkit.getLogger().info(makePlainText(message));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,50 @@
|
||||
package com.github.ucchyocean.lc3.member;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.ucchyocean.lc3.util.BlockLocation;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* 任意の内容を設定できるChannelMember
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ChannelMemberOther extends ChannelMember {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private String displayName;
|
||||
private String prefix;
|
||||
private String suffix;
|
||||
private BlockLocation location;
|
||||
|
||||
public ChannelMemberOther(String name) {
|
||||
this.name = name;
|
||||
this.displayName = name;
|
||||
this(name, name);
|
||||
}
|
||||
|
||||
public ChannelMemberOther(String name, String displayName) {
|
||||
this(name, displayName, "", "");
|
||||
}
|
||||
|
||||
public ChannelMemberOther(String name, String displayName,
|
||||
String prefix, String suffix) {
|
||||
this(name, displayName, prefix, suffix, null);
|
||||
}
|
||||
|
||||
public ChannelMemberOther(String name, String displayName,
|
||||
String prefix, String suffix, BlockLocation location) {
|
||||
this(name, displayName, prefix, suffix, location, null);
|
||||
}
|
||||
|
||||
public ChannelMemberOther(String name, String displayName,
|
||||
String prefix, String suffix, BlockLocation location, String id) {
|
||||
this.name = name;
|
||||
this.displayName = displayName;
|
||||
this.prefix = prefix;
|
||||
this.suffix = suffix;
|
||||
this.location = location;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -34,12 +64,12 @@ public class ChannelMemberOther extends ChannelMember {
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return "";
|
||||
return prefix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuffix() {
|
||||
return "";
|
||||
return suffix;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,9 +84,16 @@ public class ChannelMemberOther extends ChannelMember {
|
||||
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
if ( location != null ) {
|
||||
return location.getWorldName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public @Nullable BlockLocation getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerName() {
|
||||
return "";
|
||||
@@ -83,4 +120,11 @@ public class ChannelMemberOther extends ChannelMember {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* @return id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ import org.bukkit.entity.Player;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatBukkit;
|
||||
import com.github.ucchyocean.lc3.bridge.VaultChatBridge;
|
||||
import com.github.ucchyocean.lc3.util.BlockLocation;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
@@ -299,4 +300,15 @@ public class ChannelMemberPlayer extends ChannelMemberBukkit {
|
||||
return new ChannelMemberPlayer(op.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
||||
public ChannelMemberOther toChannelMemberOther() {
|
||||
return new ChannelMemberOther(getName(), getDisplayName(), getPrefix(), getSuffix(),
|
||||
getBlockLocation(), id.toString());
|
||||
}
|
||||
|
||||
private BlockLocation getBlockLocation() {
|
||||
Location loc = getLocation();
|
||||
if ( loc == null ) return null;
|
||||
return new BlockLocation(getWorldName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.messaging;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberOther;
|
||||
import com.github.ucchyocean.lc3.util.BlockLocation;
|
||||
|
||||
/**
|
||||
* BukkitからBungeeCordへプレイヤーの発言を送信するためのメッセージクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class BukkitChatMessage {
|
||||
|
||||
private ChannelMemberOther member;
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param member 発言者
|
||||
* @param message 発言内容
|
||||
*/
|
||||
public BukkitChatMessage(ChannelMemberOther member, String message) {
|
||||
this.member = member;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者を取得する
|
||||
* @return member
|
||||
*/
|
||||
public ChannelMember getMember() {
|
||||
return member;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言内容を取得する
|
||||
* @return message
|
||||
*/
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* このメッセージをbyte配列に変換する
|
||||
* @return byte配列
|
||||
*/
|
||||
public byte[] toByteArray() {
|
||||
try ( ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(baos) ) {
|
||||
out.writeUTF(member.getName());
|
||||
out.writeUTF(member.getDisplayName());
|
||||
out.writeUTF(member.getPrefix());
|
||||
out.writeUTF(member.getSuffix());
|
||||
out.writeUTF(member.getLocation() == null ? "null" : member.getLocation().toString());
|
||||
out.writeUTF(message);
|
||||
return baos.toByteArray();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new byte[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* byte配列からメッセージに変換する
|
||||
* @param bytes byte配列
|
||||
* @return メッセージ
|
||||
*/
|
||||
public static @Nullable BukkitChatMessage fromByteArray(byte[] bytes) {
|
||||
try ( DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes)) ) {
|
||||
String name = in.readUTF();
|
||||
String displayName = in.readUTF();
|
||||
String prefix = in.readUTF();
|
||||
String suffix = in.readUTF();
|
||||
BlockLocation location = BlockLocation.fromString(in.readUTF());
|
||||
ChannelMemberOther member = new ChannelMemberOther(name, displayName, prefix, suffix, location);
|
||||
String message = in.readUTF();
|
||||
return new BukkitChatMessage(member, message);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("n=%s, d=%s, p=%s, s=%s, m=%s",
|
||||
member.getName(), member.getDisplayName(), member.getPrefix(), member.getSuffix(), message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* 座標を保持するためのオブジェクトクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class BlockLocation {
|
||||
|
||||
private String worldName;
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param worldName ワールド名
|
||||
* @param x X座標
|
||||
* @param y Y座標
|
||||
* @param z Z座標
|
||||
*/
|
||||
public BlockLocation(String worldName, int x, int y, int z) {
|
||||
this.worldName = worldName;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* ワールド名を取得する
|
||||
* @return worldName
|
||||
*/
|
||||
public String getWorldName() {
|
||||
return worldName;
|
||||
}
|
||||
|
||||
/**
|
||||
* X座標を取得する
|
||||
* @return x
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Y座標を取得する
|
||||
* @return y
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Z座標を取得する
|
||||
* @return z
|
||||
*/
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列に変換する
|
||||
* @return 文字列
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s,%d,%d,%d", worldName, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列からBlockLocationに変換する
|
||||
* @param str 文字列
|
||||
* @return BlockLocation
|
||||
*/
|
||||
public static @Nullable BlockLocation fromString(String str) {
|
||||
if ( str == null ) return null;
|
||||
String[] temp = str.split(",");
|
||||
if ( temp.length < 4 ) return null;
|
||||
return new BlockLocation(
|
||||
temp[0], toInt(temp[1]), toInt(temp[2]), toInt(temp[3]));
|
||||
}
|
||||
|
||||
private static int toInt(String str) {
|
||||
if ( !str.matches("-?[0-9]+") ) return 0;
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
} catch (NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする