LunaChat v3-k2 : Added UUIDCacheData feature.
このコミットが含まれているのは:
1 親
2091e4f66c
コミット
62ba2bab60
10ファイル変更
+166
-3
検索条件に一致するファイルはありません
@@ -57,4 +57,8 @@ public class LunaChat {
|
||||
public static LunaChatLogger getNormalChatLogger() {
|
||||
return instance.getNormalChatLogger();
|
||||
}
|
||||
|
||||
public static UUIDCacheData getUUIDCacheData() {
|
||||
return instance.getUUIDCacheData();
|
||||
}
|
||||
}
|
||||
@@ -57,4 +57,10 @@ public interface PluginInterface {
|
||||
* @param msg ログメッセージ
|
||||
*/
|
||||
public void log(Level level, String msg);
|
||||
|
||||
/**
|
||||
* UUIDキャッシュデータを取得する
|
||||
* @return UUIDキャッシュデータ
|
||||
*/
|
||||
public UUIDCacheData getUUIDCacheData();
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* @author ucchy
|
||||
* @license LGPLv3
|
||||
* @copyright Copyright ucchy 2020
|
||||
*/
|
||||
package com.github.ucchyocean.lc3;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* UUIDのキャッシュデータを管理するクラス
|
||||
* @author ucchy
|
||||
*/
|
||||
public class UUIDCacheData {
|
||||
|
||||
// キャッシュデータ key=UUID文字列、value=プレイヤー名
|
||||
private Map<String, String> caches;
|
||||
|
||||
private File dataFolder;
|
||||
|
||||
/**
|
||||
* コンストラクタ
|
||||
* @param dataFolder プラグインのデータ格納フォルダ
|
||||
*/
|
||||
public UUIDCacheData(File dataFolder) {
|
||||
caches = new HashMap<String, String>();
|
||||
this.dataFolder = dataFolder;
|
||||
reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* キャッシュデータを読み込む
|
||||
*/
|
||||
public void reload() {
|
||||
|
||||
caches.clear();
|
||||
|
||||
File file = new File(dataFolder, "uuidcache.yml");
|
||||
if ( !file.exists() ) {
|
||||
// キャッシュファイルがまだ無いなら、からファイルを作成しておく。
|
||||
YamlConfig yaml = new YamlConfig();
|
||||
try {
|
||||
yaml.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
YamlConfig yaml = YamlConfig.load(file);
|
||||
|
||||
for ( String uuid : yaml.getKeys(false) ) {
|
||||
caches.put(uuid, yaml.getString(uuid));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* キャッシュデータをファイルに保存する
|
||||
*/
|
||||
public void save() {
|
||||
|
||||
YamlConfig yaml = new YamlConfig();
|
||||
for ( String uuid : caches.keySet() ) {
|
||||
yaml.set(uuid, caches.get(uuid));
|
||||
}
|
||||
|
||||
File file = new File(dataFolder, "uuidcache.yml");
|
||||
try {
|
||||
yaml.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのUUIDとプレイヤー名を追加する。
|
||||
* @param uuid UUID
|
||||
* @param name プレイヤー名
|
||||
*/
|
||||
public void put(String uuid, String name) {
|
||||
caches.put(uuid, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* プレイヤーのUUIDからプレイヤー名を取得する。
|
||||
* @param uuid UUID
|
||||
* @return プレイヤー名(キャッシュされていない場合はnullが返される)
|
||||
*/
|
||||
public @Nullable String get(String uuid) {
|
||||
return caches.get(uuid);
|
||||
}
|
||||
}
|
||||
@@ -117,6 +117,10 @@ public class BukkitEventListener implements Listener {
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
Player player = event.getPlayer();
|
||||
|
||||
// UUIDをキャッシュ
|
||||
LunaChat.getUUIDCacheData().put(player.getUniqueId().toString(), player.getName());
|
||||
LunaChat.getUUIDCacheData().save();
|
||||
|
||||
// 強制参加チャンネル設定を確認し、参加させる
|
||||
forceJoinToForceJoinChannels(player);
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import com.github.ucchyocean.lc3.LunaChatLogger;
|
||||
import com.github.ucchyocean.lc3.LunaChatMode;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.PluginInterface;
|
||||
import com.github.ucchyocean.lc3.UUIDCacheData;
|
||||
import com.github.ucchyocean.lc3.bridge.DynmapBridge;
|
||||
import com.github.ucchyocean.lc3.bridge.McMMOBridge;
|
||||
import com.github.ucchyocean.lc3.bridge.MultiverseCoreBridge;
|
||||
@@ -48,6 +49,7 @@ public class LunaChatBukkit extends JavaPlugin implements PluginInterface {
|
||||
|
||||
private LunaChatConfig config;
|
||||
private ChannelManager manager;
|
||||
private UUIDCacheData uuidCacheData;
|
||||
|
||||
private VaultChatBridge vaultchat;
|
||||
private DynmapBridge dynmap;
|
||||
@@ -73,6 +75,7 @@ public class LunaChatBukkit extends JavaPlugin implements PluginInterface {
|
||||
|
||||
// 変数などの初期化
|
||||
config = new LunaChatConfig(getDataFolder(), getFile());
|
||||
uuidCacheData = new UUIDCacheData(getDataFolder());
|
||||
Messages.initialize(new File(getDataFolder(), "messages"), getFile(), config.getLang());
|
||||
manager = new ChannelManager();
|
||||
normalChatLogger = new LunaChatLogger("==normalchat");
|
||||
@@ -271,4 +274,14 @@ public class LunaChatBukkit extends JavaPlugin implements PluginInterface {
|
||||
public void log(Level level, String msg) {
|
||||
getLogger().log(level, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* UUIDキャッシュデータを取得する
|
||||
* @return UUIDキャッシュデータ
|
||||
* @see com.github.ucchyocean.lc3.PluginInterface#getUUIDCacheData()
|
||||
*/
|
||||
@Override
|
||||
public UUIDCacheData getUUIDCacheData() {
|
||||
return uuidCacheData;
|
||||
}
|
||||
}
|
||||
@@ -128,6 +128,10 @@ public class BungeeEventListener implements Listener {
|
||||
LunaChatConfig config = LunaChat.getConfig();
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
|
||||
// UUIDをキャッシュ
|
||||
LunaChat.getUUIDCacheData().put(player.getUniqueId().toString(), player.getName());
|
||||
LunaChat.getUUIDCacheData().save();
|
||||
|
||||
// 強制参加チャンネル設定を確認し、参加させる
|
||||
forceJoinToForceJoinChannels(player);
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.github.ucchyocean.lc3.LunaChatLogger;
|
||||
import com.github.ucchyocean.lc3.LunaChatMode;
|
||||
import com.github.ucchyocean.lc3.Messages;
|
||||
import com.github.ucchyocean.lc3.PluginInterface;
|
||||
import com.github.ucchyocean.lc3.UUIDCacheData;
|
||||
import com.github.ucchyocean.lc3.channel.ChannelManager;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@@ -35,6 +36,7 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
|
||||
private HashMap<String, String> history;
|
||||
private LunaChatConfig config;
|
||||
private ChannelManager manager;
|
||||
private UUIDCacheData uuidCacheData;
|
||||
private LunaChatLogger normalChatLogger;
|
||||
|
||||
/**
|
||||
@@ -49,6 +51,7 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
|
||||
|
||||
// 初期化
|
||||
config = new LunaChatConfig(getDataFolder(), getFile());
|
||||
uuidCacheData = new UUIDCacheData(getDataFolder());
|
||||
Messages.initialize(new File(getDataFolder(), "messages"), getFile(), config.getLang());
|
||||
history = new HashMap<String, String>();
|
||||
|
||||
@@ -172,4 +175,14 @@ public class LunaChatBungee extends Plugin implements PluginInterface {
|
||||
public void log(Level level, String msg) {
|
||||
getLogger().log(level, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* UUIDキャッシュデータを取得する
|
||||
* @return UUIDキャッシュデータ
|
||||
* @see com.github.ucchyocean.lc3.PluginInterface#getUUIDCacheData()
|
||||
*/
|
||||
@Override
|
||||
public UUIDCacheData getUUIDCacheData() {
|
||||
return uuidCacheData;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
import com.github.ucchyocean.lc3.bridge.VaultChatBridge;
|
||||
import com.github.ucchyocean.lc3.bukkit.LunaChatBukkit;
|
||||
|
||||
@@ -88,6 +89,10 @@ public class ChannelMemberPlayer extends ChannelMemberBukkit {
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
String cache = LunaChat.getUUIDCacheData().get(id.toString());
|
||||
if ( cache != null ) {
|
||||
return cache;
|
||||
}
|
||||
Player player = Bukkit.getPlayer(id);
|
||||
if ( player != null ) {
|
||||
return player.getName();
|
||||
|
||||
@@ -9,6 +9,8 @@ import java.util.UUID;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.github.ucchyocean.lc3.LunaChat;
|
||||
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
@@ -70,13 +72,14 @@ public class ChannelMemberProxiedPlayer extends ChannelMemberBungee {
|
||||
*/
|
||||
@Override
|
||||
public String getName() {
|
||||
String cache = LunaChat.getUUIDCacheData().get(id.toString());
|
||||
if ( cache != null ) {
|
||||
return cache;
|
||||
}
|
||||
ProxiedPlayer player = getPlayer();
|
||||
if ( player != null ) {
|
||||
return player.getName();
|
||||
}
|
||||
|
||||
// TODO 接続していないプレイヤーのUUIDを取得する方法を検討する
|
||||
|
||||
return id.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.github.ucchyocean.lc3.LunaChatConfig;
|
||||
import com.github.ucchyocean.lc3.LunaChatLogger;
|
||||
import com.github.ucchyocean.lc3.LunaChatMode;
|
||||
import com.github.ucchyocean.lc3.PluginInterface;
|
||||
import com.github.ucchyocean.lc3.UUIDCacheData;
|
||||
import com.github.ucchyocean.lc3.channel.ChannelManager;
|
||||
|
||||
/**
|
||||
@@ -26,6 +27,7 @@ public class LunaChatStandalone implements PluginInterface {
|
||||
|
||||
private LunaChatConfig config;
|
||||
private ChannelManager manager;
|
||||
private UUIDCacheData uuidCacheData;
|
||||
|
||||
public void onEnable() {
|
||||
|
||||
@@ -37,6 +39,9 @@ public class LunaChatStandalone implements PluginInterface {
|
||||
|
||||
// コンフィグ取得
|
||||
config = new LunaChatConfig(getDataFolder(), getPluginJarFile());
|
||||
|
||||
// UUIDキャッシュデータ (これ要る?)
|
||||
uuidCacheData = new UUIDCacheData(getDataFolder());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,4 +93,13 @@ public class LunaChatStandalone implements PluginInterface {
|
||||
// TODO 未実装
|
||||
}
|
||||
|
||||
/**
|
||||
* UUIDキャッシュデータを取得する
|
||||
* @return UUIDキャッシュデータ
|
||||
* @see com.github.ucchyocean.lc3.PluginInterface#getUUIDCacheData()
|
||||
*/
|
||||
@Override
|
||||
public UUIDCacheData getUUIDCacheData() {
|
||||
return uuidCacheData;
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする