Search in sources :

Example 1 with IServerPlayerEntity

use of de.siphalor.nbtcrafting.util.duck.IServerPlayerEntity in project nbt-crafting by Siphalor.

the class NbtCrafting method onInitialize.

@Override
public void onInitialize() {
    ServerLoginConnectionEvents.QUERY_START.register((handler, server, sender, synchronizer) -> {
        sender.sendPacket(PRESENCE_CHANNEL, new PacketByteBuf(Unpooled.buffer()));
    });
    ServerLoginConnectionEvents.DISCONNECT.register((handler, server) -> {
        hasModClientConnectionHashes.remove(handler.client.hashCode());
    });
    ServerLoginNetworking.registerGlobalReceiver(PRESENCE_CHANNEL, (server, handler, understood, buf, synchronizer, responseSender) -> {
        if (understood) {
            hasModClientConnectionHashes.add(handler.client.hashCode());
        }
    });
    ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
        if (hasModClientConnectionHashes.contains(handler.client.hashCode())) {
            ((IServerPlayerEntity) handler.player).nbtCrafting$setClientModPresent(true);
            hasModClientConnectionHashes.remove(handler.client.hashCode());
        }
    });
}
Also used : IServerPlayerEntity(de.siphalor.nbtcrafting.util.duck.IServerPlayerEntity) PacketByteBuf(net.minecraft.util.PacketByteBuf)

Aggregations

IServerPlayerEntity (de.siphalor.nbtcrafting.util.duck.IServerPlayerEntity)1 PacketByteBuf (net.minecraft.util.PacketByteBuf)1