1
mirror of https://github.com/CarmJos/MineSQL.git synced 2026-06-04 16:43:03 +08:00

fix(load): 修复插件加载时出现的问题

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