perf: 优化性能
This commit is contained in:
@@ -5,12 +5,10 @@ import cn.hamster3.mc.plugin.ball.bukkit.data.BukkitLocation;
|
|||||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||||
import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo;
|
import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo;
|
||||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||||
import cn.hamster3.mc.plugin.ball.common.event.operate.DispatchConsoleCommandEvent;
|
import cn.hamster3.mc.plugin.ball.common.event.operate.*;
|
||||||
import cn.hamster3.mc.plugin.ball.common.event.operate.DispatchPlayerCommandEvent;
|
|
||||||
import cn.hamster3.mc.plugin.ball.common.event.operate.SendPlayerToLocationEvent;
|
|
||||||
import cn.hamster3.mc.plugin.ball.common.event.operate.SendPlayerToPlayerEvent;
|
|
||||||
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||||
import cn.hamster3.mc.plugin.core.bukkit.api.CoreBukkitAPI;
|
import cn.hamster3.mc.plugin.core.bukkit.api.CoreBukkitAPI;
|
||||||
|
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||||
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
||||||
import cn.hamster3.mc.plugin.core.common.util.Pair;
|
import cn.hamster3.mc.plugin.core.common.util.Pair;
|
||||||
@@ -44,6 +42,13 @@ public class BallBukkitListener implements Listener, BallListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(@NotNull BallMessageInfo info) {
|
public void onMessageReceived(@NotNull BallMessageInfo info) {
|
||||||
switch (info.getAction()) {
|
switch (info.getAction()) {
|
||||||
|
case BroadcastPlayerMessageEvent.ACTION: {
|
||||||
|
BroadcastPlayerMessageEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BroadcastPlayerMessageEvent.class);
|
||||||
|
DisplayMessage message = event.getMessage();
|
||||||
|
Audience audience = CoreAPI.getInstance().getAudienceProvider().all();
|
||||||
|
message.show(audience);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case DispatchConsoleCommandEvent.ACTION: {
|
case DispatchConsoleCommandEvent.ACTION: {
|
||||||
DispatchConsoleCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
|
DispatchConsoleCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
|
||||||
if (event.getType() != null && event.getType() != BallServerType.GAME) {
|
if (event.getType() != null && event.getType() != BallServerType.GAME) {
|
||||||
|
@@ -2,11 +2,8 @@ package cn.hamster3.mc.plugin.core.bungee;
|
|||||||
|
|
||||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||||
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
||||||
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.ball.common.event.server.ServerOnlineEvent;
|
||||||
import cn.hamster3.mc.plugin.core.bungee.api.BallBungeeCordAPI;
|
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.listener.BallBungeeCordListener;
|
||||||
import cn.hamster3.mc.plugin.core.bungee.util.BallBungeeCordUtils;
|
import cn.hamster3.mc.plugin.core.bungee.util.BallBungeeCordUtils;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@@ -25,8 +22,6 @@ public class HamsterBallPlugin extends Plugin {
|
|||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
instance = this;
|
instance = this;
|
||||||
Logger logger = getLogger();
|
Logger logger = getLogger();
|
||||||
BallConfigManager.init();
|
|
||||||
logger.info("BallConfigManager 已初始化.");
|
|
||||||
BallBungeeCordAPI.init();
|
BallBungeeCordAPI.init();
|
||||||
logger.info("BallBungeeCordAPI 已初始化.");
|
logger.info("BallBungeeCordAPI 已初始化.");
|
||||||
try {
|
try {
|
||||||
@@ -43,16 +38,6 @@ public class HamsterBallPlugin extends Plugin {
|
|||||||
Logger logger = getLogger();
|
Logger logger = getLogger();
|
||||||
ProxyServer.getInstance().getPluginManager().registerListener(this, BallBungeeCordListener.INSTANCE);
|
ProxyServer.getInstance().getPluginManager().registerListener(this, BallBungeeCordListener.INSTANCE);
|
||||||
logger.info("已注册 BallBungeeCordListener.");
|
logger.info("已注册 BallBungeeCordListener.");
|
||||||
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() + " 的接入点配置.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
BallAPI.getInstance().sendBallMessage(
|
BallAPI.getInstance().sendBallMessage(
|
||||||
BallAPI.BALL_CHANNEL,
|
BallAPI.BALL_CHANNEL,
|
||||||
ServerOnlineEvent.ACTION,
|
ServerOnlineEvent.ACTION,
|
||||||
|
@@ -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.entity.BallServerType;
|
||||||
import cn.hamster3.mc.plugin.ball.common.listener.BallDebugListener;
|
import cn.hamster3.mc.plugin.ball.common.listener.BallDebugListener;
|
||||||
import cn.hamster3.mc.plugin.core.bungee.HamsterBallPlugin;
|
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.listener.BallBungeeCordListener;
|
||||||
|
import cn.hamster3.mc.plugin.core.bungee.util.BungeeCordUtils;
|
||||||
import net.md_5.bungee.config.Configuration;
|
import net.md_5.bungee.config.Configuration;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -27,7 +27,8 @@ public class BallBungeeCordAPI extends BallAPI {
|
|||||||
if (instance != null) {
|
if (instance != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Configuration pluginConfig = BallConfigManager.getPluginConfig();
|
HamsterBallPlugin plugin = HamsterBallPlugin.getInstance();
|
||||||
|
Configuration pluginConfig = BungeeCordUtils.getPluginConfig(plugin);
|
||||||
BallConfig config = new BallConfig(
|
BallConfig config = new BallConfig(
|
||||||
new BallServerInfo(
|
new BallServerInfo(
|
||||||
pluginConfig.getString("server-info.id"),
|
pluginConfig.getString("server-info.id"),
|
||||||
|
@@ -1,27 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -3,19 +3,14 @@ package cn.hamster3.mc.plugin.core.bungee.listener;
|
|||||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||||
import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo;
|
import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo;
|
||||||
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
||||||
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.entity.BallServerType;
|
||||||
import cn.hamster3.mc.plugin.ball.common.event.operate.*;
|
import cn.hamster3.mc.plugin.ball.common.event.operate.*;
|
||||||
import cn.hamster3.mc.plugin.ball.common.event.player.*;
|
import cn.hamster3.mc.plugin.ball.common.event.player.*;
|
||||||
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.ball.common.listener.BallListener;
|
||||||
import cn.hamster3.mc.plugin.core.bungee.HamsterBallPlugin;
|
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.bungee.util.BallBungeeCordUtils;
|
||||||
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||||
import cn.hamster3.mc.plugin.core.common.data.DisplayMessage;
|
|
||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
@@ -28,7 +23,6 @@ import net.md_5.bungee.event.EventHandler;
|
|||||||
import net.md_5.bungee.event.EventPriority;
|
import net.md_5.bungee.event.EventPriority;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class BallBungeeCordListener implements Listener, BallListener {
|
public final class BallBungeeCordListener implements Listener, BallListener {
|
||||||
@@ -40,13 +34,6 @@ public final class BallBungeeCordListener implements Listener, BallListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(@NotNull BallMessageInfo info) {
|
public void onMessageReceived(@NotNull BallMessageInfo info) {
|
||||||
switch (info.getAction()) {
|
switch (info.getAction()) {
|
||||||
case BroadcastPlayerMessageEvent.ACTION: {
|
|
||||||
BroadcastPlayerMessageEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BroadcastPlayerMessageEvent.class);
|
|
||||||
DisplayMessage message = event.getMessage();
|
|
||||||
Audience audience = CoreAPI.getInstance().getAudienceProvider().all();
|
|
||||||
message.show(audience);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DispatchConsoleCommandEvent.ACTION: {
|
case DispatchConsoleCommandEvent.ACTION: {
|
||||||
DispatchConsoleCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
|
DispatchConsoleCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
|
||||||
if (event.getType() != null && event.getType() != BallServerType.PROXY) {
|
if (event.getType() != null && event.getType() != BallServerType.PROXY) {
|
||||||
@@ -121,30 +108,6 @@ public final class BallBungeeCordListener implements Listener, BallListener {
|
|||||||
ProxyServer.getInstance().stop("HamsterBall 重连失败.");
|
ProxyServer.getInstance().stop("HamsterBall 重连失败.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServerOnline(@NotNull ServerOnlineEvent event) {
|
|
||||||
if (!BallConfigManager.isAutoRegisterServer()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
BallServerInfo serverInfo = event.getServerInfo();
|
|
||||||
if (serverInfo.getType() != BallServerType.GAME) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ProxyServer.getInstance().getServers().put(serverInfo.getId(), BallBungeeCordUtils.getServerInfo(serverInfo));
|
|
||||||
HamsterBallPlugin.getInstance().getLogger().info("已添加子服 " + serverInfo.getId() + " 的接入点配置.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@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() + " 的接入点配置.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
public void onPreLogin(PreLoginEvent event) {
|
public void onPreLogin(PreLoginEvent event) {
|
||||||
BallAPI.getInstance().sendBallMessage(
|
BallAPI.getInstance().sendBallMessage(
|
||||||
|
@@ -2,16 +2,12 @@ package cn.hamster3.mc.plugin.core.bungee.util;
|
|||||||
|
|
||||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||||
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
||||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo;
|
|
||||||
import cn.hamster3.mc.plugin.ball.common.event.player.BallPlayerInfoUpdateEvent;
|
import cn.hamster3.mc.plugin.ball.common.event.player.BallPlayerInfoUpdateEvent;
|
||||||
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.connection.Server;
|
import net.md_5.bungee.api.connection.Server;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@@ -31,15 +27,6 @@ public final class BallBungeeCordUtils {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ServerInfo getServerInfo(BallServerInfo serverInfo) {
|
|
||||||
return ProxyServer.getInstance().constructServerInfo(
|
|
||||||
serverInfo.getId(),
|
|
||||||
new InetSocketAddress(serverInfo.getHost(), serverInfo.getPort()),
|
|
||||||
serverInfo.getName(),
|
|
||||||
false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void uploadPlayerInfo(BallPlayerInfo playerInfo) {
|
public static void uploadPlayerInfo(BallPlayerInfo playerInfo) {
|
||||||
CoreConstantObjects.WORKER_EXECUTOR.execute(() -> {
|
CoreConstantObjects.WORKER_EXECUTOR.execute(() -> {
|
||||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||||
|
@@ -13,9 +13,3 @@ server-info:
|
|||||||
name: "代理端"
|
name: "代理端"
|
||||||
host: 0.0.0.0
|
host: 0.0.0.0
|
||||||
port: 25577
|
port: 25577
|
||||||
|
|
||||||
# 是否允许 HamsterBall 自动添加子服接入点配置
|
|
||||||
# 开启该功能后,插件启动时将会自动清除 BC 中配置的所有子服信息
|
|
||||||
# 并从数据库中读取子服的数据,然后自动填充
|
|
||||||
# 使用的链接地址取决于子服 HamsterBall 配置文件中的 server-info 信息
|
|
||||||
auto-register-server: true
|
|
||||||
|
Reference in New Issue
Block a user