Skip to content

Commit

Permalink
fix potential crash. Fixes #2041
Browse files Browse the repository at this point in the history
  • Loading branch information
gnembon committed Feb 26, 2025
1 parent d5ef0a8 commit ac72645
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/carpet/CarpetServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import net.minecraft.server.commands.PerfCommand;
import net.minecraft.server.level.ServerPlayer;

import javax.annotation.Nullable;

public class CarpetServer // static for now - easier to handle all around the code, its one anyways
{
public static MinecraftServer minecraft_server;
Expand Down Expand Up @@ -172,15 +174,15 @@ public static void clientPreClosing()
scriptServer = null;
}

public static void onServerClosed(MinecraftServer server)
public static void onServerClosed(@Nullable MinecraftServer server)
{
// this for whatever reason gets called multiple times even when joining on SP
// so we allow to pass multiple times gating it only on existing server ref
if (minecraft_server != null)
{
if (scriptServer != null) scriptServer.onClose();
// this is a mess, will cleanip onlly when global reference is gone
if (!Vanilla.MinecraftServer_getScriptServer(server).stopAll) {
if (server != null && !Vanilla.MinecraftServer_getScriptServer(server).stopAll) {
Vanilla.MinecraftServer_getScriptServer(server).onClose();
}

Expand Down

0 comments on commit ac72645

Please sign in to comment.