mirror of
https://github.com/CarmJos/MineSQL.git
synced 2026-06-05 00:48:16 +08:00
feat(proj): 项目完成,测试使用。
This commit is contained in:
@@ -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"
|
||||
Reference in New Issue
Block a user