Skip to content

Commit

Permalink
feat: 修改代码以处理登录事件
Browse files Browse the repository at this point in the history
  • Loading branch information
shulng committed Sep 18, 2024
1 parent 7240041 commit e8ab6b0
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/main/java/cc/baka9/catseedlogin/bungee/Listeners.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public class Listeners implements Listener {
*/
@EventHandler
public void onChat(ChatEvent event) {
if (!(event.isProxyCommand() && event.getSender() instanceof ProxiedPlayer)) return;

ProxiedPlayer player = (ProxiedPlayer) event.getSender();
String playerName = player.getName();
if (event.isProxyCommand() && event.getSender() instanceof ProxiedPlayer) {
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
String playerName = player.getName();

if (!loggedInPlayerList.contains(playerName)) {
event.setCancelled(true);
handleLogin(player, event.getMessage());
if (!loggedInPlayerList.contains(playerName)) {
event.setCancelled(true);
handleLogin(player, event.getMessage());
}
}
}

Expand All @@ -47,14 +47,14 @@ public void onChat(ChatEvent event) {
@EventHandler
public void onServerConnect(ServerConnectEvent event) {
ServerInfo target = event.getTarget();
if (event.isCancelled() || target.getName().equals(Config.LoginServerName)) return;

ProxiedPlayer player = event.getPlayer();
String playerName = player.getName();
if (!event.isCancelled() && !target.getName().equals(Config.LoginServerName)) {
ProxiedPlayer player = event.getPlayer();
String playerName = player.getName();

if (!loggedInPlayerList.contains(playerName)) {
handleLogin(player, null);
event.setTarget(proxyServer.getServerInfo(Config.LoginServerName));
if (!loggedInPlayerList.contains(playerName)) {
handleLogin(player, null);
event.setTarget(proxyServer.getServerInfo(Config.LoginServerName));
}
}
}

Expand All @@ -65,10 +65,8 @@ public void onServerConnect(ServerConnectEvent event) {
public void onServerConnected(ServerConnectedEvent event) {
if (event.getServer().getInfo().getName().equals(Config.LoginServerName)) {
ProxiedPlayer player = event.getPlayer();
String playerName = player.getName();

if (loggedInPlayerList.contains(playerName)) {
PluginMain.runAsync(() -> Communication.sendKeepLoggedInRequest(playerName));
if (loggedInPlayerList.contains(player.getName())) {
PluginMain.runAsync(() -> Communication.sendKeepLoggedInRequest(player.getName()));
}
}
}
Expand Down Expand Up @@ -107,7 +105,7 @@ private void handleLogin(ProxiedPlayer player, String message) {
PluginMain.runAsync(() -> {
if (Communication.sendConnectRequest(playerName) == 1) {
loggedInPlayerList.add(playerName);
if (message != null) {
if (message != null && !message.isEmpty()) {
proxyServer.getPluginManager().dispatchCommand(player, message.substring(1));
}
}
Expand Down

0 comments on commit e8ab6b0

Please sign in to comment.