mirror of
https://github.com/CarmJos/MineSQL.git
synced 2026-06-04 16:43:03 +08:00
fix(load): 修复插件加载时出现的问题
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
||||
@@ -27,7 +27,11 @@ public class FileBasedConfig extends SQLDriverConfig {
|
||||
@Override
|
||||
public SQLSourceConfig createSource() {
|
||||
File file = new File(MineSQL.getDataSourceFolder(), filePath);
|
||||
return SQLSourceConfig.create(getType().getDriverClass(), file.getAbsolutePath(), getType().getInitializer());
|
||||
return SQLSourceConfig.create(
|
||||
getType().getDriverClass(),
|
||||
getType().getJdbcPrefix() + file.getAbsolutePath(),
|
||||
getType().getInitializer()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
@@ -130,7 +130,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<scope>provided</scope>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -6,8 +6,8 @@ import cc.carm.lib.easyplugin.utils.JarResourceUtils;
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.lib.githubreleases4j.GithubReleases4J;
|
||||
import cc.carm.plugin.minesql.api.source.SQLSourceConfig;
|
||||
import cc.carm.plugin.minesql.command.EasySQLCommand;
|
||||
import cc.carm.plugin.minesql.command.EasySQLHelpFormatter;
|
||||
import cc.carm.plugin.minesql.command.MineSQLCommand;
|
||||
import cc.carm.plugin.minesql.command.MineSQLHelpFormatter;
|
||||
import cc.carm.plugin.minesql.conf.PluginConfiguration;
|
||||
import cc.carm.plugin.minesql.conf.SQLSourceGroup;
|
||||
import cc.carm.plugin.minesql.util.DBPropertiesUtil;
|
||||
@@ -43,6 +43,9 @@ public class MineSQLCore implements IMineSQL {
|
||||
this.config = new PluginConfiguration();
|
||||
this.configProvider.initialize(this.config);
|
||||
|
||||
getLogger().info("初始化MineSQL API...");
|
||||
MineSQL.initializeAPI(this);
|
||||
|
||||
getLogger().info("初始化注册池...");
|
||||
this.registry = new MineSQLRegistry(this);
|
||||
|
||||
@@ -78,7 +81,9 @@ public class MineSQLCore implements IMineSQL {
|
||||
public @NotNull Map<String, SQLSourceConfig> readConfigurations() {
|
||||
SQLSourceGroup group = getConfig().SOURCES.getNotNull();
|
||||
Map<String, SQLSourceConfig> sources = new LinkedHashMap<>();
|
||||
group.getSources().forEach((k, v) -> sources.put(k, v.createSource()));
|
||||
group.getSources().entrySet().stream()
|
||||
.filter(entry -> !entry.getKey().startsWith("example-"))
|
||||
.forEach(entry -> sources.put(entry.getKey(), entry.getValue().createSource()));
|
||||
return sources;
|
||||
}
|
||||
|
||||
@@ -90,12 +95,17 @@ public class MineSQLCore implements IMineSQL {
|
||||
|
||||
File file = new File(getPluginFolder(), propertiesFolder);
|
||||
if (!file.exists() || !file.isDirectory()) {
|
||||
try {
|
||||
JarResourceUtils.copyFolderFromJar(
|
||||
"db-properties", file, JarResourceUtils.CopyOption.COPY_IF_NOT_EXIST
|
||||
);
|
||||
} catch (Exception ex) {
|
||||
getLogger().severe("初始化properties示例文件失败:" + ex.getMessage());
|
||||
if ((propertiesFolder.equals("db-properties/") || propertiesFolder.equals("db-properties"))) {
|
||||
try {
|
||||
JarResourceUtils.copyFolderFromJar(
|
||||
"db-properties", getPluginFolder(),
|
||||
JarResourceUtils.CopyOption.COPY_IF_NOT_EXIST
|
||||
);
|
||||
} catch (Exception ex) {
|
||||
getLogger().severe("初始化properties示例文件失败:" + ex.getMessage());
|
||||
}
|
||||
} else {
|
||||
file.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +115,7 @@ public class MineSQLCore implements IMineSQL {
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void initializeCommands(CommandManager<?, ?, ?, ?, ?, ?> commandManager) {
|
||||
commandManager.enableUnstableAPI("help");
|
||||
commandManager.setHelpFormatter(new EasySQLHelpFormatter(commandManager));
|
||||
commandManager.setHelpFormatter(new MineSQLHelpFormatter(commandManager));
|
||||
commandManager.getLocales().setDefaultLocale(Locales.SIMPLIFIED_CHINESE);
|
||||
commandManager.getCommandContexts().registerContext(SQLManager.class, c -> {
|
||||
String name = c.popFirstArg();
|
||||
@@ -119,7 +129,7 @@ public class MineSQLCore implements IMineSQL {
|
||||
if (c.getIssuer().isPlayer()) return ImmutableList.of();
|
||||
else return ImmutableList.copyOf(getRegistry().list().keySet());
|
||||
});
|
||||
commandManager.registerCommand(new EasySQLCommand(this));
|
||||
commandManager.registerCommand(new MineSQLCommand(this));
|
||||
}
|
||||
|
||||
public void checkUpdate(String currentVersion) {
|
||||
|
||||
@@ -45,21 +45,25 @@ public class MineSQLRegistry implements SQLRegistry {
|
||||
|
||||
dbProperties.forEach((id, properties) -> {
|
||||
try {
|
||||
core.getLogger().info("正在初始化数据库 #" + id + " ...");
|
||||
SQLManagerImpl sqlManager = create(id, properties);
|
||||
this.managers.put(id, sqlManager);
|
||||
} catch (Exception exception) {
|
||||
core.getLogger().warning("初始化SQLManager(#" + id + ") 出错,请检查配置文件.");
|
||||
exception.printStackTrace();
|
||||
core.getLogger().info("完成成初始化数据库 #" + id + " 。");
|
||||
} catch (Exception ex) {
|
||||
core.getLogger().severe("初始化SQLManager(#" + id + ") 出错,请检查配置文件: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
dbConfigurations.forEach((id, configuration) -> {
|
||||
try {
|
||||
core.getLogger().info("正在初始化数据库 #" + id + " ...");
|
||||
SQLManagerImpl sqlManager = create(id, configuration);
|
||||
this.managers.put(id, sqlManager);
|
||||
} catch (Exception exception) {
|
||||
core.getLogger().warning("初始化SQLManager(#" + id + ") 出错,请检查配置文件.");
|
||||
exception.printStackTrace();
|
||||
core.getLogger().info("完成初始化数据库 #" + id + " 。");
|
||||
} catch (Exception ex) {
|
||||
core.getLogger().severe("初始化SQLManager(#" + id + ") 出错,请检查配置文件: " + ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -69,7 +73,8 @@ public class MineSQLRegistry implements SQLRegistry {
|
||||
this.managers.forEach((k, manager) -> {
|
||||
getCore().getLogger().info(" 正在关闭数据库 " + k + "...");
|
||||
shutdown(manager, activeQueries -> {
|
||||
getCore().getLogger().info(" 数据库 " + k + " 仍有有 " + activeQueries + " 条活动查询");
|
||||
if (activeQueries.isEmpty()) return;
|
||||
getCore().getLogger().info(" 数据库 " + k + " 仍有 " + activeQueries.size() + " 条活动查询");
|
||||
if (manager.getDataSource() instanceof BeeDataSource
|
||||
&& this.core.getConfig().SETTINGS.FORCE_CLOSE.getNotNull()) {
|
||||
getCore().getLogger().info(" 将强制关闭全部活跃链接...");
|
||||
|
||||
+3
-3
@@ -15,13 +15,13 @@ import java.util.UUID;
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@CommandAlias("EasySQL")
|
||||
@CommandAlias("MineSQL")
|
||||
@Description("MineSQL的主指令,用于开发者进行调试,只允许后台执行。")
|
||||
public class EasySQLCommand extends BaseCommand {
|
||||
public class MineSQLCommand extends BaseCommand {
|
||||
|
||||
protected final MineSQLCore core;
|
||||
|
||||
public EasySQLCommand(MineSQLCore core) {
|
||||
public MineSQLCommand(MineSQLCore core) {
|
||||
this.core = core;
|
||||
}
|
||||
|
||||
+2
-2
@@ -2,9 +2,9 @@ package cc.carm.plugin.minesql.command;
|
||||
|
||||
import co.aikar.commands.*;
|
||||
|
||||
public class EasySQLHelpFormatter extends CommandHelpFormatter {
|
||||
public class MineSQLHelpFormatter extends CommandHelpFormatter {
|
||||
|
||||
public EasySQLHelpFormatter(CommandManager manager) {
|
||||
public MineSQLHelpFormatter(CommandManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ public class PluginConfiguration extends ConfigurationRoot {
|
||||
.asValue(SQLSourceGroup.class).fromSection()
|
||||
.parseValue((w, d) -> SQLSourceGroup.parse(w))
|
||||
.serializeValue(SQLSourceGroup::serialize)
|
||||
.defaults(SQLSourceGroup.defaults())
|
||||
.build();
|
||||
|
||||
public static class PropertiesConfig extends ConfigurationRoot {
|
||||
|
||||
@@ -32,6 +32,18 @@ public class SQLSourceGroup {
|
||||
return data;
|
||||
}
|
||||
|
||||
public static @NotNull SQLSourceGroup defaults() {
|
||||
LinkedHashMap<String, SQLDriverConfig> configs = new LinkedHashMap<>();
|
||||
configs.put("example-mysql", new RemoteAuthConfig(
|
||||
SQLDriverType.MARIADB, "127.0.0.1", 3306,
|
||||
"minecraft", "minecraft", "minecraft",
|
||||
"?sslMode=false"
|
||||
));
|
||||
configs.put("example-h2-file", new FileBasedConfig(SQLDriverType.H2_FILE, "test"));
|
||||
configs.put("example-h2-mem", new H2MemConfig("temp"));
|
||||
return new SQLSourceGroup(configs);
|
||||
}
|
||||
|
||||
public static @NotNull SQLSourceGroup parse(ConfigurationWrapper<?> rootSection) {
|
||||
LinkedHashMap<String, SQLDriverConfig> configs = new LinkedHashMap<>();
|
||||
for (String name : rootSection.getKeys(false)) {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -69,7 +69,6 @@
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-main</artifactId>
|
||||
<version>${deps.easyplugin.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -84,7 +83,6 @@
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -92,7 +90,6 @@
|
||||
<groupId>co.aikar</groupId>
|
||||
<artifactId>acf-paper</artifactId>
|
||||
<version>0.5.1-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -22,9 +22,6 @@ public class MineSQLBukkit extends EasyPlugin implements MineSQLPlatform {
|
||||
|
||||
log("加载基础核心...");
|
||||
this.core = new MineSQLCore(this);
|
||||
|
||||
log("初始化MineSQL API...");
|
||||
MineSQL.initializeAPI(this.core);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -94,7 +94,6 @@
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bungeecord</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -102,7 +101,6 @@
|
||||
<groupId>co.aikar</groupId>
|
||||
<artifactId>acf-bungee</artifactId>
|
||||
<version>0.5.1-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -25,9 +25,6 @@ public class MineSQLBungee extends Plugin implements MineSQLPlatform {
|
||||
|
||||
getLogger().info("加载基础核心...");
|
||||
this.core = new MineSQLCore(this);
|
||||
|
||||
getLogger().info("初始化MineSQL API...");
|
||||
MineSQL.initializeAPI(this.core);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@@ -66,6 +66,7 @@
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>minesql-core</artifactId>
|
||||
@@ -73,6 +74,7 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!--suppress VulnerableLibrariesLocal -->
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
@@ -85,16 +87,13 @@
|
||||
<artifactId>bstats-velocity</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>co.aikar</groupId>
|
||||
<artifactId>acf-velocity</artifactId>
|
||||
<version>0.5.1-SNAPSHOT</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
@@ -53,9 +53,6 @@ public class MineSQLVelocity implements MineSQLPlatform {
|
||||
|
||||
getLogger().info("加载基础核心...");
|
||||
this.core = new MineSQLCore(this);
|
||||
|
||||
getLogger().info("初始化MineSQL API...");
|
||||
MineSQL.initializeAPI(this.core);
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
|
||||
+66
-1
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<properties>
|
||||
@@ -45,6 +45,18 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
@@ -79,6 +91,20 @@
|
||||
<pattern>cc.carm.lib.githubreleases4j</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.githubreleases4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib.configuration</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.configuration</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.bspfsystems.yamlconfiguration</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.configuration.yaml
|
||||
</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.yaml.snakeyaml</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.yaml</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>co.aikar.commands</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.acf</shadedPattern> <!-- Replace this -->
|
||||
@@ -87,6 +113,45 @@
|
||||
<pattern>co.aikar.locales</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.locales</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cn.beecp</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.beecp</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>org.h2</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.driver.h2</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.mariadb</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.driver.mariadb</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.mysql</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.driver.mysql</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
|
||||
<relocation>
|
||||
<pattern>com.sun.jna</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.jna</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.google</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.google</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>com.github</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.github</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.checkerframework</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.checkerframework</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>waffle</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.waffle</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
|
||||
</relocations>
|
||||
<filters>
|
||||
<filter>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<version>1.0.0</version>
|
||||
<modules>
|
||||
<module>api</module>
|
||||
<module>core</module>
|
||||
@@ -182,14 +182,7 @@
|
||||
<configuration>
|
||||
<filesets>
|
||||
<fileset>
|
||||
<directory>${project.basedir}/asset/</directory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
</fileset>
|
||||
<fileset>
|
||||
<directory>${project.basedir}/api-docs/</directory>
|
||||
<directory>${project.basedir}/.asset/</directory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
|
||||
Reference in New Issue
Block a user