Search in sources :

Example 1 with PacketPlayOutWindowItems

use of net.minecraft.network.protocol.game.PacketPlayOutWindowItems in project Panilla by ds58.

the class PacketInspector method checkPacketPlayOutWindowItems.

@Override
public void checkPacketPlayOutWindowItems(Object _packet) throws NbtNotPermittedException {
    if (_packet instanceof PacketPlayOutWindowItems) {
        PacketPlayOutWindowItems packet = (PacketPlayOutWindowItems) _packet;
        try {
            Field windowIdField = PacketPlayOutWindowItems.class.getDeclaredField("a");
            windowIdField.setAccessible(true);
            int windowId = (int) windowIdField.get(packet);
            // check if window is not player inventory
            if (windowId != 0) {
                return;
            }
            Field itemStacksField = PacketPlayOutWindowItems.class.getDeclaredField("c");
            itemStacksField.setAccessible(true);
            List<ItemStack> itemStacks = (List<ItemStack>) itemStacksField.get(packet);
            for (ItemStack itemStack : itemStacks) {
                if (itemStack == null || !itemStack.s()) {
                    continue;
                }
                NbtTagCompound tag = new NbtTagCompound(itemStack.t());
                String itemClass = itemStack.getClass().getSimpleName();
                String packetClass = packet.getClass().getSimpleName();
                // TODO: set slot?
                NbtChecks.checkPacketPlayOut(0, tag, itemClass, packetClass, panilla);
            }
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : Field(java.lang.reflect.Field) PacketPlayOutWindowItems(net.minecraft.network.protocol.game.PacketPlayOutWindowItems) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_18_R2.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) List(java.util.List) ItemStack(net.minecraft.world.item.ItemStack)

Example 2 with PacketPlayOutWindowItems

use of net.minecraft.network.protocol.game.PacketPlayOutWindowItems in project Panilla by ds58.

the class PacketInspector method checkPacketPlayOutWindowItems.

@Override
public void checkPacketPlayOutWindowItems(Object _packet) throws NbtNotPermittedException {
    if (_packet instanceof PacketPlayOutWindowItems) {
        PacketPlayOutWindowItems packet = (PacketPlayOutWindowItems) _packet;
        try {
            Field windowIdField = PacketPlayOutWindowItems.class.getDeclaredField("a");
            windowIdField.setAccessible(true);
            int windowId = (int) windowIdField.get(packet);
            // check if window is not player inventory
            if (windowId != 0) {
                return;
            }
            Field itemStacksField = PacketPlayOutWindowItems.class.getDeclaredField("c");
            itemStacksField.setAccessible(true);
            List<ItemStack> itemStacks = (List<ItemStack>) itemStacksField.get(packet);
            for (ItemStack itemStack : itemStacks) {
                if (itemStack == null || !itemStack.hasTag()) {
                    continue;
                }
                NbtTagCompound tag = new NbtTagCompound(itemStack.getTag());
                String itemClass = itemStack.getClass().getSimpleName();
                String packetClass = packet.getClass().getSimpleName();
                // TODO: set slot?
                NbtChecks.checkPacketPlayOut(0, tag, itemClass, packetClass, panilla);
            }
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : Field(java.lang.reflect.Field) PacketPlayOutWindowItems(net.minecraft.network.protocol.game.PacketPlayOutWindowItems) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_17_R1.nbt.NbtTagCompound) List(java.util.List) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with PacketPlayOutWindowItems

use of net.minecraft.network.protocol.game.PacketPlayOutWindowItems in project Panilla by ds58.

the class PacketInspector method checkPacketPlayOutWindowItems.

@Override
public void checkPacketPlayOutWindowItems(Object _packet) throws NbtNotPermittedException {
    if (_packet instanceof PacketPlayOutWindowItems) {
        PacketPlayOutWindowItems packet = (PacketPlayOutWindowItems) _packet;
        try {
            Field windowIdField = PacketPlayOutWindowItems.class.getDeclaredField("a");
            windowIdField.setAccessible(true);
            int windowId = (int) windowIdField.get(packet);
            // check if window is not player inventory
            if (windowId != 0) {
                return;
            }
            Field itemStacksField = PacketPlayOutWindowItems.class.getDeclaredField("c");
            itemStacksField.setAccessible(true);
            List<ItemStack> itemStacks = (List<ItemStack>) itemStacksField.get(packet);
            for (ItemStack itemStack : itemStacks) {
                if (itemStack == null || !itemStack.r()) {
                    continue;
                }
                NbtTagCompound tag = new NbtTagCompound(itemStack.s());
                String itemClass = itemStack.getClass().getSimpleName();
                String packetClass = packet.getClass().getSimpleName();
                // TODO: set slot?
                NbtChecks.checkPacketPlayOut(0, tag, itemClass, packetClass, panilla);
            }
        } catch (NoSuchFieldException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : Field(java.lang.reflect.Field) PacketPlayOutWindowItems(net.minecraft.network.protocol.game.PacketPlayOutWindowItems) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_18_R1.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) List(java.util.List) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

INbtTagCompound (com.ruinscraft.panilla.api.nbt.INbtTagCompound)3 Field (java.lang.reflect.Field)3 List (java.util.List)3 PacketPlayOutWindowItems (net.minecraft.network.protocol.game.PacketPlayOutWindowItems)3 ItemStack (net.minecraft.world.item.ItemStack)3 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_17_R1.nbt.NbtTagCompound)1 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_18_R1.nbt.NbtTagCompound)1 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_18_R2.nbt.NbtTagCompound)1