Skip to content

Commit

Permalink
fix possible npe issues on player join/leave
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyGalbreath committed Oct 25, 2023
1 parent 22010a8 commit 8011d71
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Patches/ServerMainPatches.cs
Expand Up @@ -21,8 +21,11 @@ private class HandleClientLoadedPatch {
prefix: GetType().GetMethod("Prefix"));
}

public static void Prefix(ConnectedClient client) {
ServerPlayer player = client.GetField<ServerPlayer>("Player")!;
public static void Prefix(ConnectedClient? client) {
ServerPlayer? player = client?.GetField<ServerPlayer>("Player");
if (player == null) {
return;
}
CONNECTED_PLAYER_UUIDS.Add(player.PlayerUID);
DiscordBotMod.Bot?.OnPlayerConnect(player, Lang.Get("{0} joined. Say hi :)", player.PlayerName));
}
Expand All @@ -35,8 +38,8 @@ private class DisconnectPlayerPatch {
}

public static void Postfix(ConnectedClient? client, string? othersKickmessage) {
ServerPlayer player = client?.GetField<ServerPlayer>("Player")!;
if (CONNECTED_PLAYER_UUIDS.Remove(player.PlayerUID)) {
ServerPlayer? player = client?.GetField<ServerPlayer>("Player");
if (player != null && CONNECTED_PLAYER_UUIDS.Remove(player.PlayerUID)) {
DiscordBotMod.Bot?.OnPlayerDisconnect(player, othersKickmessage);
}
}
Expand Down

0 comments on commit 8011d71

Please sign in to comment.