LunaChat v3-k2 : Implement Backward Compatibility. (WIP)
このコミットが含まれているのは:
1 親
172e64aa50
コミット
7abc57f9ac
21ファイル変更
+267
-63
検索条件に一致するファイルはありません
@@ -7,8 +7,6 @@ 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;
|
||||
|
||||
@@ -18,8 +16,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
public class UUIDCacheData {
|
||||
|
||||
// キャッシュデータ key=UUID文字列、value=プレイヤー名
|
||||
private Map<String, String> caches;
|
||||
private static final String FILE_NAME = "uuidcache.yml";
|
||||
|
||||
// キャッシュデータ key=UUID文字列、value=プレイヤー名
|
||||
private YamlConfig cache;
|
||||
|
||||
private File dataFolder;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class UUIDCacheData {
|
||||
* @param dataFolder プラグインのデータ格納フォルダ
|
||||
*/
|
||||
public UUIDCacheData(File dataFolder) {
|
||||
caches = new HashMap<String, String>();
|
||||
cache = new YamlConfig();
|
||||
this.dataFolder = dataFolder;
|
||||
reload();
|
||||
}
|
||||
@@ -37,41 +37,27 @@ public class UUIDCacheData {
|
||||
* キャッシュデータを読み込む
|
||||
*/
|
||||
public void reload() {
|
||||
|
||||
caches.clear();
|
||||
|
||||
File file = new File(dataFolder, "uuidcache.yml");
|
||||
File file = new File(dataFolder, FILE_NAME);
|
||||
if ( !file.exists() ) {
|
||||
// キャッシュファイルがまだ無いなら、からファイルを作成しておく。
|
||||
YamlConfig yaml = new YamlConfig();
|
||||
cache = new YamlConfig();
|
||||
try {
|
||||
yaml.save(file);
|
||||
cache.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));
|
||||
}
|
||||
cache = YamlConfig.load(file);
|
||||
}
|
||||
|
||||
/**
|
||||
* キャッシュデータをファイルに保存する
|
||||
*/
|
||||
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");
|
||||
File file = new File(dataFolder, FILE_NAME);
|
||||
try {
|
||||
yaml.save(file);
|
||||
cache.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -83,7 +69,7 @@ public class UUIDCacheData {
|
||||
* @param name プレイヤー名
|
||||
*/
|
||||
public void put(String uuid, String name) {
|
||||
caches.put(uuid, name);
|
||||
cache.set(uuid, name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,6 +78,6 @@ public class UUIDCacheData {
|
||||
* @return プレイヤー名(キャッシュされていない場合はnullが返される)
|
||||
*/
|
||||
public @Nullable String get(String uuid) {
|
||||
return caches.get(uuid);
|
||||
return cache.getString(uuid);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする