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

修改文件夹名称

This commit is contained in:
2022-03-13 19:42:48 +08:00
parent aa83feea05
commit a2ab7d4d9f
31 changed files with 7 additions and 7 deletions
+169
View File
@@ -0,0 +1,169 @@
<?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>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.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-bukkit</artifactId>
<packaging>jar</packaging>
<name>EasySQL-Plugin-Bukkit</name>
<description>轻松(用)SQL的独立运行库Bukkit版本插件。</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>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>easysql-plugin-core</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-main</artifactId>
<version>${easyplugin.version}</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-paper</artifactId>
<version>0.5.1-SNAPSHOT</version>
<optional>true</optional>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<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.easysql.lib.bstats</shadedPattern>
</relocation>
<relocation>
<pattern>org.json</pattern>
<shadedPattern>cc.carm.plugin.easysql.lib.json</shadedPattern>
</relocation>
<relocation>
<pattern>cc.carm.lib.easyplugin</pattern>
<shadedPattern>cc.carm.plugin.easysql.lib.easyplugin</shadedPattern>
</relocation>
<relocation>
<pattern>cc.carm.lib.githubreleases4j</pattern>
<shadedPattern>cc.carm.plugin.easysql.lib.githubreleases4j</shadedPattern>
</relocation>
<relocation>
<pattern>co.aikar.commands</pattern>
<shadedPattern>cc.carm.plugin.easysql.lib.acf</shadedPattern> <!-- Replace this -->
</relocation>
<relocation>
<pattern>co.aikar.locales</pattern>
<shadedPattern>cc.carm.plugin.easysql.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>
</plugin>
</plugins>
</build>
</project>
@@ -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