LunaChat v3.0.2 : implementation of TODO tasks.
このコミットが含まれているのは:
1 親
7f877d0674
コミット
f0fe3f02e6
29ファイル変更
+525
-196
検索条件に一致するファイルはありません
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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のコンフィグクラス
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -83,7 +83,7 @@ public class LunaChatStandalone implements PluginInterface {
|
||||
|
||||
@Override
|
||||
public void log(Level level, String msg) {
|
||||
// TODO 未実装
|
||||
// TODO Standaloneサーバーのログ出力 未実装
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -10,6 +10,10 @@ import java.io.IOException;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import com.github.ucchyocean.lc3.util.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
import com.github.ucchyocean.lc3.util.YamlConfig;
|
||||
|
||||
/**
|
||||
* プラグインのメッセージリソース管理クラス
|
||||
* @author ucchy
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -22,19 +22,19 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import com.github.ucchyocean.lc3.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatBukkit;
|
||||
import com.github.ucchyocean.lc3.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.Utility;
|
||||
import com.github.ucchyocean.lc3.bridge.VaultChatBridge;
|
||||
import com.github.ucchyocean.lc3.channel.Channel;
|
||||
import com.github.ucchyocean.lc3.event.EventResult;
|
||||
import com.github.ucchyocean.lc3.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberBukkit;
|
||||
import com.github.ucchyocean.lc3.util.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
|
||||
/**
|
||||
* Bukkit関連のイベントを監視するリスナ
|
||||
|
||||
@@ -14,20 +14,20 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.ucchyocean.lc3.ChatColor;
|
||||
import com.github.ucchyocean.lc3.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatBungee;
|
||||
import com.github.ucchyocean.lc3.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.Utility;
|
||||
import com.github.ucchyocean.lc3.bridge.BungeePermsBridge;
|
||||
import com.github.ucchyocean.lc3.bridge.LuckPermsBridge;
|
||||
import com.github.ucchyocean.lc3.channel.Channel;
|
||||
import com.github.ucchyocean.lc3.event.EventResult;
|
||||
import com.github.ucchyocean.lc3.japanize.Japanizer;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.util.ChatColor;
|
||||
import com.github.ucchyocean.lc3.util.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
@@ -16,18 +16,18 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc3.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatBukkit;
|
||||
import com.github.ucchyocean.lc3.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.Utility;
|
||||
import com.github.ucchyocean.lc3.UtilityBukkit;
|
||||
import com.github.ucchyocean.lc3.bridge.DynmapBridge;
|
||||
import com.github.ucchyocean.lc3.event.EventResult;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberBukkit;
|
||||
import com.github.ucchyocean.lc3.util.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
import com.github.ucchyocean.lc3.util.UtilityBukkit;
|
||||
|
||||
/**
|
||||
* チャンネルの実装クラス
|
||||
@@ -81,6 +81,8 @@ public class BukkitChannel extends Channel {
|
||||
// 範囲チャット
|
||||
|
||||
if ( player instanceof ChannelMemberBukkit ) {
|
||||
// ↑常にtrueだと思うが、念のため。
|
||||
|
||||
Location origin = ((ChannelMemberBukkit)player).getLocation();
|
||||
for ( Player p : Bukkit.getOnlinePlayers() ) {
|
||||
ChannelMember cp = ChannelMember.getChannelMember(p);
|
||||
@@ -90,8 +92,6 @@ public class BukkitChannel extends Channel {
|
||||
recipients.add(ChannelMember.getChannelMember(p));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO 何かするか?検討する
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
@@ -10,15 +10,15 @@ import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.github.ucchyocean.lc3.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatBungee;
|
||||
import com.github.ucchyocean.lc3.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc3.Utility;
|
||||
import com.github.ucchyocean.lc3.event.EventResult;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMemberProxiedPlayer;
|
||||
import com.github.ucchyocean.lc3.util.KeywordReplacer;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.github.ucchyocean.lc3.ChatColor;
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatAPI;
|
||||
import com.github.ucchyocean.lc3.LunaChatConfig;
|
||||
@@ -24,11 +23,12 @@ import com.github.ucchyocean.lc3.LunaChatLogger;
|
||||
import com.github.ucchyocean.lc3.LunaChatMode;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.NGWordAction;
|
||||
import com.github.ucchyocean.lc3.Utility;
|
||||
import com.github.ucchyocean.lc3.YamlConfig;
|
||||
import com.github.ucchyocean.lc3.event.EventResult;
|
||||
import com.github.ucchyocean.lc3.japanize.JapanizeType;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.util.ChatColor;
|
||||
import com.github.ucchyocean.lc3.util.Utility;
|
||||
import com.github.ucchyocean.lc3.util.YamlConfig;
|
||||
|
||||
/**
|
||||
* チャンネル
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
* チャンネルマネージャー
|
||||
|
||||
@@ -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変換を実行して、実行後に発言を行うタスク
|
||||
|
||||
@@ -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,10 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.github.ucchyocean.lc3.ChatColor;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.channel.Channel;
|
||||
import com.github.ucchyocean.lc3.member.ChannelMember;
|
||||
import com.github.ucchyocean.lc3.util.ChatColor;
|
||||
|
||||
/**
|
||||
* listコマンドの実行クラス
|
||||
|
||||
@@ -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コマンドの実行クラス
|
||||
|
||||
@@ -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コマンドの実行クラス
|
||||
|
||||
@@ -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クラス用のメソッドを生成するツール
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3;
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3;
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
/**
|
||||
* Event優先度列挙子
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3;
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
/**
|
||||
* 文字列のキーワード置き換えを行うユーティリティクラス
|
||||
+10
-2
@@ -3,7 +3,7 @@
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3;
|
||||
package com.github.ucchyocean.lc3.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
@@ -17,6 +17,9 @@ import java.util.Locale;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.LunaChatMode;
|
||||
|
||||
/**
|
||||
* ユーティリティクラス
|
||||
* @author ucchy
|
||||
@@ -176,7 +179,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする