mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-14 19:25:43 +00:00
Do not access the current server from the client
Just missing some guards in a few places. Fixes #867
This commit is contained in:
parent
82ca19c296
commit
924b8ef30f
@ -7,11 +7,13 @@ package dan200.computercraft.shared.command;
|
||||
|
||||
import dan200.computercraft.ComputerCraft;
|
||||
import dan200.computercraft.shared.util.IDAssigner;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.client.event.ClientChatEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@ -35,6 +37,9 @@ public final class ClientCommands
|
||||
// Emulate the command on the client side
|
||||
if( event.getMessage().startsWith( OPEN_COMPUTER ) )
|
||||
{
|
||||
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
|
||||
if( server == null || server.isDedicatedServer() ) return;
|
||||
|
||||
event.setCanceled( true );
|
||||
|
||||
String idStr = event.getMessage().substring( OPEN_COMPUTER.length() ).trim();
|
||||
|
@ -21,7 +21,6 @@ import net.minecraftforge.fml.network.NetworkEvent;
|
||||
import net.minecraftforge.fml.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.network.PacketDistributor;
|
||||
import net.minecraftforge.fml.network.simple.SimpleChannel;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
@ -68,10 +67,7 @@ public final class NetworkHandler
|
||||
|
||||
public static void sendToAllPlayers( NetworkMessage packet )
|
||||
{
|
||||
for( ServerPlayerEntity player : ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayers() )
|
||||
{
|
||||
sendToPlayer( player, packet );
|
||||
}
|
||||
network.send( PacketDistributor.ALL.noArg(), packet );
|
||||
}
|
||||
|
||||
public static void sendToServer( NetworkMessage packet )
|
||||
|
@ -47,7 +47,10 @@ public class TileSpeaker extends TileGeneric implements ITickableTileEntity
|
||||
public void setRemoved()
|
||||
{
|
||||
super.setRemoved();
|
||||
NetworkHandler.sendToAllPlayers( new SpeakerStopClientMessage( source ) );
|
||||
if( level != null && !level.isClientSide )
|
||||
{
|
||||
NetworkHandler.sendToAllPlayers( new SpeakerStopClientMessage( source ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
Loading…
Reference in New Issue
Block a user