コミットを比較
| 作成者 | SHA1 | 日付 | |
|---|---|---|---|
|
|
18c47505c7 | ||
|
|
a7234efe84 | ||
|
|
9d5fd5ceb5 | ||
|
|
9e65f0f63b | ||
|
|
7b73ad1c21 | ||
|
|
167293d5e5 | ||
|
|
d14840f144 | ||
|
|
b3ed3103e4 | ||
|
|
d652fcb39a | ||
|
|
e2eea8798d | ||
|
|
0466653e89 | ||
|
|
74a2e4de8c | ||
|
|
881d3504b6 | ||
|
|
f0fe3f02e6 | ||
|
|
7f877d0674 | ||
|
|
b9fcb18aac | ||
|
|
134ad9b264 | ||
|
|
59f7ffd858 | ||
|
|
86773b9b85 |
検索条件に一致するファイルはありません
@@ -0,0 +1 @@
|
||||
github: ucchyocean
|
||||
@@ -6,3 +6,4 @@
|
||||
.idea/
|
||||
*.iml
|
||||
/.sts4-cache
|
||||
/LunaChat
|
||||
@@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.github.ucchyocean</groupId>
|
||||
<artifactId>LunaChat</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<version>3.0.4</version>
|
||||
<description>A powerfull chat channel plugin with IME (Kana-Kanji conversion) support</description>
|
||||
<url>https://github.com/ucchyocean/LunaChat</url>
|
||||
|
||||
@@ -70,6 +70,7 @@
|
||||
<version>3.2.1</version>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
@@ -91,11 +92,27 @@
|
||||
<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>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12.4</version>
|
||||
<configuration>
|
||||
<junitArtifactName>junit:junit</junitArtifactName>
|
||||
<encoding>UTF-8</encoding>
|
||||
<inputEncoding>UTF-8</inputEncoding>
|
||||
<outputEncoding>UTF-8</outputEncoding>
|
||||
<argLine>-Dfile.encoding=UTF-8</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -117,7 +134,7 @@
|
||||
</repository>
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
<name>mcMMO Repository</name>
|
||||
<name>CodeMC Repository</name>
|
||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
@@ -139,15 +156,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>
|
||||
@@ -156,6 +182,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>
|
||||
@@ -163,6 +195,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>
|
||||
@@ -177,14 +215,55 @@
|
||||
<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>
|
||||
<version>4.0-dev-106</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>
|
||||
<artifactId>gson</artifactId>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,15 @@
|
||||
package com.github.ucchyocean.lc3;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.Callable;
|
||||
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 +70,19 @@ public class LunaChatBukkit extends JavaPlugin implements PluginInterface {
|
||||
LunaChat.setPlugin(this);
|
||||
LunaChat.setMode(LunaChatMode.BUKKIT);
|
||||
|
||||
// Metrics
|
||||
Metrics metrics = new Metrics(this, 7936);
|
||||
metrics.addCustomChart(new Metrics.DrilldownPie(
|
||||
"minecraft_server_version", new Callable<Map<String, Map<String, Integer>>>() {
|
||||
public Map<String, Map<String, Integer>> call() throws Exception {
|
||||
Map<String, Map<String, Integer>> map = new HashMap<>();
|
||||
Map<String, Integer> sub = new HashMap<>();
|
||||
sub.put(Bukkit.getVersion(), 1);
|
||||
map.put(Bukkit.getName(), sub);
|
||||
return map;
|
||||
}
|
||||
}));
|
||||
|
||||
// 変数などの初期化
|
||||
config = new LunaChatConfig(getDataFolder(), getFile());
|
||||
uuidCacheData = new UUIDCacheData(getDataFolder());
|
||||
@@ -148,7 +165,7 @@ public class LunaChatBukkit extends JavaPlugin implements PluginInterface {
|
||||
return messageCommand.execute(ChannelMember.getChannelMember(sender), label, args);
|
||||
} else if ( command.getName().equals("reply") ) {
|
||||
return replyCommand.execute(ChannelMember.getChannelMember(sender), label, args);
|
||||
} else if ( command.getName().equals("lcjapanize") ) {
|
||||
} else if ( command.getName().equals("japanize") ) {
|
||||
return lcjapanizeCommand.execute(ChannelMember.getChannelMember(sender), label, args);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,16 @@ package com.github.ucchyocean.lc3;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.Callable;
|
||||
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;
|
||||
@@ -39,6 +44,7 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
|
||||
private LunaChatLogger normalChatLogger;
|
||||
|
||||
private BungeePermsBridge bungeeperms;
|
||||
private LuckPermsBridge luckperms;
|
||||
|
||||
/**
|
||||
* プラグインが有効化されたときに呼び出されるメソッド
|
||||
@@ -50,6 +56,19 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
|
||||
LunaChat.setPlugin(this);
|
||||
LunaChat.setMode(LunaChatMode.BUNGEE);
|
||||
|
||||
// Metrics
|
||||
Metrics metrics = new Metrics(this, 7936);
|
||||
metrics.addCustomChart(new Metrics.DrilldownPie(
|
||||
"minecraft_server_version", new Callable<Map<String, Map<String, Integer>>>() {
|
||||
public Map<String, Map<String, Integer>> call() throws Exception {
|
||||
Map<String, Map<String, Integer>> map = new HashMap<>();
|
||||
Map<String, Integer> sub = new HashMap<>();
|
||||
sub.put(getProxy().getVersion(), 1);
|
||||
map.put(getProxy().getName(), sub);
|
||||
return map;
|
||||
}
|
||||
}));
|
||||
|
||||
// 初期化
|
||||
config = new LunaChatConfig(getDataFolder(), getFile());
|
||||
uuidCacheData = new UUIDCacheData(getDataFolder());
|
||||
@@ -65,7 +84,16 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
|
||||
}
|
||||
|
||||
// BungeePermsのロード
|
||||
bungeeperms = BungeePermsBridge.load();
|
||||
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,
|
||||
@@ -210,4 +238,12 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
|
||||
public BungeePermsBridge getBungeePerms() {
|
||||
return bungeeperms;
|
||||
}
|
||||
|
||||
/**
|
||||
* LuckPerms連携クラスを取得する
|
||||
* @return LuckPerms連携クラス
|
||||
*/
|
||||
public LuckPermsBridge getLuckPerms() {
|
||||
return luckperms;
|
||||
}
|
||||
}
|
||||
@@ -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チャンネルが、使用可能なチャンネル名かどうかを調べる
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 未実装
|
||||
// 画面に表示する
|
||||
System.out.println(String.format("[%s]%s", level.toString(), msg));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
ファイル差分が大きすぎるため表示されません。
差分を読み込み
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,164 +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) {
|
||||
|
||||
// 対象ファイルが存在しない場合やからっぽの場合は、からっぽの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();
|
||||
}
|
||||
|
||||
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) {
|
||||
if (defaults == null) {
|
||||
this.defaults = new HashMap<String, Object>();
|
||||
} else {
|
||||
this.defaults = defaults.map;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
package com.github.ucchyocean.lc3.bridge;
|
||||
|
||||
import net.alpenblock.bungeeperms.BungeePermsAPI;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* BungeePerms連携クラス
|
||||
@@ -20,12 +20,13 @@ public class BungeePermsBridge {
|
||||
|
||||
/**
|
||||
* BungeePermsをロードする
|
||||
* @param plugin BungeePermsのインスタンス
|
||||
* @return ロードされたBungeePermsBridge
|
||||
*/
|
||||
public static BungeePermsBridge load() {
|
||||
public static BungeePermsBridge load(Plugin plugin) {
|
||||
|
||||
// BungeePermsが動作しているかどうか確認
|
||||
boolean loaded = ProxyServer.getInstance().getPluginManager().getPlugin("BungeePerms") != null;
|
||||
// BungeePermsが指定されたかどうかを確認
|
||||
boolean loaded = (plugin != null);
|
||||
|
||||
// ロードされているならBungeePermsBridgeのインスタンスを、ロードされていないならnullを返す
|
||||
return loaded ? new BungeePermsBridge() : null;
|
||||
|
||||
@@ -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 : "";
|
||||
}
|
||||
}
|
||||
@@ -18,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;
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
package com.github.ucchyocean.lc3.bukkit;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -27,13 +27,16 @@ 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.ClickableFormat;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
/**
|
||||
* Bukkit関連のイベントを監視するリスナ
|
||||
@@ -41,16 +44,7 @@ import com.github.ucchyocean.lc3.member.ChannelMemberBukkit;
|
||||
*/
|
||||
public class BukkitEventListener implements Listener {
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
*/
|
||||
public BukkitEventListener() {
|
||||
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
timeFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
}
|
||||
private static final int MAX_LIST_ITEMS = 8;
|
||||
|
||||
/**
|
||||
* プレイヤーがチャット発言したときに呼び出されるメソッド
|
||||
@@ -131,9 +125,8 @@ public class BukkitEventListener implements Listener {
|
||||
|
||||
// チャンネルチャット情報を表示する
|
||||
if ( config.isShowListOnJoin() ) {
|
||||
ArrayList<String> list = getListForMotd(player);
|
||||
for ( String msg : list ) {
|
||||
player.sendMessage(msg);
|
||||
for ( BaseComponent[] msg : getListForMotd(player) ) {
|
||||
ChannelMember.getChannelMember(player).sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,10 +302,16 @@ public class BukkitEventListener implements Listener {
|
||||
}
|
||||
|
||||
// チャットフォーマット装飾の適用
|
||||
ClickableFormat format;
|
||||
if ( config.isEnableNormalChatMessageFormat() ) {
|
||||
String format = config.getNormalChatMessageFormat();
|
||||
format = replaceNormalChatFormatKeywords(format, event.getPlayer());
|
||||
event.setFormat(format);
|
||||
String f = config.getNormalChatMessageFormat();
|
||||
format = ClickableFormat.makeFormat(f, ChannelMember.getChannelMember(event.getPlayer()));
|
||||
// event.setFormat(format);
|
||||
} else {
|
||||
String f = event.getFormat()
|
||||
.replace("%1$s", "%displayName")
|
||||
.replace("%2$s", "%msg");
|
||||
format = ClickableFormat.makeFormat(f, ChannelMember.getChannelMember(event.getPlayer()));
|
||||
}
|
||||
|
||||
// カラーコード置き換え
|
||||
@@ -378,7 +377,20 @@ public class BukkitEventListener implements Listener {
|
||||
}
|
||||
|
||||
// 発言内容の設定
|
||||
event.setMessage(message);
|
||||
// event.setMessage(message);
|
||||
|
||||
// 発言内容の送信
|
||||
format.replace("%msg", message);
|
||||
BaseComponent[] comps = format.makeTextComponent();
|
||||
for ( Player recipient : event.getRecipients() ) {
|
||||
ChannelMember cm = ChannelMember.getChannelMember(recipient);
|
||||
if ( cm != null ) {
|
||||
cm.sendMessage(comps);
|
||||
}
|
||||
}
|
||||
|
||||
// イベントのキャンセル
|
||||
event.setCancelled(true);
|
||||
|
||||
// ロギング
|
||||
logNormalChat(message, player.getName());
|
||||
@@ -439,7 +451,7 @@ public class BukkitEventListener implements Listener {
|
||||
channel.addMember(cp);
|
||||
}
|
||||
|
||||
// デフォルト発言先が無いなら、グローバルチャンネルに設定する
|
||||
// デフォルト発言先が無いなら、デフォルトチャンネルに設定する
|
||||
Channel dchannel = api.getDefaultChannel(player.getName());
|
||||
if ( dchannel == null ) {
|
||||
api.setDefaultChannel(player.getName(), cname);
|
||||
@@ -447,62 +459,12 @@ public class BukkitEventListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットのフォーマット設定のキーワードを置き換えして返す
|
||||
* @param org フォーマット設定
|
||||
* @param player 発言プレイヤー
|
||||
* @return キーワード置き換え済みの文字列
|
||||
*/
|
||||
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());
|
||||
|
||||
if ( format.contains("%date") ) {
|
||||
format = format.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( format.contains("%time") ) {
|
||||
format = format.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( format.contains("%prefix") || format.contains("%suffix") ) {
|
||||
|
||||
String prefix = "";
|
||||
String suffix = "";
|
||||
VaultChatBridge vaultchat = LunaChatBukkit.getInstance().getVaultChat();
|
||||
if ( vaultchat != null ) {
|
||||
prefix = vaultchat.getPlayerPrefix(player);
|
||||
suffix = vaultchat.getPlayerSuffix(player);
|
||||
}
|
||||
format = format.replace("%prefix", prefix);
|
||||
format = format.replace("%suffix", suffix);
|
||||
}
|
||||
|
||||
if ( format.contains("%world") ) {
|
||||
|
||||
String worldname = null;
|
||||
if ( LunaChatBukkit.getInstance().getMultiverseCore() != null ) {
|
||||
worldname = LunaChatBukkit.getInstance().getMultiverseCore().getWorldAlias(player.getWorld());
|
||||
}
|
||||
if ( worldname == null || worldname.equals("") ) {
|
||||
worldname = player.getWorld().getName();
|
||||
}
|
||||
format = format.replace("%world", worldname);
|
||||
}
|
||||
|
||||
format = format.replace("%server", "");
|
||||
|
||||
return Utility.replaceColorCode(format);
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのサーバー参加時用の参加チャンネルリストを返す
|
||||
* @param player プレイヤー
|
||||
* @return リスト
|
||||
*/
|
||||
private ArrayList<String> getListForMotd(Player player) {
|
||||
private ArrayList<BaseComponent[]> getListForMotd(Player player) {
|
||||
|
||||
ChannelMember cp = ChannelMember.getChannelMember(player);
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
@@ -512,9 +474,19 @@ public class BukkitEventListener implements Listener {
|
||||
dchannel = dc.getName().toLowerCase();
|
||||
}
|
||||
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
items.add(Messages.motdFirstLine());
|
||||
for ( Channel channel : api.getChannels() ) {
|
||||
// チャンネル一覧を取得して、参加人数でソートする
|
||||
ArrayList<Channel> channels = new ArrayList<>(api.getChannels());
|
||||
Collections.sort(channels, new Comparator<Channel>() {
|
||||
public int compare(Channel c1, Channel c2) {
|
||||
if ( c1.getOnlineNum() == c2.getOnlineNum() ) return c1.getName().compareTo(c2.getName());
|
||||
return c2.getOnlineNum() - c1.getOnlineNum();
|
||||
}
|
||||
});
|
||||
|
||||
int count = 0;
|
||||
ArrayList<BaseComponent[]> items = new ArrayList<>();
|
||||
items.add(TextComponent.fromLegacyText(Messages.motdFirstLine()));
|
||||
for ( Channel channel : channels ) {
|
||||
|
||||
// BANされているチャンネルは表示しない
|
||||
if ( channel.getBanned().contains(cp) ) {
|
||||
@@ -539,10 +511,14 @@ public class BukkitEventListener implements Listener {
|
||||
String desc = channel.getDescription();
|
||||
int onlineNum = channel.getOnlineNum();
|
||||
int memberNum = channel.getTotalNum();
|
||||
String item = Messages.listFormat(disp, onlineNum, memberNum, desc);
|
||||
items.add(item);
|
||||
items.add(Messages.listFormat(disp, onlineNum, memberNum, desc));
|
||||
count++;
|
||||
|
||||
if ( count > MAX_LIST_ITEMS ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
items.add(Messages.listEndLine());
|
||||
items.add(TextComponent.fromLegacyText(Messages.listEndLine()));
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
@@ -1,33 +1,34 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.bungee;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
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.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.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;
|
||||
@@ -44,11 +45,8 @@ import net.md_5.bungee.event.EventPriority;
|
||||
*/
|
||||
public class BungeeEventListener implements Listener {
|
||||
|
||||
private static final String DATE_FORMAT_PATTERN = "yyyy/MM/dd";
|
||||
private static final String TIME_FORMAT_PATTERN = "HH:mm:ss";
|
||||
private static final int MAX_LIST_ITEMS = 8;
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
private LunaChatBungee parent;
|
||||
private LunaChatConfig config;
|
||||
private LunaChatAPI api;
|
||||
@@ -61,8 +59,6 @@ public class BungeeEventListener implements Listener {
|
||||
this.parent = parent;
|
||||
config = parent.getConfig();
|
||||
api = parent.getLunaChatAPI();
|
||||
dateFormat = new SimpleDateFormat(DATE_FORMAT_PATTERN);
|
||||
timeFormat = new SimpleDateFormat(TIME_FORMAT_PATTERN);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,9 +140,8 @@ public class BungeeEventListener implements Listener {
|
||||
|
||||
// チャンネルチャット情報を表示する
|
||||
if ( config.isShowListOnJoin() ) {
|
||||
ArrayList<String> list = getListForMotd(player);
|
||||
for ( String msg : list ) {
|
||||
player.sendMessage(TextComponent.fromLegacyText(msg));
|
||||
for ( BaseComponent[] msg : getListForMotd(player) ) {
|
||||
player.sendMessage(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -284,8 +279,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;
|
||||
}
|
||||
|
||||
@@ -318,27 +314,33 @@ public class BungeeEventListener implements Listener {
|
||||
}
|
||||
|
||||
String result;
|
||||
|
||||
if ( config.isEnableNormalChatMessageFormat() ) {
|
||||
// チャットフォーマット装飾を適用する場合
|
||||
String format = config.getNormalChatMessageFormat();
|
||||
result = replaceNormalChatFormatKeywords(format, sender, 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は適用しない(できない)仕様とする。
|
||||
@@ -391,51 +393,6 @@ public class BungeeEventListener implements Listener {
|
||||
LunaChat.getNormalChatLogger().log(Utility.stripColorCode(result), sender.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 通常チャットのフォーマット設定のキーワードを置き換えして返す
|
||||
* @param org フォーマット設定
|
||||
* @param player 発言プレイヤー
|
||||
* @param msg 発言内容
|
||||
* @return キーワード置き換え済みの文字列
|
||||
*/
|
||||
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());
|
||||
|
||||
if ( format.contains("%date") ) {
|
||||
format = format.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( format.contains("%time") ) {
|
||||
format = format.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( format.contains("%prefix") || format.contains("%suffix") ) {
|
||||
|
||||
String prefix = "";
|
||||
String suffix = "";
|
||||
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 = format.replace("%prefix", prefix);
|
||||
format = format.replace("%suffix", suffix);
|
||||
}
|
||||
|
||||
if ( format.contains("%world") ) {
|
||||
format = format.replace("%world", "");
|
||||
}
|
||||
|
||||
if ( format.contains("%server") ) {
|
||||
format = format.replace("%server", player.getServer().getInfo().getName());
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(format);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルに発言処理を行う
|
||||
* @param player プレイヤー
|
||||
@@ -545,7 +502,7 @@ public class BungeeEventListener implements Listener {
|
||||
* @param player プレイヤー
|
||||
* @return リスト
|
||||
*/
|
||||
private ArrayList<String> getListForMotd(ProxiedPlayer player) {
|
||||
private ArrayList<BaseComponent[]> getListForMotd(ProxiedPlayer player) {
|
||||
|
||||
ChannelMember cp = ChannelMember.getChannelMember(player);
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
@@ -555,9 +512,19 @@ public class BungeeEventListener implements Listener {
|
||||
dchannel = dc.getName().toLowerCase();
|
||||
}
|
||||
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
items.add(Messages.motdFirstLine());
|
||||
for ( Channel channel : api.getChannels() ) {
|
||||
// チャンネル一覧を取得して、参加人数でソートする
|
||||
ArrayList<Channel> channels = new ArrayList<>(api.getChannels());
|
||||
Collections.sort(channels, new Comparator<Channel>() {
|
||||
public int compare(Channel c1, Channel c2) {
|
||||
if ( c1.getOnlineNum() == c2.getOnlineNum() ) return c1.getName().compareTo(c2.getName());
|
||||
return c2.getOnlineNum() - c1.getOnlineNum();
|
||||
}
|
||||
});
|
||||
|
||||
int count = 0;
|
||||
ArrayList<BaseComponent[]> items = new ArrayList<>();
|
||||
items.add(TextComponent.fromLegacyText(Messages.motdFirstLine()));
|
||||
for ( Channel channel : channels ) {
|
||||
|
||||
// BANされているチャンネルは表示しない
|
||||
if ( channel.getBanned().contains(cp) ) {
|
||||
@@ -582,10 +549,14 @@ public class BungeeEventListener implements Listener {
|
||||
String desc = channel.getDescription();
|
||||
int onlineNum = channel.getOnlineNum();
|
||||
int memberNum = channel.getTotalNum();
|
||||
String item = Messages.listFormat(disp, onlineNum, memberNum, desc);
|
||||
items.add(item);
|
||||
items.add(Messages.listFormat(disp, onlineNum, memberNum, desc));
|
||||
count++;
|
||||
|
||||
if ( count > MAX_LIST_ITEMS ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
items.add(Messages.listEndLine());
|
||||
items.add(TextComponent.fromLegacyText(Messages.listEndLine()));
|
||||
|
||||
return items;
|
||||
}
|
||||
@@ -597,7 +568,23 @@ public class BungeeEventListener implements Listener {
|
||||
*/
|
||||
private void sendMessage(CommandSender reciever, String message) {
|
||||
if ( message == null ) return;
|
||||
reciever.sendMessage(TextComponent.fromLegacyText(message));
|
||||
ChannelMember cm = ChannelMember.getChannelMember(reciever);
|
||||
if ( cm != null ) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.channel;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -15,18 +13,21 @@ 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;
|
||||
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.ClickableFormat;
|
||||
import com.github.ucchyocean.lc3.util.UtilityBukkit;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* チャンネルの実装クラス
|
||||
@@ -34,19 +35,12 @@ import com.github.ucchyocean.lc3.member.ChannelMemberBukkit;
|
||||
*/
|
||||
public class BukkitChannel extends Channel {
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param name チャンネル名
|
||||
*/
|
||||
protected BukkitChannel(String name) {
|
||||
|
||||
super(name);
|
||||
|
||||
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
timeFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,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();
|
||||
|
||||
@@ -80,6 +74,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 +85,6 @@ public class BukkitChannel extends Channel {
|
||||
recipients.add(ChannelMember.getChannelMember(p));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO 何かするか?検討する
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -105,7 +99,7 @@ public class BukkitChannel extends Channel {
|
||||
}
|
||||
|
||||
// 受信者が自分以外いない場合は、メッセージを表示する
|
||||
if ( !Messages.noRecipientMessage("", "").isEmpty() && (
|
||||
if ( Messages.noRecipientMessage("", "").length > 0 && (
|
||||
recipients.size() == 0 ||
|
||||
(recipients.size() == 1 &&
|
||||
recipients.get(0).getName().equals(player.getName()) ) ) ) {
|
||||
@@ -154,12 +148,8 @@ public class BukkitChannel extends Channel {
|
||||
}
|
||||
}
|
||||
|
||||
// フォーマットがある場合は置き換える
|
||||
if ( format != null ) {
|
||||
message = format.replace("%msg", message);
|
||||
}
|
||||
|
||||
// LunaChatChannelMessageEvent イベントコール
|
||||
String name = (player != null) ? player.getDisplayName() : "<null>";
|
||||
EventResult result = LunaChat.getEventSender().sendLunaChatChannelMessageEvent(
|
||||
getName(), player, message, recipients, name, originalMessage);
|
||||
message = result.getMessage();
|
||||
@@ -183,8 +173,16 @@ public class BukkitChannel extends Channel {
|
||||
}
|
||||
|
||||
// 送信する
|
||||
for ( ChannelMember p : recipients ) {
|
||||
p.sendMessage(message);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 設定に応じて、コンソールに出力する
|
||||
@@ -198,7 +196,7 @@ public class BukkitChannel extends Channel {
|
||||
}
|
||||
|
||||
// ロギング
|
||||
log(originalMessage, name, player);
|
||||
log(originalMessage, name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,89 +252,13 @@ public class BukkitChannel extends Channel {
|
||||
return super.getMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param player プレイヤー
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
@Override
|
||||
protected String replaceKeywords(String format, ChannelMember player) {
|
||||
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
String msg = 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));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg = msg.replace("%ch", getName());
|
||||
//msg = msg.replace("%msg", message);
|
||||
msg = msg.replace("%color", getColorCode());
|
||||
if ( getPrivateMessageTo() != null ) {
|
||||
msg = msg.replace("%to", getPrivateMessageTo().getDisplayName());
|
||||
} else {
|
||||
msg = msg.replace("%to", "");
|
||||
}
|
||||
msg = msg.replace("%recieverserver", "");
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg = msg.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg = msg.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( player != null ) {
|
||||
msg = msg.replace("%username", player.getDisplayName());
|
||||
msg = msg.replace("%player", player.getName());
|
||||
|
||||
if ( msg.contains("%prefix") || msg.contains("%suffix") ) {
|
||||
msg = msg.replace("%prefix", player.getPrefix());
|
||||
msg = msg.replace("%suffix", player.getSuffix());
|
||||
}
|
||||
|
||||
if ( msg.contains("%world") ) {
|
||||
|
||||
String worldname = null;
|
||||
if ( LunaChatBukkit.getInstance().getMultiverseCore() != null ) {
|
||||
worldname = LunaChatBukkit.getInstance().getMultiverseCore().getWorldAlias(player.getWorldName());
|
||||
}
|
||||
if ( worldname == null || worldname.equals("") ) {
|
||||
worldname = player.getWorldName();
|
||||
}
|
||||
msg = msg.replace("%world", worldname);
|
||||
}
|
||||
|
||||
msg = 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", "");
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* ログを記録する
|
||||
* @param name 発言者
|
||||
* @param message 記録するメッセージ
|
||||
* @param player プレイヤー
|
||||
*/
|
||||
private void log(String message, String name, ChannelMember player) {
|
||||
@Override
|
||||
protected void log(String message, String name) {
|
||||
|
||||
// LunaChatのチャットログへ記録
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.channel;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
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.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.ClickableFormat;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
/**
|
||||
@@ -28,19 +28,12 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
*/
|
||||
public class BungeeChannel extends Channel {
|
||||
|
||||
private SimpleDateFormat dateFormat;
|
||||
private SimpleDateFormat timeFormat;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param name チャンネル名
|
||||
*/
|
||||
protected BungeeChannel(String name) {
|
||||
|
||||
super(name);
|
||||
|
||||
dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
||||
timeFormat = new SimpleDateFormat("HH:mm:ss");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,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();
|
||||
|
||||
@@ -107,19 +99,25 @@ public class BungeeChannel extends Channel {
|
||||
}
|
||||
|
||||
// フォーマットがある場合は置き換える
|
||||
if ( format != null ) {
|
||||
message = format.replace("%msg", message);
|
||||
}
|
||||
|
||||
// LunaChatChannelMessageEvent イベントコール
|
||||
String name = (player != null) ? player.getDisplayName() : "<null>";
|
||||
EventResult result = LunaChat.getEventSender().sendLunaChatChannelMessageEvent(
|
||||
getName(), player, message, recipients, name, originalMessage);
|
||||
message = result.getMessage();
|
||||
recipients = result.getRecipients();
|
||||
|
||||
// 送信する
|
||||
for ( ChannelMember p : recipients ) {
|
||||
p.sendMessage(message);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// 設定に応じて、コンソールに出力する
|
||||
@@ -128,7 +126,7 @@ public class BungeeChannel extends Channel {
|
||||
}
|
||||
|
||||
// ロギング
|
||||
log(originalMessage, name, player);
|
||||
log(originalMessage, name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,91 +182,13 @@ public class BungeeChannel extends Channel {
|
||||
return super.getMembers();
|
||||
}
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param player プレイヤー
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
@Override
|
||||
protected String replaceKeywords(String format, ChannelMember player) {
|
||||
|
||||
LunaChatAPI api = LunaChat.getAPI();
|
||||
|
||||
String msg = 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));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg = msg.replace("%ch", getName());
|
||||
//msg = msg.replace("%msg", message);
|
||||
msg = msg.replace("%color", getColorCode());
|
||||
if ( getPrivateMessageTo() != null ) {
|
||||
msg = msg.replace("%to", getPrivateMessageTo().getDisplayName());
|
||||
if ( getPrivateMessageTo() instanceof ChannelMemberProxiedPlayer ) {
|
||||
ChannelMemberProxiedPlayer cm = (ChannelMemberProxiedPlayer)getPrivateMessageTo();
|
||||
msg = msg.replace("%recieverserver", cm.getServer().getInfo().getName());
|
||||
} else {
|
||||
msg = msg.replace("%recieverserver", "");
|
||||
}
|
||||
} else {
|
||||
msg = msg.replace("%to", "");
|
||||
msg = msg.replace("%recieverserver", "");
|
||||
}
|
||||
|
||||
if ( msg.contains("%date") ) {
|
||||
msg = msg.replace("%date", dateFormat.format(new Date()));
|
||||
}
|
||||
if ( msg.contains("%time") ) {
|
||||
msg = msg.replace("%time", timeFormat.format(new Date()));
|
||||
}
|
||||
|
||||
if ( player != null ) {
|
||||
msg = msg.replace("%username", player.getDisplayName());
|
||||
msg = 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 = msg.replace("%world", "");
|
||||
|
||||
if ( msg.contains("%server") ) {
|
||||
if ( player instanceof ChannelMemberProxiedPlayer ) {
|
||||
String serverName = ((ChannelMemberProxiedPlayer)player).getServer().getInfo().getName();
|
||||
msg = msg.replace("%server", serverName);
|
||||
}
|
||||
msg = 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", "");
|
||||
}
|
||||
|
||||
return Utility.replaceColorCode(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* ログを記録する
|
||||
* @param name 発言者
|
||||
* @param message 記録するメッセージ
|
||||
* @param player プレイヤー
|
||||
*/
|
||||
private void log(String message, String name, ChannelMember player) {
|
||||
@Override
|
||||
protected void log(String message, String name) {
|
||||
|
||||
// LunaChatのチャットログへ記録
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
@@ -16,19 +16,30 @@ import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.ucchyocean.lc3.ChatColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
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.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.bridge.DynmapBridge;
|
||||
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.util.ChatColor;
|
||||
import com.github.ucchyocean.lc3.util.ClickableFormat;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
import com.github.ucchyocean.lc3.util.YamlConfig;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
/**
|
||||
* チャンネル
|
||||
@@ -256,7 +267,7 @@ public abstract class Channel {
|
||||
}
|
||||
|
||||
// キーワード置き換え
|
||||
String msgFormat = replaceKeywords(getFormat(), player);
|
||||
ClickableFormat cf = ClickableFormat.makeFormat(getFormat(), player, this, true);
|
||||
|
||||
// カラーコード置き換え
|
||||
// チャンネルで許可されていて、発言者がパーミッションを持っている場合に置き換える
|
||||
@@ -266,11 +277,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変換は行わない
|
||||
@@ -294,10 +305,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());
|
||||
@@ -310,7 +321,7 @@ public abstract class Channel {
|
||||
|
||||
if ( isIncludeSyncChat ) {
|
||||
// メッセージの送信
|
||||
sendMessage(player, maskedMessage, msgFormat, true, player.getDisplayName());
|
||||
sendMessage(player, maskedMessage, cf, true);
|
||||
}
|
||||
|
||||
// 非同期実行タスクがある場合、追加で実行する
|
||||
@@ -326,10 +337,10 @@ public abstract class Channel {
|
||||
if ( !isGlobalChannel() ) {
|
||||
getBanned().add(player);
|
||||
removeMember(player);
|
||||
if ( !Messages.banNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.banNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
if ( Messages.banNGWordMessage("", "", "").length > 0 ) {
|
||||
BaseComponent[] m = Messages.banNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
sendSystemMessage(m, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,10 +349,10 @@ public abstract class Channel {
|
||||
|
||||
if ( !isGlobalChannel() ) {
|
||||
removeMember(player);
|
||||
if ( !Messages.kickNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.kickNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
if ( Messages.kickNGWordMessage("", "", "").length > 0 ) {
|
||||
BaseComponent[] m = Messages.kickNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
sendSystemMessage(m, true, "system");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,10 +361,10 @@ public abstract class Channel {
|
||||
|
||||
getMuted().add(player);
|
||||
save();
|
||||
if ( !Messages.muteNGWordMessage("", "", "").isEmpty() ) {
|
||||
String m = Messages.muteNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
if ( Messages.muteNGWordMessage("", "", "").length > 0 ) {
|
||||
BaseComponent[] m = Messages.muteNGWordMessage(getColorCode(), getName(), player.getName());
|
||||
player.sendMessage(m);
|
||||
sendMessage(null, m, null, true, "system");
|
||||
sendSystemMessage(m, true, "system");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -365,7 +376,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();
|
||||
|
||||
@@ -388,9 +399,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() ) {
|
||||
@@ -399,7 +408,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -409,12 +418,68 @@ public abstract class Channel {
|
||||
* @param name 発言者の表示名
|
||||
*/
|
||||
public void sendSystemMessage(String message, boolean sendDynmap, String name) {
|
||||
sendMessage(null, message, null, sendDynmap, name);
|
||||
sendSystemMessage(TextComponent.fromLegacyText(message), sendDynmap, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネルにシステムメッセージを送信する。
|
||||
* @param message メッセージ
|
||||
* @param sendDynmap Dynmapにも表示するかどうか
|
||||
* @param name 発言者の表示名
|
||||
*/
|
||||
public void sendSystemMessage(BaseComponent[] message, boolean sendDynmap, String name) {
|
||||
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
|
||||
// 受信者(=メンバー全員からhideしているプレイヤーを除く)
|
||||
List<ChannelMember> recipients = new ArrayList<>(getMembers());
|
||||
for ( ChannelMember cp : getHided() ) {
|
||||
if ( recipients.contains(cp) ) {
|
||||
recipients.remove(cp);
|
||||
}
|
||||
}
|
||||
|
||||
// opListenAllChannel 設定がある場合は、
|
||||
// パーミッション lunachat-admin.listen-all-channels を持つプレイヤーを
|
||||
// 受信者に加える。
|
||||
if ( config.isOpListenAllChannel() ) {
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
ChannelMember cp = ChannelMember.getChannelMember(p);
|
||||
if ( cp.hasPermission("lunachat-admin.listen-all-channels")
|
||||
&& !recipients.contains(cp) ) {
|
||||
recipients.add(cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 通常ブロードキャストなら、設定に応じてdynmapへ送信する
|
||||
DynmapBridge dynmap = LunaChatBukkit.getInstance().getDynmap();
|
||||
if ( config.isSendBroadcastChannelChatToDynmap() &&
|
||||
sendDynmap &&
|
||||
dynmap != null &&
|
||||
isBroadcastChannel() &&
|
||||
!isWorldRange() ) {
|
||||
|
||||
dynmap.broadcast(makeLegacyText(message));
|
||||
}
|
||||
|
||||
// 送信する
|
||||
for ( ChannelMember p : recipients ) {
|
||||
p.sendMessage(message);
|
||||
}
|
||||
|
||||
// 設定に応じて、コンソールに出力する
|
||||
if ( config.isDisplayChatOnConsole() ) {
|
||||
Bukkit.getLogger().info(makePlainText(message));
|
||||
}
|
||||
|
||||
// ロギング
|
||||
log(makePlainText(message), name);
|
||||
}
|
||||
|
||||
/**
|
||||
* メンバーを追加する
|
||||
* @param name 追加するプレイヤー
|
||||
* @param player 追加するプレイヤー
|
||||
*/
|
||||
public void addMember(ChannelMember player) {
|
||||
|
||||
@@ -448,7 +513,7 @@ public abstract class Channel {
|
||||
|
||||
/**
|
||||
* メンバーを削除する
|
||||
* @param name 削除するプレイヤー
|
||||
* @param player 削除するプレイヤー
|
||||
*/
|
||||
public void removeMember(ChannelMember player) {
|
||||
|
||||
@@ -548,22 +613,30 @@ 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 name 発言者
|
||||
* @param message 記録するメッセージ
|
||||
*/
|
||||
protected abstract void log(String message, String name);
|
||||
|
||||
/**
|
||||
* チャットフォーマット内のキーワードを置き換えする
|
||||
* @param format チャットフォーマット
|
||||
* @param player プレイヤー
|
||||
* @param member プレイヤー
|
||||
* @return 置き換え結果
|
||||
*/
|
||||
protected abstract String replaceKeywords(String format, ChannelMember player);
|
||||
protected ClickableFormat replaceKeywords(String format, ChannelMember member) {
|
||||
return ClickableFormat.makeFormat(format, member, this, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* チャンネル情報を返す
|
||||
@@ -576,7 +649,7 @@ public abstract class Channel {
|
||||
info.add(Messages.channelInfoFirstLine());
|
||||
|
||||
// チャンネル名、参加人数、総人数、チャンネル説明文
|
||||
info.add(Messages.listFormat(getName(), getOnlineNum(), getTotalNum(), getDescription()));
|
||||
info.add(makeLegacyText(Messages.listFormat(getName(), getOnlineNum(), getTotalNum(), getDescription())));
|
||||
|
||||
// チャンネル別名
|
||||
String alias = getAlias();
|
||||
@@ -709,14 +782,14 @@ public abstract class Channel {
|
||||
save();
|
||||
|
||||
// メッセージ通知を流す
|
||||
String msg = Messages.expiredBanMessage(getColorCode(), getName(), cp.getName());
|
||||
if ( !msg.isEmpty() ) {
|
||||
sendMessage(null, msg, null, false, "system");
|
||||
BaseComponent[] msg = Messages.expiredBanMessage(getColorCode(), getName(), cp.getName());
|
||||
if ( msg.length > 0 ) {
|
||||
sendSystemMessage(msg, true, "system");
|
||||
}
|
||||
|
||||
msg = Messages.cmdmsgPardoned(getName());
|
||||
if ( cp.isOnline() && !msg.isEmpty() ) {
|
||||
cp.sendMessage(msg);
|
||||
String pardonedMsg = Messages.cmdmsgPardoned(getName());
|
||||
if ( cp.isOnline() && !pardonedMsg.isEmpty() ) {
|
||||
cp.sendMessage(pardonedMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -733,14 +806,14 @@ public abstract class Channel {
|
||||
save();
|
||||
|
||||
// メッセージ通知を流す
|
||||
String msg = Messages.expiredMuteMessage(getColorCode(), getName(), cp.getName());
|
||||
if ( !msg.isEmpty() ) {
|
||||
sendMessage(null, msg, null, false, "system");
|
||||
BaseComponent[] msg = Messages.expiredMuteMessage(getColorCode(), getName(), cp.getName());
|
||||
if ( msg.length > 0 ) {
|
||||
sendSystemMessage(msg, true, "system");
|
||||
}
|
||||
|
||||
msg = Messages.cmdmsgUnmuted(getName());
|
||||
if ( cp.isOnline() && !msg.isEmpty() ) {
|
||||
cp.sendMessage(msg);
|
||||
String unmutedMsg = Messages.cmdmsgUnmuted(getName());
|
||||
if ( cp.isOnline() && !unmutedMsg.isEmpty() ) {
|
||||
cp.sendMessage(unmutedMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1051,7 +1124,7 @@ public abstract class Channel {
|
||||
|
||||
/**
|
||||
* 1:1チャットのときに、会話の相手先を設定する
|
||||
* @param name 会話の相手のプレイヤー名
|
||||
* @param to 会話の相手のプレイヤー名
|
||||
*/
|
||||
public void setPrivateMessageTo(ChannelMember to) {
|
||||
this.privateMessageTo = to;
|
||||
@@ -1196,23 +1269,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 変換元
|
||||
@@ -1324,4 +1380,20 @@ public abstract class Channel {
|
||||
}
|
||||
return (Map<String, Long>)obj;
|
||||
}
|
||||
|
||||
private static String makeLegacyText(BaseComponent[] comps) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for ( BaseComponent comp : comps ) {
|
||||
builder.append(comp.toLegacyText());
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String makePlainText(BaseComponent[] comps) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for ( BaseComponent comp : comps ) {
|
||||
builder.append(comp.toPlainText());
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* チャンネルマネージャー
|
||||
@@ -412,8 +412,9 @@ public class ChannelManager implements LunaChatAPI {
|
||||
channel = new BukkitChannel(name);
|
||||
} else if ( LunaChat.getMode() == LunaChatMode.BUNGEE ) {
|
||||
channel = new BungeeChannel(name);
|
||||
} else {
|
||||
channel = new StandaloneChannel(name);
|
||||
}
|
||||
// TODO Standalone のチャンネル作成
|
||||
|
||||
channels.put(name.toLowerCase(), channel);
|
||||
channel.save();
|
||||
|
||||
@@ -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変換を実行して、実行後に発言を行うタスク
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* @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 チャンネルのメンバーに送信
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void log(String message, String name) {
|
||||
|
||||
// デバッグ表示メッセージ
|
||||
System.out.println(String.format("room=%s, name=%s, message=%s",
|
||||
getName(), name, message));
|
||||
|
||||
// TODO ログファイルを出力
|
||||
}
|
||||
}
|
||||
@@ -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コマンドの実行クラス
|
||||
|
||||
@@ -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コマンドの実行クラス
|
||||
|
||||
@@ -9,10 +9,13 @@ 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;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
/**
|
||||
* listコマンドの実行クラス
|
||||
@@ -79,14 +82,13 @@ public class ListCommand extends LunaChatSubCommand {
|
||||
public boolean runCommand(
|
||||
ChannelMember sender, String label, String[] args) {
|
||||
|
||||
int page = 0;
|
||||
int page = 1;
|
||||
if ( args.length >= 2 && args[1].matches("[0-9]") ) {
|
||||
page = Integer.parseInt(args[1]);
|
||||
}
|
||||
|
||||
// リストを取得して表示する
|
||||
ArrayList<String> list = getList(sender, page);
|
||||
for (String msg : list) {
|
||||
for (BaseComponent[] msg : getList(sender, page)) {
|
||||
sender.sendMessage(msg);
|
||||
}
|
||||
return true;
|
||||
@@ -98,25 +100,25 @@ public class ListCommand extends LunaChatSubCommand {
|
||||
* @param page 表示するページ、0を指定した場合は全表示
|
||||
* @return リスト
|
||||
*/
|
||||
private ArrayList<String> getList(ChannelMember player, int page) {
|
||||
private ArrayList<BaseComponent[]> getList(ChannelMember player, int page) {
|
||||
|
||||
ArrayList<String> list = getPlayerList(player);
|
||||
ArrayList<BaseComponent[]> list = getPlayerList(player);
|
||||
int size = list.size();
|
||||
int maxPage = (int)(size / PAGE_SIZE) + 1;
|
||||
|
||||
if ( page < 0 ) page = 0;
|
||||
if ( page > maxPage ) page = maxPage;
|
||||
|
||||
ArrayList<String> items = new ArrayList<>();
|
||||
ArrayList<BaseComponent[]> items = new ArrayList<>();
|
||||
if ( page == 0 ) { // 全表示
|
||||
items.add(Messages.listFirstLine());
|
||||
items.add(TextComponent.fromLegacyText(Messages.listFirstLine()));
|
||||
items.addAll(list);
|
||||
items.add(Messages.listEndLine());
|
||||
items.add(TextComponent.fromLegacyText(Messages.listEndLine()));
|
||||
} else { // ページ表示
|
||||
items.add(Messages.listFirstLinePaging(page, maxPage));
|
||||
items.add(TextComponent.fromLegacyText(Messages.listFirstLinePaging(page, maxPage)));
|
||||
int endIndex = (page * PAGE_SIZE > size) ? size : page * PAGE_SIZE;
|
||||
items.addAll(list.subList((page - 1) * PAGE_SIZE, endIndex));
|
||||
items.add(Messages.listEndLine());
|
||||
items.add(TextComponent.fromLegacyText(Messages.listEndLine()));
|
||||
}
|
||||
|
||||
return items;
|
||||
@@ -127,9 +129,8 @@ public class ListCommand extends LunaChatSubCommand {
|
||||
* @param player プレイヤー
|
||||
* @return チャンネルリスト
|
||||
*/
|
||||
private ArrayList<String> getPlayerList(ChannelMember player) {
|
||||
private ArrayList<BaseComponent[]> getPlayerList(ChannelMember player) {
|
||||
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
String dchannel = "";
|
||||
String playerName = "";
|
||||
if ( player != null ) {
|
||||
@@ -142,15 +143,17 @@ public class ListCommand extends LunaChatSubCommand {
|
||||
}
|
||||
}
|
||||
|
||||
// チャンネルを取得して、チャンネル名でソートする
|
||||
// チャンネルを取得して、参加人数でソートする
|
||||
ArrayList<Channel> channels = new ArrayList<>(api.getChannels());
|
||||
Collections.sort(channels, new Comparator<Channel>() {
|
||||
public int compare(Channel c1, Channel c2) {
|
||||
return c1.getName().compareTo(c2.getName());
|
||||
if ( c1.getOnlineNum() == c2.getOnlineNum() ) return c1.getName().compareTo(c2.getName());
|
||||
return c2.getOnlineNum() - c1.getOnlineNum();
|
||||
}
|
||||
});
|
||||
|
||||
// 指定されたプレイヤー名に合うように、フィルタ&表示用整形する。
|
||||
ArrayList<BaseComponent[]> items = new ArrayList<>();
|
||||
for ( Channel channel : channels ) {
|
||||
|
||||
// BANされているチャンネルは表示しない
|
||||
@@ -183,8 +186,7 @@ public class ListCommand extends LunaChatSubCommand {
|
||||
String desc = channel.getDescription();
|
||||
int onlineNum = channel.getOnlineNum();
|
||||
int memberNum = channel.getTotalNum();
|
||||
String item = Messages.listFormat(disp, onlineNum, memberNum, desc);
|
||||
items.add(item);
|
||||
items.add(Messages.listFormat(disp, onlineNum, memberNum, desc));
|
||||
}
|
||||
|
||||
return items;
|
||||
|
||||
@@ -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("&", "&"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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コマンドの実行クラス
|
||||
|
||||
@@ -8,6 +8,8 @@ package com.github.ucchyocean.lc3.member;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatMode;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* チャンネルメンバーの抽象クラス
|
||||
* @author ucchy
|
||||
@@ -50,12 +52,24 @@ public abstract class ChannelMember implements Comparable<ChannelMember> {
|
||||
*/
|
||||
public abstract void sendMessage(String message);
|
||||
|
||||
/**
|
||||
* メッセージを送る
|
||||
* @param message 送るメッセージ
|
||||
*/
|
||||
public abstract void sendMessage(BaseComponent[] message);
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドのワールド名を取得する
|
||||
* @return ワールド名
|
||||
*/
|
||||
public abstract String getWorldName();
|
||||
|
||||
/**
|
||||
* 発言者が今いるサーバーのサーバー名を取得する
|
||||
* @return サーバー名
|
||||
*/
|
||||
public abstract String getServerName();
|
||||
|
||||
/**
|
||||
* 指定されたパーミッションノードの権限を持っているかどうかを取得する
|
||||
* @param node パーミッションノード
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.bukkit.World;
|
||||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* ChannelMemberのBukkit-BlockCommandSender実装
|
||||
* @author ucchy
|
||||
@@ -87,6 +89,15 @@ public class ChannelMemberBlock extends ChannelMemberBukkit {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを送る、実際は何もせずにメッセージを捨てる
|
||||
* @param message 送るメッセージ
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#sendMessage(net.md_5.bungee.api.chat.BaseComponent[])
|
||||
*/
|
||||
public void sendMessage(BaseComponent[] message) {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
/**
|
||||
* BukkitのPlayerを取得する
|
||||
* @return 常にnullが返される
|
||||
@@ -99,12 +110,12 @@ public class ChannelMemberBlock extends ChannelMemberBukkit {
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドのワールド名を取得する
|
||||
* @return 常に "-" が返される。
|
||||
* @return 常に空文字列
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getWorldName()
|
||||
*/
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
return "-";
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,7 +159,7 @@ public class ChannelMemberBlock extends ChannelMemberBukkit {
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#chat(java.lang.String)
|
||||
*/
|
||||
public void chat(String message) {
|
||||
Bukkit.broadcastMessage("<" + getName() + ">" + message);
|
||||
Bukkit.broadcastMessage("<" + getName() + "> " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,10 +32,18 @@ public abstract class ChannelMemberBukkit extends ChannelMember {
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドを取得する
|
||||
* @return 発言者の位置
|
||||
* @return 発言者が今いるワールド
|
||||
*/
|
||||
public abstract World getWorld();
|
||||
|
||||
/**
|
||||
* 発言者が今いるサーバーのサーバー名を取得する
|
||||
* @return サーバー名
|
||||
*/
|
||||
public String getServerName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* CommandSenderから、ChannelMemberを作成して返す
|
||||
* @param sender
|
||||
|
||||
@@ -11,6 +11,8 @@ import org.bukkit.World;
|
||||
import org.bukkit.command.ConsoleCommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* ChannelMemberのBukkit-ConsoleCommandSender実装
|
||||
* @author ucchy
|
||||
@@ -88,6 +90,16 @@ public class ChannelMemberBukkitConsole extends ChannelMemberBukkit {
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを送る
|
||||
* @param message 送るメッセージ
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#sendMessage(net.md_5.bungee.api.chat.BaseComponent[])
|
||||
*/
|
||||
public void sendMessage(BaseComponent[] message) {
|
||||
if ( message == null || message.length == 0 ) return;
|
||||
sender.spigot().sendMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* BukkitのPlayerを取得する
|
||||
* @return 常にnullが返される
|
||||
|
||||
@@ -27,6 +27,28 @@ public abstract class ChannelMemberBungee extends ChannelMember {
|
||||
*/
|
||||
public abstract Server getServer();
|
||||
|
||||
/**
|
||||
* 発言者が今いるサーバーのサーバー名を取得する
|
||||
* @return サーバー名
|
||||
*/
|
||||
public String getServerName() {
|
||||
Server server = getServer();
|
||||
if ( server != null ) {
|
||||
return server.getInfo().getName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールド名を返す
|
||||
* @return 常に空文字列が返される
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#getWorldName()
|
||||
*/
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* CommandSenderから、ChannelMemberを作成して返す
|
||||
* @param sender
|
||||
|
||||
@@ -7,6 +7,7 @@ package com.github.ucchyocean.lc3.member;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
@@ -104,17 +105,18 @@ public class ChannelMemberBungeeConsole extends ChannelMemberBungee {
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
if ( message == null || message.isEmpty() ) return;
|
||||
sender.sendMessage(TextComponent.fromLegacyText(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールド名を返す
|
||||
* @return 常に"-"が返される
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#getWorldName()
|
||||
* メッセージを送る
|
||||
* @param message 送るメッセージ
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#sendMessage(net.md_5.bungee.api.chat.BaseComponent[])
|
||||
*/
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
return "-";
|
||||
public void sendMessage(BaseComponent[] message) {
|
||||
if ( message == null || message.length == 0 ) return;
|
||||
sender.sendMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,6 +18,8 @@ import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatBukkit;
|
||||
import com.github.ucchyocean.lc3.bridge.VaultChatBridge;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* ChannelMemberのBukkitPlayer実装
|
||||
* @author ucchy
|
||||
@@ -169,6 +171,19 @@ public class ChannelMemberPlayer extends ChannelMemberBukkit {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* メッセージを送る
|
||||
* @param message 送るメッセージ
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#sendMessage(net.md_5.bungee.api.chat.BaseComponent[])
|
||||
*/
|
||||
public void sendMessage(BaseComponent[] message) {
|
||||
if ( message == null || message.length == 0 ) return;
|
||||
Player player = getPlayer();
|
||||
if ( player != null ) {
|
||||
player.spigot().sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* BukkitのPlayerを取得する
|
||||
* @return Player
|
||||
@@ -179,6 +194,18 @@ public class ChannelMemberPlayer extends ChannelMemberBukkit {
|
||||
return Bukkit.getPlayer(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドを取得する
|
||||
* @return 発言者が今いるワールド
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMemberBukkit#getWorld()
|
||||
*/
|
||||
@Override
|
||||
public World getWorld() {
|
||||
Player player = getPlayer();
|
||||
if ( player != null ) return player.getWorld();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドのワールド名を取得する
|
||||
* @return ワールド名
|
||||
@@ -186,11 +213,12 @@ public class ChannelMemberPlayer extends ChannelMemberBukkit {
|
||||
*/
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
Player player = getPlayer();
|
||||
if ( player != null ) {
|
||||
return player.getWorld().getName();
|
||||
World world = getWorld();
|
||||
if ( world == null ) return "";
|
||||
if ( LunaChatBukkit.getInstance().getMultiverseCore() != null ) {
|
||||
return LunaChatBukkit.getInstance().getMultiverseCore().getWorldAlias(world.getName());
|
||||
}
|
||||
return "-";
|
||||
return world.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -261,13 +289,6 @@ public class ChannelMemberPlayer extends ChannelMemberBukkit {
|
||||
return "$" + id.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
Player player = getPlayer();
|
||||
if ( player != null ) return player.getWorld();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ChannelMemberPlayer getChannelMember(String nameOrUuid) {
|
||||
if ( nameOrUuid.startsWith("$") ) {
|
||||
return new ChannelMemberPlayer(nameOrUuid.substring(1));
|
||||
|
||||
@@ -12,8 +12,10 @@ 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.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
@@ -105,11 +107,16 @@ public class ChannelMemberProxiedPlayer extends ChannelMemberBungee {
|
||||
*/
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
BungeePermsBridge bungeeperms = LunaChatBungee.getInstance().getBungeePerms();
|
||||
if ( bungeeperms == null ) {
|
||||
return "";
|
||||
|
||||
LuckPermsBridge luckperms = LunaChatBungee.getInstance().getLuckPerms();
|
||||
if ( luckperms != null ) {
|
||||
return luckperms.getPlayerPrefix(id);
|
||||
}
|
||||
return bungeeperms.userPrefix(id.toString(), null, null);
|
||||
BungeePermsBridge bungeeperms = LunaChatBungee.getInstance().getBungeePerms();
|
||||
if ( bungeeperms != null ) {
|
||||
return bungeeperms.userPrefix(id.toString(), null, null);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,11 +126,16 @@ public class ChannelMemberProxiedPlayer extends ChannelMemberBungee {
|
||||
*/
|
||||
@Override
|
||||
public String getSuffix() {
|
||||
BungeePermsBridge bungeeperms = LunaChatBungee.getInstance().getBungeePerms();
|
||||
if ( bungeeperms == null ) {
|
||||
return "";
|
||||
|
||||
LuckPermsBridge luckperms = LunaChatBungee.getInstance().getLuckPerms();
|
||||
if ( luckperms != null ) {
|
||||
return luckperms.getPlayerPrefix(id);
|
||||
}
|
||||
return bungeeperms.userSuffix(id.toString(), null, null);
|
||||
BungeePermsBridge bungeeperms = LunaChatBungee.getInstance().getBungeePerms();
|
||||
if ( bungeeperms != null ) {
|
||||
return bungeeperms.userPrefix(id.toString(), null, null);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,13 +153,16 @@ public class ChannelMemberProxiedPlayer extends ChannelMemberBungee {
|
||||
}
|
||||
|
||||
/**
|
||||
* 発言者が今いるワールドのワールド名を取得する
|
||||
* @return ワールド名
|
||||
* @see com.github.ucchyocean.lc.channel.ChannelPlayer#getWorldName()
|
||||
* メッセージを送る
|
||||
* @param message 送るメッセージ
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#sendMessage(net.md_5.bungee.api.chat.BaseComponent[])
|
||||
*/
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
return "-";
|
||||
public void sendMessage(BaseComponent[] message) {
|
||||
if ( message == null || message.length == 0 ) return;
|
||||
ProxiedPlayer player = getPlayer();
|
||||
if ( player != null ) {
|
||||
player.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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クラス用のメソッドを生成するツール
|
||||
@@ -30,6 +30,18 @@ public class MessageParser {
|
||||
private static final String START_MARKER = " // === Auto-generated methods area start. ===";
|
||||
private static final String END_MARKER = " // === Auto-generated methods area end. ===";
|
||||
|
||||
private static final List<String> CLICKABLE_MESSAGES;
|
||||
static {
|
||||
CLICKABLE_MESSAGES = new ArrayList<>();
|
||||
for ( String s : new String[] {
|
||||
"joinMessage", "quitMessage", "banMessage", "kickMessage",
|
||||
"muteMessage", "banNGWordMessage", "kickNGWordMessage", "muteNGWordMessage", "banWithExpireMessage",
|
||||
"muteWithExpireMessage", "pardonMessage", "unmuteMessage", "expiredBanMessage", "expiredMuteMessage",
|
||||
"addModeratorMessage", "removeModeratorMessage", "noRecipientMessage", "listFormat", } ) {
|
||||
CLICKABLE_MESSAGES.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
// 自動生成メソッドを作成する
|
||||
@@ -99,29 +111,53 @@ public class MessageParser {
|
||||
}
|
||||
|
||||
// 出力
|
||||
result.add("");
|
||||
result.add(" /**");
|
||||
result.add(" * " + value);
|
||||
result.add(" */");
|
||||
result.add(String.format(
|
||||
" public static String %s(%s) {", key, arguments));
|
||||
result.add(String.format(
|
||||
" String msg = resources.getString(\"%s\");", key));
|
||||
result.add(String.format(
|
||||
" if ( msg == null ) return \"\";", key));
|
||||
|
||||
for ( String keyword : keywords ) {
|
||||
if ( !CLICKABLE_MESSAGES.contains(key) ) {
|
||||
result.add("");
|
||||
result.add(" /**");
|
||||
result.add(" * " + value);
|
||||
result.add(" */");
|
||||
result.add(String.format(
|
||||
" msg = msg.replace(\"%%%s%%\", %s.toString());", keyword, keyword));
|
||||
}
|
||||
if ( key.startsWith("errmsg") ) {
|
||||
result.add(" return Utility.replaceColorCode(resources.getString(\"errorPrefix\", \"\") + msg);");
|
||||
} else if ( key.startsWith("cmdmsg") ) {
|
||||
result.add(" return Utility.replaceColorCode(resources.getString(\"infoPrefix\", \"\") + msg);");
|
||||
" public static String %s(%s) {", key, arguments));
|
||||
result.add(String.format(
|
||||
" 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(
|
||||
" kr.replace(\"%%%s%%\", %s.toString());", keyword, keyword));
|
||||
}
|
||||
if ( key.startsWith("errmsg") ) {
|
||||
result.add(" return Utility.replaceColorCode(resources.getString(\"errorPrefix\", \"\") + kr.toString());");
|
||||
} else if ( key.startsWith("cmdmsg") ) {
|
||||
result.add(" return Utility.replaceColorCode(resources.getString(\"infoPrefix\", \"\") + kr.toString());");
|
||||
} else {
|
||||
result.add(" return Utility.replaceColorCode(kr.toString());");
|
||||
}
|
||||
result.add(" }");
|
||||
} else {
|
||||
result.add(" return Utility.replaceColorCode(msg);");
|
||||
result.add("");
|
||||
result.add(" /**");
|
||||
result.add(" * " + value);
|
||||
result.add(" */");
|
||||
result.add(String.format(
|
||||
" public static BaseComponent[] %s(%s) {", key, arguments));
|
||||
result.add(String.format(
|
||||
" String msg = resources.getString(\"%s\");", key));
|
||||
result.add(String.format(
|
||||
" if ( msg == null ) return new BaseComponent[0];", key));
|
||||
result.add(" ClickableFormat cf = ClickableFormat.makeChannelClickableMessage(msg, channel.toString());");
|
||||
|
||||
for ( String keyword : keywords ) {
|
||||
if ( keyword.equals("%channel%") ) continue;
|
||||
result.add(String.format(
|
||||
" cf.replace(\"%%%s%%\", %s.toString());", keyword, keyword));
|
||||
}
|
||||
result.add(" return cf.makeTextComponent();");
|
||||
result.add(" }");
|
||||
|
||||
}
|
||||
result.add(" }");
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
/*
|
||||
* @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 static ClickableFormat makeChannelClickableMessage(String format, String channelName) {
|
||||
|
||||
KeywordReplacer msg = new KeywordReplacer(format);
|
||||
String stripped = Utility.stripColorCode(channelName);
|
||||
msg.replace("%channel%", String.format(
|
||||
PLACEHOLDER_RUN_COMMAND,
|
||||
channelName,
|
||||
Messages.hoverChannelName(stripped),
|
||||
String.format(JOIN_COMMAND_TEMPLATE, stripped)));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3;
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
/**
|
||||
* Event優先度列挙子
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 文字列のキーワード置き換えを行うユーティリティクラス
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 正規表現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 キーワード
|
||||
* @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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列を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();
|
||||
}
|
||||
}
|
||||
+68
-32
@@ -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,10 @@ 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;
|
||||
import com.google.common.io.Files;
|
||||
|
||||
/**
|
||||
* ユーティリティクラス
|
||||
* @author ucchy
|
||||
@@ -38,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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +92,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,17 +118,18 @@ 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])", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* 文字列に含まれているカラーコード候補(&a)を除去して返す
|
||||
* 文字列に含まれているカラーコード候補(&aや#99AABB)を除去して返す
|
||||
* @param source 置き換え元の文字列
|
||||
* @return 置き換え後の文字列
|
||||
*/
|
||||
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,17 +139,17 @@ 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]");
|
||||
}
|
||||
|
||||
/**
|
||||
* カラーコード候補(&a)かどうかを判断する
|
||||
* カラーコード候補(&aや#99AABB)かどうかを判断する
|
||||
* @param color カラーコード候補
|
||||
* @return カラーコード候補かどうか
|
||||
*/
|
||||
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 +168,11 @@ public class Utility {
|
||||
}
|
||||
|
||||
/**
|
||||
* カラー表記の文字列を、カラーコードに変換する
|
||||
* カラー表記の文字列(REDとかGREENとか)を、カラーコード候補(&a)に変換する
|
||||
* @param color カラー表記の文字列
|
||||
* @return カラーコード
|
||||
* @return カラーコード候補
|
||||
*/
|
||||
public static String changeToColorCode(String color) {
|
||||
|
||||
return "&" + changeToChatColor(color).getChar();
|
||||
}
|
||||
|
||||
@@ -150,7 +182,6 @@ public class Utility {
|
||||
* @return ChatColorクラス
|
||||
*/
|
||||
public static ChatColor changeToChatColor(String color) {
|
||||
|
||||
if (isValidColor(color)) {
|
||||
return ChatColor.valueOf(color.toUpperCase());
|
||||
}
|
||||
@@ -176,7 +207,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;
|
||||
}
|
||||
|
||||
+10
-1
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<String>に変換して返す
|
||||
* @param key
|
||||
* @return keyに対応する値(値が無いかList<String>に変換できない場合はnullが返される)
|
||||
*/
|
||||
public @Nullable List<String> getStringList(String key) {
|
||||
return getStringList(key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたkeyの値をList<String>に変換して返す
|
||||
* @param key
|
||||
* @param defaultValue デフォルト値
|
||||
* @return keyに対応する値(値が無いかList<String>に変換できない場合は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<String, Object>に変換して返す
|
||||
* @param key
|
||||
* @return keyに対応する値(値が無いかMap<String, Object>に変換できない場合はnullが返される)
|
||||
*/
|
||||
public @Nullable Map<String, Object> getMap(String key) {
|
||||
return getMap(key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたkeyの値をMap<String, Object>に変換して返す
|
||||
* @param key
|
||||
* @param defaultValue デフォルト値
|
||||
* @return keyに対応する値(値が無いかMap<String, Object>に変換できない場合は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<String, Object>に変換できない場合はnullが返される)
|
||||
*/
|
||||
public @Nullable YamlSection getSection(String key) {
|
||||
return getSection(key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定されたkeyの値をYamlSectionに変換して返す
|
||||
* @param key
|
||||
* @param defaultValue デフォルト値
|
||||
* @return YamlSection(値が無いかMap<String, Object>に変換できない場合は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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ formatConstraint: ['%username','%msg']
|
||||
# The following keywords can be used for formatting.
|
||||
# %ch: Channel name
|
||||
# %color: Channel color
|
||||
# %username: Speaker display name
|
||||
# %displayname: Speaker display name
|
||||
# %player: Speaker ID
|
||||
# %world: world name
|
||||
# %prefix: prefix (replaced if Vault and Prefix/Suffix plugin are installed)
|
||||
@@ -69,7 +69,7 @@ formatConstraint: ['%username','%msg']
|
||||
# %date: date
|
||||
# %time: time
|
||||
# %msg: Content of statement
|
||||
defaultFormat: '&f[%color%ch&f]%prefix%username%suffix&a:&f %msg'
|
||||
defaultFormat: '&f[%color%ch&f]%prefix%displayname%suffix&a:&f %msg'
|
||||
|
||||
# Setting to display the content of all channels on the OP screen.
|
||||
opListenAllChannel: false
|
||||
@@ -98,7 +98,7 @@ quickChannelChatSeparator: ':'
|
||||
# When sending a private message with the # /tell, /msg or /r command, applied formatting.
|
||||
# The following keywords can be used for formatting.
|
||||
# %ch: Channel name (same as "%player>%to")
|
||||
# %username: Speaker display name
|
||||
# %displayname: Speaker display name
|
||||
# %player: Speaker ID
|
||||
# %server: Speaker's connection server name (valid when installed on BungeeCord side.)
|
||||
# %to: ID of the person (recipient) who speaks
|
||||
@@ -110,7 +110,7 @@ quickChannelChatSeparator: ':'
|
||||
# %time: time
|
||||
# %msg: Content of statement (When converted to Japanize, the result of Japanize is included.)
|
||||
defaultFormatForPrivateMessage: '&7[%player -> %to]&f %msg'
|
||||
#defaultFormatForPrivateMessage: '&7[%player@%server >%to@%recieverserver] %msg'
|
||||
#defaultFormatForPrivateMessage: '&7[%player@%server > %to@%recieverserver] %msg'
|
||||
|
||||
|
||||
# -------------------- dynmap linkage setting --------------------
|
||||
@@ -154,7 +154,7 @@ enableNormalChatMessageFormat: true
|
||||
|
||||
# Chat decoration formatting.
|
||||
# The following keywords can be used for formatting.
|
||||
# %username: Speaker display name
|
||||
# %displayname: Speaker display name
|
||||
# %player: Speaker ID
|
||||
# %world: Name of the world you said (Valid when it is installed on the spigot side. When MultiVerse is installed, the display name of the world is acquired and used.)
|
||||
# %server: Speaker's connection server name (valid when installed on BungeeCord side.)
|
||||
@@ -163,8 +163,8 @@ enableNormalChatMessageFormat: true
|
||||
# %date: date
|
||||
# %time: time
|
||||
# %msg: Content of statement (When converted to Japanize, the result of Japanize is included.)
|
||||
normalChatMessageFormat: '&f%prefix%username%suffix&a:&f %msg'
|
||||
#normalChatMessageFormat: '&f%username@%server&a:&f %msg'
|
||||
normalChatMessageFormat: '&f%prefix%displayname%suffix&a:&f %msg'
|
||||
#normalChatMessageFormat: '&f%displayname@%server&a:&f %msg'
|
||||
|
||||
# Color code (&a, &b, etc.) in normal chat (non-channel chat)
|
||||
# Whether to enable. If set to false, color codes will not be converted.
|
||||
@@ -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: '$'
|
||||
@@ -62,7 +62,7 @@ formatConstraint: ['%username', '%msg']
|
||||
# フォーマット設定には、下記のキーワードが使用できます。
|
||||
# %ch : チャンネル名
|
||||
# %color : チャンネルカラー
|
||||
# %username : 発言者表示名
|
||||
# %displayname : 発言者表示名
|
||||
# %player : 発言者ID
|
||||
# %world : 発言したワールド名
|
||||
# %prefix : プレフィックス(VaultとPermissionsExが導入されている場合に置き換えられます)
|
||||
@@ -70,7 +70,7 @@ formatConstraint: ['%username', '%msg']
|
||||
# %date : 日付
|
||||
# %time : 時刻
|
||||
# %msg : 発言内容(Japanize変換された場合は、Japanize結果を含みます。)
|
||||
defaultFormat: '&f[%color%ch&f]%prefix%username%suffix&a:&f %msg'
|
||||
defaultFormat: '&f[%color%ch&f]%prefix%displayname%suffix&a:&f %msg'
|
||||
|
||||
# OPの画面に、全チャンネルの発言内容を表示する設定。
|
||||
opListenAllChannel: false
|
||||
@@ -100,7 +100,7 @@ quickChannelChatSeparator: ':'
|
||||
# 適用されるフォーマット設定。
|
||||
# フォーマット設定には、下記のキーワードが使用できます。
|
||||
# %ch : チャンネル名(「%player>%to」と同一です。)
|
||||
# %username : 発言者表示名
|
||||
# %displayname : 発言者表示名
|
||||
# %player : 発言者ID
|
||||
# %server : 発言者の接続サーバー名(BungeeCord側に導入したときに有効です。)
|
||||
# %to : 発言の相手(受信者)のID
|
||||
@@ -159,7 +159,7 @@ enableNormalChatMessageFormat: true
|
||||
|
||||
# チャット装飾のフォーマット設定。
|
||||
# フォーマット設定には、下記のキーワードが使用できます。
|
||||
# %username : 発言者表示名
|
||||
# %displayname : 発言者表示名
|
||||
# %player : 発言者ID
|
||||
# %world : 発言したワールド名(spigot側に導入したときに有効です。MultiVerseが導入されている場合は、ワールドの表示名を取得して使用します。)
|
||||
# %server : 発言者の接続サーバー名(BungeeCord側に導入したときに有効です。)
|
||||
@@ -168,8 +168,8 @@ enableNormalChatMessageFormat: true
|
||||
# %date : 日付
|
||||
# %time : 時刻
|
||||
# %msg : 発言内容(Japanize変換された場合は、Japanize結果を含みます。)
|
||||
normalChatMessageFormat: '&f%prefix%username%suffix&a:&f %msg'
|
||||
#normalChatMessageFormat: '&f%username@%server&a:&f %msg'
|
||||
normalChatMessageFormat: '&f%prefix%displayname%suffix&a:&f %msg'
|
||||
#normalChatMessageFormat: '&f%displayname@%server&a:&f %msg'
|
||||
|
||||
# 通常チャット(非チャンネルチャット)で、カラーコード(&aや&bなど)を
|
||||
# 使用可能にするかどうか。falseに設定すると、カラーコードは変換されません。
|
||||
@@ -213,6 +213,6 @@ japanizeIgnorePlayerName: true
|
||||
|
||||
# ノンジャパナイズマーカー。
|
||||
# これが発言の頭に入っている場合は、一時的にJapanize変換を実行しない。
|
||||
noneJapanizeMarker: '#'
|
||||
noneJapanizeMarker: '$'
|
||||
|
||||
|
||||
@@ -206,3 +206,6 @@ usageJapanizeOther: '&6/%label% (player) on|off &7- Turn on/off the Japanize con
|
||||
usageTop: '&e----- &6LunaChat %type% command (&c%num%&6/&c%max%&6) &e-----'
|
||||
usageFoot: '&e-----------------------------------------'
|
||||
usageNoticeNextPage: '&6 To see the next page, run &c/%label% help %type% %next%&6. '
|
||||
|
||||
hoverChannelName: 'Set %channel% as your speak channel'
|
||||
hoverPlayerName: 'Send private message to %player%'
|
||||
@@ -206,3 +206,6 @@ usageJapanizeOther: '&6/%label% (player) on|off &7- Turn on/off the Japanize con
|
||||
usageTop: '&e----- &6LunaChat %type% command (&c%num%&6/&c%max%&6) &e-----'
|
||||
usageFoot: '&e-----------------------------------------'
|
||||
usageNoticeNextPage: '&6次のページを見るには、&c/%label% help %type% %next%&6 と実行してください。'
|
||||
|
||||
hoverChannelName: '発言先を%channel%にする'
|
||||
hoverPlayerName: '%player%にプライベートメッセージを送る'
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.member;
|
||||
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
* テスト用のダミーメンバー
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ChannelMemberDummy extends ChannelMember {
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#isOnline()
|
||||
*/
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#getName()
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return "ucchy";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#getDisplayName()
|
||||
*/
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return "うっちぃ";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#getPrefix()
|
||||
*/
|
||||
@Override
|
||||
public String getPrefix() {
|
||||
return "[P]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#getSuffix()
|
||||
*/
|
||||
@Override
|
||||
public String getSuffix() {
|
||||
return "[S]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#sendMessage(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
System.out.println(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#sendMessage(net.md_5.bungee.api.chat.BaseComponent[])
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(BaseComponent[] message) {
|
||||
for ( BaseComponent comp : message ) {
|
||||
System.out.print(comp.toLegacyText());
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#getWorldName()
|
||||
*/
|
||||
@Override
|
||||
public String getWorldName() {
|
||||
return "w";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#getServerName()
|
||||
*/
|
||||
@Override
|
||||
public String getServerName() {
|
||||
return "s";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param node
|
||||
* @return
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#hasPermission(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(String node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChannelMemberDummy{name=ucchy}";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param node
|
||||
* @return
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#isPermissionSet(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public boolean isPermissionSet(String node) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param message
|
||||
* @see com.github.ucchyocean.lc3.member.ChannelMember#chat(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public void chat(String message) {
|
||||
// do nothing.
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChatStandalone;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.channel.Channel;
|
||||
import com.github.ucchyocean.lc3.channel.StandaloneChannel;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberDummy;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ucchy
|
||||
*/
|
||||
public class ClickableFormatTest extends TestCase {
|
||||
|
||||
private static final String DATA_FOLDER = "target" + File.separator + "LunaChatTest";
|
||||
private static final String MESSAGES_FOLDER = "target" + File.separator + "classes";
|
||||
|
||||
public void testChannelChatKeyword() {
|
||||
|
||||
File dataFolder = new File(DATA_FOLDER);
|
||||
System.out.println("dataFolder : " + dataFolder.getAbsolutePath());
|
||||
if ( !dataFolder.exists() ) {
|
||||
dataFolder.mkdirs();
|
||||
}
|
||||
|
||||
LunaChatStandalone lunachat = new LunaChatStandalone(dataFolder);
|
||||
lunachat.onEnable();
|
||||
|
||||
Messages.initialize(new File(MESSAGES_FOLDER), null, "ja");
|
||||
|
||||
String format = "&f[%color%ch&f]%prefix%displayname%suffix&a:&f %msg";
|
||||
ChannelMember member = new ChannelMemberDummy();
|
||||
Channel channel = new StandaloneChannel("r");
|
||||
|
||||
ClickableFormat f = ClickableFormat.makeFormat(format, member, channel, true);
|
||||
|
||||
System.out.println("pre = " + f.toString() + ", legacy text = " + f.toLegacyText());
|
||||
|
||||
BaseComponent[] comps = f.makeTextComponent();
|
||||
|
||||
System.out.println("post : comps len = " + comps.length + ", legacy text = " + makeLegacyText(comps));
|
||||
for ( BaseComponent comp : comps ) {
|
||||
System.out.println(comp.toString());
|
||||
}
|
||||
|
||||
// assertTrue(f.toLegacyText().equals(makeLegacyText(comps)));
|
||||
}
|
||||
|
||||
public void testEventChatKeyword() {
|
||||
|
||||
String format = "&f%prefix%displayname%suffix&a:&f %msg";
|
||||
ChannelMember member = new ChannelMemberDummy();
|
||||
|
||||
Messages.initialize(new File(MESSAGES_FOLDER), null, "ja");
|
||||
|
||||
ClickableFormat f = ClickableFormat.makeFormat(format, member);
|
||||
|
||||
System.out.println("pre = " + f.toString() + ", legacy text = " + f.toLegacyText());
|
||||
|
||||
BaseComponent[] comps = f.makeTextComponent();
|
||||
|
||||
System.out.println("post : comps len = " + comps.length + ", legacy text = " + makeLegacyText(comps));
|
||||
for ( BaseComponent comp : comps ) {
|
||||
System.out.println(comp.toString());
|
||||
}
|
||||
|
||||
// assertTrue(f.toLegacyText().equals(makeLegacyText(comps)));
|
||||
}
|
||||
|
||||
private static String makeLegacyText(BaseComponent[] comps) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for ( BaseComponent comp : comps ) {
|
||||
builder.append(comp.toLegacyText());
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ucchy
|
||||
*/
|
||||
public class KeywordReplacerTest extends TestCase {
|
||||
|
||||
private static final int MAX = 10;
|
||||
|
||||
public void test() {
|
||||
|
||||
String testee = "";
|
||||
for ( int i=1; i<=MAX; i++ ) {
|
||||
testee += String.format("%%test%d%%%d", i, i);
|
||||
}
|
||||
|
||||
|
||||
String test1 = new String(testee);
|
||||
long start = System.currentTimeMillis();
|
||||
for ( int i=1; i<=MAX; i++ ) {
|
||||
test1 = test1.replace("%test" + i + "%", i + "");
|
||||
}
|
||||
long time = System.currentTimeMillis() - start;
|
||||
System.out.println("test1 time = " + time);
|
||||
|
||||
|
||||
KeywordReplacer test2 = new KeywordReplacer(testee);
|
||||
start = System.currentTimeMillis();
|
||||
for ( int i=1; i<=MAX; i++ ) {
|
||||
test2.replace("%test" + i + "%", i + "");
|
||||
}
|
||||
time = System.currentTimeMillis() - start;
|
||||
System.out.println("test2 time = " + time);
|
||||
|
||||
assertTrue(test1.equals(test2.toString()));
|
||||
}
|
||||
}
|
||||
@@ -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 UtilityTest 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)));
|
||||
}
|
||||
}
|
||||
@@ -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 YamlConfigTest 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);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする