perf: 优化代码
This commit is contained in:
@@ -3,15 +3,11 @@
|
||||
evaluationDependsOn(":ball-common")
|
||||
|
||||
dependencies {
|
||||
implementation(project(":ball-common")) {
|
||||
isTransitive = false
|
||||
}
|
||||
api(project(":ball-common")) { isTransitive = false }
|
||||
compileOnly("org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT")
|
||||
|
||||
compileOnly("cn.hamster3.mc.plugin:core-bukkit:+")
|
||||
compileOnly("me.clip:placeholderapi:2.11.5") {
|
||||
isTransitive = false
|
||||
}
|
||||
|
||||
compileOnly("me.clip:placeholderapi:2.11.5") { isTransitive = false }
|
||||
}
|
||||
|
||||
tasks {
|
||||
|
@@ -18,9 +18,9 @@ import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public class HamsterBallPlugin extends JavaPlugin {
|
||||
@Getter
|
||||
private static HamsterBallPlugin instance;
|
||||
@@ -58,7 +58,9 @@ public class HamsterBallPlugin extends JavaPlugin {
|
||||
BallBukkitAPI.init(configFile);
|
||||
logger.info("已初始化 BallAPI");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.log(Level.SEVERE, "BallAPI 初始化失败", e);
|
||||
Bukkit.shutdown();
|
||||
return;
|
||||
}
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠球初始化完成,总计耗时 " + time + " ms");
|
||||
@@ -72,9 +74,8 @@ public class HamsterBallPlugin extends JavaPlugin {
|
||||
try {
|
||||
BallBukkitAPI.getInstance().enable();
|
||||
} catch (Exception e) {
|
||||
getLogger().info("仓鼠球启动失败,原因:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
getLogger().info("由于仓鼠球启动失败,服务器将立即关闭");
|
||||
logger.log(Level.SEVERE, "仓鼠球启动失败", e);
|
||||
logger.info("由于仓鼠球启动失败,服务器将立即关闭");
|
||||
Bukkit.shutdown();
|
||||
return;
|
||||
}
|
||||
@@ -121,7 +122,7 @@ public class HamsterBallPlugin extends JavaPlugin {
|
||||
try {
|
||||
BallBukkitAPI.getInstance().disable();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.log(Level.SEVERE, "关闭仓鼠球时遇到了一个异常", e);
|
||||
}
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠球已关闭,总计耗时 " + time + " ms");
|
||||
|
@@ -30,8 +30,8 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public class BallBukkitListener implements Listener {
|
||||
public static final BallBukkitListener INSTANCE = new BallBukkitListener();
|
||||
|
||||
@@ -81,7 +81,7 @@ public class BallBukkitListener implements Listener {
|
||||
}
|
||||
removeCachedPlayerMessage(uuid);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
BallAPI.getInstance().getLogger().log(Level.SEVERE, "发送玩家缓存消息时出现了一个异常", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@@ -10,8 +10,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public final class BallBukkitUtils {
|
||||
private BallBukkitUtils() {
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public final class BallBukkitUtils {
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
BallAPI.getInstance().getLogger().log(Level.SEVERE, "更新玩家数据时遇到了一个异常", e);
|
||||
}
|
||||
BallAPI.getInstance().sendBallMessage(
|
||||
BallAPI.PLAYER_INFO_CHANNEL,
|
||||
|
@@ -3,11 +3,8 @@
|
||||
evaluationDependsOn(":ball-common")
|
||||
|
||||
dependencies {
|
||||
implementation(project(":ball-common")) {
|
||||
isTransitive = false
|
||||
}
|
||||
api(project(":ball-common")) { isTransitive = false }
|
||||
compileOnly("net.md-5:bungeecord-api:1.20-R0.1")
|
||||
|
||||
compileOnly("cn.hamster3.mc.plugin:core-bungee:+")
|
||||
}
|
||||
|
||||
|
@@ -16,9 +16,9 @@ import net.md_5.bungee.api.plugin.Plugin;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public class HamsterBallPlugin extends Plugin {
|
||||
@Getter
|
||||
private static HamsterBallPlugin instance;
|
||||
@@ -45,8 +45,9 @@ public class HamsterBallPlugin extends Plugin {
|
||||
BallBungeeCordAPI.init(configFile);
|
||||
logger.info("已初始化 BallAPI");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ProxyServer.getInstance().stop("由于 HamsterBall 未能成功连接, 服务器将立即关闭");
|
||||
logger.log(Level.SEVERE, "BallAPI 初始化失败", e);
|
||||
ProxyServer.getInstance().stop("由于 HamsterBall 初始化失败, 服务器将立即关闭");
|
||||
return;
|
||||
}
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠球初始化完成,总计耗时 " + time + " ms");
|
||||
@@ -60,9 +61,8 @@ public class HamsterBallPlugin extends Plugin {
|
||||
try {
|
||||
BallBungeeCordAPI.getInstance().enable();
|
||||
} catch (Exception e) {
|
||||
getLogger().info("仓鼠球启动失败,原因:" + e.getMessage());
|
||||
e.printStackTrace();
|
||||
getLogger().info("由于仓鼠球启动失败,服务器将立即关闭");
|
||||
logger.log(Level.SEVERE, "仓鼠球启动失败", e);
|
||||
logger.info("由于仓鼠球启动失败,服务器将立即关闭");
|
||||
ProxyServer.getInstance().stop("仓鼠球启动失败");
|
||||
return;
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public class HamsterBallPlugin extends Plugin {
|
||||
try {
|
||||
BallBungeeCordAPI.getInstance().disable();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
logger.log(Level.SEVERE, "关闭仓鼠球时遇到了一个异常", e);
|
||||
}
|
||||
long time = System.currentTimeMillis() - start;
|
||||
logger.info("仓鼠球已关闭,总计耗时 " + time + " ms");
|
||||
|
@@ -55,6 +55,9 @@ public class BallBungeeListener {
|
||||
@Subscribe
|
||||
public void onKickPlayerEvent(KickPlayerEvent event) {
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(event.getUuid());
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
BaseComponent[] components = BungeeComponentSerializer.get().serialize(event.getReason());
|
||||
player.disconnect(components);
|
||||
}
|
||||
@@ -70,8 +73,8 @@ public class BallBungeeListener {
|
||||
@Subscribe
|
||||
public void onSendPlayerToLocationEvent(SendPlayerToLocationEvent event) {
|
||||
String serverID = event.getLocation().getServerID();
|
||||
ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo(serverID);
|
||||
if (serverInfo == null) {
|
||||
ServerInfo toServer = ProxyServer.getInstance().getServerInfo(serverID);
|
||||
if (toServer == null) {
|
||||
HamsterBallPlugin.getInstance().getLogger().warning("试图传送玩家时失败: 服务器 " + serverID + " 不在线");
|
||||
return;
|
||||
}
|
||||
@@ -83,12 +86,12 @@ public class BallBungeeListener {
|
||||
if (player.getServer().getInfo().getName().equals(serverID)) {
|
||||
continue;
|
||||
}
|
||||
player.connect(serverInfo);
|
||||
player.connect(toServer);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onSendPlayerToPlayerEvent(SendPlayerToPlayerEvent event) {
|
||||
public void onSendPlayerToPlayer(SendPlayerToPlayerEvent event) {
|
||||
UUID toPlayerUUID = event.getToPlayerUUID();
|
||||
ProxiedPlayer toPlayer = ProxyServer.getInstance().getPlayer(toPlayerUUID);
|
||||
if (toPlayer == null) {
|
||||
@@ -98,6 +101,9 @@ public class BallBungeeListener {
|
||||
ServerInfo toServer = toPlayer.getServer().getInfo();
|
||||
for (UUID uuid : event.getSendPlayerUUID()) {
|
||||
ProxiedPlayer sendPlayer = ProxyServer.getInstance().getPlayer(uuid);
|
||||
if (sendPlayer == null) {
|
||||
continue;
|
||||
}
|
||||
if (sendPlayer.getServer().getInfo().getName().equals(toServer.getName())) {
|
||||
continue;
|
||||
}
|
||||
|
@@ -12,8 +12,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
@SuppressWarnings("CallToPrintStackTrace")
|
||||
public final class BallBungeeCordUtils {
|
||||
private BallBungeeCordUtils() {
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public final class BallBungeeCordUtils {
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
BallAPI.getInstance().getLogger().log(Level.SEVERE, "更新玩家数据时遇到了一个异常", e);
|
||||
}
|
||||
if (!BallAPI.getInstance().getBallConfig().isGameServerUpdatePlayerInfo()) {
|
||||
BallAPI.getInstance().sendRawBallMessage(
|
||||
|
@@ -32,10 +32,11 @@ import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Getter
|
||||
@SuppressWarnings({"unused", "CallToPrintStackTrace"})
|
||||
public abstract class BallAPI {
|
||||
/**
|
||||
* API 使用的通信频道
|
||||
@@ -336,7 +337,7 @@ public abstract class BallAPI {
|
||||
statement.executeUpdate();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
BallAPI.getInstance().getLogger().log(Level.SEVERE, "更新玩家缓存消息时遇到了一个异常", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -13,7 +13,6 @@ public enum BallActions {
|
||||
BallPlayerLogin,
|
||||
BallPlayerPostLogin,
|
||||
BallPlayerPreConnectServer,
|
||||
BallPlayerConnectServer,
|
||||
BallPlayerPostConnectServer,
|
||||
BallPlayerLogout,
|
||||
|
||||
|
@@ -1,27 +0,0 @@
|
||||
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;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* 玩家进入子服
|
||||
* <p>
|
||||
* 仅在使用 velocity 代理端时才会触发这个事件
|
||||
*
|
||||
* @see BallPlayerPreConnectServerEvent 玩家准备进入子服
|
||||
* @see BallPlayerConnectServerEvent 玩家进入子服
|
||||
* @see BallPlayerPostConnectServerEvent 玩家已经进入子服
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class BallPlayerConnectServerEvent {
|
||||
@NotNull
|
||||
private final BallPlayerInfo playerInfo;
|
||||
@Nullable
|
||||
private final String from;
|
||||
@NotNull
|
||||
private final String to;
|
||||
}
|
@@ -9,7 +9,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
* 玩家已经进入子服
|
||||
*
|
||||
* @see BallPlayerPreConnectServerEvent 玩家准备进入子服
|
||||
* @see BallPlayerConnectServerEvent 玩家进入子服
|
||||
* @see BallPlayerPostConnectServerEvent 玩家已经进入子服
|
||||
*/
|
||||
@Data
|
||||
|
@@ -10,7 +10,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
* 玩家准备进入子服
|
||||
*
|
||||
* @see BallPlayerPreConnectServerEvent 玩家准备进入子服
|
||||
* @see BallPlayerConnectServerEvent 玩家进入子服
|
||||
* @see BallPlayerPostConnectServerEvent 玩家已经进入子服
|
||||
*/
|
||||
@Data
|
||||
|
@@ -83,11 +83,6 @@ public class BallCommonListener {
|
||||
BallAPI.getInstance().getEventBus().post(event);
|
||||
break;
|
||||
}
|
||||
case BallPlayerConnectServer: {
|
||||
BallPlayerConnectServerEvent event = CoreAPI.getInstance().getGson().fromJson(message.getContent(), BallPlayerConnectServerEvent.class);
|
||||
BallAPI.getInstance().getEventBus().post(event);
|
||||
break;
|
||||
}
|
||||
case BallPlayerPostConnectServer: {
|
||||
BallPlayerPostConnectServerEvent event = CoreAPI.getInstance().getGson().fromJson(message.getContent(), BallPlayerPostConnectServerEvent.class);
|
||||
BallAPI.getInstance().getEventBus().post(event);
|
||||
@@ -125,12 +120,6 @@ public class BallCommonListener {
|
||||
BallAPI.getInstance().getEventBus().post(event);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onBallPlayerConnectServer(BallPlayerConnectServerEvent event) {
|
||||
BallPlayerInfo info = event.getPlayerInfo();
|
||||
BallAPI.getInstance().getAllPlayerInfo().put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onBallPlayerInfoUpdate(BallPlayerInfoUpdateEvent event) {
|
||||
BallPlayerInfo info = event.getPlayerInfo();
|
||||
|
@@ -1,5 +1,5 @@
|
||||
plugins {
|
||||
id("java")
|
||||
id("java-library")
|
||||
id("maven-publish")
|
||||
id("com.github.johnrengelman.shadow") version "8+"
|
||||
}
|
||||
|
Reference in New Issue
Block a user