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

修改实现方式

This commit is contained in:
2022-02-10 02:36:03 +08:00
parent 2f55d732ba
commit c46d00d5c4
24 changed files with 687 additions and 558 deletions
+7 -1
View File
@@ -29,11 +29,17 @@
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>easysql-plugin-impl</artifactId>
<artifactId>easysql-plugin-core</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-main</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
@@ -1,121 +1,28 @@
package cc.carm.plugin.easysql;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.plugin.easysql.api.EasySQLAPI;
import cc.carm.plugin.easysql.api.EasySQLPluginPlatform;
import cn.beecp.BeeDataSource;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import cc.carm.lib.easyplugin.EasyPlugin;
import cc.carm.plugin.easysql.api.DBConfiguration;
import org.bukkit.event.Listener;
import org.bukkit.event.server.PluginDisableEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class EasySQLBukkit extends JavaPlugin implements EasySQLPluginPlatform, Listener {
private EasySQLAPI apiImpl;
import java.util.HashMap;
import java.util.Map;
private boolean setup = false;
public class EasySQLBukkit extends EasyPlugin implements EasySQLPluginPlatform, Listener {
@Override
protected void load() {
public void setup() {
if (setup) return;
apiImpl = new EasySQLManager(this);
saveDefaultConfig();
// 读取配置文件 - 预注册 instance
ConfigurationSection instancesConfig = getConfig().getConfigurationSection("instances");
if (instancesConfig != null) {
for (String instanceName : instancesConfig.getKeys(false)) {
SQLManager sqlManager = new SQLManagerImpl(
new BeeDataSource("com.mysql.jdbc.Driver"
, instancesConfig.getString("url")
, instancesConfig.getString("username")
, instancesConfig.getString("password")
)
);
this.register(this, instanceName, sqlManager);
}
}
// 获取指定UUID的玩家的盔甲
setup = true;
}
@Override
public void onLoad() {
setup(); // 尽可能早的初始化预注册的 SQLManager
protected boolean initialize() {
return false;
}
@Override
public void onEnable() {
setup(); // 在特定情况下 Bukkit 可能不会调用 onLoad 函数
Bukkit.getPluginManager().registerEvents(this,this);
public @NotNull Map<String, DBConfiguration> readConfigurations() {
return new HashMap<>();
}
@Override
public void onDisable() {
getLogger().info("Shutting down...");
this.unregister(this);
apiImpl.getSQLManagers().keySet().forEach(apiImpl::unregisterSQLManager);
super.onDisable();
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event){
this.unregister(event.getPlugin());
}
// =========== 平台注册方法 ===========
/**
* 注册 SQLManager 实例
* @param plugin 插件实例
* @param name SQLManager 映射名称
* @param sqlManager SQLManager 实例
*/
public void register(@NotNull Plugin plugin, @NotNull String name, @NotNull SQLManager sqlManager){
if(this.apiImpl.getSQLManagers().containsKey(name)){
// 名称冲突处理
throw new IllegalArgumentException("Instance name conflict: " + name+", Already registered by "+this.apiImpl.getNameSpace(name));
}
this.apiImpl.registerSQLManager(plugin.getDescription().getName(), name, sqlManager);
}
/**
* 注销指定 SQLManager 实例
* @param sqlManager SQLManager 实例
*/
public void unregister(@NotNull SQLManager sqlManager){
String name = this.apiImpl.getName(sqlManager);
if(name != null){
this.apiImpl.unregisterSQLManager(name);
}
}
/**
* 注销指定名称的 SQLManager
* @param name SQLManager 名称
*/
public void unregister(@NotNull String name){
this.apiImpl.unregisterSQLManager(name);
}
/**
* 注销指定插件注册的所有 SQLManager 实例
* @param plugin 插件
*/
public void unregister(@NotNull Plugin plugin){
this.apiImpl.unregisterSQLManagerAll(plugin.getName());
}
/**
* 获取 SQL 管理器
*
* @param name 注册键
* @return SQL管理器
*/
@Override
public @Nullable SQLManager getSqlManager(@NotNull String name) {
return this.apiImpl.getSQLManager(name);
}
}
+1 -1
View File
@@ -36,7 +36,7 @@
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>easysql-plugin-impl</artifactId>
<artifactId>easysql-plugin-core</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
@@ -1,28 +1,24 @@
package cc.carm.plugin.easysql;
import cc.carm.lib.easysql.api.SQLManager;
import cc.carm.lib.easysql.manager.SQLManagerImpl;
import cc.carm.plugin.easysql.api.EasySQLAPI;
import cc.carm.plugin.easysql.api.EasySQLPluginPlatform;
import cn.beecp.BeeDataSource;
import cc.carm.plugin.easysql.api.DBConfiguration;
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 org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
public class EasySQLBungee extends Plugin implements EasySQLPluginPlatform {
private EasySQLAPI apiImpl;
private boolean setup = false;
private void saveDefaultConfig(){
private void saveDefaultConfig() {
if (!getDataFolder().exists())
getDataFolder().mkdir();
@@ -40,7 +36,6 @@ public class EasySQLBungee extends Plugin implements EasySQLPluginPlatform {
public void setup() {
if (setup) return;
apiImpl = new EasySQLManager(this);
saveDefaultConfig();
// 读取配置文件 - 预注册 instance
Configuration configuration;
@@ -52,16 +47,6 @@ public class EasySQLBungee extends Plugin implements EasySQLPluginPlatform {
}
Configuration instancesConfig = configuration.getSection("instances");
if (instancesConfig != null) {
for (String instanceName : instancesConfig.getKeys()) {
SQLManager sqlManager = new SQLManagerImpl(
new BeeDataSource("com.mysql.jdbc.Driver"
, instancesConfig.getString("url")
, instancesConfig.getString("username")
, instancesConfig.getString("password")
)
);
this.register(this, instanceName, sqlManager);
}
}
setup = true;
}
@@ -75,64 +60,15 @@ public class EasySQLBungee extends Plugin implements EasySQLPluginPlatform {
public void onEnable() {
setup();
}
@Override
public void onDisable() {
getLogger().info("Shutting down...");
this.unregister(this);
apiImpl.getSQLManagers().keySet().forEach(apiImpl::unregisterSQLManager);
super.onDisable();
}
// =========== 平台注册方法 ===========
/**
* 注册 SQLManager 实例
* @param plugin 插件实例
* @param name SQLManager 映射名称
* @param sqlManager SQLManager 实例
*/
public void register(@NotNull Plugin plugin, @NotNull String name, @NotNull SQLManager sqlManager){
if(this.apiImpl.getSQLManagers().containsKey(name)){
// 名称冲突处理
throw new IllegalArgumentException("Instance name conflict: " + name+", Already registered by "+this.apiImpl.getNameSpace(name));
}
this.apiImpl.registerSQLManager(plugin.getDescription().getName(), name, sqlManager);
}
/**
* 注销指定 SQLManager 实例
* @param sqlManager SQLManager 实例
*/
public void unregister(@NotNull SQLManager sqlManager){
String name = this.apiImpl.getName(sqlManager);
if(name != null){
this.apiImpl.unregisterSQLManager(name);
}
}
/**
* 注销指定名称的 SQLManager
* @param name SQLManager 名称
*/
public void unregister(@NotNull String name){
this.apiImpl.unregisterSQLManager(name);
}
/**
* 注销指定插件注册的所有 SQLManager 实例
* @param plugin 插件
*/
public void unregister(@NotNull Plugin plugin){
this.apiImpl.unregisterSQLManagerAll(plugin.getDescription().getName());
}
/**
* 获取 SQL 管理器
*
* @param name 注册键
* @return SQL管理器
*/
@Override
public @Nullable SQLManager getSqlManager(@NotNull String name) {
return this.apiImpl.getSQLManager(name);
public @NotNull Map<String, DBConfiguration> readConfigurations() {
return new HashMap<>();
}
}
-88
View File
@@ -1,88 +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.2</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-fabric</artifactId>
<packaging>jar</packaging>
<name>EasySQL-Plugin-Fabric</name>
<dependencies>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>easysql-plugin-impl</artifactId>
<version>${project.parent.version}</version>
<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>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -1,10 +0,0 @@
package cc.carm.plugin.easysql;
public class EasySQLFabric {
// Sadly I don't know how to create a fabric plugins,
// If you know how to make a fabric plugin , just contribute your code here!
}
+1 -1
View File
@@ -37,7 +37,7 @@
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>easysql-plugin-impl</artifactId>
<artifactId>easysql-plugin-core</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
@@ -10,40 +10,42 @@ import com.velocitypowered.api.proxy.ProxyServer;
import java.util.logging.Logger;
@Plugin(id = "easysql-plugin", name = "EasySQL Plugin For Velocity", version = "1.0.0",
description = "",
url = "https://github.com/CarmJos/EasySQL-Plugin", authors = "CarmJos"
@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 {
public class EasySQLVelocity {
private static EasySQLVelocity instance;
private static EasySQLVelocity instance;
private final ProxyServer server;
private final Logger logger;
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);
}
@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 static EasySQLVelocity getInstance() {
return instance;
}
public ProxyServer getServer() {
return server;
}
public ProxyServer getServer() {
return server;
}
public Logger getLogger() {
return logger;
}
public Logger getLogger() {
return logger;
}
@Subscribe
public void onInitialize(ProxyInitializeEvent event) {
}
@Subscribe
public void onInitialize(ProxyInitializeEvent event) {
}
}