+ 调整 TConfiguration 类,增加 runListener 方法运行重载任务 + 调整 ItemBuilder 类,增加玩家皮肤头构造方法 + 调整 TagDataHandler 类,兼容了弱智 BedwarsRel 的计分板冲突 + 调整 SupportWorldGuard 类,新增了获取所有区域的方法。 + 重构 ItemUtils 类,现在更加整洁了。。 + SkullUtils 被赋予尊贵的 @Deprecated + 优化本地通讯网,修复了心跳包的语法错误问题,并新增了 /tclient 命令用于简单的操作通讯网络。
89 lines
2.1 KiB
Java
89 lines
2.1 KiB
Java
package me.skymc.taboolib.common.configuration;
|
|
|
|
import com.ilummc.tlib.TLib;
|
|
import com.ilummc.tlib.logger.TLogger;
|
|
import org.bukkit.configuration.InvalidConfigurationException;
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.Optional;
|
|
|
|
/**
|
|
* @Author sky
|
|
* @Since 2018-09-08 15:00
|
|
*/
|
|
public class TConfiguration extends YamlConfiguration {
|
|
|
|
private File file;
|
|
private Runnable runnable;
|
|
|
|
private TConfiguration(File file) {
|
|
this.file = file;
|
|
reload();
|
|
TLib.getTLib().getConfigWatcher().addSimpleListener(this.file, this::reload);
|
|
}
|
|
|
|
public void release() {
|
|
TLib.getTLib().getConfigWatcher().removeListener(file);
|
|
}
|
|
|
|
public void reload() {
|
|
try {
|
|
load(file);
|
|
runListener();
|
|
} catch (IOException | InvalidConfigurationException e) {
|
|
TLogger.getGlobalLogger().warn("Cannot load configuration from stream: " + e.toString());
|
|
}
|
|
}
|
|
|
|
public void runListener() {
|
|
try {
|
|
Optional.ofNullable(runnable).ifPresent(Runnable::run);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 创建配置文件
|
|
*
|
|
* @param file 文件
|
|
* @return {@link TConfiguration}
|
|
*/
|
|
public static TConfiguration create(File file) {
|
|
return new TConfiguration(file);
|
|
}
|
|
|
|
/**
|
|
* 从插件里释放文件并创建
|
|
*
|
|
* @param plugin 插件
|
|
* @param path 目录
|
|
* @return {@link TConfiguration}
|
|
*/
|
|
public static TConfiguration createInResource(Plugin plugin, String path) {
|
|
File file = new File(plugin.getDataFolder(), path);
|
|
if (!file.exists()) {
|
|
plugin.saveResource(path, true);
|
|
}
|
|
return create(file);
|
|
}
|
|
|
|
// *********************************
|
|
//
|
|
// Getter and Setter
|
|
//
|
|
// *********************************
|
|
|
|
public File getFile() {
|
|
return file;
|
|
}
|
|
|
|
public TConfiguration listener(Runnable runnable) {
|
|
this.runnable = runnable;
|
|
return this;
|
|
}
|
|
}
|