mirror of
https://github.com/CarmJos/MineSQL.git
synced 2026-06-04 16:43:03 +08:00
sync with github
This commit is contained in:
@@ -47,14 +47,6 @@
|
||||
<version>2.2.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-main</artifactId>
|
||||
<optional>true</optional>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
+96
-1
@@ -1,4 +1,99 @@
|
||||
package cc.carm.plugin.easysql;
|
||||
|
||||
public class EasySQLBukkit {
|
||||
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.configuration.ConfigurationSection;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EasySQLBukkit extends JavaPlugin implements EasySQLPluginPlatform, Listener {
|
||||
private EasySQLAPI apiImpl;
|
||||
|
||||
private boolean setup = false;
|
||||
|
||||
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("mysql"
|
||||
, instancesConfig.getString("url")
|
||||
, instancesConfig.getString("username")
|
||||
, instancesConfig.getString("password")
|
||||
)
|
||||
);
|
||||
this.register(this, instanceName, sqlManager);
|
||||
}
|
||||
}
|
||||
setup = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
setup(); // 尽可能早的初始化预注册的 SQLManager
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
setup(); // 在特定情况下 Bukkit 可能不会调用 onLoad 函数
|
||||
}
|
||||
|
||||
@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 JavaPlugin 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 JavaPlugin plugin){
|
||||
this.apiImpl.unregisterSQLManagerAll(plugin.getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+123
-1
@@ -1,4 +1,126 @@
|
||||
package cc.carm.plugin.easysql;
|
||||
|
||||
public class EasySQLBungee {
|
||||
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 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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class EasySQLBungee extends Plugin implements EasySQLPluginPlatform {
|
||||
private EasySQLAPI apiImpl;
|
||||
|
||||
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;
|
||||
apiImpl = new EasySQLManager(this);
|
||||
saveDefaultConfig();
|
||||
// 读取配置文件 - 预注册 instance
|
||||
Configuration configuration = null;
|
||||
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) {
|
||||
for (String instanceName : instancesConfig.getKeys()) {
|
||||
SQLManager sqlManager = new SQLManagerImpl(
|
||||
new BeeDataSource("mysql"
|
||||
, instancesConfig.getString("url")
|
||||
, instancesConfig.getString("username")
|
||||
, instancesConfig.getString("password")
|
||||
)
|
||||
);
|
||||
this.register(this, instanceName, sqlManager);
|
||||
}
|
||||
}
|
||||
setup = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
setup();
|
||||
}
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
+10
-3
@@ -2,16 +2,19 @@ package cc.carm.plugin.easysql;
|
||||
|
||||
|
||||
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 For Velocity", version = "1.0.0",
|
||||
description = "",
|
||||
url = "https://github.com/CarmJos/EasySQL-Plugin", authors = "CarmJos"
|
||||
)
|
||||
public class EasySQLVelocity {
|
||||
public class EasySQLVelocity {
|
||||
|
||||
private static EasySQLVelocity instance;
|
||||
|
||||
@@ -23,10 +26,10 @@ public class EasySQLVelocity {
|
||||
instance = this;
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
|
||||
// register listeners
|
||||
server.getEventManager().register(this,this);
|
||||
}
|
||||
|
||||
|
||||
public static EasySQLVelocity getInstance() {
|
||||
return instance;
|
||||
}
|
||||
@@ -39,5 +42,9 @@ public class EasySQLVelocity {
|
||||
return logger;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onInitialize(ProxyInitializeEvent event) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user