feat: 添加 velocity 支持,取消重定向包名
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id("java")
|
id("java-library")
|
||||||
id("maven-publish")
|
id("maven-publish")
|
||||||
id("com.github.johnrengelman.shadow") version "8+"
|
id("com.github.johnrengelman.shadow") version "8+"
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ version = "1.3.2-SNAPSHOT"
|
|||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
apply {
|
apply {
|
||||||
plugin("java")
|
plugin("java-library")
|
||||||
plugin("maven-publish")
|
plugin("maven-publish")
|
||||||
plugin("com.github.johnrengelman.shadow")
|
plugin("com.github.johnrengelman.shadow")
|
||||||
}
|
}
|
||||||
@@ -55,20 +55,7 @@ subprojects {
|
|||||||
expand(map)
|
expand(map)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jar {
|
|
||||||
archiveClassifier = "dev"
|
|
||||||
}
|
|
||||||
shadowJar {
|
shadowJar {
|
||||||
archiveClassifier = ""
|
|
||||||
relocate("org.quartz", "cn.hamster3.mc.plugin.core.lib.org.quartz")
|
|
||||||
relocate("org.terracotta.quartz", "cn.hamster3.mc.plugin.core.lib.org.terracotta.quartz")
|
|
||||||
|
|
||||||
relocate("com.zaxxer.hikari", "cn.hamster3.mc.plugin.core.lib.com.zaxxer.hikari")
|
|
||||||
relocate("redis.clients.jedis", "cn.hamster3.mc.plugin.core.lib.redis.clients.jedis")
|
|
||||||
relocate("org.json", "cn.hamster3.mc.plugin.core.lib.org.json")
|
|
||||||
relocate("org.apache.commons.pool2", "cn.hamster3.mc.plugin.core.lib.org.apache.commons.pool2")
|
|
||||||
|
|
||||||
relocate("net.kyori", "cn.hamster3.mc.plugin.core.lib.net.kyori")
|
|
||||||
relocate("de.tr7zw.changeme.nbtapi", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi")
|
relocate("de.tr7zw.changeme.nbtapi", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi")
|
||||||
relocate("de.tr7zw.annotations", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi.annotations")
|
relocate("de.tr7zw.annotations", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi.annotations")
|
||||||
}
|
}
|
||||||
|
@@ -1,32 +1,45 @@
|
|||||||
@file:Suppress("VulnerableLibrariesLocal")
|
@file:Suppress("VulnerableLibrariesLocal")
|
||||||
|
|
||||||
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
|
|
||||||
evaluationDependsOn(":core-common")
|
evaluationDependsOn(":core-common")
|
||||||
|
|
||||||
|
val shade = configurations.create("shade")
|
||||||
|
val shadeJava8 = configurations.create("shadeJava8")
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":core-common")) { isTransitive = false }
|
api(project(":core-common")) { isTransitive = false }
|
||||||
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||||
|
|
||||||
implementation("de.tr7zw:item-nbt-api:2.12.3-SNAPSHOT")
|
|
||||||
compileOnly("net.milkbowl.vault:VaultAPI:1.7") { isTransitive = false }
|
compileOnly("net.milkbowl.vault:VaultAPI:1.7") { isTransitive = false }
|
||||||
compileOnly("org.black_ixx:playerpoints:3.2.6") { isTransitive = false }
|
compileOnly("org.black_ixx:playerpoints:3.2.6") { isTransitive = false }
|
||||||
compileOnly("me.clip:placeholderapi:2.11.5") { isTransitive = false }
|
compileOnly("me.clip:placeholderapi:2.11.5") { isTransitive = false }
|
||||||
|
|
||||||
implementation("net.kyori:adventure-platform-bukkit:4.3.2") {
|
api("net.kyori:adventure-platform-bukkit:4.3.2") {
|
||||||
exclude(group = "org.jetbrains")
|
exclude(group = "org.jetbrains")
|
||||||
exclude(group = "com.google.code.gson")
|
exclude(group = "com.google.code.gson")
|
||||||
}
|
}
|
||||||
implementation("net.kyori:adventure-text-minimessage:4.15.0") {
|
api("net.kyori:adventure-text-minimessage:4.15.0") {
|
||||||
exclude(module = "adventure-api")
|
exclude(module = "adventure-api")
|
||||||
exclude(group = "org.jetbrains")
|
exclude(group = "org.jetbrains")
|
||||||
}
|
}
|
||||||
implementation("com.zaxxer:HikariCP:4.0.3") { exclude(group = "org.slf4j") }
|
|
||||||
// https://mvnrepository.com/artifact/redis.clients/jedis
|
// https://mvnrepository.com/artifact/redis.clients/jedis
|
||||||
implementation("redis.clients:jedis:5.1.2") {
|
api("redis.clients:jedis:5.1.2") {
|
||||||
exclude(group = "com.google.code.gson")
|
exclude(group = "com.google.code.gson")
|
||||||
exclude(group = "org.slf4j")
|
exclude(group = "org.slf4j")
|
||||||
}
|
}
|
||||||
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
|
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
|
||||||
implementation("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
api("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
||||||
|
|
||||||
|
// https://www.spigotmc.org/resources/nbt-api.7939/
|
||||||
|
implementation("de.tr7zw:item-nbt-api:2.12.2")
|
||||||
|
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||||
|
implementation("com.zaxxer:HikariCP:4.0.3") { exclude(group = "org.slf4j") }
|
||||||
|
|
||||||
|
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib
|
||||||
|
shade("org.jetbrains.kotlin:kotlin-stdlib:1.9.23") { exclude(group = "org.jetbrains") }
|
||||||
|
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8
|
||||||
|
shadeJava8("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.23") { exclude(group = "org.jetbrains") }
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
@@ -39,6 +52,20 @@ tasks {
|
|||||||
archiveBaseName = "HamsterCore-Bukkit"
|
archiveBaseName = "HamsterCore-Bukkit"
|
||||||
}
|
}
|
||||||
shadowJar {
|
shadowJar {
|
||||||
|
from(shade.map { if (it.isDirectory) it else zipTree(it) })
|
||||||
destinationDirectory = rootProject.layout.buildDirectory
|
destinationDirectory = rootProject.layout.buildDirectory
|
||||||
}
|
}
|
||||||
|
val shadowJava8 = register<ShadowJar>("shadowJava8") {
|
||||||
|
dependsOn(":core-common:build")
|
||||||
|
archiveClassifier = "Java8"
|
||||||
|
from(project.configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
|
||||||
|
from(processResources.get().outputs)
|
||||||
|
from(shadeJava8.map { if (it.isDirectory) it else zipTree(it) })
|
||||||
|
destinationDirectory = rootProject.layout.buildDirectory
|
||||||
|
relocate("de.tr7zw.changeme.nbtapi", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi")
|
||||||
|
relocate("de.tr7zw.annotations", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi.annotations")
|
||||||
|
}
|
||||||
|
build {
|
||||||
|
dependsOn(shadowJava8)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,28 +1,38 @@
|
|||||||
@file:Suppress("VulnerableLibrariesLocal")
|
@file:Suppress("VulnerableLibrariesLocal")
|
||||||
|
|
||||||
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||||
|
|
||||||
evaluationDependsOn(":core-common")
|
evaluationDependsOn(":core-common")
|
||||||
|
|
||||||
|
val shade = configurations.create("shade")
|
||||||
|
val shadeJava8 = configurations.create("shadeJava8")
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation(project(":core-common")) { isTransitive = false }
|
api(project(":core-common")) { isTransitive = false }
|
||||||
compileOnly("net.md-5:bungeecord-api:1.20-R0.1")
|
compileOnly("net.md-5:bungeecord-api:1.20-R0.1")
|
||||||
|
|
||||||
implementation("net.kyori:adventure-platform-bungeecord:4.3.2") {
|
api("net.kyori:adventure-platform-bungeecord:4.3.2") {
|
||||||
exclude(group = "org.jetbrains")
|
exclude(group = "org.jetbrains")
|
||||||
exclude(group = "com.google.code.gson")
|
exclude(group = "com.google.code.gson")
|
||||||
}
|
}
|
||||||
implementation("net.kyori:adventure-text-minimessage:4.15.0") {
|
api("net.kyori:adventure-text-minimessage:4.15.0") {
|
||||||
exclude(module = "adventure-api")
|
exclude(module = "adventure-api")
|
||||||
exclude(group = "org.jetbrains")
|
exclude(group = "org.jetbrains")
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation("com.zaxxer:HikariCP:4.0.3") { exclude(group = "org.slf4j") }
|
|
||||||
// https://mvnrepository.com/artifact/redis.clients/jedis
|
// https://mvnrepository.com/artifact/redis.clients/jedis
|
||||||
implementation("redis.clients:jedis:5.1.2") {
|
api("redis.clients:jedis:5.1.2") {
|
||||||
exclude(group = "com.google.code.gson")
|
exclude(group = "com.google.code.gson")
|
||||||
exclude(group = "org.slf4j")
|
exclude(group = "org.slf4j")
|
||||||
}
|
}
|
||||||
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
|
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
|
||||||
implementation("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
api("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
||||||
|
|
||||||
|
implementation("com.zaxxer:HikariCP:4.0.3") { exclude(group = "org.slf4j") }
|
||||||
|
|
||||||
|
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib
|
||||||
|
shade("org.jetbrains.kotlin:kotlin-stdlib:1.9.23") { exclude(group = "org.jetbrains") }
|
||||||
|
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib-jdk8
|
||||||
|
shadeJava8("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.23") { exclude(group = "org.jetbrains") }
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
@@ -35,6 +45,24 @@ tasks {
|
|||||||
archiveBaseName = "HamsterCore-BungeeCord"
|
archiveBaseName = "HamsterCore-BungeeCord"
|
||||||
}
|
}
|
||||||
shadowJar {
|
shadowJar {
|
||||||
|
from(shade.map { if (it.isDirectory) it else zipTree(it) })
|
||||||
destinationDirectory = rootProject.layout.buildDirectory
|
destinationDirectory = rootProject.layout.buildDirectory
|
||||||
}
|
}
|
||||||
|
shadowJar {
|
||||||
|
from(shade.map { if (it.isDirectory) it else zipTree(it) })
|
||||||
|
destinationDirectory = rootProject.layout.buildDirectory
|
||||||
|
}
|
||||||
|
val shadowJava8 = register<ShadowJar>("shadowJava8") {
|
||||||
|
dependsOn(":core-common:build")
|
||||||
|
archiveClassifier = "Java8"
|
||||||
|
from(project.configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
|
||||||
|
from(processResources.get().outputs)
|
||||||
|
from(shadeJava8.map { if (it.isDirectory) it else zipTree(it) })
|
||||||
|
destinationDirectory = rootProject.layout.buildDirectory
|
||||||
|
relocate("de.tr7zw.changeme.nbtapi", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi")
|
||||||
|
relocate("de.tr7zw.annotations", "cn.hamster3.mc.plugin.core.lib.de.tr7zw.nbtapi.annotations")
|
||||||
|
}
|
||||||
|
build {
|
||||||
|
dependsOn(shadowJava8)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -4,21 +4,24 @@ dependencies {
|
|||||||
compileOnly("com.google.code.gson:gson:2.8.0")
|
compileOnly("com.google.code.gson:gson:2.8.0")
|
||||||
// https://mvnrepository.com/artifact/org.yaml/snakeyaml
|
// https://mvnrepository.com/artifact/org.yaml/snakeyaml
|
||||||
compileOnly("org.yaml:snakeyaml:1.30")
|
compileOnly("org.yaml:snakeyaml:1.30")
|
||||||
|
// https://mvnrepository.com/artifact/org.slf4j/slf4j-api
|
||||||
|
compileOnly("org.slf4j:slf4j-api:2.0.12")
|
||||||
|
|
||||||
implementation("net.kyori:adventure-platform-api:4.3.2") { exclude(group = "org.jetbrains") }
|
compileOnlyApi("net.kyori:adventure-platform-api:4.3.2") { exclude(group = "org.jetbrains") }
|
||||||
implementation("net.kyori:adventure-text-serializer-gson:4.13.1") {
|
compileOnlyApi("net.kyori:adventure-text-serializer-gson:4.13.1") {
|
||||||
exclude(group = "org.jetbrains")
|
exclude(group = "org.jetbrains")
|
||||||
exclude(group = "com.google.code.gson")
|
exclude(group = "com.google.code.gson")
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
|
||||||
compileOnly("com.zaxxer:HikariCP:4.0.3") { isTransitive = false }
|
|
||||||
// https://mvnrepository.com/artifact/redis.clients/jedis
|
// https://mvnrepository.com/artifact/redis.clients/jedis
|
||||||
implementation("redis.clients:jedis:5.1.2") {
|
compileOnlyApi("redis.clients:jedis:5.1.2") {
|
||||||
exclude(group = "com.google.code.gson")
|
exclude(group = "com.google.code.gson")
|
||||||
exclude(group = "org.slf4j")
|
exclude(group = "org.slf4j")
|
||||||
}
|
}
|
||||||
compileOnly("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
compileOnlyApi("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
||||||
|
|
||||||
|
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||||
|
compileOnly("com.zaxxer:HikariCP:4.0.3") { isTransitive = false }
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks {
|
tasks {
|
||||||
|
57
core-velocity/build.gradle.kts
Normal file
57
core-velocity/build.gradle.kts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
@file:Suppress("VulnerableLibrariesLocal")
|
||||||
|
|
||||||
|
evaluationDependsOn(":core-common")
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api(project(":core-common")) { isTransitive = false }
|
||||||
|
compileOnly("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
|
||||||
|
annotationProcessor("com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
|
||||||
|
|
||||||
|
implementation("net.kyori:adventure-platform-api:4.3.2") { exclude(group = "org.jetbrains") }
|
||||||
|
// https://mvnrepository.com/artifact/redis.clients/jedis
|
||||||
|
api("redis.clients:jedis:5.1.2") {
|
||||||
|
exclude(group = "com.google.code.gson")
|
||||||
|
exclude(group = "org.slf4j")
|
||||||
|
}
|
||||||
|
// https://mvnrepository.com/artifact/org.quartz-scheduler/quartz
|
||||||
|
api("org.quartz-scheduler:quartz:2.3.2") { isTransitive = false }
|
||||||
|
|
||||||
|
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||||
|
implementation("com.zaxxer:HikariCP:5.1.0") { isTransitive = false }
|
||||||
|
|
||||||
|
// https://mvnrepository.com/artifact/com.mysql/mysql-connector-j
|
||||||
|
runtimeOnly("com.mysql:mysql-connector-j:8.3.0")
|
||||||
|
// https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-stdlib
|
||||||
|
runtimeOnly("org.jetbrains.kotlin:kotlin-stdlib:1.9.23") { exclude(group = "org.jetbrains") }
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets.create("templates") {
|
||||||
|
java {
|
||||||
|
srcDir("src/main/templates")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val templateSource = file("src/main/templates")
|
||||||
|
val templateDest = layout.buildDirectory.dir("generated/sources/templates")
|
||||||
|
val generateTemplates = tasks.register<Copy>("generateTemplates") {
|
||||||
|
from(templateSource)
|
||||||
|
into(templateDest)
|
||||||
|
expand(project.properties)
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceSets.main.get().java.srcDir(generateTemplates.map { it.outputs })
|
||||||
|
|
||||||
|
java {
|
||||||
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks {
|
||||||
|
withType<Jar> {
|
||||||
|
archiveBaseName = "AirGameCore-Velocity"
|
||||||
|
}
|
||||||
|
shadowJar {
|
||||||
|
destinationDirectory = rootProject.layout.buildDirectory
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,97 @@
|
|||||||
|
package cn.hamster3.mc.plugin.core.velocity;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||||
|
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||||
|
import com.velocitypowered.api.plugin.Plugin;
|
||||||
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import lombok.Getter;
|
||||||
|
import cn.hamster3.mc.plugin.core.velocity.api.CoreVelocityAPI;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@Plugin(
|
||||||
|
id = "airgame-core",
|
||||||
|
name = "AirGameCore",
|
||||||
|
version = BuildConstants.VERSION,
|
||||||
|
description = BuildConstants.DESCRIPTION,
|
||||||
|
authors = {"MiniDay"}
|
||||||
|
)
|
||||||
|
public class AirGameCorePlugin {
|
||||||
|
@Getter
|
||||||
|
private static AirGameCorePlugin instance;
|
||||||
|
@Getter
|
||||||
|
private final java.util.logging.Logger logger;
|
||||||
|
@Getter
|
||||||
|
private final Logger slf4jLogger;
|
||||||
|
@Getter
|
||||||
|
private final ProxyServer proxyServer;
|
||||||
|
@Getter
|
||||||
|
private final File dataFolder;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public AirGameCorePlugin(Logger slf4jLogger, ProxyServer proxyServer, @DataDirectory Path dataPath) {
|
||||||
|
logger = java.util.logging.Logger.getLogger("airgame-core");
|
||||||
|
this.slf4jLogger = slf4jLogger;
|
||||||
|
this.proxyServer = proxyServer;
|
||||||
|
dataFolder = dataPath.toFile();
|
||||||
|
instance = this;
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
try {
|
||||||
|
if (dataFolder.mkdir()) {
|
||||||
|
slf4jLogger.info("已生成插件存档文件夹");
|
||||||
|
}
|
||||||
|
File configFile = new File(dataFolder, "config.yml");
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
Files.copy(
|
||||||
|
Objects.requireNonNull(AirGameCorePlugin.class.getResourceAsStream("/config.yml")),
|
||||||
|
configFile.toPath(),
|
||||||
|
StandardCopyOption.REPLACE_EXISTING
|
||||||
|
);
|
||||||
|
}
|
||||||
|
CoreVelocityAPI.init(configFile);
|
||||||
|
slf4jLogger.info("已初始化 CoreAPI");
|
||||||
|
} catch (Exception e) {
|
||||||
|
slf4jLogger.error("初始化 CoreAPI 出错", e);
|
||||||
|
}
|
||||||
|
long time = System.currentTimeMillis() - start;
|
||||||
|
slf4jLogger.info("AirGameCore 初始化完成,总计耗时 " + time + " ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
slf4jLogger.info("仓鼠核心正在启动");
|
||||||
|
// CoreMessage.init(getLogger(), new File(dataFolder, "messages.yml"));
|
||||||
|
// logger.info("已初始化语言文本");
|
||||||
|
long time = System.currentTimeMillis() - start;
|
||||||
|
slf4jLogger.info("仓鼠核心启动完成,总计耗时 " + time + " ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onProxyInitialization(ProxyShutdownEvent event) {
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
CoreAPI.getInstance().getJedisPool().close();
|
||||||
|
slf4jLogger.info("已关闭 Redis 连接池");
|
||||||
|
if (CoreAPI.getInstance().getDataSource() instanceof HikariDataSource dataSource) {
|
||||||
|
dataSource.close();
|
||||||
|
slf4jLogger.info("已关闭数据库连接池");
|
||||||
|
}
|
||||||
|
CoreAPI.getInstance().getExecutorService().shutdownNow();
|
||||||
|
slf4jLogger.info("已关闭 ExecutorService 线程池");
|
||||||
|
CoreAPI.getInstance().getScheduledService().shutdownNow();
|
||||||
|
slf4jLogger.info("已关闭 ScheduledExecutorService 线程池");
|
||||||
|
long time = System.currentTimeMillis() - start;
|
||||||
|
slf4jLogger.info("AirGameCore 关闭完成,总计耗时 " + time + " ms");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,73 @@
|
|||||||
|
package cn.hamster3.mc.plugin.core.velocity.api;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||||
|
import cn.hamster3.mc.plugin.core.common.config.ConfigSection;
|
||||||
|
import cn.hamster3.mc.plugin.core.common.config.YamlConfig;
|
||||||
|
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
||||||
|
import cn.hamster3.mc.plugin.core.common.impl.ComponentTypeAdapter;
|
||||||
|
import cn.hamster3.mc.plugin.core.common.impl.MessageTypeAdapter;
|
||||||
|
import cn.hamster3.mc.plugin.core.velocity.AirGameCorePlugin;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import cn.hamster3.mc.plugin.core.velocity.impl.AudienceProviderImpl;
|
||||||
|
import net.kyori.adventure.platform.AudienceProvider;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public final class CoreVelocityAPI extends CoreAPI {
|
||||||
|
@NotNull
|
||||||
|
private final Gson gson;
|
||||||
|
@NotNull
|
||||||
|
private final Gson gsonHuman;
|
||||||
|
|
||||||
|
public CoreVelocityAPI(@NotNull ConfigSection config) {
|
||||||
|
super(config);
|
||||||
|
gson = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(Component.class, ComponentTypeAdapter.INSTANCE)
|
||||||
|
.registerTypeAdapter(DisplayMessage.class, MessageTypeAdapter.INSTANCE)
|
||||||
|
.create();
|
||||||
|
gsonHuman = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(Component.class, ComponentTypeAdapter.INSTANCE)
|
||||||
|
.registerTypeAdapter(DisplayMessage.class, MessageTypeAdapter.INSTANCE)
|
||||||
|
.serializeNulls()
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CoreVelocityAPI getInstance() {
|
||||||
|
return (CoreVelocityAPI) instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void init(@NotNull File configFile) throws IOException {
|
||||||
|
if (instance != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
YamlConfig config = YamlConfig.load(configFile);
|
||||||
|
instance = new CoreVelocityAPI(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull AudienceProvider getAudienceProvider() {
|
||||||
|
return AudienceProviderImpl.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Logger getLogger() {
|
||||||
|
return AirGameCorePlugin.getInstance().getLogger();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Gson getGson() {
|
||||||
|
return gson;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Gson getGsonHuman() {
|
||||||
|
return gsonHuman;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,67 @@
|
|||||||
|
package cn.hamster3.mc.plugin.core.velocity.impl;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.core.velocity.AirGameCorePlugin;
|
||||||
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.key.Key;
|
||||||
|
import net.kyori.adventure.platform.AudienceProvider;
|
||||||
|
import net.kyori.adventure.text.flattener.ComponentFlattener;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class AudienceProviderImpl implements AudienceProvider {
|
||||||
|
public static final AudienceProviderImpl INSTANCE = new AudienceProviderImpl();
|
||||||
|
|
||||||
|
private AudienceProviderImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Audience all() {
|
||||||
|
return Audience.audience(console(), players());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Audience console() {
|
||||||
|
return AirGameCorePlugin.getInstance().getProxyServer().getConsoleCommandSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Audience players() {
|
||||||
|
return Audience.audience(AirGameCorePlugin.getInstance().getProxyServer().getAllPlayers());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Audience player(@NotNull UUID playerId) {
|
||||||
|
Player player = AirGameCorePlugin.getInstance().getProxyServer().getPlayer(playerId).orElse(null);
|
||||||
|
if (player == null) {
|
||||||
|
return Audience.empty();
|
||||||
|
}
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Audience permission(@NotNull String permission) {
|
||||||
|
return Audience.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Audience world(@NotNull Key world) {
|
||||||
|
return Audience.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Audience server(@NotNull String serverName) {
|
||||||
|
return Audience.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull ComponentFlattener flattener() {
|
||||||
|
return ComponentFlattener.basic();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
47
core-velocity/src/main/resources/config.yml
Normal file
47
core-velocity/src/main/resources/config.yml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# redis 连接配置
|
||||||
|
# 完整格式如下:
|
||||||
|
# redis://用户名:密码@主机名:端口/数据库索引?参数名=参数值&参数名=参数值
|
||||||
|
# 若没有设置 redis 用户名,但设置了密码,则可以使用以下格式:
|
||||||
|
# redis://密码@localhost:6379/0?clientName=AirGameCore
|
||||||
|
# 若没有设置 redis 用户名,也没有设置密码,则可以使用以下格式:
|
||||||
|
# redis://localhost:6379/0?clientName=AirGameCore
|
||||||
|
# 若不设置数据库,则默认使用 0
|
||||||
|
redis-url: "redis://localhost:6379/0?clientName=AirGameCore&timeout=5s"
|
||||||
|
|
||||||
|
datasource:
|
||||||
|
# 数据库链接驱动地址
|
||||||
|
# 除非你知道自己在做什么,否则不建议更改该项
|
||||||
|
# 旧版服务端(低于1.13)请使用:com.mysql.jdbc.Driver
|
||||||
|
driver: "com.mysql.cj.jdbc.Driver"
|
||||||
|
# 数据库链接填写格式:
|
||||||
|
# jdbc:mysql://{数据库地址}:{数据库端口}/{使用的库名}?参数
|
||||||
|
# 除非你知道自己在做什么,否则不建议随意更改参数
|
||||||
|
url: "jdbc:mysql://localhost:3306/Test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true"
|
||||||
|
# 如果你不需要做多端跨服,那么请使用 sqlite 作本地数据库
|
||||||
|
# driver: "org.sqlite.JDBC"
|
||||||
|
# url: "jdbc:sqlite:./plugins/AirGameCore/database.db"
|
||||||
|
# 用户名
|
||||||
|
username: "root"
|
||||||
|
# 密码
|
||||||
|
password: "Root123.."
|
||||||
|
# 最小闲置链接数
|
||||||
|
# 推荐值:1~3
|
||||||
|
minimum-idle: 0
|
||||||
|
# 最大链接数
|
||||||
|
# 推荐值:不低于3
|
||||||
|
maximum-pool-size: 3
|
||||||
|
# 保持连接池可用的间隔
|
||||||
|
# 除非你的服务器数据库连接经常断开,否则不建议启用该选项
|
||||||
|
# 单位:毫秒
|
||||||
|
# 默认值为0(禁用)
|
||||||
|
keep-alive-time: 0
|
||||||
|
# 连接闲置回收时间
|
||||||
|
# 单位:毫秒
|
||||||
|
# 推荐值:600000(10分钟)
|
||||||
|
idle-timeout: 600000
|
||||||
|
# 链接最长存活时间
|
||||||
|
# 单位:毫秒
|
||||||
|
max-lifetime: 1800000
|
||||||
|
# 验证连接存活的超时时间
|
||||||
|
# 单位:毫秒
|
||||||
|
validation-timeout: 5000
|
6
core-velocity/src/main/resources/jenkins.yml
Normal file
6
core-velocity/src/main/resources/jenkins.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
BUILD_ID: ${BUILD_ID}
|
||||||
|
BUILD_NUMBER: ${BUILD_NUMBER}
|
||||||
|
BUILD_DISPLAY_NAME: ${BUILD_DISPLAY_NAME}
|
||||||
|
JOB_URL: ${JOB_URL}
|
||||||
|
BUILD_URL: ${BUILD_URL}
|
||||||
|
GIT_COMMIT: ${GIT_COMMIT}
|
@@ -0,0 +1,8 @@
|
|||||||
|
package cn.hamster3.mc.plugin.core.velocity;
|
||||||
|
|
||||||
|
// The constants are replaced before compilation
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
public class BuildConstants {
|
||||||
|
public static final String VERSION = "${version}";
|
||||||
|
public static final String DESCRIPTION = "${description}";
|
||||||
|
}
|
@@ -9,3 +9,4 @@ rootProject.name = "hamster-core"
|
|||||||
include("core-common")
|
include("core-common")
|
||||||
include("core-bukkit")
|
include("core-bukkit")
|
||||||
include("core-bungee")
|
include("core-bungee")
|
||||||
|
include("core-velocity")
|
||||||
|
Reference in New Issue
Block a user