perf: 优化代码
This commit is contained in:
@@ -19,7 +19,7 @@ processResources {
|
||||
}
|
||||
|
||||
tasks.compileJava.dependsOn(":hamster-ball-common:build")
|
||||
tasks.create("shadowJar", Jar) {
|
||||
tasks.register("shadowJar", Jar) {
|
||||
dependsOn("jar")
|
||||
from([
|
||||
tasks.jar.outputs.files.collect {
|
||||
|
@@ -6,6 +6,7 @@ import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent;
|
||||
import cn.hamster3.mc.plugin.core.bungee.api.BallBungeeCordAPI;
|
||||
import cn.hamster3.mc.plugin.core.bungee.core.BallConfigManager;
|
||||
import cn.hamster3.mc.plugin.core.bungee.listener.BallBungeeCordListener;
|
||||
import cn.hamster3.mc.plugin.core.bungee.util.BallBungeeCordUtils;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@@ -24,6 +25,8 @@ public class HamsterBallPlugin extends Plugin {
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
Logger logger = getLogger();
|
||||
BallConfigManager.init();
|
||||
logger.info("BallConfigManager 已初始化.");
|
||||
BallBungeeCordAPI.init();
|
||||
logger.info("BallBungeeCordAPI 已初始化.");
|
||||
try {
|
||||
@@ -40,12 +43,15 @@ public class HamsterBallPlugin extends Plugin {
|
||||
Logger logger = getLogger();
|
||||
ProxyServer.getInstance().getPluginManager().registerListener(this, BallBungeeCordListener.INSTANCE);
|
||||
logger.info("已注册 BallBungeeCordListener.");
|
||||
for (BallServerInfo serverInfo : BallAPI.getInstance().getAllServerInfo().values()) {
|
||||
if (serverInfo.getType() != BallServerType.GAME) {
|
||||
continue;
|
||||
if (BallConfigManager.isAutoRegisterServer()) {
|
||||
ProxyServer.getInstance().getServers().clear();
|
||||
for (BallServerInfo serverInfo : BallAPI.getInstance().getAllServerInfo().values()) {
|
||||
if (serverInfo.getType() != BallServerType.GAME) {
|
||||
continue;
|
||||
}
|
||||
ProxyServer.getInstance().getServers().put(serverInfo.getId(), BallBungeeCordUtils.getServerInfo(serverInfo));
|
||||
HamsterBallPlugin.getInstance().getLogger().info("已添加子服 " + serverInfo.getId() + " 的接入点配置.");
|
||||
}
|
||||
ProxyServer.getInstance().getServers().put(serverInfo.getId(), BallBungeeCordUtils.getServerInfo(serverInfo));
|
||||
HamsterBallPlugin.getInstance().getLogger().info("已添加子服 " + serverInfo.getId() + " 的接入点配置.");
|
||||
}
|
||||
BallAPI.getInstance().sendBallMessage(
|
||||
BallAPI.BALL_CHANNEL,
|
||||
|
@@ -6,8 +6,8 @@ import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||
import cn.hamster3.mc.plugin.ball.common.listener.BallDebugListener;
|
||||
import cn.hamster3.mc.plugin.core.bungee.HamsterBallPlugin;
|
||||
import cn.hamster3.mc.plugin.core.bungee.core.BallConfigManager;
|
||||
import cn.hamster3.mc.plugin.core.bungee.listener.BallBungeeCordListener;
|
||||
import cn.hamster3.mc.plugin.core.bungee.util.BungeeCordUtils;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -27,8 +27,7 @@ public class BallBungeeCordAPI extends BallAPI {
|
||||
if (instance != null) {
|
||||
return;
|
||||
}
|
||||
HamsterBallPlugin plugin = HamsterBallPlugin.getInstance();
|
||||
Configuration pluginConfig = BungeeCordUtils.getPluginConfig(plugin);
|
||||
Configuration pluginConfig = BallConfigManager.getPluginConfig();
|
||||
BallConfig config = new BallConfig(
|
||||
new BallServerInfo(
|
||||
pluginConfig.getString("server-info.id"),
|
||||
|
@@ -0,0 +1,27 @@
|
||||
package cn.hamster3.mc.plugin.core.bungee.core;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.bungee.HamsterBallPlugin;
|
||||
import cn.hamster3.mc.plugin.core.bungee.util.BungeeCordUtils;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
|
||||
public final class BallConfigManager {
|
||||
private static Configuration pluginConfig;
|
||||
private static boolean autoRegisterServer;
|
||||
|
||||
private BallConfigManager() {
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
HamsterBallPlugin plugin = HamsterBallPlugin.getInstance();
|
||||
pluginConfig = BungeeCordUtils.getPluginConfig(plugin);
|
||||
autoRegisterServer = pluginConfig.getBoolean("auto-register-server", true);
|
||||
}
|
||||
|
||||
public static Configuration getPluginConfig() {
|
||||
return pluginConfig;
|
||||
}
|
||||
|
||||
public static boolean isAutoRegisterServer() {
|
||||
return autoRegisterServer;
|
||||
}
|
||||
}
|
@@ -11,6 +11,7 @@ import cn.hamster3.mc.plugin.ball.common.event.server.ServerOfflineEvent;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent;
|
||||
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||
import cn.hamster3.mc.plugin.core.bungee.HamsterBallPlugin;
|
||||
import cn.hamster3.mc.plugin.core.bungee.core.BallConfigManager;
|
||||
import cn.hamster3.mc.plugin.core.bungee.util.BallBungeeCordUtils;
|
||||
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
@@ -102,6 +103,9 @@ public final class BallBungeeCordListener extends BallListener implements Listen
|
||||
|
||||
@Override
|
||||
public void onServerOnline(@NotNull ServerOnlineEvent event) {
|
||||
if (!BallConfigManager.isAutoRegisterServer()) {
|
||||
return;
|
||||
}
|
||||
BallServerInfo serverInfo = event.getServerInfo();
|
||||
if (serverInfo.getType() != BallServerType.GAME) {
|
||||
return;
|
||||
@@ -112,6 +116,9 @@ public final class BallBungeeCordListener extends BallListener implements Listen
|
||||
|
||||
@Override
|
||||
public void onServerOffline(@NotNull ServerOfflineEvent event) {
|
||||
if (!BallConfigManager.isAutoRegisterServer()) {
|
||||
return;
|
||||
}
|
||||
Map<String, ServerInfo> map = ProxyServer.getInstance().getServers();
|
||||
if (map.remove(event.getServerID()) != null) {
|
||||
HamsterBallPlugin.getInstance().getLogger().info("已移除子服 " + event.getServerID() + " 的接入点配置.");
|
||||
|
@@ -13,3 +13,9 @@ server-info:
|
||||
name: "代理端"
|
||||
host: 0.0.0.0
|
||||
port: 25577
|
||||
|
||||
# 是否允许 HamsterBall 自动添加子服接入点配置
|
||||
# 开启该功能后,插件启动时将会自动清除 BC 中配置的所有子服信息
|
||||
# 并从数据库中读取子服的数据,然后自动填充
|
||||
# 使用的链接地址取决于子服 HamsterBall 配置文件中的 server-info 信息
|
||||
auto-register-server: true
|
||||
|
Reference in New Issue
Block a user