feat: 修复 getPluginConfig 可能的报错

This commit is contained in:
2023-10-28 17:07:39 +08:00
parent ced7f673c5
commit dc39dfa827

View File

@@ -217,15 +217,15 @@ public final class CoreBukkitUtils {
@NotNull @NotNull
public static YamlConfiguration getPluginConfig(@NotNull Plugin plugin, @NotNull String filename) { public static YamlConfiguration getPluginConfig(@NotNull Plugin plugin, @NotNull String filename) {
File dataFolder = plugin.getDataFolder(); File file = new File(plugin.getDataFolder(), filename);
if (dataFolder.mkdirs()) { File parentFile = file.getParentFile();
plugin.getLogger().info("已生成插件存档文件夹..."); if (parentFile.mkdirs()) {
plugin.getLogger().info("已生成插件存档文件夹 " + parentFile.getName());
} }
File file = new File(dataFolder, filename);
if (!file.exists()) { if (!file.exists()) {
try (InputStream stream = plugin.getResource(filename)) { try (InputStream stream = plugin.getResource(filename)) {
if (stream == null) { if (stream == null) {
throw new IllegalArgumentException("在插件 " + plugin.getName() + " 的文件内部未找到 " + filename + " !"); throw new NullPointerException("在插件 " + plugin.getName() + " 的文件内部未找到 " + filename + " !");
} }
Files.copy(stream, file.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.copy(stream, file.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) { } catch (IOException e) {