LunaChat v3.0.2 : Refined keyword replacement of strings.
このコミットが含まれているのは:
1 親
b9fcb18aac
コミット
7f877d0674
7ファイル変更
+694
-450
検索条件に一致するファイルはありません
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3;
|
||||
|
||||
/**
|
||||
* 文字列のキーワード置き換えを行うユーティリティクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class KeywordReplacer {
|
||||
|
||||
private StringBuilder str;
|
||||
|
||||
/**
|
||||
* 指定された文字列で初期化を行う
|
||||
* @param src
|
||||
*/
|
||||
public KeywordReplacer(String src) {
|
||||
str = new StringBuilder(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列keywordえを、文字列valueに置き替える
|
||||
* @param keyword キーワード
|
||||
* @param value 値
|
||||
*/
|
||||
public void replace(String keyword, String value) {
|
||||
int start;
|
||||
while ( (start = str.indexOf(keyword)) > -1 ) {
|
||||
str.replace(start, start + keyword.length(), value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定された文字列が含まれているかどうかを判定する
|
||||
* @param keyword キーワード
|
||||
* @return 含まれているかどうか
|
||||
*/
|
||||
public boolean contains(String keyword) {
|
||||
return str.indexOf(keyword) > -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列をStringで取得する
|
||||
* @return String
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return str.toString();
|
||||
}
|
||||
}
|
||||
ファイル差分が大きすぎるため表示されません。
差分を読み込み
@@ -22,6 +22,7 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import com.github.ucchyocean.lc3.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatBukkit;
|
||||
@@ -455,16 +456,16 @@ public class BukkitEventListener implements Listener {
|
||||
*/
|
||||
private String replaceNormalChatFormatKeywords(String org, Player player) {
|
||||
|
||||
String format = org;
|
||||
format = format.replace("%username", "%1$s");
|
||||
format = format.replace("%msg", "%2$s");
|
||||
format = format.replace("%player", player.getName());
|
||||
KeywordReplacer format = new KeywordReplacer(org);
|
||||
format.replace("%username", "%1$s");
|
||||
format.replace("%msg", "%2$s");
|
||||
format.replace("%player", player.getName());
|
||||
|
||||
if ( format.contains("%date") ) {
|
||||
format = format.replace("%date", dateFormat.format(new Date()));
|
||||
format.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( format.contains("%time") ) {
|
||||
format = format.replace("%time", timeFormat.format(new Date()));
|
||||
format.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( format.contains("%prefix") || format.contains("%suffix") ) {
|
||||
@@ -476,8 +477,8 @@ public class BukkitEventListener implements Listener {
|
||||
prefix = vaultchat.getPlayerPrefix(player);
|
||||
suffix = vaultchat.getPlayerSuffix(player);
|
||||
}
|
||||
format = format.replace("%prefix", prefix);
|
||||
format = format.replace("%suffix", suffix);
|
||||
format.replace("%prefix", prefix);
|
||||
format.replace("%suffix", suffix);
|
||||
}
|
||||
|
||||
if ( format.contains("%world") ) {
|
||||
@@ -489,12 +490,12 @@ public class BukkitEventListener implements Listener {
|
||||
if ( worldname == null || worldname.equals("") ) {
|
||||
worldname = player.getWorld().getName();
|
||||
}
|
||||
format = format.replace("%world", worldname);
|
||||
format.replace("%world", worldname);
|
||||
}
|
||||
|
||||
format = format.replace("%server", "");
|
||||
format.replace("%server", "");
|
||||
|
||||
return Utility.replaceColorCode(format);
|
||||
return Utility.replaceColorCode(format.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.ucchyocean.lc3.ChatColor;
|
||||
import com.github.ucchyocean.lc3.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatBungee;
|
||||
@@ -401,16 +402,16 @@ public class BungeeEventListener implements Listener {
|
||||
*/
|
||||
private String replaceNormalChatFormatKeywords(String org, ProxiedPlayer player, String msg) {
|
||||
|
||||
String format = org;
|
||||
format = format.replace("%username", player.getDisplayName());
|
||||
format = format.replace("%msg", msg);
|
||||
format = format.replace("%player", player.getName());
|
||||
KeywordReplacer format = new KeywordReplacer(org);
|
||||
format.replace("%username", player.getDisplayName());
|
||||
format.replace("%msg", msg);
|
||||
format.replace("%player", player.getName());
|
||||
|
||||
if ( format.contains("%date") ) {
|
||||
format = format.replace("%date", dateFormat.format(new Date()));
|
||||
format.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( format.contains("%time") ) {
|
||||
format = format.replace("%time", timeFormat.format(new Date()));
|
||||
format.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( format.contains("%prefix") || format.contains("%suffix") ) {
|
||||
@@ -427,19 +428,19 @@ public class BungeeEventListener implements Listener {
|
||||
prefix = bungeeperms.userPrefix(player.getUniqueId().toString(), null, null);
|
||||
suffix = bungeeperms.userSuffix(player.getUniqueId().toString(), null, null);
|
||||
}
|
||||
format = format.replace("%prefix", prefix);
|
||||
format = format.replace("%suffix", suffix);
|
||||
format.replace("%prefix", prefix);
|
||||
format.replace("%suffix", suffix);
|
||||
}
|
||||
|
||||
if ( format.contains("%world") ) {
|
||||
format = format.replace("%world", "");
|
||||
format.replace("%world", "");
|
||||
}
|
||||
|
||||
if ( format.contains("%server") ) {
|
||||
format = format.replace("%server", player.getServer().getInfo().getName());
|
||||
format.replace("%server", player.getServer().getInfo().getName());
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(format);
|
||||
return Utility.replaceColorCode(format.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc3.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatBukkit;
|
||||
@@ -265,43 +266,43 @@ public class BukkitChannel extends Channel {
|
||||
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
String msg = format;
|
||||
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 = msg.replace(key, api.getTemplate("" + i));
|
||||
msg.replace(key, api.getTemplate("" + i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg = msg.replace("%ch", getName());
|
||||
//msg = msg.replace("%msg", message);
|
||||
msg = msg.replace("%color", getColorCode());
|
||||
msg.replace("%ch", getName());
|
||||
//msg.replace("%msg", message);
|
||||
msg.replace("%color", getColorCode());
|
||||
if ( getPrivateMessageTo() != null ) {
|
||||
msg = msg.replace("%to", getPrivateMessageTo().getDisplayName());
|
||||
msg.replace("%to", getPrivateMessageTo().getDisplayName());
|
||||
} else {
|
||||
msg = msg.replace("%to", "");
|
||||
msg.replace("%to", "");
|
||||
}
|
||||
msg = msg.replace("%recieverserver", "");
|
||||
msg.replace("%recieverserver", "");
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg = msg.replace("%date", dateFormat.format(new Date()));
|
||||
msg.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg = msg.replace("%time", timeFormat.format(new Date()));
|
||||
msg.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( player != null ) {
|
||||
msg = msg.replace("%username", player.getDisplayName());
|
||||
msg = msg.replace("%player", player.getName());
|
||||
msg.replace("%username", player.getDisplayName());
|
||||
msg.replace("%player", player.getName());
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
msg = msg.replace("%prefix", player.getPrefix());
|
||||
msg = msg.replace("%suffix", player.getSuffix());
|
||||
msg.replace("%prefix", player.getPrefix());
|
||||
msg.replace("%suffix", player.getSuffix());
|
||||
}
|
||||
|
||||
if ( msg.contains("%world") ) {
|
||||
@@ -313,21 +314,21 @@ public class BukkitChannel extends Channel {
|
||||
if ( worldname == null || worldname.equals("") ) {
|
||||
worldname = player.getWorldName();
|
||||
}
|
||||
msg = msg.replace("%world", worldname);
|
||||
msg.replace("%world", worldname);
|
||||
}
|
||||
|
||||
msg = msg.replace("%server", "");
|
||||
msg.replace("%server", "");
|
||||
|
||||
} else {
|
||||
msg = msg.replace("%username", "");
|
||||
msg = msg.replace("%player", "");
|
||||
msg = msg.replace("%prefix", "");
|
||||
msg = msg.replace("%suffix", "");
|
||||
msg = msg.replace("%world", "");
|
||||
msg = msg.replace("%server", "");
|
||||
msg.replace("%username", "");
|
||||
msg.replace("%player", "");
|
||||
msg.replace("%prefix", "");
|
||||
msg.replace("%suffix", "");
|
||||
msg.replace("%world", "");
|
||||
msg.replace("%server", "");
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
return Utility.replaceColorCode(msg.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.ucchyocean.lc3.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatBungee;
|
||||
@@ -195,71 +196,71 @@ public class BungeeChannel extends Channel {
|
||||
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
String msg = format;
|
||||
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 = msg.replace(key, api.getTemplate("" + i));
|
||||
msg.replace(key, api.getTemplate("" + i));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg = msg.replace("%ch", getName());
|
||||
//msg = msg.replace("%msg", message);
|
||||
msg = msg.replace("%color", getColorCode());
|
||||
msg.replace("%ch", getName());
|
||||
//msg.replace("%msg", message);
|
||||
msg.replace("%color", getColorCode());
|
||||
if ( getPrivateMessageTo() != null ) {
|
||||
msg = msg.replace("%to", getPrivateMessageTo().getDisplayName());
|
||||
msg.replace("%to", getPrivateMessageTo().getDisplayName());
|
||||
if ( getPrivateMessageTo() instanceof ChannelMemberProxiedPlayer ) {
|
||||
ChannelMemberProxiedPlayer cm = (ChannelMemberProxiedPlayer)getPrivateMessageTo();
|
||||
msg = msg.replace("%recieverserver", cm.getServer().getInfo().getName());
|
||||
msg.replace("%recieverserver", cm.getServer().getInfo().getName());
|
||||
} else {
|
||||
msg = msg.replace("%recieverserver", "");
|
||||
msg.replace("%recieverserver", "");
|
||||
}
|
||||
} else {
|
||||
msg = msg.replace("%to", "");
|
||||
msg = msg.replace("%recieverserver", "");
|
||||
msg.replace("%to", "");
|
||||
msg.replace("%recieverserver", "");
|
||||
}
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg = msg.replace("%date", dateFormat.format(new Date()));
|
||||
msg.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg = msg.replace("%time", timeFormat.format(new Date()));
|
||||
msg.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( player != null ) {
|
||||
msg = msg.replace("%username", player.getDisplayName());
|
||||
msg = msg.replace("%player", player.getName());
|
||||
msg.replace("%username", player.getDisplayName());
|
||||
msg.replace("%player", player.getName());
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
msg = msg.replace("%prefix", player.getPrefix());
|
||||
msg = msg.replace("%suffix", player.getSuffix());
|
||||
msg.replace("%prefix", player.getPrefix());
|
||||
msg.replace("%suffix", player.getSuffix());
|
||||
}
|
||||
|
||||
msg = msg.replace("%world", "");
|
||||
msg.replace("%world", "");
|
||||
|
||||
if ( msg.contains("%server") ) {
|
||||
if ( player instanceof ChannelMemberProxiedPlayer ) {
|
||||
String serverName = ((ChannelMemberProxiedPlayer)player).getServer().getInfo().getName();
|
||||
msg = msg.replace("%server", serverName);
|
||||
msg.replace("%server", serverName);
|
||||
}
|
||||
msg = msg.replace("%server", "");
|
||||
msg.replace("%server", "");
|
||||
}
|
||||
|
||||
} else {
|
||||
msg = msg.replace("%username", "");
|
||||
msg = msg.replace("%player", "");
|
||||
msg = msg.replace("%prefix", "");
|
||||
msg = msg.replace("%suffix", "");
|
||||
msg = msg.replace("%world", "");
|
||||
msg = msg.replace("%server", "");
|
||||
msg.replace("%username", "");
|
||||
msg.replace("%player", "");
|
||||
msg.replace("%prefix", "");
|
||||
msg.replace("%suffix", "");
|
||||
msg.replace("%world", "");
|
||||
msg.replace("%server", "");
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
return Utility.replaceColorCode(msg.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -109,17 +109,18 @@ public class MessageParser {
|
||||
" String msg = resources.getString(\"%s\");", key));
|
||||
result.add(String.format(
|
||||
" if ( msg == null ) return \"\";", key));
|
||||
result.add(" KeywordReplacer kr = new KeywordReplacer(msg);");
|
||||
|
||||
for ( String keyword : keywords ) {
|
||||
result.add(String.format(
|
||||
" msg = msg.replace(\"%%%s%%\", %s.toString());", keyword, keyword));
|
||||
" kr.replace(\"%%%s%%\", %s.toString());", keyword, keyword));
|
||||
}
|
||||
if ( key.startsWith("errmsg") ) {
|
||||
result.add(" return Utility.replaceColorCode(resources.getString(\"errorPrefix\", \"\") + msg);");
|
||||
result.add(" return Utility.replaceColorCode(resources.getString(\"errorPrefix\", \"\") + kr.toString());");
|
||||
} else if ( key.startsWith("cmdmsg") ) {
|
||||
result.add(" return Utility.replaceColorCode(resources.getString(\"infoPrefix\", \"\") + msg);");
|
||||
result.add(" return Utility.replaceColorCode(resources.getString(\"infoPrefix\", \"\") + kr.toString());");
|
||||
} else {
|
||||
result.add(" return Utility.replaceColorCode(msg);");
|
||||
result.add(" return Utility.replaceColorCode(kr.toString());");
|
||||
}
|
||||
result.add(" }");
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする