Search in sources :

Example 16 with NbtTagCompound

use of com.ruinscraft.panilla.craftbukkit.v1_16_R3.nbt.NbtTagCompound in project Panilla by ds58.

the class PacketInspector method checkPacketPlayInSetCreativeSlot.

@Override
public void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException {
    if (_packet instanceof PacketPlayInSetCreativeSlot) {
        PacketPlayInSetCreativeSlot packet = (PacketPlayInSetCreativeSlot) _packet;
        int slot = packet.b();
        ItemStack itemStack = packet.getItemStack();
        if (itemStack == null || !itemStack.hasTag())
            return;
        NbtTagCompound tag = new NbtTagCompound(itemStack.getTag());
        String itemClass = itemStack.getItem().getClass().getSimpleName();
        String packetClass = packet.getClass().getSimpleName();
        NbtChecks.checkPacketPlayIn(slot, tag, itemClass, packetClass, panilla);
    }
}
Also used : INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_17_R1.nbt.NbtTagCompound) PacketPlayInSetCreativeSlot(net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot) ItemStack(net.minecraft.world.item.ItemStack)

Example 17 with NbtTagCompound

use of com.ruinscraft.panilla.craftbukkit.v1_16_R3.nbt.NbtTagCompound in project Panilla by ds58.

the class PacketInspector method checkPacketPlayOutSetSlot.

@Override
public void checkPacketPlayOutSetSlot(Object _packet) throws NbtNotPermittedException {
    if (_packet instanceof PacketPlayOutSetSlot) {
        PacketPlayOutSetSlot packet = (PacketPlayOutSetSlot) _packet;
        try {
            Field windowIdField = PacketPlayOutSetSlot.class.getDeclaredField("c");
            windowIdField.setAccessible(true);
            int windowId = (int) windowIdField.get(packet);
            // check if window is not player inventory and we are ignoring non-player inventories
            if (windowId != 0 && panilla.getPConfig().ignoreNonPlayerInventories) {
                return;
            }
            Field slotField = PacketPlayOutSetSlot.class.getDeclaredField("e");
            Field itemStackField = PacketPlayOutSetSlot.class.getDeclaredField("f");
            slotField.setAccessible(true);
            itemStackField.setAccessible(true);
            int slot = (int) slotField.get(packet);
            ItemStack itemStack = (ItemStack) itemStackField.get(packet);
            if (itemStack == null || !itemStack.hasTag())
                return;
            NbtTagCompound tag = new NbtTagCompound(itemStack.getTag());
            String itemClass = itemStack.getClass().getSimpleName();
            String packetClass = packet.getClass().getSimpleName();
            NbtChecks.checkPacketPlayOut(slot, tag, itemClass, packetClass, panilla);
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : Field(java.lang.reflect.Field) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_17_R1.nbt.NbtTagCompound) PacketPlayOutSetSlot(net.minecraft.network.protocol.game.PacketPlayOutSetSlot) ItemStack(net.minecraft.world.item.ItemStack)

Example 18 with NbtTagCompound

use of com.ruinscraft.panilla.craftbukkit.v1_16_R3.nbt.NbtTagCompound 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 19 with NbtTagCompound

use of com.ruinscraft.panilla.craftbukkit.v1_16_R3.nbt.NbtTagCompound in project Panilla by ds58.

the class PacketInspector method checkPacketPlayInSetCreativeSlot.

@Override
public void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException {
    if (_packet instanceof PacketPlayInSetCreativeSlot) {
        PacketPlayInSetCreativeSlot packet = (PacketPlayInSetCreativeSlot) _packet;
        int slot = packet.b();
        ItemStack itemStack = packet.c();
        if (itemStack == null || !itemStack.r())
            return;
        NbtTagCompound tag = new NbtTagCompound(itemStack.s());
        String itemClass = itemStack.c().getClass().getSimpleName();
        String packetClass = packet.getClass().getSimpleName();
        NbtChecks.checkPacketPlayIn(slot, tag, itemClass, packetClass, panilla);
    }
}
Also used : NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_18_R1.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) PacketPlayInSetCreativeSlot(net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot) ItemStack(net.minecraft.world.item.ItemStack)

Example 20 with NbtTagCompound

use of com.ruinscraft.panilla.craftbukkit.v1_16_R3.nbt.NbtTagCompound in project Panilla by ds58.

the class PacketInspector method checkPacketPlayInSetCreativeSlot.

@Override
public void checkPacketPlayInSetCreativeSlot(Object _packet) throws NbtNotPermittedException {
    if (_packet instanceof PacketPlayInSetCreativeSlot) {
        PacketPlayInSetCreativeSlot packet = (PacketPlayInSetCreativeSlot) _packet;
        int slot = packet.b();
        ItemStack itemStack = packet.getItemStack();
        if (itemStack == null || !itemStack.hasTag())
            return;
        NbtTagCompound tag = new NbtTagCompound(itemStack.getTag());
        String itemClass = itemStack.getItem().getClass().getSimpleName();
        String packetClass = packet.getClass().getSimpleName();
        NbtChecks.checkPacketPlayIn(slot, tag, itemClass, packetClass, panilla);
    }
}
Also used : INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_16_R2.nbt.NbtTagCompound)

Aggregations

INbtTagCompound (com.ruinscraft.panilla.api.nbt.INbtTagCompound)55 Field (java.lang.reflect.Field)34 FailedNbt (com.ruinscraft.panilla.api.exception.FailedNbt)22 ItemStack (net.minecraft.world.item.ItemStack)12 List (java.util.List)11 EntityNbtNotPermittedException (com.ruinscraft.panilla.api.exception.EntityNbtNotPermittedException)10 UUID (java.util.UUID)10 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_12_R1.nbt.NbtTagCompound)5 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_13_R2.nbt.NbtTagCompound)5 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_14_R1.nbt.NbtTagCompound)5 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_15_R1.nbt.NbtTagCompound)5 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_16_R1.nbt.NbtTagCompound)5 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_16_R2.nbt.NbtTagCompound)5 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_16_R3.nbt.NbtTagCompound)5 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_17_R1.nbt.NbtTagCompound)5 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_18_R1.nbt.NbtTagCompound)5 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_18_R2.nbt.NbtTagCompound)5 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_8_R3.nbt.NbtTagCompound)5 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 PacketPlayInSetCreativeSlot (net.minecraft.network.protocol.game.PacketPlayInSetCreativeSlot)3