mirror of
https://github.com/CarmJos/MineSQL.git
synced 2026-06-05 00:48:16 +08:00
feat(proj): 项目完成,测试使用。
This commit is contained in:
+17
-68
@@ -3,7 +3,7 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>easysql-plugin</artifactId>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
@@ -19,12 +19,12 @@
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<artifactId>easysql-plugin-bukkit</artifactId>
|
||||
<artifactId>minesql-bukkit</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EasySQL-Plugin-Bukkit</name>
|
||||
<name>MineSQL-Bukkit</name>
|
||||
<description>轻松(用)SQL的独立运行库Bukkit版本插件。</description>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin</url>
|
||||
<url>https://github.com/CarmJos/MineSQL</url>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
@@ -48,19 +48,19 @@
|
||||
|
||||
<issueManagement>
|
||||
<system>GitHub Issues</system>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin/issues</url>
|
||||
<url>https://github.com/CarmJos/MineSQL/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<ciManagement>
|
||||
<system>GitHub Actions</system>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin/actions/workflows/maven.yml</url>
|
||||
<url>https://github.com/CarmJos/MineSQL/actions/workflows/maven.yml</url>
|
||||
</ciManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easysql-plugin-core</artifactId>
|
||||
<artifactId>minesql-core</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@@ -68,7 +68,7 @@
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-main</artifactId>
|
||||
<version>${easyplugin.version}</version>
|
||||
<version>${deps.easyplugin.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@@ -102,66 +102,15 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
<configuration>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
<outputDirectory>${project.parent.basedir}/asset/</outputDirectory>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.json</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.json</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib.easyplugin</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.easyplugin</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib.githubreleases4j</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.githubreleases4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>co.aikar.commands</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.acf</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>co.aikar.locales</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.locales</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
</relocations>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>co.aikar:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
<exclude>META-INF/*.txt</exclude>
|
||||
<exclude>acf-core*.properties</exclude>
|
||||
<exclude>acf-minecraft*.properties</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
<exclude>META-INF/*.txt</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
<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>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
package cc.carm.plugin.minesql;
|
||||
|
||||
import cc.carm.plugin.minesql.api.DBConfiguration;
|
||||
import cc.carm.plugin.minesql.api.SQLDriverType;
|
||||
import cc.carm.plugin.minesql.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) {
|
||||
MineSQLBukkit.getInstance().error("不存在预设的驱动类型 " + driverString + "," + " 请检查配置文件 databases." + dbName + "。");
|
||||
continue;
|
||||
}
|
||||
String host = dbSection.getString("host");
|
||||
if (host == null) {
|
||||
MineSQLBukkit.getInstance().error("地址配置不得为空," + " 请检查配置文件 databases." + dbName + "。");
|
||||
continue;
|
||||
}
|
||||
|
||||
int port = dbSection.getInt("port", -1);
|
||||
if (port < 0) {
|
||||
MineSQLBukkit.getInstance().error("端口未配置正确," + " 请检查配置文件 databases." + dbName + "。");
|
||||
continue;
|
||||
}
|
||||
DBConfiguration dbConfiguration = DBConfiguration.create(driverType, host + ":" + port);
|
||||
|
||||
String username = dbSection.getString("username");
|
||||
String password = dbSection.getString("password");
|
||||
|
||||
dbConfiguration.setUsername(username);
|
||||
dbConfiguration.setPassword(password);
|
||||
|
||||
dbConfigurations.put(dbName, dbConfiguration);
|
||||
}
|
||||
}
|
||||
return dbConfigurations;
|
||||
}
|
||||
}
|
||||
@@ -1,147 +1,88 @@
|
||||
package cc.carm.plugin.minesql;
|
||||
|
||||
import cc.carm.lib.easyplugin.EasyPlugin;
|
||||
import cc.carm.lib.easyplugin.i18n.EasyPluginMessageProvider;
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.plugin.minesql.api.DBConfiguration;
|
||||
import cc.carm.plugin.minesql.util.DBPropertiesUtil;
|
||||
import cc.carm.plugin.minesql.util.JarResourceUtils;
|
||||
import cn.beecp.BeeDataSource;
|
||||
import cc.carm.plugin.minesql.conf.PluginConfiguration;
|
||||
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 MineSQLBukkit extends EasyPlugin implements MineSQLPlatform {
|
||||
|
||||
public MineSQLBukkit() {
|
||||
super(new EasyPluginMessageProvider.zh_CN());
|
||||
}
|
||||
|
||||
protected static MineSQLBukkit instance;
|
||||
|
||||
private BukkitConfiguration configuration;
|
||||
private MineSQLRegistry registry;
|
||||
|
||||
private PaperCommandManager commandManager;
|
||||
protected MineSQLCore core;
|
||||
protected PaperCommandManager commandManager;
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
MineSQLBukkit.instance = this;
|
||||
|
||||
log("加载配置文件...");
|
||||
getInstance().saveDefaultConfig();
|
||||
this.configuration = new BukkitConfiguration(getInstance().getConfig());
|
||||
log("加载基础核心...");
|
||||
this.core = new MineSQLCore(this);
|
||||
|
||||
log("初始化EasySQL注册器...");
|
||||
this.registry = new MineSQLRegistry(this);
|
||||
|
||||
log("初始化EasySQLAPI...");
|
||||
initializeAPI(getRegistry()); // 尽快地初始化接口,方便其他插件调用
|
||||
log("初始化MineSQL API...");
|
||||
MineSQL.initializeAPI(this.core);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean initialize() {
|
||||
log("初始化指令管理器...");
|
||||
this.commandManager = new PaperCommandManager(this);
|
||||
log("注册相关指令...");
|
||||
initializeCommands(getCommandManager());
|
||||
|
||||
if (getConfiguration().isMetricsEnabled()) {
|
||||
log("注册相关指令...");
|
||||
this.core.initializeCommands(getCommandManager());
|
||||
|
||||
if (getConfiguration().METRICS.getNotNull()) {
|
||||
log("启用统计数据...");
|
||||
Metrics metrics = new Metrics(this, 14075);
|
||||
metrics.addCustomChart(new SimplePie("update_check",
|
||||
() -> getConfiguration().isUpdateCheckerEnabled() ? "ENABLED" : "DISABLED")
|
||||
() -> getConfiguration().UPDATE_CHECKER.getNotNull() ? "ENABLED" : "DISABLED")
|
||||
);
|
||||
metrics.addCustomChart(new SimplePie("properties_configuration",
|
||||
() -> getConfiguration().isPropertiesEnabled() ? "ENABLED" : "DISABLED")
|
||||
() -> getConfiguration().PROPERTIES.ENABLE.getNotNull() ? "ENABLED" : "DISABLED")
|
||||
);
|
||||
}
|
||||
|
||||
if (getConfiguration().isUpdateCheckerEnabled()) {
|
||||
log("开始检查更新...");
|
||||
getRegistry().checkUpdate(getDescription().getVersion());
|
||||
if (getConfiguration().PROPERTIES.ENABLE.getNotNull()) {
|
||||
log("开始检查更新,可能需要一小段时间...");
|
||||
log(" 如不希望检查更新,可在配置文件中关闭。");
|
||||
getScheduler().runAsync(() -> this.core.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
|
||||
this.core.getRegistry().shutdownAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugging() {
|
||||
return getConfiguration().isDebugEnabled();
|
||||
return getConfiguration().DEBUG.getNotNull();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public MineSQLRegistry 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 MineSQLBukkit getInstance() {
|
||||
public static @NotNull MineSQLBukkit getInstance() {
|
||||
return MineSQLBukkit.instance;
|
||||
}
|
||||
|
||||
protected BukkitConfiguration getConfiguration() {
|
||||
return configuration;
|
||||
public @NotNull PluginConfiguration getConfiguration() {
|
||||
return this.core.getConfig();
|
||||
}
|
||||
|
||||
protected PaperCommandManager getCommandManager() {
|
||||
public @NotNull PaperCommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull File getPluginFolder() {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
main: cc.carm.plugin.easysql.EasySQLBukkit
|
||||
main: cc.carm.plugin.minesql.MineSQLBukkit
|
||||
version: ${project.version}
|
||||
prefix: EasySQL-Plugin
|
||||
name: EasySQL-Plugin
|
||||
|
||||
prefix: MineSQL
|
||||
name: MineSQL
|
||||
load: STARTUP
|
||||
|
||||
website: ${project.url}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>easysql-plugin</artifactId>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
@@ -19,12 +19,12 @@
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<artifactId>easysql-plugin-bungee</artifactId>
|
||||
<artifactId>minesql-bungee</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EasySQL-Plugin-Bungee</name>
|
||||
<name>MineSQL-Bungee</name>
|
||||
<description>轻松(用)SQL的独立运行库Bungee版本插件。</description>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin</url>
|
||||
<url>https://github.com/CarmJos/MineSQL</url>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
@@ -48,12 +48,12 @@
|
||||
|
||||
<issueManagement>
|
||||
<system>GitHub Issues</system>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin/issues</url>
|
||||
<url>https://github.com/CarmJos/MineSQL/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<ciManagement>
|
||||
<system>GitHub Actions</system>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin/actions/workflows/maven.yml</url>
|
||||
<url>https://github.com/CarmJos/MineSQL/actions/workflows/maven.yml</url>
|
||||
</ciManagement>
|
||||
|
||||
<repositories>
|
||||
@@ -69,7 +69,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easysql-plugin-core</artifactId>
|
||||
<artifactId>minesql-core</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@@ -108,7 +108,6 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -123,60 +122,6 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
<outputDirectory>${project.parent.basedir}/asset/</outputDirectory>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
<exclude>META-INF/*.txt</exclude>
|
||||
<exclude>acf-minecraft*.properties</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.json</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.json</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib.githubreleases4j</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.githubreleases4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>co.aikar.commands</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.acf</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>co.aikar.locales</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.locales</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
package cc.carm.plugin.minesql;
|
||||
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import net.md_5.bungee.config.ConfigurationProvider;
|
||||
import net.md_5.bungee.config.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class EasySQLBungee extends Plugin {
|
||||
|
||||
private boolean setup = false;
|
||||
|
||||
private void saveDefaultConfig() {
|
||||
if (!getDataFolder().exists())
|
||||
getDataFolder().mkdir();
|
||||
|
||||
File file = new File(getDataFolder(), "config.yml");
|
||||
|
||||
|
||||
if (!file.exists()) {
|
||||
try (InputStream in = getResourceAsStream("config.yml")) {
|
||||
Files.copy(in, file.toPath());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setup() {
|
||||
if (setup) return;
|
||||
saveDefaultConfig();
|
||||
// 读取配置文件 - 预注册 instance
|
||||
Configuration configuration;
|
||||
try {
|
||||
configuration = ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(getDataFolder(), "config.yml"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
Configuration instancesConfig = configuration.getSection("instances");
|
||||
if (instancesConfig != null) {
|
||||
}
|
||||
setup = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getLogger().info("Shutting down...");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package cc.carm.plugin.minesql;
|
||||
|
||||
import cc.carm.plugin.minesql.conf.PluginConfiguration;
|
||||
import co.aikar.commands.BungeeCommandManager;
|
||||
import co.aikar.commands.CommandManager;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class MineSQLBungee extends Plugin implements MineSQLPlatform {
|
||||
|
||||
protected static MineSQLBungee instance;
|
||||
|
||||
protected MineSQLCore core;
|
||||
protected BungeeCommandManager commandManager;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
MineSQLBungee.instance = this;
|
||||
|
||||
getLogger().info("加载基础核心...");
|
||||
this.core = new MineSQLCore(this);
|
||||
|
||||
getLogger().info("初始化MineSQL API...");
|
||||
MineSQL.initializeAPI(this.core);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getLogger().info("初始化指令管理器...");
|
||||
this.commandManager = new BungeeCommandManager(this);
|
||||
|
||||
getLogger().info("注册相关指令...");
|
||||
this.core.initializeCommands(getCommandManager());
|
||||
|
||||
if (getConfiguration().METRICS.getNotNull()) {
|
||||
getLogger().info("启用统计数据...");
|
||||
Metrics metrics = new Metrics(this, 14076);
|
||||
metrics.addCustomChart(new SimplePie("update_check",
|
||||
() -> getConfiguration().UPDATE_CHECKER.getNotNull() ? "ENABLED" : "DISABLED")
|
||||
);
|
||||
metrics.addCustomChart(new SimplePie("properties_configuration",
|
||||
() -> getConfiguration().PROPERTIES.ENABLE.getNotNull() ? "ENABLED" : "DISABLED")
|
||||
);
|
||||
}
|
||||
|
||||
if (getConfiguration().PROPERTIES.ENABLE.getNotNull()) {
|
||||
getLogger().info("开始检查更新,可能需要一小段时间...");
|
||||
getLogger().info(" 如不希望检查更新,可在配置文件中关闭。");
|
||||
ProxyServer.getInstance().getScheduler().runAsync(
|
||||
this, () -> this.core.checkUpdate(getDescription().getVersion())
|
||||
);
|
||||
} else {
|
||||
getLogger().info("已禁用检查更新,跳过。");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
getLogger().info("终止全部数据库连接...");
|
||||
this.core.getRegistry().shutdownAll();
|
||||
}
|
||||
|
||||
public static MineSQLBungee getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Logger getLogger() {
|
||||
return super.getLogger();
|
||||
}
|
||||
|
||||
public @NotNull PluginConfiguration getConfiguration() {
|
||||
return this.core.getConfig();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull File getPluginFolder() {
|
||||
return getDataFolder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CommandManager<?, ?, ?, ?, ?, ?> getCommandManager() {
|
||||
return this.commandManager;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
main: cc.carm.plugin.minesql.MineSQLBungee
|
||||
name: MineSQL
|
||||
version: ${project.version}
|
||||
|
||||
website: ${project.url}
|
||||
description: ${project.description}
|
||||
|
||||
author: "CarmJos"
|
||||
@@ -1,165 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>easysql-plugin</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>${project.jdk.version}</maven.compiler.source>
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<maven.javadoc.skip>true</maven.javadoc.skip>
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<artifactId>easysql-plugin-sponge</artifactId>
|
||||
|
||||
<name>EasySQL-Plugin-Sponge</name>
|
||||
<description>轻松(用)SQL的独立运行库Sponge版本插件。</description>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin</url>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
<id>CarmJos</id>
|
||||
<name>Carm Jos</name>
|
||||
<email>carm@carm.cc</email>
|
||||
<url>https://www.carm.cc</url>
|
||||
<roles>
|
||||
<role>Main Developer</role>
|
||||
<role>Designer</role>
|
||||
</roles>
|
||||
</developer>
|
||||
</developers>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>GNU General Public License v3.0</name>
|
||||
<url>https://opensource.org/licenses/GPL-3.0</url>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<issueManagement>
|
||||
<system>GitHub Issues</system>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<ciManagement>
|
||||
<system>GitHub Actions</system>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin/actions/workflows/maven.yml</url>
|
||||
</ciManagement>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>sponge</id>
|
||||
<url>http://repo.spongepowered.org/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easysql-plugin-core</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spongepowered</groupId>
|
||||
<artifactId>spongeapi</artifactId>
|
||||
<version>8.0.0</version>
|
||||
<scope>provided</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>ninja.leaping.configurate</groupId>
|
||||
<artifactId>configurate-hocon</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-sponge</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<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-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
<outputDirectory>${project.parent.basedir}/asset/</outputDirectory>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
<exclude>META-INF/*.txt</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.bstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.json</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.json</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cc.carm.lib.githubreleases4j</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.githubreleases4j</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>co.aikar.commands</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.acf</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>co.aikar.locales</pattern>
|
||||
<shadedPattern>cc.carm.plugin.minesql.lib.locales</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,184 +0,0 @@
|
||||
package cc.carm.plugin.minesql;
|
||||
|
||||
import cc.carm.lib.easysql.api.SQLManager;
|
||||
import cc.carm.plugin.minesql.api.DBConfiguration;
|
||||
import cc.carm.plugin.minesql.configuration.PluginConfiguration;
|
||||
import cc.carm.plugin.minesql.util.DBPropertiesUtil;
|
||||
import cc.carm.plugin.minesql.util.JarResourceUtils;
|
||||
import cn.beecp.BeeDataSource;
|
||||
import com.google.common.io.MoreFiles;
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bstats.sponge.Metrics;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.api.Server;
|
||||
import org.spongepowered.api.config.ConfigDir;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent;
|
||||
import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.hocon.HoconConfigurationLoader;
|
||||
import org.spongepowered.plugin.PluginContainer;
|
||||
import org.spongepowered.plugin.builtin.jvm.Plugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* 2022/6/20<br>
|
||||
* MineSQL<br>
|
||||
*
|
||||
* @author huanmeng_qwq
|
||||
*/
|
||||
@Plugin("easysql-plugin")
|
||||
public class MineSQLSponge implements MineSQLPlatform {
|
||||
@Inject
|
||||
@ConfigDir(sharedRoot = false)
|
||||
private Path configDirectory;
|
||||
@Inject
|
||||
private org.apache.logging.log4j.Logger logger;
|
||||
|
||||
private static MineSQLSponge instance;
|
||||
private ConfigurationNode root;
|
||||
private PluginConfiguration configuration;
|
||||
private MineSQLRegistry registry;
|
||||
private PluginContainer pluginContainer;
|
||||
|
||||
private final Metrics metrics;
|
||||
|
||||
@Inject
|
||||
public MineSQLSponge(Metrics.Factory factory, PluginContainer pluginContainer) {
|
||||
this.metrics = factory.make(14075);
|
||||
instance = this;
|
||||
HoconConfigurationLoader loader = HoconConfigurationLoader.builder().path(resolveConfig()).build();
|
||||
try {
|
||||
this.root = loader.load();
|
||||
this.configuration = new SpongeConfiguration(root);
|
||||
this.registry = new MineSQLRegistry(this);
|
||||
this.pluginContainer = pluginContainer;
|
||||
enable();
|
||||
} catch (ConfigurateException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Listener
|
||||
public void disable(StoppingEngineEvent<Server> e) {
|
||||
getLog().info("终止全部数据库连接...");
|
||||
for (String dbName : new HashSet<>(getRegistry().list().keySet())) {
|
||||
getLog().info(" 正在关闭数据库 " + dbName + "...");
|
||||
SQLManager manager = getRegistry().get(dbName);
|
||||
getRegistry().shutdown(manager, activeQueries -> {
|
||||
getLog().info(" 数据库 " + dbName + " 仍有有 " + activeQueries + " 条活动查询,强制关闭中...");
|
||||
if (manager.getDataSource() instanceof BeeDataSource) {
|
||||
BeeDataSource dataSource = (BeeDataSource) manager.getDataSource();
|
||||
dataSource.close(); //Close bee connection pool
|
||||
}
|
||||
});
|
||||
}
|
||||
getRegistry().getManagers().clear(); // release all managers
|
||||
}
|
||||
|
||||
|
||||
public void enable() {
|
||||
/*
|
||||
//todo acf-commands not support sponge8
|
||||
getLog().info("初始化指令管理器...");
|
||||
getLog().info("注册相关指令...");
|
||||
*/
|
||||
|
||||
if (getConfiguration().isMetricsEnabled()) {
|
||||
getLog().info("启用统计数据...");
|
||||
metrics.addCustomChart(new SimplePie("update_check",
|
||||
() -> getConfiguration().isUpdateCheckerEnabled() ? "ENABLED" : "DISABLED")
|
||||
);
|
||||
metrics.addCustomChart(new SimplePie("properties_configuration",
|
||||
() -> getConfiguration().isPropertiesEnabled() ? "ENABLED" : "DISABLED")
|
||||
);
|
||||
}
|
||||
|
||||
if (getConfiguration().isUpdateCheckerEnabled()) {
|
||||
getLog().info("开始检查更新...");
|
||||
getRegistry().checkUpdate(pluginContainer.metadata().version().getQualifier());
|
||||
} else {
|
||||
getLog().info("已禁用检查更新,跳过。");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, DBConfiguration> readConfigurations() {
|
||||
return configuration.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(configDirectory.toFile(), propertiesFolder);
|
||||
if (!file.exists() || !file.isDirectory()) {
|
||||
try {
|
||||
JarResourceUtils.copyFolderFromJar(
|
||||
"db-properties", file,
|
||||
JarResourceUtils.CopyOption.COPY_IF_NOT_EXIST
|
||||
);
|
||||
} catch (Exception ex) {
|
||||
logger.error("初始化properties示例文件失败:" + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return DBPropertiesUtil.readFromFolder(file);
|
||||
}
|
||||
|
||||
|
||||
private Path resolveConfig() {
|
||||
Path path = configDirectory.resolve("easysql.conf");
|
||||
if (!Files.exists(path)) {
|
||||
try {
|
||||
//noinspection UnstableApiUsage
|
||||
MoreFiles.createParentDirectories(configDirectory);
|
||||
try (InputStream is = getClass().getClassLoader().getResourceAsStream("easysql.conf")) {
|
||||
Files.copy(is, path);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
public ConfigurationNode getRootConfig() {
|
||||
return root;
|
||||
}
|
||||
|
||||
public PluginConfiguration getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull MineSQLRegistry getRegistry() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
public java.util.logging.Logger getLogger() {
|
||||
return java.util.logging.Logger.getLogger("easysql-plugin");
|
||||
}
|
||||
|
||||
public static MineSQLSponge getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Logger getLog() {
|
||||
return logger;
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
package cc.carm.plugin.minesql;
|
||||
|
||||
import cc.carm.plugin.minesql.api.DBConfiguration;
|
||||
import cc.carm.plugin.minesql.api.SQLDriverType;
|
||||
import cc.carm.plugin.minesql.configuration.PluginConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 2022/6/20<br>
|
||||
* MineSQL<br>
|
||||
*
|
||||
* @author huanmeng_qwq
|
||||
*/
|
||||
public class SpongeConfiguration implements PluginConfiguration {
|
||||
private final ConfigurationNode config;
|
||||
|
||||
public SpongeConfiguration(ConfigurationNode config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugEnabled() {
|
||||
return config.node("debug").getBoolean(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMetricsEnabled() {
|
||||
return config.node("metrics").getBoolean(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdateCheckerEnabled() {
|
||||
return config.node("check-update").getBoolean(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPropertiesEnabled() {
|
||||
return config.node("properties", "enable").getBoolean(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPropertiesFolder() {
|
||||
return config.node("properties", "folder").getString("db-properties/");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Map<String, DBConfiguration> getDBConfigurations() {
|
||||
Map<String, DBConfiguration> dbConfigurations = new LinkedHashMap<>();
|
||||
ConfigurationNode dbConfigurationsSection = config.node("databases");
|
||||
if (dbConfigurationsSection != null) {
|
||||
for (Map.Entry<Object, ? extends ConfigurationNode> dbEntry : dbConfigurationsSection.childrenMap().entrySet()) {
|
||||
if (dbEntry.getKey().toString().startsWith("example-")) continue;
|
||||
ConfigurationNode dbSection = dbEntry.getValue();
|
||||
if (dbSection == null) continue;
|
||||
|
||||
String driverString = dbSection.getString("driver-type");
|
||||
SQLDriverType driverType = SQLDriverType.parse(driverString);
|
||||
if (driverType == null) {
|
||||
MineSQLSponge.getInstance().getLog().error("不存在预设的驱动类型 " + driverString + "," + " 请检查配置文件 databases." + dbEntry + "。");
|
||||
continue;
|
||||
}
|
||||
String host = dbSection.getString("host");
|
||||
if (host == null) {
|
||||
MineSQLSponge.getInstance().getLog().error("地址配置不得为空," + " 请检查配置文件 databases." + dbEntry + "。");
|
||||
continue;
|
||||
}
|
||||
|
||||
int port = dbSection.node("port").getInt(-1);
|
||||
if (port < 0) {
|
||||
MineSQLSponge.getInstance().getLog().error("端口未配置正确," + " 请检查配置文件 databases." + dbEntry + "。");
|
||||
continue;
|
||||
}
|
||||
DBConfiguration dbConfiguration = DBConfiguration.create(driverType, host + ":" + port);
|
||||
|
||||
String username = dbSection.getString("username");
|
||||
String password = dbSection.getString("password");
|
||||
|
||||
dbConfiguration.setUsername(username);
|
||||
dbConfiguration.setPassword(password);
|
||||
dbConfigurations.put(dbEntry.getKey().toString(), dbConfiguration);
|
||||
}
|
||||
}
|
||||
return dbConfigurations;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
debug = false
|
||||
metrics = false
|
||||
check-update = true
|
||||
properties {
|
||||
enable = true
|
||||
folder = "db-properties/"
|
||||
}
|
||||
databases {
|
||||
example-test {
|
||||
driver-type = "MYSQL"
|
||||
host = "localhost"
|
||||
port = -1
|
||||
username = "root"
|
||||
password = "root"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>easysql-plugin</artifactId>
|
||||
<artifactId>minesql-parent</artifactId>
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<version>0.0.3-SNAPSHOT</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
@@ -19,12 +19,12 @@
|
||||
<maven.deploy.skip>true</maven.deploy.skip>
|
||||
</properties>
|
||||
|
||||
<artifactId>easysql-plugin-velocity</artifactId>
|
||||
<artifactId>minesql-velocity</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EasySQL-Plugin-Velocity</name>
|
||||
<name>MineSQL-Velocity</name>
|
||||
<description>轻松(用)SQL的独立运行库Velocity版本插件。</description>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin</url>
|
||||
<url>https://github.com/CarmJos/MineSQL</url>
|
||||
|
||||
<developers>
|
||||
<developer>
|
||||
@@ -48,12 +48,12 @@
|
||||
|
||||
<issueManagement>
|
||||
<system>GitHub Issues</system>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin/issues</url>
|
||||
<url>https://github.com/CarmJos/MineSQL/issues</url>
|
||||
</issueManagement>
|
||||
|
||||
<ciManagement>
|
||||
<system>GitHub Actions</system>
|
||||
<url>https://github.com/CarmJos/EasySQL-Plugin/actions/workflows/maven.yml</url>
|
||||
<url>https://github.com/CarmJos/MineSQL/actions/workflows/maven.yml</url>
|
||||
</ciManagement>
|
||||
|
||||
<repositories>
|
||||
@@ -68,7 +68,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>${project.parent.groupId}</groupId>
|
||||
<artifactId>easysql-plugin-core</artifactId>
|
||||
<artifactId>minesql-core</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
@@ -97,9 +97,9 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -114,37 +114,6 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
<outputDirectory>${project.parent.basedir}/asset/</outputDirectory>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<filters>
|
||||
<filter>
|
||||
<artifact>*:*</artifact>
|
||||
<excludes>
|
||||
<exclude>META-INF/MANIFEST.MF</exclude>
|
||||
<exclude>META-INF/*.txt</exclude>
|
||||
</excludes>
|
||||
</filter>
|
||||
</filters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package cc.carm.plugin.minesql;
|
||||
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
@Plugin(id = "easysql-plugin", name = "EasySQL-Plugin",
|
||||
version = "1.0.0",
|
||||
description = "EasySQL Plugin For Velocity",
|
||||
url = "https://github.com/CarmJos/EasySQL-Plugin",
|
||||
authors = {"CarmJos", "GhostChu"}
|
||||
)
|
||||
public class EasySQLVelocity {
|
||||
|
||||
private static EasySQLVelocity instance;
|
||||
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
|
||||
@Inject
|
||||
public EasySQLVelocity(ProxyServer server, Logger logger) {
|
||||
instance = this;
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
// register listeners
|
||||
server.getEventManager().register(this, this);
|
||||
}
|
||||
|
||||
public static EasySQLVelocity getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ProxyServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onInitialize(ProxyInitializeEvent event) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package cc.carm.plugin.minesql;
|
||||
|
||||
|
||||
import cc.carm.plugin.minesql.conf.PluginConfiguration;
|
||||
import co.aikar.commands.CommandManager;
|
||||
import co.aikar.commands.VelocityCommandManager;
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.PluginContainer;
|
||||
import com.velocitypowered.api.plugin.PluginDescription;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bstats.velocity.Metrics;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
@Plugin(id = "minesql", name = "MineSQL (EasySQL-Plugin)", version = "1.0.0",
|
||||
description = "EasySQL Plugin For Velocity",
|
||||
url = "https://github.com/CarmJos/MineSQL",
|
||||
authors = {"CarmJos", "GhostChu"}
|
||||
)
|
||||
public class MineSQLVelocity implements MineSQLPlatform {
|
||||
|
||||
private static MineSQLVelocity instance;
|
||||
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private final File dataFolder;
|
||||
|
||||
private final Metrics.Factory metricsFactory;
|
||||
|
||||
protected MineSQLCore core;
|
||||
protected VelocityCommandManager commandManager;
|
||||
|
||||
@Inject
|
||||
public MineSQLVelocity(ProxyServer server, Logger logger,
|
||||
@DataDirectory Path dataDirectory,
|
||||
Metrics.Factory metricsFactory) {
|
||||
instance = this;
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
this.dataFolder = dataDirectory.toFile();
|
||||
this.metricsFactory = metricsFactory;
|
||||
|
||||
getLogger().info("加载基础核心...");
|
||||
this.core = new MineSQLCore(this);
|
||||
|
||||
getLogger().info("初始化MineSQL API...");
|
||||
MineSQL.initializeAPI(this.core);
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onInitialize(ProxyInitializeEvent event) {
|
||||
|
||||
getLogger().info("初始化指令管理器...");
|
||||
this.commandManager = new VelocityCommandManager(server, this);
|
||||
|
||||
getLogger().info("注册相关指令...");
|
||||
this.core.initializeCommands(getCommandManager());
|
||||
|
||||
if (getConfiguration().METRICS.getNotNull()) {
|
||||
getLogger().info("启用统计数据...");
|
||||
Metrics metrics = this.metricsFactory.make(this, 14078);
|
||||
metrics.addCustomChart(new SimplePie("update_check",
|
||||
() -> getConfiguration().UPDATE_CHECKER.getNotNull() ? "ENABLED" : "DISABLED")
|
||||
);
|
||||
metrics.addCustomChart(new SimplePie("properties_configuration",
|
||||
() -> getConfiguration().PROPERTIES.ENABLE.getNotNull() ? "ENABLED" : "DISABLED")
|
||||
);
|
||||
}
|
||||
|
||||
if (getConfiguration().PROPERTIES.ENABLE.getNotNull()) {
|
||||
getLogger().info("开始检查更新,可能需要一小段时间...");
|
||||
getLogger().info(" 如不希望检查更新,可在配置文件中关闭。");
|
||||
server.getScheduler().buildTask(this, () -> this.core.checkUpdate(getVersion())).schedule();
|
||||
} else {
|
||||
getLogger().info("已禁用检查更新,跳过。");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
public void onShutdown(ProxyShutdownEvent event) {
|
||||
getLogger().info("终止全部数据库连接...");
|
||||
this.core.getRegistry().shutdownAll();
|
||||
}
|
||||
|
||||
public static MineSQLVelocity getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public ProxyServer getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.server.getPluginManager().getPlugin("minesql")
|
||||
.map(PluginContainer::getDescription)
|
||||
.flatMap(PluginDescription::getVersion).orElse("1.0.0");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull File getPluginFolder() {
|
||||
return this.dataFolder;
|
||||
}
|
||||
|
||||
public @NotNull Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull CommandManager<?, ?, ?, ?, ?, ?> getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
||||
public @NotNull PluginConfiguration getConfiguration() {
|
||||
return this.core.getConfig();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user