1
mirror of https://github.com/CarmJos/MineSQL.git synced 2024-09-19 20:25:45 +00:00

feat(platform): Support Sponge8 (#4)

This commit is contained in:
Carm Jos 2023-01-14 21:07:37 +08:00
parent 3d885a85a2
commit d2df91d45c
12 changed files with 120 additions and 66 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>minesql-parent</artifactId>
<groupId>cc.carm.plugin</groupId>
<version>1.2.2</version>
<version>1.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>minesql-parent</artifactId>
<groupId>cc.carm.plugin</groupId>
<version>1.2.2</version>
<version>1.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>minesql-parent</artifactId>
<groupId>cc.carm.plugin</groupId>
<version>1.2.2</version>
<version>1.3.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>minesql-parent</artifactId>
<groupId>cc.carm.plugin</groupId>
<version>1.2.2</version>
<version>1.3.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>minesql-parent</artifactId>
<groupId>cc.carm.plugin</groupId>
<version>1.2.2</version>
<version>1.3.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
@ -94,7 +94,7 @@
<dependency>
<groupId>co.aikar</groupId>
<artifactId>acf-core</artifactId>
<artifactId>acf-sponge</artifactId>
<version>0.5.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>

View File

@ -1,9 +1,11 @@
package cc.carm.plugin.minesql;
import cc.carm.lib.easyplugin.utils.ColorParser;
import cc.carm.lib.easyplugin.utils.JarResourceUtils;
import cc.carm.plugin.minesql.conf.PluginConfiguration;
import co.aikar.commands.CommandManager;
import com.google.inject.Inject;
import org.apache.logging.log4j.Logger;
import net.kyori.adventure.text.Component;
import org.bstats.charts.SimplePie;
import org.bstats.sponge.Metrics;
import org.jetbrains.annotations.NotNull;
@ -12,6 +14,7 @@ import org.spongepowered.api.Server;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.config.ConfigDir;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.lifecycle.StartingEngineEvent;
import org.spongepowered.api.event.lifecycle.StoppingEngineEvent;
import org.spongepowered.plugin.PluginContainer;
@ -19,50 +22,50 @@ import org.spongepowered.plugin.builtin.jvm.Plugin;
import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Optional;
/**
* 2022/6/20<br>
* MineSQL<br>
*
* @author huanmeng_qwq
* @author huanmeng_qwq, CarmJos
*/
@Plugin("minesql")
public class MineSQLSponge implements MineSQLPlatform {
private static MineSQLSponge instance;
@Inject
@ConfigDir(sharedRoot = false)
private Path configDirectory;
@Inject
private org.apache.logging.log4j.Logger logger;
private final PluginContainer pluginContainer;
private final Metrics metrics;
private final Metrics.Factory metricsFactory;
protected MineSQLCore core;
protected final MineSQLCore core;
// protected SpongeCommandManager commandManager;
@Inject
public MineSQLSponge(Metrics.Factory factory, PluginContainer pluginContainer) {
this.metrics = factory.make(14075);
instance = this;
this.core = new MineSQLCore(this);
public MineSQLSponge(Metrics.Factory factory,
PluginContainer pluginContainer) {
this.pluginContainer = pluginContainer;
this.metricsFactory = factory;
getLogger().info("加载基础核心...");
this.core = new MineSQLCore(this);
}
@Listener
@Listener(order = Order.PRE)
public void starting(StartingEngineEvent<Server> e) {
enable();
}
outputInfo();
// getLogger().info("初始化指令管理器...");
// this.commandManager = new SpongeCommandManager(pluginContainer);
//
// getLogger().info("注册相关指令...");
// this.core.initializeCommands(getCommandManager());
@Listener
public void disable(StoppingEngineEvent<Server> e) {
logger.info("终止全部数据库连接...");
this.core.shutdownAll();
}
public void enable() {
if (getConfiguration().METRICS.getNotNull()) {
getLog().info("启用统计数据...");
getLogger().info("启用统计数据...");
Metrics metrics = this.metricsFactory.make(14078);
metrics.addCustomChart(new SimplePie("update_check",
() -> getConfiguration().UPDATE_CHECKER.getNotNull() ? "ENABLED" : "DISABLED")
);
@ -72,25 +75,27 @@ public class MineSQLSponge implements MineSQLPlatform {
}
if (getConfiguration().PROPERTIES.ENABLE.getNotNull()) {
logger.info("开始检查更新,可能需要一小段时间...");
logger.info(" 如不希望检查更新,可在配置文件中关闭。");
getLogger().info("开始检查更新,可能需要一小段时间...");
getLogger().info(" 如不希望检查更新,可在配置文件中关闭。");
Sponge.asyncScheduler().executor(pluginContainer)
.execute(() -> this.core.checkUpdate(pluginContainer.metadata().version().getQualifier()))
;
.execute(() -> this.core.checkUpdate(getVersion()));
} else {
logger.info("已禁用检查更新,跳过。");
getLogger().info("已禁用检查更新,跳过。");
}
}
@Listener
public void disable(StoppingEngineEvent<Server> e) {
outputInfo();
logger.info("终止全部数据库连接...");
this.core.shutdownAll();
}
@Override
public @NotNull File getPluginFolder() {
return configDirectory.toFile();
}
public static @NotNull MineSQLSponge getInstance() {
return instance;
}
public @NotNull PluginConfiguration getConfiguration() {
return this.core.getConfig();
}
@ -105,8 +110,14 @@ public class MineSQLSponge implements MineSQLPlatform {
return null;
}
private Logger getLog() {
return logger;
public String getVersion() {
return pluginContainer.metadata().version().toString();
}
public void outputInfo() {
Optional.ofNullable(JarResourceUtils.readResource(this.getClass().getResourceAsStream("PLUGIN_INFO")))
.map(v -> ColorParser.parse(Arrays.asList(v)))
.ifPresent(list -> list.forEach(s -> Sponge.server().sendMessage(Component.text(s))));
}
}

View File

@ -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"
}
}

View File

@ -0,0 +1,39 @@
{
"loader": {
"name": "java_plain",
"version": "1.0"
},
"license": "GPL-3.0-or-later",
"global": {
"version": "8.0.0",
"links": {
"homepage": "${project.url}",
"source": "${project.url}",
"issues": "${project.url}/issues"
},
"contributors": [
{
"name": "huanmeng",
"description": "ContributorContributor"
},
{
"name": "CarmJos",
"description": "Lead Developer"
}
],
"dependencies": [
{
"id": "spongeapi",
"version": "8.0.0"
}
]
},
"plugins": [
{
"id": "minesql",
"name": "MineSQL (EasySQL-Plugin)",
"entrypoint": "cc.carm.plugin.minesql.MineSQLSponge",
"description": "${project.description}"
}
]
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>minesql-parent</artifactId>
<groupId>cc.carm.plugin</groupId>
<version>1.2.2</version>
<version>1.3.0</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -1,6 +1,8 @@
package cc.carm.plugin.minesql;
import cc.carm.lib.easyplugin.utils.ColorParser;
import cc.carm.lib.easyplugin.utils.JarResourceUtils;
import cc.carm.plugin.minesql.conf.PluginConfiguration;
import co.aikar.commands.CommandManager;
import co.aikar.commands.VelocityCommandManager;
@ -14,6 +16,7 @@ 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 net.kyori.adventure.text.Component;
import org.bstats.charts.SimplePie;
import org.bstats.velocity.Metrics;
import org.jetbrains.annotations.NotNull;
@ -21,6 +24,8 @@ import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Optional;
import java.util.logging.Logger;
@ -120,6 +125,9 @@ public class MineSQLVelocity implements MineSQLPlatform {
}
public void outputInfo() {
Optional.ofNullable(JarResourceUtils.readResource(this.getClass().getResourceAsStream("PLUGIN_INFO")))
.map(v -> ColorParser.parse(Arrays.asList(v)))
.ifPresent(list -> list.forEach(s -> getServer().getConsoleCommandSource().sendMessage(Component.text(s))));
}
}

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>minesql-parent</artifactId>
<groupId>cc.carm.plugin</groupId>
<version>1.2.2</version>
<version>1.3.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<properties>
@ -34,6 +34,13 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>minesql-sponge</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.parent.groupId}</groupId>
<artifactId>minesql-velocity</artifactId>
@ -137,11 +144,13 @@
</relocation>
<relocation>
<pattern>com.google.protobuf</pattern>
<shadedPattern>cc.carm.plugin.minesql.lib.google.protobuf</shadedPattern> <!-- Replace this -->
<shadedPattern>cc.carm.plugin.minesql.lib.google.protobuf
</shadedPattern> <!-- Replace this -->
</relocation>
<relocation>
<pattern>com.google.errorprone</pattern>
<shadedPattern>cc.carm.plugin.minesql.lib.google.errorprone</shadedPattern> <!-- Replace this -->
<shadedPattern>cc.carm.plugin.minesql.lib.google.errorprone
</shadedPattern> <!-- Replace this -->
</relocation>
<relocation>
<pattern>com.github</pattern>
@ -149,7 +158,8 @@
</relocation>
<relocation>
<pattern>org.checkerframework</pattern>
<shadedPattern>cc.carm.plugin.minesql.lib.checkerframework</shadedPattern> <!-- Replace this -->
<shadedPattern>cc.carm.plugin.minesql.lib.checkerframework
</shadedPattern> <!-- Replace this -->
</relocation>
<relocation>
<pattern>waffle</pattern>
@ -172,6 +182,8 @@
<excludes>
<exclude>META-INF/MANIFEST.MF</exclude>
<exclude>META-INF/*.txt</exclude>
<exclude>LICENSE</exclude>
<exclude>README</exclude>
</excludes>
</filter>
</filters>

View File

@ -24,7 +24,7 @@
<groupId>cc.carm.plugin</groupId>
<artifactId>minesql-parent</artifactId>
<packaging>pom</packaging>
<version>1.2.2</version>
<version>1.3.0</version>
<modules>
<module>api</module>
<module>core</module>
@ -33,6 +33,7 @@
<module>platforms/bungee</module>
<module>platforms/velocity</module>
<module>platforms/sponge8</module>
<module>plugin</module>
</modules>