feat: 初版完成
初版完成
This commit is contained in:
49
hamster-core-bungeecord/build.gradle
Normal file
49
hamster-core-bungeecord/build.gradle
Normal file
@@ -0,0 +1,49 @@
|
||||
setArchivesBaseName("HamsterCore-BungeeCord")
|
||||
|
||||
evaluationDependsOn(':hamster-core-common')
|
||||
|
||||
dependencies {
|
||||
apiShade(project(":hamster-core-common")) {
|
||||
exclude group: "*"
|
||||
}
|
||||
//noinspection GradlePackageUpdate
|
||||
compileOnly('net.md-5:bungeecord-api:1.17-R0.1-SNAPSHOT')
|
||||
// https://mvnrepository.com/artifact/net.kyori/adventure-platform-bungeecord
|
||||
apiShade 'net.kyori:adventure-platform-bungeecord:4.1.2'
|
||||
|
||||
// https://mvnrepository.com/artifact/com.zaxxer/HikariCP
|
||||
//noinspection GradlePackageUpdate
|
||||
apiShade 'com.zaxxer:HikariCP:4.0.3'
|
||||
// https://mvnrepository.com/artifact/mysql/mysql-connector-java
|
||||
shade 'mysql:mysql-connector-java:8.0.31'
|
||||
// https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp
|
||||
apiShade 'com.squareup.okhttp3:okhttp:4.10.0'
|
||||
}
|
||||
|
||||
processResources {
|
||||
inputs.property "version", project.version
|
||||
filesMatching("bungee.yml") {
|
||||
expand "version": project.version
|
||||
}
|
||||
}
|
||||
|
||||
tasks.compileJava.dependsOn(":hamster-core-common:build")
|
||||
tasks.create("shadowJar", Jar) {
|
||||
dependsOn("jar")
|
||||
from([
|
||||
tasks.jar.outputs.files.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
},
|
||||
configurations.shade.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
},
|
||||
configurations.apiShade.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
},
|
||||
configurations.implementationShade.collect {
|
||||
it.isDirectory() ? it : zipTree(it)
|
||||
}
|
||||
])
|
||||
destinationDir(getRootProject().buildDir)
|
||||
}
|
||||
tasks.build.dependsOn(shadowJar)
|
@@ -0,0 +1,44 @@
|
||||
package cn.hamster3.mc.plugin.core.bungee;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.bungee.api.CoreBungeeAPI;
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class HamsterCorePlugin extends Plugin {
|
||||
private static HamsterCorePlugin instance;
|
||||
|
||||
public static HamsterCorePlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Logger logger = getLogger();
|
||||
long start = System.currentTimeMillis();
|
||||
logger.info("仓鼠核心正在启动...");
|
||||
CoreBungeeAPI.init();
|
||||
logger.info("CoreAPI 已初始化.");
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠核心已启动,总计耗时 " + time + " ms.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
Logger logger = getLogger();
|
||||
long start = System.currentTimeMillis();
|
||||
logger.info("仓鼠核心正在关闭...");
|
||||
CoreConstantObjects.WORKER_EXECUTOR.shutdownNow();
|
||||
logger.info("已暂停 WORKER_EXECUTOR.");
|
||||
CoreConstantObjects.SCHEDULED_EXECUTOR.shutdownNow();
|
||||
logger.info("已暂停 SCHEDULED_EXECUTOR.");
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠核心已关闭,总计耗时 " + time + " ms.");
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
package cn.hamster3.mc.plugin.core.bungee.api;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.bungee.HamsterCorePlugin;
|
||||
import cn.hamster3.mc.plugin.core.bungee.util.BungeeCordUtils;
|
||||
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.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class CoreBungeeAPI extends CoreAPI {
|
||||
private final BungeeAudiences audienceProvider;
|
||||
private final HikariDataSource datasource;
|
||||
|
||||
public CoreBungeeAPI() {
|
||||
HamsterCorePlugin plugin = HamsterCorePlugin.getInstance();
|
||||
audienceProvider = BungeeAudiences.create(plugin);
|
||||
|
||||
Configuration config = BungeeCordUtils.getPluginConfig(plugin);
|
||||
|
||||
Configuration datasourceConfig = config.getSection("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));
|
||||
hikariConfig.setIdleTimeout(datasourceConfig.getLong("idle-timeout", 5 * 60 * 1000));
|
||||
hikariConfig.setMaxLifetime(datasourceConfig.getLong("max-lifetime", 0));
|
||||
datasource = new HikariDataSource(hikariConfig);
|
||||
}
|
||||
|
||||
public static CoreBungeeAPI getInstance() {
|
||||
return (CoreBungeeAPI) instance;
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
instance = new CoreBungeeAPI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull AudienceProvider getAudienceProvider() {
|
||||
return audienceProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull HikariDataSource getDataSource() {
|
||||
return datasource;
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public final class BungeeCordUtils {
|
||||
private BungeeCordUtils() {
|
||||
}
|
||||
|
||||
public static Configuration getPluginConfig(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);
|
||||
}
|
||||
}
|
||||
|
||||
public static Configuration saveDefaultConfig(Plugin plugin) {
|
||||
try {
|
||||
if (plugin.getDataFolder().mkdir()) {
|
||||
plugin.getLogger().info("创建插件文件夹...");
|
||||
}
|
||||
File configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||
InputStream in = plugin.getResourceAsStream("config.yml");
|
||||
Files.copy(in, configFile.toPath());
|
||||
return ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
3
hamster-core-bungeecord/src/main/resources/bungee.yml
Normal file
3
hamster-core-bungeecord/src/main/resources/bungee.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
name: HamsterCore-BungeeCord
|
||||
main: cn.hamster3.mc.plugin.core.bungee.HamsterCorePlugin
|
||||
version: ${version}
|
23
hamster-core-bungeecord/src/main/resources/config.yml
Normal file
23
hamster-core-bungeecord/src/main/resources/config.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
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"
|
||||
# 用户名
|
||||
username: "Test"
|
||||
# 密码
|
||||
password: "Test123.."
|
||||
# 最大链接数
|
||||
maximum-pool-size: 10
|
||||
# 最小链接数
|
||||
minimum-idle: 1
|
||||
# 超时回收时间
|
||||
# 单位:毫秒
|
||||
idle-timeout: 300000
|
||||
# 链接最长存活时间
|
||||
# 单位:毫秒
|
||||
# 建议设置为比数据库上的 wait_timeout 参数少 30 秒
|
||||
max-lifetime: 1800000
|
Reference in New Issue
Block a user