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