perf: 重写部分代码
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package cn.hamster3.mc.plugin.core.bungee.api;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.bungee.HamsterCorePlugin;
|
||||
import cn.hamster3.mc.plugin.core.bungee.util.BungeeCordUtils;
|
||||
import cn.hamster3.mc.plugin.core.bungee.util.CoreBungeeCordUtils;
|
||||
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
@@ -16,8 +16,7 @@ public final class CoreBungeeAPI extends CoreAPI {
|
||||
private CoreBungeeAPI() {
|
||||
HamsterCorePlugin plugin = HamsterCorePlugin.getInstance();
|
||||
|
||||
Configuration config = BungeeCordUtils.getPluginConfig(plugin);
|
||||
|
||||
Configuration config = CoreBungeeCordUtils.getPluginConfig(plugin);
|
||||
Configuration datasourceConfig = config.getSection("datasource");
|
||||
if (datasourceConfig == null) {
|
||||
throw new IllegalArgumentException("配置文件中未找到 datasource 节点!");
|
||||
|
@@ -12,10 +12,11 @@ import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class BungeeCordUtils {
|
||||
private BungeeCordUtils() {
|
||||
public final class CoreBungeeCordUtils {
|
||||
private CoreBungeeCordUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Configuration getConfig(@NotNull File file) {
|
||||
if (!file.exists()) {
|
||||
throw new IllegalArgumentException("文件不存在!");
|
||||
@@ -27,20 +28,20 @@ public final class BungeeCordUtils {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Configuration getPluginConfig(@NotNull Plugin plugin) {
|
||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
if (!configFile.exists()) {
|
||||
return saveDefaultConfig(plugin);
|
||||
}
|
||||
|
||||
try {
|
||||
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Configuration saveDefaultConfig(@NotNull Plugin plugin) {
|
||||
if (plugin.getDataFolder().mkdir()) {
|
||||
plugin.getLogger().info("创建插件文件夹...");
|
||||
@@ -51,8 +52,7 @@ public final class BungeeCordUtils {
|
||||
Files.copy(in, configFile.toPath());
|
||||
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user