build: 更改项目结构
This commit is contained in:
70
core-bungeecord/build.gradle
Normal file
70
core-bungeecord/build.gradle
Normal file
@@ -0,0 +1,70 @@
|
||||
//file:noinspection GroovyAssignabilityCheck
|
||||
//file:noinspection VulnerableLibrariesLocal
|
||||
//file:noinspection GrDeprecatedAPIUsage
|
||||
plugins {
|
||||
id 'com.github.johnrengelman.shadow' version '7+'
|
||||
}
|
||||
setArchivesBaseName("HamsterCore-BungeeCord")
|
||||
|
||||
evaluationDependsOn(':core-common')
|
||||
|
||||
dependencies {
|
||||
//noinspection VulnerableLibrariesLocal
|
||||
compileOnly 'net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT'
|
||||
|
||||
implementation project(":core-common") transitive false
|
||||
//noinspection GradlePackageUpdate
|
||||
implementation "com.zaxxer:HikariCP:${HikariCP_version}"
|
||||
// https://mvnrepository.com/artifact/net.kyori/adventure-platform-bungeecord
|
||||
implementation "net.kyori:adventure-platform-bungeecord:${adventure_version}" exclude group: 'org.jetbrains' exclude group: 'com.google.code.gson'
|
||||
// https://mvnrepository.com/artifact/net.kyori/adventure-text-minimessage
|
||||
implementation "net.kyori:adventure-text-minimessage:${adventure_serializer_version}" exclude group: 'org.jetbrains'
|
||||
// https://mvnrepository.com/artifact/net.kyori/adventure-text-serializer-gson
|
||||
implementation "net.kyori:adventure-text-serializer-gson:${adventure_serializer_version}" exclude group: 'org.jetbrains' exclude group: 'com.google.code.gson'
|
||||
// https://mvnrepository.com/artifact/net.kyori/adventure-text-serializer-legacy
|
||||
implementation "net.kyori:adventure-text-serializer-legacy:${adventure_serializer_version}" exclude group: 'org.jetbrains'
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
filesMatching("bungee.yml") {
|
||||
expand "version": project.version
|
||||
}
|
||||
}
|
||||
|
||||
jar {
|
||||
classifier = 'dev'
|
||||
}
|
||||
|
||||
tasks.compileJava.dependsOn(":core-common:build")
|
||||
shadowJar {
|
||||
classifier = ''
|
||||
relocate 'org.slf4j', 'cn.hamster3.mc.plugin.core.lib.slf4j'
|
||||
relocate 'net.kyori', 'cn.hamster3.mc.plugin.core.lib.kyori'
|
||||
relocate 'com.zaxxer.hikari', 'cn.hamster3.mc.plugin.core.lib.hikari'
|
||||
destinationDir(getRootProject().buildDir)
|
||||
}
|
||||
tasks.build.dependsOn(shadowJar)
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
shadow(MavenPublication) { publication ->
|
||||
{
|
||||
from components.java
|
||||
}
|
||||
}
|
||||
}
|
||||
repositories {
|
||||
maven {
|
||||
def releasesRepoUrl = 'https://maven.airgame.net/maven-releases/'
|
||||
def snapshotsRepoUrl = 'https://maven.airgame.net/maven-snapshots/'
|
||||
|
||||
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
|
||||
|
||||
credentials {
|
||||
username = rootProject.properties.getOrDefault("maven_username", "")
|
||||
password = rootProject.properties.getOrDefault("maven_password", "")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
package cn.hamster3.mc.plugin.core.bungee;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.bungee.api.CoreBungeeAPI;
|
||||
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class HamsterCorePlugin extends Plugin {
|
||||
private static HamsterCorePlugin instance;
|
||||
private BungeeAudiences audienceProvider;
|
||||
|
||||
public static HamsterCorePlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
Logger logger = getLogger();
|
||||
long start = System.currentTimeMillis();
|
||||
logger.info("仓鼠核心正在初始化...");
|
||||
CoreBungeeAPI.init();
|
||||
logger.info("CoreBungeeAPI 已初始化.");
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠核心初始化完成,总计耗时 " + time + " ms.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Logger logger = getLogger();
|
||||
long start = System.currentTimeMillis();
|
||||
logger.info("仓鼠核心正在启动...");
|
||||
audienceProvider = BungeeAudiences.create(this);
|
||||
logger.info("完成 BungeeAudiences 挂载.");
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠核心启动完成,总计耗时 " + time + " ms.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Logger logger = getLogger();
|
||||
long start = System.currentTimeMillis();
|
||||
logger.info("仓鼠核心正在关闭...");
|
||||
CoreUtils.WORKER_EXECUTOR.shutdownNow();
|
||||
logger.info("已暂停 WORKER_EXECUTOR.");
|
||||
CoreUtils.SCHEDULED_EXECUTOR.shutdownNow();
|
||||
logger.info("已暂停 SCHEDULED_EXECUTOR.");
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms.");
|
||||
}
|
||||
|
||||
public BungeeAudiences getAudienceProvider() {
|
||||
return audienceProvider;
|
||||
}
|
||||
}
|
@@ -0,0 +1,64 @@
|
||||
package cn.hamster3.mc.plugin.core.bungee.api;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.bungee.HamsterCorePlugin;
|
||||
import cn.hamster3.mc.plugin.core.bungee.util.CoreBungeeCordUtils;
|
||||
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import net.kyori.adventure.platform.AudienceProvider;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class CoreBungeeAPI extends CoreAPI {
|
||||
private final HikariDataSource datasource;
|
||||
|
||||
private CoreBungeeAPI() {
|
||||
HamsterCorePlugin plugin = HamsterCorePlugin.getInstance();
|
||||
|
||||
Configuration config = CoreBungeeCordUtils.getPluginConfig(plugin);
|
||||
Configuration datasourceConfig = config.getSection("datasource");
|
||||
if (datasourceConfig == null) {
|
||||
throw new IllegalArgumentException("配置文件中未找到 datasource 节点!");
|
||||
}
|
||||
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
hikariConfig.setDriverClassName(datasourceConfig.getString("driver"));
|
||||
hikariConfig.setJdbcUrl(datasourceConfig.getString("url"));
|
||||
hikariConfig.setUsername(datasourceConfig.getString("username"));
|
||||
hikariConfig.setPassword(datasourceConfig.getString("password"));
|
||||
hikariConfig.setMaximumPoolSize(datasourceConfig.getInt("maximum-pool-size", 3));
|
||||
hikariConfig.setMinimumIdle(datasourceConfig.getInt("minimum-idle", 1));
|
||||
long keepAliveTime = datasourceConfig.getLong("keep-alive-time", 0);
|
||||
if (keepAliveTime > 5000) {
|
||||
hikariConfig.setKeepaliveTime(keepAliveTime);
|
||||
}
|
||||
hikariConfig.setIdleTimeout(datasourceConfig.getLong("idle-timeout", 10 * 60 * 1000));
|
||||
hikariConfig.setMaxLifetime(datasourceConfig.getLong("max-lifetime", 30 * 60 * 1000));
|
||||
hikariConfig.setValidationTimeout(datasourceConfig.getLong("validation-timeout", 5000));
|
||||
hikariConfig.setPoolName("HamsterCore-Pool");
|
||||
|
||||
datasource = new HikariDataSource(hikariConfig);
|
||||
}
|
||||
|
||||
public static CoreBungeeAPI getInstance() {
|
||||
return (CoreBungeeAPI) instance;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
if (instance != null) {
|
||||
return;
|
||||
}
|
||||
instance = new CoreBungeeAPI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull AudienceProvider getAudienceProvider() {
|
||||
return HamsterCorePlugin.getInstance().getAudienceProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HikariDataSource getDataSource() {
|
||||
return datasource;
|
||||
}
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
package cn.hamster3.mc.plugin.core.bungee.util;
|
||||
|
||||
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;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class CoreBungeeCordUtils {
|
||||
private CoreBungeeCordUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Configuration getConfig(@NotNull File file) {
|
||||
if (!file.exists()) {
|
||||
throw new IllegalArgumentException("文件不存在!");
|
||||
}
|
||||
try {
|
||||
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Configuration getPluginConfig(@NotNull Plugin plugin) {
|
||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
if (!configFile.exists()) {
|
||||
return saveDefaultConfig(plugin);
|
||||
}
|
||||
try {
|
||||
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Configuration saveDefaultConfig(@NotNull Plugin plugin) {
|
||||
if (plugin.getDataFolder().mkdir()) {
|
||||
plugin.getLogger().info("创建插件文件夹...");
|
||||
}
|
||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
try {
|
||||
InputStream in = plugin.getResourceAsStream("config.yml");
|
||||
Files.copy(in, configFile.toPath());
|
||||
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
5
core-bungeecord/src/main/resources/bungee.yml
Normal file
5
core-bungeecord/src/main/resources/bungee.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
name: HamsterCore
|
||||
main: cn.hamster3.mc.plugin.core.bungee.HamsterCorePlugin
|
||||
version: ${version}
|
||||
|
||||
author: MiniDay
|
33
core-bungeecord/src/main/resources/config.yml
Normal file
33
core-bungeecord/src/main/resources/config.yml
Normal file
@@ -0,0 +1,33 @@
|
||||
datasource:
|
||||
# 数据库链接驱动地址
|
||||
# 除非你知道自己在做什么,否则不建议更改该项
|
||||
driver: "com.mysql.cj.jdbc.Driver"
|
||||
# 数据库链接填写格式:
|
||||
# jdbc:mysql://{数据库地址}:{数据库端口}/{使用的库名}?参数
|
||||
# 除非你知道自己在做什么,否则不建议随意更改参数
|
||||
url: "jdbc:mysql://sql.hamster3.cn:3306/Test1?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false&allowPublicKeyRetrieval=true"
|
||||
# 用户名
|
||||
username: "Test"
|
||||
# 密码
|
||||
password: "Test123.."
|
||||
# 最小闲置链接数
|
||||
# 推荐值:1~3
|
||||
minimum-idle: 0
|
||||
# 最大链接数
|
||||
# 推荐值:不低于5
|
||||
maximum-pool-size: 5
|
||||
# 保持连接池可用的间隔
|
||||
# 除非你的服务器数据库连接经常断开,否则不建议启用该选项
|
||||
# 单位:毫秒
|
||||
# 默认值为0(禁用)
|
||||
keep-alive-time: 0
|
||||
# 连接闲置回收时间
|
||||
# 单位:毫秒
|
||||
# 推荐值:600000(10分钟)
|
||||
idle-timeout: 600000
|
||||
# 链接最长存活时间
|
||||
# 单位:毫秒
|
||||
max-lifetime: 1800000
|
||||
# 验证连接存活的超时时间
|
||||
# 单位:毫秒
|
||||
validation-timeout: 5000
|
Reference in New Issue
Block a user