perf: 优化稳定性
This commit is contained in:
@@ -106,6 +106,5 @@ public class BallBukkitListener extends BallListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH)
|
||||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package cn.hamster3.mc.plugin.core.bungee;
|
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.BallServerInfo;
|
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.server.ServerOnlineEvent;
|
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent;
|
||||||
@@ -52,6 +53,13 @@ public class HamsterBallPlugin extends Plugin {
|
|||||||
new ServerOnlineEvent(BallAPI.getInstance().getLocalServerInfo())
|
new ServerOnlineEvent(BallAPI.getInstance().getLocalServerInfo())
|
||||||
);
|
);
|
||||||
logger.info("HamsterBall 已启动.");
|
logger.info("HamsterBall 已启动.");
|
||||||
|
BallAPI.getInstance().getAllPlayerInfo().values().stream()
|
||||||
|
.filter(BallPlayerInfo::isOnline)
|
||||||
|
.filter(o -> BallAPI.getInstance().isLocalServer(o.getProxyServer()))
|
||||||
|
.forEach(playerInfo -> {
|
||||||
|
playerInfo.setOnline(false);
|
||||||
|
BallBungeeCordUtils.uploadPlayerInfo(playerInfo);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -27,9 +27,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.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -157,7 +154,7 @@ public final class BallBungeeCordListener extends BallListener implements Listen
|
|||||||
BallPlayerPostLoginEvent.ACTION,
|
BallPlayerPostLoginEvent.ACTION,
|
||||||
new BallPlayerPostLoginEvent(playerInfo)
|
new BallPlayerPostLoginEvent(playerInfo)
|
||||||
);
|
);
|
||||||
uploadPlayerInfo(playerInfo);
|
BallBungeeCordUtils.uploadPlayerInfo(playerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
@@ -169,7 +166,7 @@ public final class BallBungeeCordListener extends BallListener implements Listen
|
|||||||
BallPlayerConnectServerEvent.ACTION,
|
BallPlayerConnectServerEvent.ACTION,
|
||||||
new BallPlayerConnectServerEvent(playerInfo, playerInfo.getGameServer(), event.getTarget().getName())
|
new BallPlayerConnectServerEvent(playerInfo, playerInfo.getGameServer(), event.getTarget().getName())
|
||||||
);
|
);
|
||||||
uploadPlayerInfo(playerInfo);
|
BallBungeeCordUtils.uploadPlayerInfo(playerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGH)
|
@EventHandler(priority = EventPriority.HIGH)
|
||||||
@@ -181,7 +178,7 @@ public final class BallBungeeCordListener extends BallListener implements Listen
|
|||||||
BallPlayerPostConnectServerEvent.ACTION,
|
BallPlayerPostConnectServerEvent.ACTION,
|
||||||
new BallPlayerPostConnectServerEvent(playerInfo)
|
new BallPlayerPostConnectServerEvent(playerInfo)
|
||||||
);
|
);
|
||||||
uploadPlayerInfo(playerInfo);
|
BallBungeeCordUtils.uploadPlayerInfo(playerInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
@@ -201,23 +198,6 @@ public final class BallBungeeCordListener extends BallListener implements Listen
|
|||||||
BallPlayerLogoutEvent.ACTION,
|
BallPlayerLogoutEvent.ACTION,
|
||||||
new BallPlayerLogoutEvent(playerInfo)
|
new BallPlayerLogoutEvent(playerInfo)
|
||||||
);
|
);
|
||||||
uploadPlayerInfo(playerInfo);
|
BallBungeeCordUtils.uploadPlayerInfo(playerInfo);
|
||||||
}
|
|
||||||
|
|
||||||
private void uploadPlayerInfo(BallPlayerInfo playerInfo) {
|
|
||||||
ProxyServer.getInstance().getScheduler().runAsync(HamsterBallPlugin.getInstance(), () -> {
|
|
||||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
|
||||||
PreparedStatement statement = connection.prepareStatement("REPLACE INTO `hamster_ball_player_info` VALUES(?, ?, ?, ?, ?);");
|
|
||||||
statement.setString(1, playerInfo.getUuid().toString());
|
|
||||||
statement.setString(2, playerInfo.getName());
|
|
||||||
statement.setString(3, playerInfo.getGameServer());
|
|
||||||
statement.setString(4, playerInfo.getProxyServer());
|
|
||||||
statement.setBoolean(5, playerInfo.isOnline());
|
|
||||||
statement.executeUpdate();
|
|
||||||
statement.close();
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,12 +3,18 @@ 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.entity.BallServerInfo;
|
||||||
|
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.constant.CoreConstantObjects;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.config.ServerInfo;
|
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.net.InetSocketAddress;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
public final class BallBungeeCordUtils {
|
public final class BallBungeeCordUtils {
|
||||||
private BallBungeeCordUtils() {
|
private BallBungeeCordUtils() {
|
||||||
@@ -33,4 +39,26 @@ public final class BallBungeeCordUtils {
|
|||||||
false
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void uploadPlayerInfo(BallPlayerInfo playerInfo) {
|
||||||
|
CoreConstantObjects.WORKER_EXECUTOR.execute(() -> {
|
||||||
|
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||||
|
PreparedStatement statement = connection.prepareStatement("REPLACE INTO `hamster_ball_player_info` VALUES(?, ?, ?, ?, ?);");
|
||||||
|
statement.setString(1, playerInfo.getUuid().toString());
|
||||||
|
statement.setString(2, playerInfo.getName());
|
||||||
|
statement.setString(3, playerInfo.getGameServer());
|
||||||
|
statement.setString(4, playerInfo.getProxyServer());
|
||||||
|
statement.setBoolean(5, playerInfo.isOnline());
|
||||||
|
statement.executeUpdate();
|
||||||
|
statement.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
BallAPI.getInstance().sendBallMessage(
|
||||||
|
BallAPI.BALL_CHANNEL,
|
||||||
|
BallPlayerInfoUpdateEvent.ACTION,
|
||||||
|
new BallPlayerInfoUpdateEvent(playerInfo)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -8,7 +8,8 @@ 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.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.BallPlayerConnectServerEvent;
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.event.player.BallPlayerInfoUpdateEvent;
|
||||||
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOfflineEvent;
|
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.event.server.ServerOnlineEvent;
|
||||||
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||||
@@ -89,31 +90,7 @@ public abstract class BallAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBallPlayerLogout(@NotNull BallPlayerLogoutEvent event) {
|
public void onBallPlayerInfoUpdate(@NotNull BallPlayerInfoUpdateEvent event) {
|
||||||
BallPlayerInfo info = event.getPlayerInfo();
|
|
||||||
playerInfo.put(info.getUuid(), info);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBallPlayerLogin(@NotNull BallPlayerLoginEvent event) {
|
|
||||||
BallPlayerInfo info = event.getPlayerInfo();
|
|
||||||
playerInfo.put(info.getUuid(), info);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBallPlayerPostConnectServer(@NotNull BallPlayerPostConnectServerEvent event) {
|
|
||||||
BallPlayerInfo info = event.getPlayerInfo();
|
|
||||||
playerInfo.put(info.getUuid(), info);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBallPlayerPostLogin(@NotNull BallPlayerPostLoginEvent event) {
|
|
||||||
BallPlayerInfo info = event.getPlayerInfo();
|
|
||||||
playerInfo.put(info.getUuid(), info);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBallPlayerPreConnectServer(@NotNull BallPlayerPreConnectServerEvent event) {
|
|
||||||
BallPlayerInfo info = event.getPlayerInfo();
|
BallPlayerInfo info = event.getPlayerInfo();
|
||||||
playerInfo.put(info.getUuid(), info);
|
playerInfo.put(info.getUuid(), info);
|
||||||
}
|
}
|
||||||
|
@@ -116,6 +116,17 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case BallPlayerInfoUpdateEvent.ACTION: {
|
||||||
|
BallPlayerInfoUpdateEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerInfoUpdateEvent.class);
|
||||||
|
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||||
|
try {
|
||||||
|
listener.onBallPlayerInfoUpdate(event);
|
||||||
|
} catch (Exception | Error e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
case BallPlayerChatEvent.ACTION: {
|
case BallPlayerChatEvent.ACTION: {
|
||||||
BallPlayerChatEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerChatEvent.class);
|
BallPlayerChatEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerChatEvent.class);
|
||||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||||
|
@@ -0,0 +1,18 @@
|
|||||||
|
package cn.hamster3.mc.plugin.ball.common.event.player;
|
||||||
|
|
||||||
|
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 玩家已进入子服
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BallPlayerInfoUpdateEvent {
|
||||||
|
public static final String ACTION = "PlayerInfoUpdateEvent";
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final BallPlayerInfo playerInfo;
|
||||||
|
}
|
@@ -6,7 +6,6 @@ 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.event.server.ServerOnlineEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
public abstract class BallListener {
|
public abstract class BallListener {
|
||||||
/**
|
/**
|
||||||
* 该监听器的执行优先级
|
* 该监听器的执行优先级
|
||||||
@@ -53,6 +52,9 @@ public abstract class BallListener {
|
|||||||
public void onBallPlayerLogout(@NotNull BallPlayerLogoutEvent event) {
|
public void onBallPlayerLogout(@NotNull BallPlayerLogoutEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onBallPlayerInfoUpdate(@NotNull BallPlayerInfoUpdateEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
public void onBallPlayerChat(@NotNull BallPlayerChatEvent event) {
|
public void onBallPlayerChat(@NotNull BallPlayerChatEvent event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,11 +14,13 @@ dependencies {
|
|||||||
shade 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
|
shade 'org.apache.logging.log4j:log4j-slf4j-impl:2.19.0'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/io.netty/netty-all
|
// https://mvnrepository.com/artifact/io.netty/netty-all
|
||||||
|
//noinspection GradlePackageUpdate
|
||||||
implementationShade 'io.netty:netty-all:4.1.82.Final'
|
implementationShade 'io.netty:netty-all:4.1.82.Final'
|
||||||
// https://mvnrepository.com/artifact/org.yaml/snakeyaml
|
// https://mvnrepository.com/artifact/org.yaml/snakeyaml
|
||||||
implementationShade 'org.yaml:snakeyaml:1.33'
|
implementationShade 'org.yaml:snakeyaml:1.33'
|
||||||
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
||||||
implementationShade 'com.google.code.gson:gson:2.8.9'
|
//noinspection GradlePackageUpdate
|
||||||
|
implementationShade 'com.google.code.gson:gson:2.8.0'
|
||||||
|
|
||||||
|
|
||||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
|
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
|
||||||
|
Reference in New Issue
Block a user