From 2fe40f669d490a42c84e2377c6e49aaaeeabfc25 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sat, 20 Nov 2021 23:20:27 +0000 Subject: [PATCH] Don't send packets when the server is stopping Fixes #956 --- .../peripheral/speaker/UpgradeSpeakerPeripheral.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/dan200/computercraft/shared/peripheral/speaker/UpgradeSpeakerPeripheral.java b/src/main/java/dan200/computercraft/shared/peripheral/speaker/UpgradeSpeakerPeripheral.java index cbe318845..52a9dc805 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/speaker/UpgradeSpeakerPeripheral.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/speaker/UpgradeSpeakerPeripheral.java @@ -8,6 +8,9 @@ package dan200.computercraft.shared.peripheral.speaker; import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.network.client.SpeakerStopClientMessage; +import net.minecraft.server.MinecraftServer; +import net.minecraftforge.fml.LogicalSide; +import net.minecraftforge.fml.LogicalSidedProvider; import javax.annotation.Nonnull; import java.util.UUID; @@ -28,6 +31,10 @@ public abstract class UpgradeSpeakerPeripheral extends SpeakerPeripheral @Override public void detach( @Nonnull IComputerAccess computer ) { + // We could be in the process of shutting down the server, so we can't send packets in this case. + MinecraftServer server = LogicalSidedProvider.INSTANCE.get( LogicalSide.SERVER ); + if( server == null || server.isStopped() ) return; + NetworkHandler.sendToAllPlayers( new SpeakerStopClientMessage( source ) ); } }