fix(bukkit): page永远从插件jar文件内覆盖
This commit is contained in:
@@ -31,10 +31,6 @@ public class PageManager {
|
|||||||
if (plugin == null) {
|
if (plugin == null) {
|
||||||
throw new IllegalArgumentException("未找到插件 " + pluginName + " !");
|
throw new IllegalArgumentException("未找到插件 " + pluginName + " !");
|
||||||
}
|
}
|
||||||
File pageFolder = new File(plugin.getDataFolder(), "pages");
|
|
||||||
if (pageFolder.mkdirs()) {
|
|
||||||
HamsterCorePlugin.getInstance().getLogger().info("为 " + pluginName + " 创建页面配置文件夹...");
|
|
||||||
}
|
|
||||||
pageConfig = getPageConfig(plugin, clazz.getSimpleName());
|
pageConfig = getPageConfig(plugin, clazz.getSimpleName());
|
||||||
PAGE_CONFIG.put(clazz.getName(), pageConfig);
|
PAGE_CONFIG.put(clazz.getName(), pageConfig);
|
||||||
return pageConfig;
|
return pageConfig;
|
||||||
@@ -48,16 +44,20 @@ public class PageManager {
|
|||||||
HamsterCorePlugin.getInstance().getLogger().info("为 " + pluginName + " 创建页面配置文件夹...");
|
HamsterCorePlugin.getInstance().getLogger().info("为 " + pluginName + " 创建页面配置文件夹...");
|
||||||
}
|
}
|
||||||
String filename = pageName + ".yml";
|
String filename = pageName + ".yml";
|
||||||
File pageFile = new File(pageFolder, filename);
|
File pageConfigFile = new File(pageFolder, filename);
|
||||||
|
if (pageConfigFile.exists()) {
|
||||||
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(pageConfigFile);
|
||||||
|
return new PageConfig(plugin, config);
|
||||||
|
}
|
||||||
try (InputStream resource = plugin.getResource("pages/" + filename)) {
|
try (InputStream resource = plugin.getResource("pages/" + filename)) {
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
throw new IllegalArgumentException("在插件 " + plugin.getName() + " 的 Jar 文件内部未找到 " + filename + " !");
|
throw new IllegalArgumentException("在插件 " + plugin.getName() + " 的 Jar 文件内部未找到 /pages/" + filename + " !");
|
||||||
}
|
}
|
||||||
Files.copy(resource, pageFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(resource, pageConfigFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(pageFile);
|
YamlConfiguration config = YamlConfiguration.loadConfiguration(pageConfigFile);
|
||||||
return new PageConfig(plugin, config);
|
return new PageConfig(plugin, config);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IllegalArgumentException("为插件 " + pluginName + " 加载页面配置文件 " + filename + " 时出错!");
|
throw new IllegalArgumentException("为插件 " + pluginName + " 加载页面配置文件 " + filename + " 时出错!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user