Do not send packet to player not logged in

This commit is contained in:
IzzelAliz 2021-01-30 17:40:32 +08:00
parent 1ef69325a4
commit 7cd2907ac1
2 changed files with 26 additions and 1 deletions

View File

@ -0,0 +1,24 @@
package io.izzel.arclight.common.mixin.forge;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.network.IPacket;
import net.minecraftforge.fml.network.PacketDistributor;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import java.util.function.Consumer;
import java.util.function.Supplier;
@Mixin(PacketDistributor.class)
public class PacketDistributorMixin {
@Overwrite
private Consumer<IPacket<?>> playerConsumer(Supplier<ServerPlayerEntity> entityPlayerMPSupplier) {
return p -> {
ServerPlayerEntity entity = entityPlayerMPSupplier.get();
if (entity.connection != null && entity.connection.netManager != null) {
entity.connection.netManager.sendPacket(p);
}
};
}
}

View File

@ -9,6 +9,7 @@
"ForgeEventFactoryMixin", "ForgeEventFactoryMixin",
"ForgeHooksMixin", "ForgeHooksMixin",
"ForgeInternalHandlerMixin", "ForgeInternalHandlerMixin",
"NetworkHooksMixin" "NetworkHooksMixin",
"PacketDistributorMixin"
] ]
} }