mirror of
https://github.com/CarmJos/MineSQL.git
synced 2026-06-05 00:48:16 +08:00
修改文件夹名称
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package cc.carm.plugin.easysql;
|
||||
|
||||
import cc.carm.plugin.easysql.api.DBConfiguration;
|
||||
import cc.carm.plugin.easysql.api.SQLDriverType;
|
||||
import cc.carm.plugin.easysql.configuration.PluginConfiguration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BukkitConfiguration implements PluginConfiguration {
|
||||
|
||||
private final @NotNull FileConfiguration configuration;
|
||||
|
||||
protected BukkitConfiguration(@NotNull FileConfiguration configuration) {
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public @NotNull FileConfiguration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return getConfiguration().getBoolean("debug", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMetricsEnabled() {
|
||||
return getConfiguration().getBoolean("metrics", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdateCheckerEnabled() {
|
||||
return getConfiguration().getBoolean("check-update", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPropertiesEnabled() {
|
||||
return getConfiguration().getBoolean("properties.enable", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPropertiesFolder() {
|
||||
return getConfiguration().getString("properties.folder", "db-properties/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, DBConfiguration> getDBConfigurations() {
|
||||
Map<String, DBConfiguration> dbConfigurations = new LinkedHashMap<>();
|
||||
ConfigurationSection dbConfigurationsSection = getConfiguration().getConfigurationSection("databases");
|
||||
if (dbConfigurationsSection != null) {
|
||||
for (String dbName : dbConfigurationsSection.getKeys(false)) {
|
||||
if (dbName.startsWith("example-")) continue;
|
||||
ConfigurationSection dbSection = dbConfigurationsSection.getConfigurationSection(dbName);
|
||||
if (dbSection == null) continue;
|
||||
|
||||
String driverString = dbSection.getString("driver-type");
|
||||
SQLDriverType driverType = SQLDriverType.parse(driverString);
|
||||
if (driverType == null) {
|
||||
EasySQLBukkit.getInstance().error("不存在预设的驱动类型 " + driverString + "," + " 请检查配置文件 databases." + dbName + "。");
|
||||
continue;
|
||||
}
|
||||
String host = dbSection.getString("host");
|
||||
if (host == null) {
|
||||
EasySQLBukkit.getInstance().error("地址配置不得为空," + " 请检查配置文件 databases." + dbName + "。");
|
||||
continue;
|
||||
}
|
||||
|
||||
int port = dbSection.getInt("port", -1);
|
||||
if (port < 0) {
|
||||
EasySQLBukkit.getInstance().error("端口未配置正确," + " 请检查配置文件 databases." + dbName + "。");
|
||||
continue;
|
||||
}
|
||||
DBConfiguration configuration = DBConfiguration.create(driverType, host + ":" + port);
|
||||
|
||||
String username = dbSection.getString("username");
|
||||
String password = dbSection.getString("password");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return dbConfigurations;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
package cc.carm.plugin.easysql;
|
||||
|
||||
import cc.carm.lib.easyplugin.EasyPlugin;
|
||||
import cc.carm.lib.easyplugin.i18n.EasyPluginMessageProvider;
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.plugin.easysql.api.DBConfiguration;
|
||||
import cc.carm.plugin.easysql.util.DBPropertiesUtil;
|
||||
import cc.carm.plugin.easysql.util.JarResourceUtils;
|
||||
import cn.beecp.BeeDataSource;
|
||||
import co.aikar.commands.PaperCommandManager;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class EasySQLBukkit extends EasyPlugin implements EasySQLPluginPlatform {
|
||||
|
||||
public EasySQLBukkit() {
|
||||
super(new EasyPluginMessageProvider.zh_CN());
|
||||
}
|
||||
|
||||
protected static EasySQLBukkit instance;
|
||||
|
||||
private BukkitConfiguration configuration;
|
||||
private EasySQLRegistryImpl registry;
|
||||
|
||||
private PaperCommandManager commandManager;
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
EasySQLBukkit.instance = this;
|
||||
|
||||
log("加载配置文件...");
|
||||
getInstance().saveDefaultConfig();
|
||||
this.configuration = new BukkitConfiguration(getInstance().getConfig());
|
||||
|
||||
log("初始化EasySQL注册器...");
|
||||
this.registry = new EasySQLRegistryImpl(this);
|
||||
|
||||
log("初始化EasySQLAPI...");
|
||||
initializeAPI(getRegistry()); // 尽快地初始化接口,方便其他插件调用
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean initialize() {
|
||||
log("初始化指令管理器...");
|
||||
this.commandManager = new PaperCommandManager(this);
|
||||
log("注册相关指令...");
|
||||
initializeCommands(getCommandManager());
|
||||
|
||||
if (getConfiguration().isMetricsEnabled()) {
|
||||
log("启用统计数据...");
|
||||
Metrics metrics = new Metrics(this, 14075);
|
||||
metrics.addCustomChart(new SimplePie("update_check",
|
||||
() -> getConfiguration().isUpdateCheckerEnabled() ? "ENABLED" : "DISABLED")
|
||||
);
|
||||
metrics.addCustomChart(new SimplePie("properties_configuration",
|
||||
() -> getConfiguration().isPropertiesEnabled() ? "ENABLED" : "DISABLED")
|
||||
);
|
||||
}
|
||||
|
||||
if (getConfiguration().isUpdateCheckerEnabled()) {
|
||||
log("开始检查更新...");
|
||||
getRegistry().checkUpdate(getDescription().getVersion());
|
||||
} else {
|
||||
log("已禁用检查更新,跳过。");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdown() {
|
||||
log("终止全部数据库连接...");
|
||||
for (String dbName : new HashSet<>(getRegistry().list().keySet())) {
|
||||
log(" 正在关闭数据库 " + dbName + "...");
|
||||
SQLManager manager = getRegistry().get(dbName);
|
||||
getRegistry().shutdown(manager, activeQueries -> {
|
||||
log(" 数据库 " + dbName + " 仍有有 " + activeQueries + " 条活动查询,强制关闭中...");
|
||||
if (manager.getDataSource() instanceof BeeDataSource) {
|
||||
BeeDataSource dataSource = (BeeDataSource) manager.getDataSource();
|
||||
dataSource.close(); //Close bee connection pool
|
||||
}
|
||||
});
|
||||
}
|
||||
getRegistry().getManagers().clear(); // release all managers
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugging() {
|
||||
return getConfiguration().isDebugEnabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public EasySQLRegistryImpl getRegistry() {
|
||||
return this.registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull
|
||||
Map<String, DBConfiguration> readConfigurations() {
|
||||
return getConfiguration().getDBConfigurations();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull
|
||||
Map<String, Properties> readProperties() {
|
||||
if (!getConfiguration().isPropertiesEnabled()) return new HashMap<>();
|
||||
String propertiesFolder = getConfiguration().getPropertiesFolder();
|
||||
if (propertiesFolder == null || propertiesFolder.length() == 0) return new HashMap<>();
|
||||
|
||||
File file = new File(getDataFolder(), propertiesFolder);
|
||||
if (!file.exists() || !file.isDirectory()) {
|
||||
try {
|
||||
JarResourceUtils.copyFolderFromJar(
|
||||
"db-properties", file,
|
||||
JarResourceUtils.CopyOption.COPY_IF_NOT_EXIST
|
||||
);
|
||||
} catch (Exception ex) {
|
||||
error("初始化properties示例文件失败:" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return DBPropertiesUtil.readFromFolder(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void outputInfo() {
|
||||
Optional.ofNullable(JarResourceUtils.readResource(this.getResource("PLUGIN_INFO"))).ifPresent(this::log);
|
||||
}
|
||||
|
||||
public static EasySQLBukkit getInstance() {
|
||||
return EasySQLBukkit.instance;
|
||||
}
|
||||
|
||||
protected BukkitConfiguration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
protected PaperCommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
main: cc.carm.plugin.easysql.EasySQLBukkit
|
||||
version: ${project.version}
|
||||
prefix: EasySQL-Plugin
|
||||
name: EasySQL-Plugin
|
||||
load: STARTUP
|
||||
|
||||
website: ${project.url}
|
||||
description: ${project.description}
|
||||
authors:
|
||||
- CarmJos
|
||||
- GhostChu
|
||||
|
||||
api-version: 1.13
|
||||
Reference in New Issue
Block a user