コミットを比較

...
13 コミット
42個のファイルの変更、1700行の追加、729行の削除

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

+1
ファイルの表示
@@ -0,0 +1 @@
github: ucchyocean
バイナリ
ファイルの表示
バイナリファイルは表示されません。
バイナリ
ファイルの表示
バイナリファイルは表示されません。
+89 -6
ファイルの表示
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.ucchyocean</groupId>
<artifactId>LunaChat</artifactId>
<version>3.0.0</version>
<version>3.0.2</version>
<description>A powerfull chat channel plugin with IME (Kana-Kanji conversion) support</description>
<url>https://github.com/ucchyocean/LunaChat</url>
@@ -91,6 +91,10 @@
<pattern>org.jetbrains</pattern>
<shadedPattern>com.github.ucchyocean.lc.lib.org.jetbrains</shadedPattern>
</relocation>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>com.github.ucchyocean.lc.lib.org.bstats</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
@@ -115,6 +119,16 @@
<name>Multiverse repository</name>
<url>http://repo.onarandombox.com/content/repositories/multiverse/</url>
</repository>
<repository>
<id>codemc-repo</id>
<name>CodeMC Repository</name>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<repository>
<id>weaondara-repo</id>
<name>wea_ondara's Repository</name>
<url>http://repo.wea-ondara.net/repository/public/</url>
</repository>
<repository>
<id>md5-repo</id>
<name>MD5 repository</name>
@@ -129,15 +143,24 @@
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.1-R0.1-SNAPSHOT</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.15-SNAPSHOT</version>
<version>1.16-R0.2-SNAPSHOT</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-chat</artifactId>
<version>1.16-R0.1</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
@@ -146,6 +169,12 @@
<version>1.7</version>
<optional>true</optional>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.dynmap</groupId>
@@ -153,6 +182,12 @@
<version>2.0</version>
<optional>true</optional>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.onarandombox.multiversecore</groupId>
@@ -164,9 +199,57 @@
<dependency>
<groupId>com.gmail.nossr50.mcMMO</groupId>
<artifactId>mcMMO</artifactId>
<version>1.5.00</version>
<version>2.1.128</version>
<optional>true</optional>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.maven.scm</groupId>
<artifactId>maven-scm-provider-gitexe</artifactId>
</exclusion>
<exclusion>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
</exclusion>
<exclusion>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
</exclusion>
<exclusion>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-core</artifactId>
</exclusion>
<exclusion>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.alpenblock</groupId>
<artifactId>BungeePerms</artifactId>
<version>LATEST</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.1</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>1.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bungeecord</artifactId>
<version>1.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
-1
ファイルの表示
@@ -90,7 +90,6 @@ public class Channel {
* @deprecated Legacy Version
*/
public void chat(ChannelPlayer player, String message) {
// TODO player.getPlayer()で問題ないか、要確認
channel.chat(ChannelMember.getChannelMember(player.getPlayer()), message);
}
-71
ファイルの表示
@@ -1,71 +0,0 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3;
import org.jetbrains.annotations.NotNull;
/**
* チャットカラー
* @author ucchy
*/
public enum ChatColor {
BLACK('0', 0x00),
DARK_BLUE('1', 0x1),
DARK_GREEN('2', 0x2),
DARK_AQUA('3', 0x3),
DARK_RED('4', 0x4),
DARK_PURPLE('5', 0x5),
GOLD('6', 0x6),
GRAY('7', 0x7),
DARK_GRAY('8', 0x8),
BLUE('9', 0x9),
GREEN('a', 0xA),
AQUA('b', 0xB),
RED('c', 0xC),
LIGHT_PURPLE('d', 0xD),
YELLOW('e', 0xE),
WHITE('f', 0xF),
MAGIC('k', 0x10, true),
BOLD('l', 0x11, true),
STRIKETHROUGH('m', 0x12, true),
UNDERLINE('n', 0x13, true),
ITALIC('o', 0x14, true),
RESET('r', 0x15);
public static final char COLOR_CHAR = '\u00A7';
@SuppressWarnings("unused")
private final int intCode;
private final char code;
private final boolean isFormat;
private final String toString;
private ChatColor(char code, int intCode) {
this(code, intCode, false);
}
private ChatColor(char code, int intCode, boolean isFormat) {
this.code = code;
this.intCode = intCode;
this.isFormat = isFormat;
this.toString = new String(new char[] {COLOR_CHAR, code});
}
public char getChar() {
return code;
}
@NotNull
@Override
public String toString() {
return toString;
}
public boolean isFormat() {
return isFormat;
}
}
+4
ファイルの表示
@@ -11,6 +11,7 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -66,6 +67,9 @@ public class LunaChatBukkit extends JavaPlugin implements PluginInterface {
LunaChat.setPlugin(this);
LunaChat.setMode(LunaChatMode.BUKKIT);
// Metrics
new Metrics(this, 7936);
// 変数などの初期化
config = new LunaChatConfig(getDataFolder(), getFile());
uuidCacheData = new UUIDCacheData(getDataFolder());
+38
ファイルの表示
@@ -11,6 +11,10 @@ import java.util.Set;
import java.util.TreeSet;
import java.util.logging.Level;
import org.bstats.bungeecord.Metrics;
import com.github.ucchyocean.lc3.bridge.BungeePermsBridge;
import com.github.ucchyocean.lc3.bridge.LuckPermsBridge;
import com.github.ucchyocean.lc3.bungee.BungeeEventListener;
import com.github.ucchyocean.lc3.bungee.BungeeEventSender;
import com.github.ucchyocean.lc3.bungee.JapanizeCommandBungee;
@@ -37,6 +41,9 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
private UUIDCacheData uuidCacheData;
private LunaChatLogger normalChatLogger;
private BungeePermsBridge bungeeperms;
private LuckPermsBridge luckperms;
/**
* プラグインが有効化されたときに呼び出されるメソッド
* @see net.md_5.bungee.api.plugin.Plugin#onEnable()
@@ -47,6 +54,9 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
LunaChat.setPlugin(this);
LunaChat.setMode(LunaChatMode.BUNGEE);
// Metrics
new Metrics(this, 7936);
// 初期化
config = new LunaChatConfig(getDataFolder(), getFile());
uuidCacheData = new UUIDCacheData(getDataFolder());
@@ -61,6 +71,18 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
manager.removeAllDefaultChannels();
}
// BungeePermsのロード
Plugin temp = getProxy().getPluginManager().getPlugin("BungeePerms");
if ( temp != null ) {
bungeeperms = BungeePermsBridge.load(temp);
}
// LuckPermsのロード
temp = getProxy().getPluginManager().getPlugin("LuckPerms");
if ( temp != null ) {
luckperms = LuckPermsBridge.load(temp);
}
// コマンド登録
getProxy().getPluginManager().registerCommand(this,
new LunaChatCommandBungee("lunachat", "", "lc", "ch"));
@@ -196,4 +218,20 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
public void runAsyncTask(Runnable task) {
ProxyServer.getInstance().getScheduler().runAsync(this, task);
}
/**
* BungeePerms連携クラスを取得する
* @return BungeePerms連携クラス
*/
public BungeePermsBridge getBungeePerms() {
return bungeeperms;
}
/**
* LuckPerms連携クラスを取得する
* @return LuckPerms連携クラス
*/
public LuckPermsBridge getLuckPerms() {
return luckperms;
}
}
+4 -1
ファイルの表示
@@ -12,6 +12,9 @@ import java.util.logging.Level;
import java.util.regex.Pattern;
import com.github.ucchyocean.lc3.japanize.JapanizeType;
import com.github.ucchyocean.lc3.util.EventPriority;
import com.github.ucchyocean.lc3.util.Utility;
import com.github.ucchyocean.lc3.util.YamlConfig;
/**
* LunaChatのコンフィグクラス
@@ -247,7 +250,7 @@ public class LunaChatConfig {
japanizeLine1Format = config.getString("japanizeLine1Format", "%msg &6(%japanize)");
japanizeLine2Format = config.getString("japanizeLine2Format", "&6[JP] %japanize");
japanizeIgnorePlayerName = config.getBoolean("japanizeIgnorePlayerName", true);
noneJapanizeMarker = config.getString("noneJapanizeMarker", "#");
noneJapanizeMarker = config.getString("noneJapanizeMarker", "$");
japanizeWait = config.getInt("japanizeWait", 1);
// globalチャンネルが、使用可能なチャンネル名かどうかを調べる
+2
ファイルの表示
@@ -19,6 +19,8 @@ import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import com.github.ucchyocean.lc3.util.Utility;
/**
* LunaChatロガー
* @author ucchy
+1 -1
ファイルの表示
@@ -83,7 +83,7 @@ public class LunaChatStandalone implements PluginInterface {
@Override
public void log(Level level, String msg) {
// TODO 未実装
// TODO Standaloneサーバーのログ出力 未実装
}
/**
ファイル差分が大きすぎるため表示されません。 差分を読み込み
+18
ファイルの表示
@@ -10,6 +10,8 @@ import java.io.IOException;
import org.jetbrains.annotations.Nullable;
import com.github.ucchyocean.lc3.util.YamlConfig;
/**
* UUIDのキャッシュデータを管理するクラス
* @author ucchy
@@ -80,4 +82,20 @@ public class UUIDCacheData {
public @Nullable String get(String uuid) {
return cache.getString(uuid);
}
/**
* プレイヤー名からUUIDを取得する
* @param name プレイヤー名
* @return UUID(キャッシュされていない場合はnullが返される)
*/
public @Nullable String getUUIDFromName(String name) {
if ( name == null ) return null;
for ( String uuid : cache.getKeys(false) ) {
String n = cache.getString(uuid);
if ( name.equalsIgnoreCase(n) ) {
return uuid;
}
}
return null;
}
}
-153
ファイルの表示
@@ -1,153 +0,0 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.yaml.snakeyaml.Yaml;
/**
* Yaml設定読み書きユーティリティクラス
* このクラスは、階層構造のデータ形式に対応していないので注意。
* @author ucchy
*/
public class YamlConfig {
private Map<String, Object> map = new HashMap<>();
private Map<String, Object> defaults = new HashMap<>();
public static YamlConfig load(InputStream stream) throws IOException {
YamlConfig config = new YamlConfig();
if ( stream == null ) return config;
Yaml yaml = new Yaml();
@SuppressWarnings("unchecked")
Map<String, Object> map = yaml.loadAs(stream, Map.class);
if ( map == null ) {
throw new IOException("Cannot load stream as yaml.");
}
config.map = map;
return config;
}
public static YamlConfig load(Reader reader) throws IOException {
YamlConfig config = new YamlConfig();
if ( reader == null ) return config;
Yaml yaml = new Yaml();
@SuppressWarnings("unchecked")
Map<String, Object> map = yaml.loadAs(reader, Map.class);
if ( map == null ) {
throw new IOException("Cannot load reader as yaml.");
}
config.map = map;
return config;
}
public static YamlConfig load(File file) {
try ( InputStreamReader reader = new InputStreamReader(new FileInputStream(file), "UTF-8") ) {
return load(reader);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public void save(File file) throws IOException {
Yaml yaml = new Yaml();
String data = yaml.dumpAsMap(map);
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
writer.write(data);
}
}
public String getRawData() {
Yaml yaml = new Yaml();
return yaml.dumpAsMap(map);
}
public void set(String key, Object value) {
map.put(key, value);
}
public Object get(String key) {
return map.get(key);
}
public boolean getBoolean(String key) {
return getBoolean(key, false);
}
public boolean getBoolean(String key, boolean defaultValue) {
Object val = map.getOrDefault(key, defaults.get(key));
return ( val != null && val instanceof Boolean ) ? (boolean)val : defaultValue;
}
public int getInt(String key) {
return getInt(key, 0);
}
public int getInt(String key, int defaultValue) {
Object val = map.getOrDefault(key, defaults.get(key));
return ( val != null && val instanceof Integer ) ? (int)val : defaultValue;
}
public String getString(String key) {
return getString(key, null);
}
public String getString(String key, String defaultValue) {
Object val = map.getOrDefault(key, defaults.get(key));
return ( val != null ) ? val.toString() : null;
}
public List<String> getStringList(String key) {
return getStringList(key, null);
}
@SuppressWarnings("unchecked")
public List<String> getStringList(String key, ArrayList<String> defaultValue) {
Object val = map.getOrDefault(key, defaults.get(key));
return ( val != null && val instanceof ArrayList<?> ) ? (List<String>)val : null;
}
public boolean contains(String key) {
return map.containsKey(key);
}
public Set<String> getKeys(boolean deeps) {
if ( !deeps ) {
return map.keySet();
} else {
// TODO 未実装
return map.keySet();
}
}
public void addDefaults(YamlConfig defaults) {
this.defaults = defaults.map;
}
}
+56
ファイルの表示
@@ -0,0 +1,56 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3.bridge;
import net.alpenblock.bungeeperms.BungeePermsAPI;
import net.md_5.bungee.api.plugin.Plugin;
/**
* BungeePerms連携クラス
* @author ucchy
*/
public class BungeePermsBridge {
// コンストラクタは外から利用不可
private BungeePermsBridge() {
}
/**
* BungeePermsをロードする
* @param plugin BungeePermsのインスタンス
* @return ロードされたBungeePermsBridge
*/
public static BungeePermsBridge load(Plugin plugin) {
// BungeePermsが指定されたかどうかを確認
boolean loaded = (plugin != null);
// ロードされているならBungeePermsBridgeのインスタンスを、ロードされていないならnullを返す
return loaded ? new BungeePermsBridge() : null;
}
/**
* Gets the full prefix of the player
* @param nameoruuid the username or uuid of the player
* @param server the server; may be null; if server == "" then the current server is used or null if BungeeCord
* @param world the world; may be null
* @return the full prefix; may be null
*/
public String userPrefix(String nameoruuid, String server, String world) {
return BungeePermsAPI.userPrefix(nameoruuid, server, world);
}
/**
* Gets the full suffix of the player
* @param nameoruuid the username or uuid of the player
* @param server the server; may be null; if server == "" then the current server is used or null if BungeeCord
* @param world the world; may be null
* @return the full suffix; may be null
*/
public String userSuffix(String nameoruuid, String server, String world) {
return BungeePermsAPI.userSuffix(nameoruuid, server, world);
}
}
+63
ファイルの表示
@@ -0,0 +1,63 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3.bridge;
import java.util.UUID;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.luckperms.api.model.user.User;
import net.md_5.bungee.api.plugin.Plugin;
/**
* LuckPerms連携クラス
* @author ucchy
*/
public class LuckPermsBridge {
private LuckPerms api;
// コンストラクタは外から利用不可
private LuckPermsBridge(LuckPerms api) {
this.api = api;
}
/**
* LuckPermsをロードする
* @param plugin LuckPermsのインスタンス
* @return ロードされたLuckPermsBridge
*/
public static LuckPermsBridge load(Plugin plugin) {
// LuckPermsが指定されたかどうかを確認
if ( plugin == null ) return null;
// ロードされているならLuckPermsBridgeのインスタンスを作成して返す
return new LuckPermsBridge(LuckPermsProvider.get());
}
/**
* プレイヤーのprefixを取得します。
* @param uniqueId プレイヤーのUUID
* @return プレイヤーのprefix
*/
public String getPlayerPrefix(UUID uniqueId) {
User user = api.getUserManager().getUser(uniqueId);
String prefix = user.getCachedData().getMetaData().getPrefix();
return (prefix != null) ? prefix : "";
}
/**
* プレイヤーのsuffixを取得します。
* @param uniqueId プレイヤーのUUID
* @return プレイヤーのsuffix
*/
public String getPlayerSuffix(UUID uniqueId) {
User user = api.getUserManager().getUser(uniqueId);
String suffix = user.getCachedData().getMetaData().getSuffix();
return (suffix != null) ? suffix : "";
}
}
+3 -2
ファイルの表示
@@ -5,6 +5,7 @@
*/
package com.github.ucchyocean.lc3.bridge;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -17,10 +18,10 @@ import com.github.ucchyocean.lc3.LunaChat;
import com.github.ucchyocean.lc3.LunaChatAPI;
import com.github.ucchyocean.lc3.LunaChatBukkit;
import com.github.ucchyocean.lc3.LunaChatConfig;
import com.github.ucchyocean.lc3.Utility;
import com.github.ucchyocean.lc3.bukkit.BukkitRecipientChatJapanizeTask;
import com.github.ucchyocean.lc3.japanize.JapanizeType;
import com.github.ucchyocean.lc3.member.ChannelMember;
import com.github.ucchyocean.lc3.util.Utility;
import com.gmail.nossr50.api.PartyAPI;
import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
@@ -72,7 +73,7 @@ public class McMMOBridge implements Listener {
// 2byteコードを含むなら、Japanize変換は行わない
String kanaTemp = Utility.stripColorCode(message);
if ( !skipJapanize &&
( kanaTemp.getBytes().length > kanaTemp.length() ||
( kanaTemp.getBytes(StandardCharsets.UTF_8).length > kanaTemp.length() ||
kanaTemp.matches("[ \\uFF61-\\uFF9F]+") ) ) {
skipJapanize = true;
}
+13 -12
ファイルの表示
@@ -27,13 +27,14 @@ import com.github.ucchyocean.lc3.LunaChatAPI;
import com.github.ucchyocean.lc3.LunaChatBukkit;
import com.github.ucchyocean.lc3.LunaChatConfig;
import com.github.ucchyocean.lc3.Messages;
import com.github.ucchyocean.lc3.Utility;
import com.github.ucchyocean.lc3.bridge.VaultChatBridge;
import com.github.ucchyocean.lc3.channel.Channel;
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.KeywordReplacer;
import com.github.ucchyocean.lc3.util.Utility;
/**
* Bukkit関連のイベントを監視するリスナ
@@ -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());
}
/**
+29 -14
ファイルの表示
@@ -14,17 +14,20 @@ import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.github.ucchyocean.lc3.ChatColor;
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.Messages;
import com.github.ucchyocean.lc3.Utility;
import com.github.ucchyocean.lc3.bridge.BungeePermsBridge;
import com.github.ucchyocean.lc3.bridge.LuckPermsBridge;
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.util.ChatColor;
import com.github.ucchyocean.lc3.util.KeywordReplacer;
import com.github.ucchyocean.lc3.util.Utility;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
@@ -399,33 +402,45 @@ 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") ) {
// TODO 未実装
format = format.replace("%prefix", "");
format = format.replace("%suffix", "");
String prefix = "";
String suffix = "";
LuckPermsBridge luckperms = LunaChatBungee.getInstance().getLuckPerms();
if ( luckperms != null ) {
prefix = luckperms.getPlayerPrefix(player.getUniqueId());
suffix = luckperms.getPlayerSuffix(player.getUniqueId());
}
BungeePermsBridge bungeeperms = LunaChatBungee.getInstance().getBungeePerms();
if ( bungeeperms != null ) {
prefix = bungeeperms.userPrefix(player.getUniqueId().toString(), null, null);
suffix = bungeeperms.userSuffix(player.getUniqueId().toString(), null, null);
}
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());
}
/**
+28 -27
ファイルの表示
@@ -21,12 +21,13 @@ import com.github.ucchyocean.lc3.LunaChatAPI;
import com.github.ucchyocean.lc3.LunaChatBukkit;
import com.github.ucchyocean.lc3.LunaChatConfig;
import com.github.ucchyocean.lc3.Messages;
import com.github.ucchyocean.lc3.Utility;
import com.github.ucchyocean.lc3.UtilityBukkit;
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.KeywordReplacer;
import com.github.ucchyocean.lc3.util.Utility;
import com.github.ucchyocean.lc3.util.UtilityBukkit;
/**
* チャンネルの実装クラス
@@ -80,6 +81,8 @@ public class BukkitChannel extends Channel {
// 範囲チャット
if ( player instanceof ChannelMemberBukkit ) {
// ↑常にtrueだと思うが、念のため。
Location origin = ((ChannelMemberBukkit)player).getLocation();
for ( Player p : Bukkit.getOnlinePlayers() ) {
ChannelMember cp = ChannelMember.getChannelMember(p);
@@ -89,8 +92,6 @@ public class BukkitChannel extends Channel {
recipients.add(ChannelMember.getChannelMember(p));
}
}
} else {
// TODO 何かするか?検討する
}
} else {
@@ -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());
}
/**
+28 -27
ファイルの表示
@@ -14,10 +14,11 @@ 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.Utility;
import com.github.ucchyocean.lc3.event.EventResult;
import com.github.ucchyocean.lc3.member.ChannelMember;
import com.github.ucchyocean.lc3.member.ChannelMemberProxiedPlayer;
import com.github.ucchyocean.lc3.util.KeywordReplacer;
import com.github.ucchyocean.lc3.util.Utility;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.connection.ProxiedPlayer;
@@ -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());
}
/**
+3 -3
ファイルの表示
@@ -16,7 +16,6 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.github.ucchyocean.lc3.ChatColor;
import com.github.ucchyocean.lc3.LunaChat;
import com.github.ucchyocean.lc3.LunaChatAPI;
import com.github.ucchyocean.lc3.LunaChatConfig;
@@ -24,11 +23,12 @@ import com.github.ucchyocean.lc3.LunaChatLogger;
import com.github.ucchyocean.lc3.LunaChatMode;
import com.github.ucchyocean.lc3.Messages;
import com.github.ucchyocean.lc3.NGWordAction;
import com.github.ucchyocean.lc3.Utility;
import com.github.ucchyocean.lc3.YamlConfig;
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.util.ChatColor;
import com.github.ucchyocean.lc3.util.Utility;
import com.github.ucchyocean.lc3.util.YamlConfig;
/**
* チャンネル
+1 -1
ファイルの表示
@@ -16,10 +16,10 @@ import com.github.ucchyocean.lc3.LunaChat;
import com.github.ucchyocean.lc3.LunaChatAPI;
import com.github.ucchyocean.lc3.LunaChatMode;
import com.github.ucchyocean.lc3.Messages;
import com.github.ucchyocean.lc3.YamlConfig;
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.util.YamlConfig;
/**
* チャンネルマネージャー
+1 -1
ファイルの表示
@@ -12,12 +12,12 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.github.ucchyocean.lc3.LunaChat;
import com.github.ucchyocean.lc3.Utility;
import com.github.ucchyocean.lc3.event.EventResult;
import com.github.ucchyocean.lc3.japanize.IMEConverter;
import com.github.ucchyocean.lc3.japanize.JapanizeType;
import com.github.ucchyocean.lc3.japanize.YukiKanaConverter;
import com.github.ucchyocean.lc3.member.ChannelMember;
import com.github.ucchyocean.lc3.util.Utility;
/**
* Japanize変換を実行して、実行後に発言を行うタスク
+1 -1
ファイルの表示
@@ -7,9 +7,9 @@ package com.github.ucchyocean.lc3.command;
import java.util.Map;
import com.github.ucchyocean.lc3.ChatColor;
import com.github.ucchyocean.lc3.Messages;
import com.github.ucchyocean.lc3.member.ChannelMember;
import com.github.ucchyocean.lc3.util.ChatColor;
/**
* dictionaryコマンドの実行クラス
+1 -1
ファイルの表示
@@ -8,9 +8,9 @@ package com.github.ucchyocean.lc3.command;
import java.util.ArrayList;
import com.github.ucchyocean.lc3.Messages;
import com.github.ucchyocean.lc3.Utility;
import com.github.ucchyocean.lc3.channel.Channel;
import com.github.ucchyocean.lc3.member.ChannelMember;
import com.github.ucchyocean.lc3.util.Utility;
/**
* hideコマンドの実行クラス
+1 -1
ファイルの表示
@@ -9,10 +9,10 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import com.github.ucchyocean.lc3.ChatColor;
import com.github.ucchyocean.lc3.Messages;
import com.github.ucchyocean.lc3.channel.Channel;
import com.github.ucchyocean.lc3.member.ChannelMember;
import com.github.ucchyocean.lc3.util.ChatColor;
/**
* listコマンドの実行クラス
+6 -3
ファイルの表示
@@ -11,11 +11,11 @@ import java.util.Map;
import com.github.ucchyocean.lc3.LunaChat;
import com.github.ucchyocean.lc3.Messages;
import com.github.ucchyocean.lc3.Utility;
import com.github.ucchyocean.lc3.channel.Channel;
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.util.Utility;
/**
* optionコマンドの実行クラス
@@ -198,16 +198,19 @@ public class OptionCommand extends LunaChatSubCommand {
} else {
String code = options.get("color");
String colorForMsg = options.get("color").replace("&", "&").replace("#", "#");
if ( Utility.isValidColor(code) ) {
code = Utility.changeToColorCode(code);
}
if ( Utility.isAltColorCode(code) ) {
channel.setColorCode(code);
sender.sendMessage(Messages.cmdmsgOption("color", options.get("color")));
sender.sendMessage(Messages.cmdmsgOption("color", colorForMsg)
.replace("#", "#").replace("&", "&"));
setOption = true;
} else {
sender.sendMessage(Messages.errmsgInvalidColorCode(options.get("color")));
sender.sendMessage(Messages.errmsgInvalidColorCode(colorForMsg)
.replace("#", "#").replace("&", "&"));
}
}
}
+1 -1
ファイルの表示
@@ -6,9 +6,9 @@
package com.github.ucchyocean.lc3.command;
import com.github.ucchyocean.lc3.Messages;
import com.github.ucchyocean.lc3.Utility;
import com.github.ucchyocean.lc3.channel.Channel;
import com.github.ucchyocean.lc3.member.ChannelMember;
import com.github.ucchyocean.lc3.util.Utility;
/**
* unhideコマンドの実行クラス
+19 -6
ファイルの表示
@@ -10,6 +10,9 @@ import java.util.UUID;
import org.jetbrains.annotations.Nullable;
import com.github.ucchyocean.lc3.LunaChat;
import com.github.ucchyocean.lc3.LunaChatBungee;
import com.github.ucchyocean.lc3.bridge.BungeePermsBridge;
import com.github.ucchyocean.lc3.bridge.LuckPermsBridge;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.chat.TextComponent;
@@ -49,7 +52,6 @@ public class ChannelMemberProxiedPlayer extends ChannelMemberBungee {
if ( nameOrUuid.startsWith("$") ) {
return new ChannelMemberProxiedPlayer(UUID.fromString(nameOrUuid.substring(1)));
} else {
// TODO オフラインのプレイヤー取得について検討する
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(nameOrUuid);
if ( player != null ) return new ChannelMemberProxiedPlayer(player.getUniqueId());
}
@@ -105,8 +107,14 @@ public class ChannelMemberProxiedPlayer extends ChannelMemberBungee {
@Override
public String getPrefix() {
// TODO 未実装
LuckPermsBridge luckperms = LunaChatBungee.getInstance().getLuckPerms();
if ( luckperms != null ) {
return luckperms.getPlayerPrefix(id);
}
BungeePermsBridge bungeeperms = LunaChatBungee.getInstance().getBungeePerms();
if ( bungeeperms != null ) {
return bungeeperms.userPrefix(id.toString(), null, null);
}
return "";
}
@@ -118,8 +126,14 @@ public class ChannelMemberProxiedPlayer extends ChannelMemberBungee {
@Override
public String getSuffix() {
// TODO 未実装
LuckPermsBridge luckperms = LunaChatBungee.getInstance().getLuckPerms();
if ( luckperms != null ) {
return luckperms.getPlayerPrefix(id);
}
BungeePermsBridge bungeeperms = LunaChatBungee.getInstance().getBungeePerms();
if ( bungeeperms != null ) {
return bungeeperms.userPrefix(id.toString(), null, null);
}
return "";
}
@@ -171,7 +185,6 @@ public class ChannelMemberProxiedPlayer extends ChannelMemberBungee {
*/
@Override
public boolean isPermissionSet(String node) {
// TODO 要テスト
ProxiedPlayer player = getPlayer();
if ( player != null ) {
return player.getPermissions().contains(node);
+6 -5
ファイルの表示
@@ -16,7 +16,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.github.ucchyocean.lc3.YamlConfig;
import com.github.ucchyocean.lc3.util.YamlConfig;
/**
* messages_ja.yml を読んで、Messagesクラス用のメソッドを生成するツール
@@ -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(" }");
}
+140
ファイルの表示
@@ -0,0 +1,140 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3.util;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* チャットカラー
* @author ucchy
*/
public final class ChatColor {
public static final ChatColor BLACK = new ChatColor("BLACK", '0', 0x00);
public static final ChatColor DARK_BLUE = new ChatColor("DARK_BLUE", '1', 0x1);
public static final ChatColor DARK_GREEN = new ChatColor("DARK_GREEN", '2', 0x2);
public static final ChatColor DARK_AQUA = new ChatColor("DARK_AQUA", '3', 0x3);
public static final ChatColor DARK_RED = new ChatColor("DARK_RED", '4', 0x4);
public static final ChatColor DARK_PURPLE = new ChatColor("DARK_PURPLE", '5', 0x5);
public static final ChatColor GOLD = new ChatColor("GOLD", '6', 0x6);
public static final ChatColor GRAY = new ChatColor("GRAY", '7', 0x7);
public static final ChatColor DARK_GRAY = new ChatColor("DARK_GRAY", '8', 0x8);
public static final ChatColor BLUE = new ChatColor("BLUE", '9', 0x9);
public static final ChatColor GREEN = new ChatColor("GREEN", 'a', 0xA);
public static final ChatColor AQUA = new ChatColor("AQUA", 'b', 0xB);
public static final ChatColor RED = new ChatColor("RED", 'c', 0xC);
public static final ChatColor LIGHT_PURPLE = new ChatColor("LIGHT_PURPLE", 'd', 0xD);
public static final ChatColor YELLOW = new ChatColor("YELLOW", 'e', 0xE);
public static final ChatColor WHITE = new ChatColor("WHITE", 'f', 0xF);
public static final ChatColor MAGIC = new ChatColor("MAGIC", 'k', 0x10, true);
public static final ChatColor BOLD = new ChatColor("BOLD", 'l', 0x11, true);
public static final ChatColor STRIKETHROUGH = new ChatColor("STRIKETHROUGH", 'm', 0x12, true);
public static final ChatColor UNDERLINE = new ChatColor("UNDERLINE", 'n', 0x13, true);
public static final ChatColor ITALIC = new ChatColor("ITALIC", 'o', 0x14, true);
public static final ChatColor RESET = new ChatColor("RESET", 'r', 0x15);
public static final char COLOR_CHAR = '\u00A7';
@SuppressWarnings("unused")
private final int intCode;
private final char code;
private final boolean isFormat;
private final String toString;
private final String name;
private ChatColor(String name, char code, int intCode) {
this(name, code, intCode, false);
}
private ChatColor(String name, char code, int intCode, boolean isFormat) {
this.name = name;
this.code = code;
this.intCode = intCode;
this.isFormat = isFormat;
this.toString = new String(new char[] {COLOR_CHAR, code});
}
private ChatColor(String name, String toString) {
this.name = name;
this.toString = toString;
this.isFormat = false;
this.code = 'c';
this.intCode =0xFF;
}
public String name() {
return name;
}
public char getChar() {
return code;
}
@NotNull
@Override
public String toString() {
return toString;
}
public boolean isFormat() {
return isFormat;
}
public static @Nullable ChatColor getChatColorFromWebColor(String code) {
if ( code == null ) return null;
if ( code.matches("#[0-9a-fA-F]{3}") ) {
return new ChatColor(code, code.replaceAll(
"#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])",
"\u00A7x\u00A7$1\u00A7$1\u00A7$2\u00A7$2\u00A7$3\u00A7$3"));
} else if ( code.matches("#[0-9a-fA-F]{6}") ) {
return new ChatColor(code, code.replaceAll(
"#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])",
"\u00A7x\u00A7$1\u00A7$2\u00A7$3\u00A7$4\u00A7$5\u00A7$6"));
}
return null;
}
public static ChatColor[] values() {
return new ChatColor[] {
BLACK,
DARK_BLUE,
DARK_GREEN,
DARK_AQUA,
DARK_RED,
DARK_PURPLE,
GOLD,
GRAY,
DARK_GRAY,
BLUE,
GREEN,
AQUA,
RED,
LIGHT_PURPLE,
YELLOW,
WHITE,
MAGIC,
BOLD,
STRIKETHROUGH,
UNDERLINE,
ITALIC,
RESET,
};
}
public static ChatColor valueOf(String code) {
if ( code.matches("#[0-9a-fA-F]{6}") ) {
return new ChatColor(code, code.replaceAll(
"#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])",
"\u00A7x\u00A7$1\u00A7$2\u00A7$3\u00A7$4\u00A7$5\u00A7$6"));
} else {
for ( ChatColor v : values() ) {
if ( v.name.equals(code) ) return v;
}
}
return null;
}
}
@@ -3,7 +3,7 @@
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3;
package com.github.ucchyocean.lc3.util;
/**
* Event優先度列挙子
+54
ファイルの表示
@@ -0,0 +1,54 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3.util;
/**
* 文字列のキーワード置き換えを行うユーティリティクラス
* @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();
}
}
@@ -3,7 +3,7 @@
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3;
package com.github.ucchyocean.lc3.util;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -17,6 +17,9 @@ import java.util.Locale;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;
import com.github.ucchyocean.lc3.LunaChat;
import com.github.ucchyocean.lc3.LunaChatMode;
/**
* ユーティリティクラス
* @author ucchy
@@ -76,7 +79,23 @@ public class Utility {
*/
public static String replaceColorCode(String source) {
if (source == null) return null;
return source.replaceAll("&([0-9a-fk-or])", "\u00A7$1");
return replaceWebColorCode(source)
.replaceAll("&([0-9a-fk-orA-FK-OR])", "\u00A7$1");
}
/**
* Webカラーコード(#99AABBなど)を、カラーコードに置き換えする
* @param source 置き換え元の文字列
* @return 置き換え後の文字列
*/
private static String replaceWebColorCode(String source) {
return source
.replaceAll(
"#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])",
"\u00A7x\u00A7$1\u00A7$2\u00A7$3\u00A7$4\u00A7$5\u00A7$6")
.replaceAll(
"#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])",
"\u00A7x\u00A7$1\u00A7$1\u00A7$2\u00A7$2\u00A7$3\u00A7$3");
}
/**
@@ -86,7 +105,7 @@ public class Utility {
*/
public static String stripColorCode(String source) {
if (source == null) return null;
return stripAltColorCode(source).replaceAll("\u00A7([0-9a-fk-or])", "").replaceAll("&([0-9a-fk-or])", "");
return stripAltColorCode(source).replaceAll("\u00A7([0-9a-fk-orxA-FK-ORX])", "");
}
/**
@@ -96,7 +115,8 @@ public class Utility {
*/
public static String stripAltColorCode(String source) {
if (source == null) return null;
return source.replaceAll("&([0-9a-fk-or])", "");
source = source.replaceAll("#[0-9a-fA-F]{6}", "").replaceAll("#[0-9a-fA-F]{3}", "");
return source.replaceAll("&([0-9a-fk-orxA-FK-ORX])", "");
}
/**
@@ -106,7 +126,7 @@ public class Utility {
*/
public static boolean isColorCode(String code) {
if (code == null) return false;
return code.matches("\u00A7[0-9a-fk-orA-FK-OR]");
return code.matches("\u00A7[0-9a-fk-orxA-FK-ORX]");
}
/**
@@ -116,7 +136,7 @@ public class Utility {
*/
public static boolean isAltColorCode(String code) {
if (code == null) return false;
return code.matches("&[0-9a-fk-orA-FK-OR]");
return code.matches("(&[0-9a-fk-orA-FK-OR]|#[0-9a-fA-F]{3}|#[0-9a-fA-F]{6})");
}
/**
@@ -135,12 +155,11 @@ public class Utility {
}
/**
* カラー表記の文字列を、カラーコードに変換する
* カラー表記の文字列(REDとかGREENとか)を、カラーコード候補(&a)に変換する
* @param color カラー表記の文字列
* @return カラーコード
* @return カラーコード候補
*/
public static String changeToColorCode(String color) {
return "&" + changeToChatColor(color).getChar();
}
@@ -150,7 +169,6 @@ public class Utility {
* @return ChatColorクラス
*/
public static ChatColor changeToChatColor(String color) {
if (isValidColor(color)) {
return ChatColor.valueOf(color.toUpperCase());
}
@@ -176,7 +194,12 @@ public class Utility {
* @return 接続したことがあるかどうか
*/
public static boolean existsOfflinePlayer(String name) {
// TODO 未実装
if ( LunaChat.getUUIDCacheData().getUUIDFromName(name) != null ) {
return true;
}
if ( LunaChat.getMode() == LunaChatMode.BUKKIT ) {
return UtilityBukkit.existsOfflinePlayer(name);
}
return false;
}
@@ -3,7 +3,7 @@
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3;
package com.github.ucchyocean.lc3.util;
import java.util.Collection;
@@ -55,4 +55,13 @@ public class UtilityBukkit {
public static Player getPlayerExact(String name) {
return Bukkit.getPlayer(Utility.stripColorCode(name));
}
/**
* 指定された名前のプレイヤーが接続したことがあるかどうかを検索する
* @param name プレイヤー名
* @return 接続したことがあるかどうか
*/
public static boolean existsOfflinePlayer(String name) {
return (getOfflinePlayer(name) != null);
}
}
+108
ファイルの表示
@@ -0,0 +1,108 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3.util;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.yaml.snakeyaml.Yaml;
/**
* Yaml設定読み書きユーティリティクラス
* @author ucchy
*/
public class YamlConfig extends YamlSection {
/**
* InputStreamからYamlConfigをロードする
* @param stream InputStream
* @return ロードされたYamlConfig
* @throws IOException InputStreamの入力がyamlとして解析できない場合など
*/
public static YamlConfig load(InputStream stream) throws IOException {
YamlConfig config = new YamlConfig();
if ( stream == null ) return config;
Yaml yaml = new Yaml();
@SuppressWarnings("unchecked")
Map<String, Object> map = yaml.loadAs(stream, Map.class);
if ( map == null ) {
throw new IOException("Cannot load stream as yaml.");
}
config.map = map;
return config;
}
/**
* ReaderからYamlConfigをロードする
* @param reader Reader
* @return ロードされたYamlConfig
* @throws IOException Readerの入力がyamlとして解析できない場合など
*/
public static YamlConfig load(Reader reader) throws IOException {
YamlConfig config = new YamlConfig();
if ( reader == null ) return config;
Yaml yaml = new Yaml();
@SuppressWarnings("unchecked")
Map<String, Object> map = yaml.loadAs(reader, Map.class);
if ( map == null ) {
throw new IOException("Cannot load reader as yaml.");
}
config.map = map;
return config;
}
/**
* FileからYamlConfigをロードする
* @param file File
* @return ロードされたYamlConfig(ロードに失敗した場合は空のYamlConfigが返される)
*/
public static @NotNull YamlConfig load(File file) {
// 対象ファイルが存在しない場合やからっぽの場合は、からっぽのYamlConfigを返す
if ( !file.exists() || !file.isFile() || file.length() == 0 ) return new YamlConfig();
// 読み込む
try ( InputStreamReader reader = new InputStreamReader(new FileInputStream(file), "UTF-8") ) {
return load(reader);
} catch (IOException e) {
e.printStackTrace();
}
// 読み込みに失敗した場合は、からっぽのYamlConfigを返す
return new YamlConfig();
}
/**
* 保存する
* @param file 保存先
* @throws IOException 保存に失敗した場合など
*/
public void save(File file) throws IOException {
Yaml yaml = new Yaml();
String data = yaml.dumpAsMap(map);
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
writer.write(data);
}
}
}
+295
ファイルの表示
@@ -0,0 +1,295 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import org.jetbrains.annotations.Nullable;
import org.yaml.snakeyaml.Yaml;
/**
* Yaml設定読み書きユーティリティクラス
* @author ucchy
*/
public class YamlSection {
Map<String, Object> map;
private Map<String, Object> defaults = new HashMap<>();
/**
* コンストラクタ
*/
public YamlSection() {
map = new HashMap<>();
}
/**
* コンストラクタ
* @param map 初期データ
*/
public YamlSection(Map<String, Object> map) {
this.map = map;
}
/**
* 保持しているデータをStringに変換して返す
* @return Stringに変換されたデータ
*/
public String getRawData() {
Yaml yaml = new Yaml();
return yaml.dumpAsMap(map);
}
/**
* 指定されたkeyにvalueを設定する
* @param key
* @param value
*/
public void set(String key, Object value) {
if ( key.contains(".") ) {
String parent = key.substring(0, key.indexOf("."));
YamlSection section = getSection(parent);
if ( section == null ) {
section = createSection(parent);
}
String remain = key.substring(key.indexOf(".") + 1);
section.set(remain, value);
} else {
map.put(key, value);
}
}
/**
* 指定されたkeyの値を取得する
* @param key
* @return keyに対応する値(値が無い場合はnullが返される)
*/
public @Nullable Object get(String key) {
return get(key, null);
}
/**
* 指定されたkeyの値を取得する
* @param key
* @param defaultValue デフォルト値
* @return keyに対応する値(値が無い場合はdefaultValueが返される)
*/
public Object get(String key, Object defaultValue) {
if ( key.contains(".") ) {
String parent = key.substring(0, key.indexOf("."));
YamlSection section = getSection(parent);
if ( section == null ) return defaultValue;
String remain = key.substring(key.indexOf(".") + 1);
return section.get(remain, defaultValue);
} else {
Object val = map.getOrDefault(key, defaults.get(key));
return ( val != null ) ? val : defaultValue;
}
}
/**
* 指定されたkeyの値をbooleanに変換して返す
* @param key
* @return keyに対応する値(値が無いかbooleanに変換できない場合はfalseが返される)
*/
public boolean getBoolean(String key) {
return getBoolean(key, false);
}
/**
* 指定されたkeyの値をbooleanに変換して返す
* @param key
* @param defaultValue デフォルト値
* @return keyに対応する値(値が無いかbooleanに変換できない場合はdefaultValueが返される)
*/
public boolean getBoolean(String key, boolean defaultValue) {
Object val = get(key, defaults.get(key));
return ( val != null && val instanceof Boolean ) ? (boolean)val : defaultValue;
}
/**
* 指定されたkeyの値をintに変換して返す
* @param key
* @return keyに対応する値(値が無いかintに変換できない場合は0が返される)
*/
public int getInt(String key) {
return getInt(key, 0);
}
/**
* 指定されたkeyの値をintに変換して返す
* @param key
* @param defaultValue デフォルト値
* @return keyに対応する値(値が無いかintに変換できない場合はdefaultValueが返される)
*/
public int getInt(String key, int defaultValue) {
Object val = get(key, defaults.get(key));
return ( val != null && val instanceof Integer ) ? (int)val : defaultValue;
}
/**
* 指定されたkeyの値をStringに変換して返す
* @param key
* @return keyに対応する値(値が無いかStringに変換できない場合は0が返される)
*/
public @Nullable String getString(String key) {
return getString(key, null);
}
/**
* 指定されたkeyの値をStringに変換して返す
* @param key
* @param defaultValue デフォルト値
* @return keyに対応する値(値が無いかStringに変換できない場合はdefaultValueが返される)
*/
public String getString(String key, String defaultValue) {
Object val = get(key, defaults.get(key));
return ( val != null ) ? val.toString() : defaultValue;
}
/**
* 指定されたkeyの値をList&lt;String&gt;に変換して返す
* @param key
* @return keyに対応する値(値が無いかList&lt;String&gt;に変換できない場合はnullが返される)
*/
public @Nullable List<String> getStringList(String key) {
return getStringList(key, null);
}
/**
* 指定されたkeyの値をList&lt;String&gt;に変換して返す
* @param key
* @param defaultValue デフォルト値
* @return keyに対応する値(値が無いかList&lt;String&gt;に変換できない場合はdefaultValueが返される)
*/
@SuppressWarnings("unchecked")
public List<String> getStringList(String key, ArrayList<String> defaultValue) {
Object val = get(key, defaults.get(key));
return ( val != null && val instanceof ArrayList<?> ) ? (List<String>)val : defaultValue;
}
/**
* 指定されたkeyの値をMap&lt;String, Object&gt;に変換して返す
* @param key
* @return keyに対応する値(値が無いかMap&lt;String, Object&gt;に変換できない場合はnullが返される)
*/
public @Nullable Map<String, Object> getMap(String key) {
return getMap(key, null);
}
/**
* 指定されたkeyの値をMap&lt;String, Object&gt;に変換して返す
* @param key
* @param defaultValue デフォルト値
* @return keyに対応する値(値が無いかMap&lt;String, Object&gt;に変換できない場合はdefaultValueが返される)
*/
@SuppressWarnings("unchecked")
public Map<String, Object> getMap(String key, Map<String, Object> defaultValue) {
Object val = get(key, defaults.get(key));
return ( val != null && val instanceof Map<?, ?> ) ? (Map<String, Object>)val : defaultValue;
}
/**
* 指定されたkeyの値をYamlSectionに変換して返す
* @param key
* @return YamlSection(値が無いかMap&lt;String, Object&gt;に変換できない場合はnullが返される)
*/
public @Nullable YamlSection getSection(String key) {
return getSection(key, null);
}
/**
* 指定されたkeyの値をYamlSectionに変換して返す
* @param key
* @param defaultValue デフォルト値
* @return YamlSection(値が無いかMap&lt;String, Object&gt;に変換できない場合はdefaultValueが返される)
*/
public YamlSection getSection(String key, YamlSection defaultValue) {
Map<String, Object> m = getMap(key);
if ( m == null ) return defaultValue;
return new YamlSection(m);
}
/**
* 指定されたkeyの値があるかどうか判定する
* @param key
* @return 値があるかどうか
*/
public boolean contains(String key) {
if ( key.contains(".") ) {
String parent = key.substring(0, key.indexOf("."));
YamlSection section = getSection(parent);
if ( section == null ) return false;
String remain = key.substring(key.indexOf(".") + 1);
return section.contains(remain);
} else {
return map.containsKey(key);
}
}
/**
* 指定されたkeyに対応するサブセクションがあるかどうか判定する
* @param key
* @return サブセクションがあるかどうか
*/
public boolean containsSection(String key) {
return (getMap(key) != null);
}
/**
* 指定されたkeyのサブセクションを作成する<br/>
* 注意:階層構造指定でセクションを作成した場合、最下層のセクションが戻り値として返されることに注意すること。<br/>
* 例えば、createSection("aa.bb.cc") の戻り値は "cc" のセクションとなる。
* @param key
* @return サブセクション
*/
public YamlSection createSection(String key) {
if ( containsSection(key) ) return getSection(key);
Map<String, Object> map = new HashMap<String, Object>();
set(key, map);
return new YamlSection(map);
}
/**
* 階層のkeyを羅列する
* @param deeps 再帰的にkeyを取得するかどうか
* @return keyの羅列
*/
public Set<String> getKeys(boolean deeps) {
if ( !deeps ) {
return map.keySet();
} else {
Set<String> result = new TreeSet<String>();
for ( String key : map.keySet() ) {
result.add(key);
if ( containsSection(key) ) {
YamlSection sec = getSection(key);
for ( String sub : sec.getKeys(true) ) {
result.add(key + "." + sub);
}
}
}
return result;
}
}
/**
* デフォルト値を設定する
* @param defaults デフォルト値
*/
public void addDefaults(YamlSection defaults) {
if (defaults == null) {
this.defaults = new HashMap<String, Object>();
} else {
this.defaults = defaults.map;
}
}
}
+1 -1
ファイルの表示
@@ -203,4 +203,4 @@ japanizeIgnorePlayerName: true
# Non-Japanese marker.
# If this is at the beginning of your remark, do not temporarily perform Japanize conversion.
noneJapanizeMarker: '#'
noneJapanizeMarker: '$'
+1 -2
ファイルの表示
@@ -213,7 +213,6 @@ japanizeIgnorePlayerName: true
# ノンジャパナイズマーカー。
# これが発言の頭に入っている場合は、一時的にJapanize変換を実行しない。
noneJapanizeMarker: '#'
noneJapanizeMarker: '$'
# -------------------- BungeeCord用設定 --------------------
+28
ファイルの表示
@@ -0,0 +1,28 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3.util;
import junit.framework.TestCase;
/**
*
* @author ucchy
*/
public class UtilityTester extends TestCase {
public void testColorCode() {
String testee = "#FFEEDDtesuto#112233aiueo";
System.out.println(Utility.replaceColorCode(testee));
assertTrue("§x§F§F§E§E§D§Dtesuto§x§1§1§2§2§3§3aiueo".equals(Utility.replaceColorCode(testee)));
testee = "#FEDtesuto#123aiueo";
System.out.println(Utility.replaceColorCode(testee));
assertTrue("§x§F§F§E§E§D§Dtesuto§x§1§1§2§2§3§3aiueo".equals(Utility.replaceColorCode(testee)));
}
}
+47
ファイルの表示
@@ -0,0 +1,47 @@
/*
* @author ucchy
* @license LGPLv3
* @copyright Copyright ucchy 2020
*/
package com.github.ucchyocean.lc3.util;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
/**
* YamlConfigのテスト
* @author ucchy
*/
public class YamlConfigTester extends TestCase {
public void testYamlConfig() {
YamlConfig config = new YamlConfig();
config.set("aaa.bbb", "test");
config.set("aaa.int", 1);
YamlSection section = config.createSection("bbb");
section.set("aiueo.aaa", "testdesu");
List<String> list = new ArrayList<>();
list.add("aa");
list.add("bb");
section.set("list", list);
System.out.println("=== Yaml Values ===");
System.out.println(config.getRawData());
System.out.println();
System.out.println("=== Yaml Keys (deeps=true) ===");
for ( String key : config.getKeys(true) ) {
System.out.println(key);
}
assertTrue("test".equals(config.getString("aaa.bbb")));
assertTrue("testdesu".equals(config.getString("bbb.aiueo.aaa")));
assertTrue(config.getInt("aaa.int") == 1);
assertTrue(config.getStringList("bbb.list").size() == 2);
}
}