Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Commit

Permalink
fix: missing null-check on bungee playe server, close #210
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Apr 2, 2024
1 parent bdd25b9 commit f05ae4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ public void onPlayerChat(ChatEvent e) {

@EventHandler(priority = EventPriority.HIGH)
public void onPlayerChangeServer(ServerSwitchEvent e) {
final String server = e.getPlayer().getServer().getInfo().getName();
final BungeeUser player = BungeeUser.adapt(e.getPlayer(), plugin);
this.handlePlayerSwitchServer(player, server);
this.handlePlayerSwitchServer(player, player.getServerName());
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
package net.william278.huskchat.user;

import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.connection.Server;
import net.william278.huskchat.HuskChat;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

/**
* Bungee implementation of a cross-platform {@link OnlineUser}
*/
Expand Down Expand Up @@ -55,12 +58,16 @@ public int getPing() {
@Override
@NotNull
public String getServerName() {
return player.getServer().getInfo().getName();
return getConnectedTo().map(s -> s.getInfo().getName()).orElse("unknown");
}

@Override
public int getPlayersOnServer() {
return player.getServer().getInfo().getPlayers().size();
return getConnectedTo().map(s -> s.getInfo().getPlayers().size()).orElse(0);
}

private Optional<Server> getConnectedTo() {
return Optional.ofNullable(player.getServer());
}

@Override
Expand Down

0 comments on commit f05ae4a

Please sign in to comment.