1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-12-14 20:20:30 +00:00

Don't send packets when the server is stopping

Fixes #956
This commit is contained in:
Jonathan Coates 2021-11-20 23:20:27 +00:00
parent 1b39c9f470
commit 2fe40f669d
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06

View File

@ -8,6 +8,9 @@ package dan200.computercraft.shared.peripheral.speaker;
import dan200.computercraft.api.peripheral.IComputerAccess; import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.shared.network.NetworkHandler; import dan200.computercraft.shared.network.NetworkHandler;
import dan200.computercraft.shared.network.client.SpeakerStopClientMessage; 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 javax.annotation.Nonnull;
import java.util.UUID; import java.util.UUID;
@ -28,6 +31,10 @@ public abstract class UpgradeSpeakerPeripheral extends SpeakerPeripheral
@Override @Override
public void detach( @Nonnull IComputerAccess computer ) 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 ) ); NetworkHandler.sendToAllPlayers( new SpeakerStopClientMessage( source ) );
} }
} }