LunaChat v3.0.3 : Clickable chat message (WIP)
このコミットが含まれているのは:
1 親
0466653e89
コミット
e2eea8798d
22ファイル変更
+756
-457
検索条件に一致するファイルはありません
@@ -21,6 +21,11 @@ public class LunaChatStandalone implements PluginInterface {
|
||||
private LunaChatConfig config;
|
||||
private ChannelManager manager;
|
||||
private UUIDCacheData uuidCacheData;
|
||||
private File dataFolder;
|
||||
|
||||
public LunaChatStandalone(File dataFolder) {
|
||||
this.dataFolder = dataFolder;
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
|
||||
@@ -33,7 +38,7 @@ public class LunaChatStandalone implements PluginInterface {
|
||||
// コンフィグ取得
|
||||
config = new LunaChatConfig(getDataFolder(), getPluginJarFile());
|
||||
|
||||
// UUIDキャッシュデータ (これ要る?)
|
||||
// UUIDキャッシュデータ
|
||||
uuidCacheData = new UUIDCacheData(getDataFolder());
|
||||
}
|
||||
|
||||
@@ -60,12 +65,7 @@ public class LunaChatStandalone implements PluginInterface {
|
||||
|
||||
@Override
|
||||
public File getDataFolder() {
|
||||
|
||||
// 現在のフォルダ下にLunaChatフォルダを作成して返す
|
||||
String cd = new File(".").getAbsoluteFile().getParent();
|
||||
File folder = new File(cd, "LunaChat");
|
||||
if ( !folder.exists() ) folder.mkdirs();
|
||||
return folder;
|
||||
return dataFolder;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,7 +83,8 @@ public class LunaChatStandalone implements PluginInterface {
|
||||
|
||||
@Override
|
||||
public void log(Level level, String msg) {
|
||||
// TODO Standaloneサーバーのログ出力 未実装
|
||||
// 画面に表示する
|
||||
System.out.println(String.format("[%s]%s", level.toString(), msg));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Messages {
|
||||
* Jarファイル内から直接 messages_en.yml をdefaultMessagesとしてロードし、
|
||||
* langに対応するメッセージをファイルからロードする。
|
||||
* @param messagesFolder メッセージ格納フォルダ
|
||||
* @param jar jarファイル
|
||||
* @param jar jarファイル(JTestからの実行時はnullを指定可)
|
||||
* @param lang デフォルト言語
|
||||
*/
|
||||
public static void initialize(File messagesFolder, File jar, String lang) {
|
||||
@@ -50,17 +50,19 @@ public class Messages {
|
||||
|
||||
// デフォルトメッセージを、jarファイル内からロードする
|
||||
YamlConfig defaultMessages = null;
|
||||
try (JarFile jarFile = new JarFile(_jar)) {
|
||||
if ( _jar != null ) {
|
||||
try (JarFile jarFile = new JarFile(_jar)) {
|
||||
|
||||
ZipEntry zipEntry = jarFile.getEntry(String.format("messages_%s.yml", lang));
|
||||
if (zipEntry == null) {
|
||||
zipEntry = jarFile.getEntry("messages_en.yml");
|
||||
ZipEntry zipEntry = jarFile.getEntry(String.format("messages_%s.yml", lang));
|
||||
if (zipEntry == null) {
|
||||
zipEntry = jarFile.getEntry("messages_en.yml");
|
||||
}
|
||||
|
||||
defaultMessages = YamlConfig.load(jarFile.getInputStream(zipEntry));
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
defaultMessages = YamlConfig.load(jarFile.getInputStream(zipEntry));
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// 対応する言語のメッセージをロードする
|
||||
@@ -366,7 +368,7 @@ public class Messages {
|
||||
}
|
||||
|
||||
/**
|
||||
* &7|
|
||||
* &7|
|
||||
*/
|
||||
public static String listPlainPrefix() {
|
||||
String msg = resources.getString("listPlainPrefix");
|
||||
@@ -386,7 +388,7 @@ public class Messages {
|
||||
}
|
||||
|
||||
/**
|
||||
* &7|
|
||||
* &7|
|
||||
*/
|
||||
public static String channelInfoPrefix() {
|
||||
String msg = resources.getString("channelInfoPrefix");
|
||||
|
||||
@@ -30,7 +30,7 @@ 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.util.ChatFormatter;
|
||||
import com.github.ucchyocean.lc3.util.ClickableFormat;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
@@ -298,17 +298,16 @@ public class BukkitEventListener implements Listener {
|
||||
}
|
||||
|
||||
// チャットフォーマット装飾の適用
|
||||
String format;
|
||||
ClickableFormat format;
|
||||
if ( config.isEnableNormalChatMessageFormat() ) {
|
||||
format = config.getNormalChatMessageFormat();
|
||||
// format = replaceNormalChatFormatKeywords(format, event.getPlayer());
|
||||
format = ChatFormatter.replaceKeywordsForEvent(
|
||||
format, ChannelMember.getChannelMember(event.getPlayer()));
|
||||
String f = config.getNormalChatMessageFormat();
|
||||
format = ClickableFormat.makeFormat(f, ChannelMember.getChannelMember(event.getPlayer()));
|
||||
// event.setFormat(format);
|
||||
} else {
|
||||
format = event.getFormat()
|
||||
.replace("%1$s", event.getPlayer().getDisplayName())
|
||||
String f = event.getFormat()
|
||||
.replace("%1$s", "%displayName")
|
||||
.replace("%2$s", "%msg");
|
||||
format = ClickableFormat.makeFormat(f, ChannelMember.getChannelMember(event.getPlayer()));
|
||||
}
|
||||
|
||||
// カラーコード置き換え
|
||||
@@ -377,7 +376,8 @@ public class BukkitEventListener implements Listener {
|
||||
// event.setMessage(message);
|
||||
|
||||
// 発言内容の送信
|
||||
BaseComponent[] comps = ChatFormatter.replaceTextComponent(format.replace("%msg", message));
|
||||
format.replace("%msg", message);
|
||||
BaseComponent[] comps = format.makeTextComponent();
|
||||
for ( Player recipient : event.getRecipients() ) {
|
||||
ChannelMember cm = ChannelMember.getChannelMember(recipient);
|
||||
if ( cm != null ) {
|
||||
@@ -386,7 +386,7 @@ public class BukkitEventListener implements Listener {
|
||||
}
|
||||
|
||||
// イベントのキャンセル
|
||||
event.setCancelled(true); // TODO いろいろテストが必要
|
||||
event.setCancelled(true);
|
||||
|
||||
// ロギング
|
||||
logNormalChat(message, player.getName());
|
||||
|
||||
@@ -22,10 +22,11 @@ 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.util.ChatColor;
|
||||
import com.github.ucchyocean.lc3.util.ChatFormatter;
|
||||
import com.github.ucchyocean.lc3.util.ClickableFormat;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@@ -275,8 +276,9 @@ public class BungeeEventListener implements Listener {
|
||||
boolean skipJapanize = !LunaChat.getAPI().isPlayerJapanize(sender.getName());
|
||||
|
||||
// 一時的なJapanizeスキップが指定されているか確認する
|
||||
if ( message.startsWith(config.getNoneJapanizeMarker()) ) {
|
||||
message = message.substring(config.getNoneJapanizeMarker().length());
|
||||
String marker = config.getNoneJapanizeMarker();
|
||||
if ( !marker.equals("") && message.startsWith(marker) ) {
|
||||
message = message.substring(marker.length());
|
||||
skipJapanize = true;
|
||||
}
|
||||
|
||||
@@ -309,29 +311,33 @@ public class BungeeEventListener implements Listener {
|
||||
}
|
||||
|
||||
String result;
|
||||
|
||||
if ( config.isEnableNormalChatMessageFormat() ) {
|
||||
// チャットフォーマット装飾を適用する場合
|
||||
String format = config.getNormalChatMessageFormat();
|
||||
// result = replaceNormalChatFormatKeywords(format, sender, message);
|
||||
result = ChatFormatter.replaceKeywordsForEvent(format, ChannelMember.getChannelMember(sender));
|
||||
result = result.replace("%msg", message);
|
||||
String f = config.getNormalChatMessageFormat();
|
||||
ClickableFormat format = ClickableFormat.makeFormat(f, ChannelMember.getChannelMember(sender));
|
||||
format.replace("%msg", message);
|
||||
|
||||
// イベントをキャンセルする
|
||||
event.setCancelled(true);
|
||||
|
||||
// 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, result);
|
||||
sendMessage(player, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = format.toLegacyText();
|
||||
|
||||
} else {
|
||||
// チャットフォーマットを適用しない場合
|
||||
// NOTE: ChatEvent経由で送信する都合上、hideは適用しない(できない)仕様とする。
|
||||
@@ -547,7 +553,20 @@ public class BungeeEventListener implements Listener {
|
||||
if ( message == null ) return;
|
||||
ChannelMember cm = ChannelMember.getChannelMember(reciever);
|
||||
if ( cm != null ) {
|
||||
cm.sendMessage(ChatFormatter.replaceTextComponent(message));
|
||||
cm.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定した対象にメッセージを送信する
|
||||
* @param reciever 送信先
|
||||
* @param message メッセージ
|
||||
*/
|
||||
private void sendMessage(CommandSender reciever, BaseComponent[] message) {
|
||||
if ( message == null ) return;
|
||||
ChannelMember cm = ChannelMember.getChannelMember(reciever);
|
||||
if ( cm != null ) {
|
||||
cm.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
@@ -23,7 +24,7 @@ import com.github.ucchyocean.lc3.bridge.DynmapBridge;
|
||||
import com.github.ucchyocean.lc3.event.EventResult;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberBukkit;
|
||||
import com.github.ucchyocean.lc3.util.ChatFormatter;
|
||||
import com.github.ucchyocean.lc3.util.ClickableFormat;
|
||||
import com.github.ucchyocean.lc3.util.UtilityBukkit;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
@@ -48,11 +49,11 @@ public class BukkitChannel extends Channel {
|
||||
* @param message メッセージ
|
||||
* @param format フォーマット
|
||||
* @param sendDynmap dynmapへ送信するかどうか
|
||||
* @param name 発言者名
|
||||
*/
|
||||
@Override
|
||||
protected void sendMessage(ChannelMember player, String message,
|
||||
String format, boolean sendDynmap, String name) {
|
||||
protected void sendMessage(
|
||||
ChannelMember player, String message,
|
||||
@Nullable ClickableFormat format, boolean sendDynmap) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
@@ -147,13 +148,8 @@ public class BukkitChannel extends Channel {
|
||||
}
|
||||
}
|
||||
|
||||
// フォーマットがある場合は置き換える
|
||||
if ( format != null ) {
|
||||
message = format.replace("%msg", message);
|
||||
}
|
||||
|
||||
// LunaChatChannelMessageEvent イベントコール
|
||||
// TODO messageがクリックイベント用のプレースホルダ―入りになっているが、問題ないか
|
||||
String name = (player != null) ? player.getDisplayName() : "<null>";
|
||||
EventResult result = LunaChat.getEventSender().sendLunaChatChannelMessageEvent(
|
||||
getName(), player, message, recipients, name, originalMessage);
|
||||
message = result.getMessage();
|
||||
@@ -177,9 +173,16 @@ public class BukkitChannel extends Channel {
|
||||
}
|
||||
|
||||
// 送信する
|
||||
BaseComponent[] comps = ChatFormatter.replaceTextComponent(message);
|
||||
for ( ChannelMember p : recipients ) {
|
||||
p.sendMessage(comps);
|
||||
if ( format != null ) {
|
||||
format.replace("%msg", message);
|
||||
BaseComponent[] comps = format.makeTextComponent();
|
||||
for ( ChannelMember p : recipients ) {
|
||||
p.sendMessage(comps);
|
||||
}
|
||||
} else {
|
||||
for ( ChannelMember p : recipients ) {
|
||||
p.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
// 設定に応じて、コンソールに出力する
|
||||
@@ -193,7 +196,7 @@ public class BukkitChannel extends Channel {
|
||||
}
|
||||
|
||||
// ロギング
|
||||
log(originalMessage, name, player);
|
||||
log(originalMessage, name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,9 +256,8 @@ public class BukkitChannel extends Channel {
|
||||
* ログを記録する
|
||||
* @param name 発言者
|
||||
* @param message 記録するメッセージ
|
||||
* @param player プレイヤー
|
||||
*/
|
||||
private void log(String message, String name, ChannelMember player) {
|
||||
private void log(String message, String name) {
|
||||
|
||||
// LunaChatのチャットログへ記録
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
@@ -8,13 +8,15 @@ package com.github.ucchyocean.lc3.channel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatBungee;
|
||||
import com.github.ucchyocean.lc3.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc3.event.EventResult;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.util.ChatFormatter;
|
||||
import com.github.ucchyocean.lc3.util.ClickableFormat;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
@@ -40,11 +42,10 @@ public class BungeeChannel extends Channel {
|
||||
* @param message メッセージ
|
||||
* @param format フォーマット
|
||||
* @param sendDynmap dynmapへ送信するかどうか
|
||||
* @param name 発言者名
|
||||
*/
|
||||
@Override
|
||||
protected void sendMessage(ChannelMember player, String message,
|
||||
String format, boolean sendDynmap, String name) {
|
||||
@Nullable ClickableFormat format, boolean sendDynmap) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
@@ -98,21 +99,25 @@ public class BungeeChannel extends Channel {
|
||||
}
|
||||
|
||||
// フォーマットがある場合は置き換える
|
||||
if ( format != null ) {
|
||||
message = format.replace("%msg", message);
|
||||
}
|
||||
|
||||
// LunaChatChannelMessageEvent イベントコール
|
||||
// TODO messageがクリックイベント用のプレースホルダ―入りになっているが、問題ないか
|
||||
String name = (player != null) ? player.getDisplayName() : "<null>";
|
||||
EventResult result = LunaChat.getEventSender().sendLunaChatChannelMessageEvent(
|
||||
getName(), player, message, recipients, name, originalMessage);
|
||||
message = result.getMessage();
|
||||
recipients = result.getRecipients();
|
||||
|
||||
// 送信する
|
||||
BaseComponent[] comps = ChatFormatter.replaceTextComponent(message);
|
||||
for ( ChannelMember p : recipients ) {
|
||||
p.sendMessage(comps);
|
||||
if ( format != null ) {
|
||||
format.replace("%msg", message);
|
||||
BaseComponent[] comps = format.makeTextComponent();
|
||||
for ( ChannelMember p : recipients ) {
|
||||
p.sendMessage(comps);
|
||||
}
|
||||
} else {
|
||||
for ( ChannelMember p : recipients ) {
|
||||
p.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
// 設定に応じて、コンソールに出力する
|
||||
@@ -121,7 +126,7 @@ public class BungeeChannel extends Channel {
|
||||
}
|
||||
|
||||
// ロギング
|
||||
log(originalMessage, name, player);
|
||||
log(originalMessage, name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,9 +186,8 @@ public class BungeeChannel extends Channel {
|
||||
* ログを記録する
|
||||
* @param name 発言者
|
||||
* @param message 記録するメッセージ
|
||||
* @param player プレイヤー
|
||||
*/
|
||||
private void log(String message, String name, ChannelMember player) {
|
||||
private void log(String message, String name) {
|
||||
|
||||
// LunaChatのチャットログへ記録
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
@@ -16,6 +16,8 @@ import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatConfig;
|
||||
@@ -26,8 +28,10 @@ import com.github.ucchyocean.lc3.NGWordAction;
|
||||
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.ChannelMemberOther;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberSystem;
|
||||
import com.github.ucchyocean.lc3.util.ChatColor;
|
||||
import com.github.ucchyocean.lc3.util.ChatFormatter;
|
||||
import com.github.ucchyocean.lc3.util.ClickableFormat;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
import com.github.ucchyocean.lc3.util.YamlConfig;
|
||||
|
||||
@@ -257,7 +261,7 @@ public abstract class Channel {
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
String msgFormat = replaceKeywords(getFormat(), player);
|
||||
ClickableFormat cf = ClickableFormat.makeFormat(getFormat(), player, this, true);
|
||||
|
||||
// カラーコード置き換え
|
||||
// チャンネルで許可されていて、発言者がパーミッションを持っている場合に置き換える
|
||||
@@ -267,11 +271,11 @@ public abstract class Channel {
|
||||
|
||||
// LunaChatChannelChatEvent イベントコール
|
||||
EventResult result = LunaChat.getEventSender().sendLunaChatChannelChatEvent(
|
||||
getName(), player, message, maskedMessage, msgFormat);
|
||||
getName(), player, message, maskedMessage, cf.toLegacyText());
|
||||
if ( result.isCancelled() ) {
|
||||
return;
|
||||
}
|
||||
msgFormat = result.getMessageFormat();
|
||||
// msgFormat = result.getMessageFormat();
|
||||
maskedMessage = result.getNgMaskedMessage();
|
||||
|
||||
// 2byteコードを含むか、半角カタカナのみなら、Japanize変換は行わない
|
||||
@@ -295,10 +299,10 @@ public abstract class Channel {
|
||||
|
||||
int lineType = config.getJapanizeDisplayLine();
|
||||
String jpFormat;
|
||||
String messageFormat = null;
|
||||
ClickableFormat messageFormat = null;
|
||||
if ( lineType == 1 ) {
|
||||
jpFormat = Utility.replaceColorCode(config.getJapanizeLine1Format());
|
||||
messageFormat = msgFormat;
|
||||
messageFormat = cf;
|
||||
isIncludeSyncChat = false;
|
||||
} else {
|
||||
jpFormat = Utility.replaceColorCode(config.getJapanizeLine2Format());
|
||||
@@ -311,7 +315,7 @@ public abstract class Channel {
|
||||
|
||||
if ( isIncludeSyncChat ) {
|
||||
// メッセージの送信
|
||||
sendMessage(player, maskedMessage, msgFormat, true, player.getDisplayName());
|
||||
sendMessage(player, maskedMessage, cf, true);
|
||||
}
|
||||
|
||||
// 非同期実行タスクがある場合、追加で実行する
|
||||
@@ -330,7 +334,7 @@ public abstract class Channel {
|
||||
if ( !Messages.banNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.banNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
sendMessage(ChannelMemberSystem.getInstance(), m, null, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +346,7 @@ public abstract class Channel {
|
||||
if ( !Messages.kickNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.kickNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
sendMessage(ChannelMemberSystem.getInstance(), m, null, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +358,7 @@ public abstract class Channel {
|
||||
if ( !Messages.muteNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.muteNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
sendMessage(ChannelMemberSystem.getInstance(), m, null, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -366,7 +370,7 @@ public abstract class Channel {
|
||||
* @param source 連携元を判別する文字列
|
||||
* @param message メッセージ
|
||||
*/
|
||||
public void chatFromOtherSource(String player, String source, String message) {
|
||||
public void chatFromOtherSource(String player, @Nullable String source, String message) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
@@ -389,9 +393,7 @@ public abstract class Channel {
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
String msgFormat = replaceKeywordsForSystemMessages(getFormat(), name);
|
||||
msgFormat = msgFormat.replace("%prefix", "");
|
||||
msgFormat = msgFormat.replace("%suffix", "");
|
||||
ClickableFormat msgFormat = ClickableFormat.makeFormat(getFormat(), new ChannelMemberOther(name));
|
||||
|
||||
// カラーコード置き換え チャンネルで許可されている場合に置き換える。
|
||||
if ( isAllowCC() ) {
|
||||
@@ -400,7 +402,7 @@ public abstract class Channel {
|
||||
|
||||
// メッセージの送信
|
||||
boolean sendDynmap = source == null || !source.equals("web");
|
||||
sendMessage(null, maskedMessage, msgFormat, sendDynmap, name);
|
||||
sendMessage(new ChannelMemberOther(name), maskedMessage, msgFormat, sendDynmap);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -410,7 +412,7 @@ public abstract class Channel {
|
||||
* @param name 発言者の表示名
|
||||
*/
|
||||
public void sendSystemMessage(String message, boolean sendDynmap, String name) {
|
||||
sendMessage(null, message, null, sendDynmap, name);
|
||||
sendMessage(new ChannelMemberOther(name), message, null, sendDynmap);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -549,23 +551,22 @@ public abstract class Channel {
|
||||
|
||||
/**
|
||||
* メッセージを表示します。指定したプレイヤーの発言として処理されます。
|
||||
* @param player プレイヤー(ワールドチャット、範囲チャットの場合は必須です)
|
||||
* @param member 発言者(ワールドチャット、範囲チャットの場合は必須です)
|
||||
* @param message メッセージ
|
||||
* @param format フォーマット
|
||||
* @param sendDynmap dynmapへ送信するかどうか
|
||||
* @param displayName 発言者の表示名(APIに使用されます)
|
||||
*/
|
||||
protected abstract void sendMessage(
|
||||
ChannelMember player, String message, String format, boolean sendDynmap, String displayName);
|
||||
ChannelMember member, String message, @Nullable ClickableFormat format, boolean sendDynmap);
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param player プレイヤー
|
||||
* @param member プレイヤー
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
protected String replaceKeywords(String format, ChannelMember player) {
|
||||
return ChatFormatter.replaceKeywordsForChannel(format, player, this);
|
||||
protected ClickableFormat replaceKeywords(String format, ChannelMember member) {
|
||||
return ClickableFormat.makeFormat(format, member, this, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -714,7 +715,7 @@ public abstract class Channel {
|
||||
// メッセージ通知を流す
|
||||
String msg = Messages.expiredBanMessage(getColorCode(), getName(), cp.getName());
|
||||
if ( !msg.isEmpty() ) {
|
||||
sendMessage(null, msg, null, false, "system");
|
||||
sendMessage(ChannelMemberSystem.getInstance(), msg, null, true);
|
||||
}
|
||||
|
||||
msg = Messages.cmdmsgPardoned(getName());
|
||||
@@ -738,7 +739,7 @@ public abstract class Channel {
|
||||
// メッセージ通知を流す
|
||||
String msg = Messages.expiredMuteMessage(getColorCode(), getName(), cp.getName());
|
||||
if ( !msg.isEmpty() ) {
|
||||
sendMessage(null, msg, null, false, "system");
|
||||
sendMessage(ChannelMemberSystem.getInstance(), msg, null, true);
|
||||
}
|
||||
|
||||
msg = Messages.cmdmsgUnmuted(getName());
|
||||
@@ -1199,23 +1200,6 @@ public abstract class Channel {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param playerName プレイヤー名
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
private String replaceKeywordsForSystemMessages(String format, String playerName) {
|
||||
|
||||
String msg = format;
|
||||
msg = msg.replace("%ch", getName());
|
||||
msg = msg.replace("%color", getColorCode());
|
||||
msg = msg.replace("%username", playerName);
|
||||
msg = msg.replace("%player", playerName);
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* List<ChannelMember>を、List<String>に変換する。
|
||||
* @param org 変換元
|
||||
|
||||
@@ -7,6 +7,7 @@ package com.github.ucchyocean.lc3.channel;
|
||||
|
||||
import com.github.ucchyocean.lc3.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.util.ClickableFormat;
|
||||
|
||||
/**
|
||||
* Japanize2行表示のときに、変換結果を遅延してチャンネルに表示するためのタスク
|
||||
@@ -16,7 +17,7 @@ public class ChannelChatJapanizeTask implements Runnable {
|
||||
|
||||
private Channel channel;
|
||||
private ChannelMember player;
|
||||
private String lineFormat;
|
||||
private ClickableFormat lineFormat;
|
||||
|
||||
private JapanizeConvertTask task;
|
||||
|
||||
@@ -27,10 +28,10 @@ public class ChannelChatJapanizeTask implements Runnable {
|
||||
* @param channel 変換後に発言する、発言先チャンネル
|
||||
* @param player 発言したプレイヤー
|
||||
* @param japanizeFormat 変換後に発言するときの、発言フォーマット
|
||||
* @param lineFormat
|
||||
* @param lineFormat チャンネルのフォーマット
|
||||
*/
|
||||
public ChannelChatJapanizeTask(String org, JapanizeType type, Channel channel,
|
||||
ChannelMember player, String japanizeFormat, String lineFormat) {
|
||||
ChannelMember player, String japanizeFormat, ClickableFormat lineFormat) {
|
||||
|
||||
task = new JapanizeConvertTask(org, type, japanizeFormat, channel, player);
|
||||
this.channel = channel;
|
||||
@@ -45,8 +46,7 @@ public class ChannelChatJapanizeTask implements Runnable {
|
||||
public void run() {
|
||||
if ( task.runSync() ) {
|
||||
// チャンネルへ送信
|
||||
String name = (player != null) ? player.getDisplayName() : "";
|
||||
channel.sendMessage(player, task.getResult(), lineFormat, true, name);
|
||||
channel.sendMessage(player, task.getResult(), lineFormat, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.channel;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.util.ClickableFormat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ucchy
|
||||
*/
|
||||
public class StandaloneChannel extends Channel {
|
||||
|
||||
public StandaloneChannel(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendMessage(ChannelMember member, String message,
|
||||
@Nullable ClickableFormat format, boolean sendDynmap) {
|
||||
|
||||
// デバッグ表示メッセージ
|
||||
System.out.println(String.format("room=%s, member=%s, format=%s, message=%s",
|
||||
getName(), member.toString(), format, message));
|
||||
|
||||
// TODO チャンネルのメンバーに送信
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.github.ucchyocean.lc3.member;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
public class ChannelMemberOther extends ChannelMember {
|
||||
|
||||
private String name;
|
||||
private String displayName;
|
||||
|
||||
public ChannelMemberOther(String name) {
|
||||
this.name = name;
|
||||
this.displayName = name;
|
||||
}
|
||||
|
||||
public ChannelMemberOther(String name, String displayName) {
|
||||
this.name = name;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuffix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(BaseComponent[] message) {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s:{name=%s, displayName=%s}",
|
||||
this.getClass().toString(), name, displayName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(String node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chat(String message) {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.github.ucchyocean.lc3.member;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
public class ChannelMemberSystem extends ChannelMember {
|
||||
|
||||
private static final String NAME = "system";
|
||||
private static final ChannelMember instance = new ChannelMemberSystem();
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuffix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(BaseComponent[] message) {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getServerName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPermissionSet(String node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chat(String message) {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
public static ChannelMember getInstance() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.channel.Channel;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
/**
|
||||
* チャットのフォーマットを作成するユーティリティクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ChatFormatter {
|
||||
|
||||
private static ChatFormatter instance;
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
|
||||
private static final String JOIN_COMMAND_TEMPLATE = "/lunachat join %s";
|
||||
private static final String TELL_COMMAND_TEMPLATE = "/tell %s ";
|
||||
|
||||
private ChatFormatter() {
|
||||
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
timeFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param member 発言者
|
||||
* @param channel チャンネル
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
public static String replaceKeywordsForChannel(String format, @Nullable ChannelMember member, @NotNull Channel channel) {
|
||||
|
||||
if ( instance == null ) {
|
||||
instance = new ChatFormatter();
|
||||
}
|
||||
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
KeywordReplacer msg = new KeywordReplacer(format);
|
||||
|
||||
// テンプレートのキーワードを、まず最初に置き換える
|
||||
for ( int i=0; i<=9; i++ ) {
|
||||
String key = "%" + i;
|
||||
if ( msg.contains(key) ) {
|
||||
if ( api.getTemplate("" + i) != null ) {
|
||||
msg.replace(key, api.getTemplate("" + i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg.replace("%ch", String.format(
|
||||
"<type=RUN_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
channel.getName(),
|
||||
Messages.hoverChannelName(channel.getName()),
|
||||
String.format(JOIN_COMMAND_TEMPLATE, channel.getName())));
|
||||
//msg.replace("%msg", message);
|
||||
msg.replace("%color", channel.getColorCode());
|
||||
if ( channel.getPrivateMessageTo() != null ) {
|
||||
// msg.replace("%to", channel.getPrivateMessageTo().getDisplayName());
|
||||
msg.replace("%to", String.format(
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
channel.getPrivateMessageTo().getDisplayName(),
|
||||
Messages.hoverPlayerName(channel.getPrivateMessageTo().getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, channel.getPrivateMessageTo().getName())));
|
||||
msg.replace("%recieverserver", channel.getPrivateMessageTo().getServerName());
|
||||
} else {
|
||||
msg.replace("%to", "");
|
||||
msg.replace("%recieverserver", "");
|
||||
}
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg.replace("%date", instance.dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg.replace("%time", instance.timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( member != null ) {
|
||||
|
||||
String playerPMPlaceHolder = String.format(
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
member.getDisplayName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName()));
|
||||
msg.replace("%displayname", playerPMPlaceHolder);
|
||||
msg.replace("%username", playerPMPlaceHolder);
|
||||
msg.replace("%player", String.format(
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
member.getName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName())));
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
msg.replace("%prefix", member.getPrefix());
|
||||
msg.replace("%suffix", member.getSuffix());
|
||||
}
|
||||
|
||||
msg.replace("%world", member.getWorldName());
|
||||
msg.replace("%server", member.getServerName());
|
||||
|
||||
} else {
|
||||
msg.replace("%displayname", "");
|
||||
msg.replace("%username", "");
|
||||
msg.replace("%player", "");
|
||||
msg.replace("%prefix", "");
|
||||
msg.replace("%suffix", "");
|
||||
msg.replace("%world", "");
|
||||
msg.replace("%server", "");
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(msg.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットのフォーマット設定のキーワードを置き換えして返す
|
||||
* @param format チャットフォーマット
|
||||
* @param member 発言者
|
||||
* @return キーワード置き換え済みの文字列
|
||||
*/
|
||||
public static String replaceKeywordsForEvent(String format, @NotNull ChannelMember member) {
|
||||
|
||||
if ( instance == null ) {
|
||||
instance = new ChatFormatter();
|
||||
}
|
||||
|
||||
KeywordReplacer msg = new KeywordReplacer(format);
|
||||
|
||||
String playerPMPlaceHolder = String.format(
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
member.getDisplayName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName()));
|
||||
msg.replace("%displayname", playerPMPlaceHolder);
|
||||
msg.replace("%username", playerPMPlaceHolder);
|
||||
msg.replace("%player", String.format(
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">",
|
||||
member.getName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName())));
|
||||
|
||||
// msg.replace("%msg", "%2$s");
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg.replace("%date", instance.dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg.replace("%time", instance.timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
msg.replace("%prefix", member.getPrefix());
|
||||
msg.replace("%suffix", member.getSuffix());
|
||||
}
|
||||
|
||||
msg.replace("%world", member.getWorldName());
|
||||
msg.replace("%server", member.getServerName());
|
||||
|
||||
return Utility.replaceColorCode(msg.toString());
|
||||
}
|
||||
|
||||
|
||||
public static BaseComponent[] replaceTextComponent(String src) {
|
||||
|
||||
List<BaseComponent> components = new ArrayList<>();
|
||||
Pattern pattern = Pattern.compile(
|
||||
"<type=(SUGGEST_COMMAND|RUN_COMMAND) text=\"([^\"]*)\" hover=\"([^\"]*)\" command=\"([^\"]*)\">");
|
||||
Matcher matcher = pattern.matcher(src);
|
||||
int lastIndex = 0;
|
||||
|
||||
while ( matcher.find() ) {
|
||||
|
||||
// マッチする箇所までの文字列を取得する
|
||||
if ( lastIndex < matcher.start() ) {
|
||||
for ( BaseComponent c : TextComponent.fromLegacyText(src.substring(lastIndex, matcher.start())) ) {
|
||||
components.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
// マッチした箇所の文字列を解析して追加する
|
||||
String type = matcher.group(1);
|
||||
String text = matcher.group(2);
|
||||
String hover = matcher.group(3);
|
||||
String command = matcher.group(4);
|
||||
TextComponent tc = new TextComponent(text);
|
||||
if ( !hover.isEmpty() ) {
|
||||
tc.setHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create()));
|
||||
}
|
||||
if ( type.equals("RUN_COMMAND") ) {
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
|
||||
} else {
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
|
||||
}
|
||||
components.add(tc);
|
||||
|
||||
lastIndex = matcher.end() + 1;
|
||||
}
|
||||
|
||||
if ( lastIndex < src.length() - 1 ) {
|
||||
// 残りの部分の文字列を取得する
|
||||
for ( BaseComponent c : TextComponent.fromLegacyText(src.substring(lastIndex)) ) {
|
||||
components.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
BaseComponent[] result = new BaseComponent[components.size()];
|
||||
components.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.channel.Channel;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
/**
|
||||
* チャットのフォーマットを作成するユーティリティクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ClickableFormat {
|
||||
|
||||
private static final String JOIN_COMMAND_TEMPLATE = "/lunachat join %s";
|
||||
private static final String TELL_COMMAND_TEMPLATE = "/tell %s";
|
||||
|
||||
private static final String PLACEHOLDER_RUN_COMMAND =
|
||||
"<type=RUN_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">";
|
||||
private static final String PLACEHOLDER_SUGGEST_COMMAND =
|
||||
"<type=SUGGEST_COMMAND text=\"%s\" hover=\"%s\" command=\"%s\">";
|
||||
private static final String PLACEHOLDER_PATTERN =
|
||||
"<type=(SUGGEST_COMMAND|RUN_COMMAND) text=\"([^\"]*)\" hover=\"([^\"]*)\" command=\"([^\"]*)\">";
|
||||
|
||||
private KeywordReplacer message;
|
||||
|
||||
private ClickableFormat(KeywordReplacer message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param member 発言者
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
public static ClickableFormat makeFormat(String format, @Nullable ChannelMember member) {
|
||||
return makeFormat(format, member, null, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param member 発言者
|
||||
* @param channel チャンネル
|
||||
* @param withPlayerLink プレイヤー名の箇所にクリック可能なプレースホルダーを挿入するか
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
public static ClickableFormat makeFormat(String format,
|
||||
@Nullable ChannelMember member, @Nullable Channel channel, boolean withPlayerLink) {
|
||||
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
KeywordReplacer msg = new KeywordReplacer(format);
|
||||
|
||||
//msg.replace("%msg", message);
|
||||
|
||||
if ( channel != null ) {
|
||||
|
||||
// テンプレートのキーワードを、まず最初に置き換える
|
||||
for ( int i=0; i<=9; i++ ) {
|
||||
String key = "%" + i;
|
||||
if ( msg.contains(key) ) {
|
||||
if ( api.getTemplate("" + i) != null ) {
|
||||
msg.replace(key, api.getTemplate("" + i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// チャンネル関連のキーワード置き換え
|
||||
msg.replace("%ch", String.format(
|
||||
PLACEHOLDER_RUN_COMMAND,
|
||||
channel.getName(),
|
||||
Messages.hoverChannelName(channel.getName()),
|
||||
String.format(JOIN_COMMAND_TEMPLATE, channel.getName())));
|
||||
msg.replace("%color", channel.getColorCode());
|
||||
if ( channel.getPrivateMessageTo() != null ) {
|
||||
msg.replace("%to", String.format(
|
||||
PLACEHOLDER_SUGGEST_COMMAND,
|
||||
channel.getPrivateMessageTo().getDisplayName(),
|
||||
Messages.hoverPlayerName(channel.getPrivateMessageTo().getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, channel.getPrivateMessageTo().getName())));
|
||||
msg.replace("%recieverserver", channel.getPrivateMessageTo().getServerName());
|
||||
}
|
||||
}
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( member != null ) {
|
||||
|
||||
// ChannelMember関連のキーワード置き換え
|
||||
if ( withPlayerLink ) {
|
||||
String playerPMPlaceHolder = String.format(
|
||||
PLACEHOLDER_SUGGEST_COMMAND,
|
||||
member.getDisplayName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName()));
|
||||
msg.replace("%displayname", playerPMPlaceHolder);
|
||||
msg.replace("%username", playerPMPlaceHolder);
|
||||
msg.replace("%player", String.format(
|
||||
PLACEHOLDER_SUGGEST_COMMAND,
|
||||
member.getName(),
|
||||
Messages.hoverPlayerName(member.getName()),
|
||||
String.format(TELL_COMMAND_TEMPLATE, member.getName())));
|
||||
} else {
|
||||
msg.replace("%displayname", member.getDisplayName());
|
||||
msg.replace("%username", member.getDisplayName());
|
||||
msg.replace("%player", member.getName());
|
||||
}
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
msg.replace("%prefix", member.getPrefix());
|
||||
msg.replace("%suffix", member.getSuffix());
|
||||
}
|
||||
|
||||
msg.replace("%world", member.getWorldName());
|
||||
msg.replace("%server", member.getServerName());
|
||||
}
|
||||
|
||||
return new ClickableFormat(msg);
|
||||
}
|
||||
|
||||
|
||||
public BaseComponent[] makeTextComponent() {
|
||||
|
||||
message.translateColorCode();
|
||||
|
||||
List<BaseComponent> components = new ArrayList<>();
|
||||
Matcher matcher = Pattern.compile(PLACEHOLDER_PATTERN).matcher(message.getStringBuilder());
|
||||
int lastIndex = 0;
|
||||
|
||||
while ( matcher.find() ) {
|
||||
|
||||
// マッチする箇所までの文字列を取得する
|
||||
if ( lastIndex < matcher.start() ) {
|
||||
for ( BaseComponent c : TextComponent.fromLegacyText(message.substring(lastIndex, matcher.start())) ) {
|
||||
components.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
// マッチした箇所の文字列を解析して追加する
|
||||
String type = matcher.group(1);
|
||||
String text = matcher.group(2);
|
||||
String hover = matcher.group(3);
|
||||
String command = matcher.group(4);
|
||||
TextComponent tc = new TextComponent(text);
|
||||
if ( !hover.isEmpty() ) {
|
||||
tc.setHoverEvent(new HoverEvent(
|
||||
HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(hover).create()));
|
||||
}
|
||||
if ( type.equals("RUN_COMMAND") ) {
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
|
||||
} else { // type.equals("SUGGEST_COMMAND")
|
||||
tc.setClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, command));
|
||||
}
|
||||
components.add(tc);
|
||||
|
||||
lastIndex = matcher.end();
|
||||
}
|
||||
|
||||
if ( lastIndex < message.length() - 1 ) {
|
||||
// 残りの部分の文字列を取得する
|
||||
for ( BaseComponent c : TextComponent.fromLegacyText(message.substring(lastIndex)) ) {
|
||||
components.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
BaseComponent[] result = new BaseComponent[components.size()];
|
||||
components.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public String toLegacyText() {
|
||||
|
||||
StringBuilder msg = new StringBuilder(message.toString());
|
||||
Matcher matcher = Pattern.compile(PLACEHOLDER_PATTERN).matcher(msg);
|
||||
|
||||
while ( matcher.find(0) ) {
|
||||
String text = matcher.group(2);
|
||||
msg.replace(matcher.start(), matcher.end(), text);
|
||||
}
|
||||
|
||||
return msg.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
public void replace(String keyword, String value) {
|
||||
message.replace(keyword, value);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 文字列のキーワード置き換えを行うユーティリティクラス
|
||||
* @author ucchy
|
||||
@@ -22,7 +24,7 @@ public class KeywordReplacer {
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列keywordえを、文字列valueに置き替える
|
||||
* 文字列keywordを、文字列valueに置き換える
|
||||
* @param keyword キーワード
|
||||
* @param value 値
|
||||
*/
|
||||
@@ -33,6 +35,22 @@ public class KeywordReplacer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 正規表現regexに一致する箇所を、文字列valueに置き換える
|
||||
* @param regex 正規表現
|
||||
* @param value 値
|
||||
*/
|
||||
public void replaceRegex(String regex, String value) {
|
||||
str = new StringBuilder(Pattern.compile(regex).matcher(str).replaceAll(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列内のカラーコード候補(&a)を、カラーコード(§a)に置き換えする
|
||||
*/
|
||||
public void translateColorCode() {
|
||||
str = new StringBuilder(Utility.replaceColorCode(str.toString()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された文字列が含まれているかどうかを判定する
|
||||
* @param keyword キーワード
|
||||
@@ -51,4 +69,24 @@ public class KeywordReplacer {
|
||||
public String toString() {
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列をStringBuilderのまま取得する
|
||||
* @return StringBuilder
|
||||
*/
|
||||
public StringBuilder getStringBuilder() {
|
||||
return str;
|
||||
}
|
||||
|
||||
public String substring(int start) {
|
||||
return str.substring(start);
|
||||
}
|
||||
|
||||
public String substring(int start, int end) {
|
||||
return str.substring(start, end);
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return str.length();
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import java.util.zip.ZipEntry;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatMode;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
/**
|
||||
* ユーティリティクラス
|
||||
@@ -41,34 +42,46 @@ public class Utility {
|
||||
parent.mkdirs();
|
||||
}
|
||||
|
||||
try ( JarFile jar = new JarFile(jarFile) ) {
|
||||
ZipEntry zipEntry = jar.getEntry(sourceFilePath);
|
||||
InputStream is = jar.getInputStream(zipEntry);
|
||||
if ( jarFile.isDirectory() ) {
|
||||
File file = new File(jarFile, sourceFilePath);
|
||||
|
||||
try ( FileOutputStream fos = new FileOutputStream(targetFile) ) {
|
||||
try {
|
||||
Files.copy(file, targetFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (isBinary) {
|
||||
byte[] buf = new byte[8192];
|
||||
int len;
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
fos.write(buf, 0, len);
|
||||
}
|
||||
} else {
|
||||
|
||||
} else {
|
||||
try ( JarFile jar = new JarFile(jarFile) ) {
|
||||
ZipEntry zipEntry = jar.getEntry(sourceFilePath);
|
||||
InputStream is = jar.getInputStream(zipEntry);
|
||||
|
||||
try ( BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")) ) {
|
||||
try ( FileOutputStream fos = new FileOutputStream(targetFile) ) {
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
if (isBinary) {
|
||||
byte[] buf = new byte[8192];
|
||||
int len;
|
||||
while ((len = is.read(buf)) != -1) {
|
||||
fos.write(buf, 0, len);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
try ( BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8")) ) {
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
writer.write(line);
|
||||
writer.newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,7 +122,7 @@ public class Utility {
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列に含まれているカラーコード候補(&a)を除去して返す
|
||||
* 文字列に含まれているカラーコード候補(&aや#99AABB)を除去して返す
|
||||
* @param source 置き換え元の文字列
|
||||
* @return 置き換え後の文字列
|
||||
*/
|
||||
@@ -130,7 +143,7 @@ public class Utility {
|
||||
}
|
||||
|
||||
/**
|
||||
* カラーコード候補(&a)かどうかを判断する
|
||||
* カラーコード候補(&aや#99AABB)かどうかを判断する
|
||||
* @param color カラーコード候補
|
||||
* @return カラーコード候補かどうか
|
||||
*/
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする