Search in sources :

Example 1 with FailedNbt

use of com.ruinscraft.panilla.api.exception.FailedNbt in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    for (int slot = 0; slot < container.slots.size(); slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : Container(net.minecraft.server.v1_16_R1.Container) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_16_R1.nbt.NbtTagCompound) NBTTagCompound(net.minecraft.server.v1_16_R1.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_16_R1.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Example 2 with FailedNbt

use of com.ruinscraft.panilla.api.exception.FailedNbt in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    int containerSlotsSize = 0;
    if (is_1_12_2) {
        containerSlotsSize = container.slots.size();
    } else {
        try {
            Field slotsField = Container.class.getField("c");
            List<Slot> slots = (List<Slot>) slotsField.get(container);
            containerSlotsSize = slots.size();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    for (int slot = 0; slot < containerSlotsSize; slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_12_R1.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) Field(java.lang.reflect.Field) Container(net.minecraft.server.v1_12_R1.Container) Slot(net.minecraft.server.v1_12_R1.Slot) List(java.util.List) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Example 3 with FailedNbt

use of com.ruinscraft.panilla.api.exception.FailedNbt in project Panilla by ds58.

the class PacketInspector method checkPacketPlayOutSpawnEntity.

@Override
public void checkPacketPlayOutSpawnEntity(Object _packet) throws EntityNbtNotPermittedException {
    if (_packet instanceof PacketPlayOutSpawnEntity) {
        PacketPlayOutSpawnEntity packet = (PacketPlayOutSpawnEntity) _packet;
        try {
            Field typeField = PacketPlayOutSpawnEntity.class.getDeclaredField("d");
            typeField.setAccessible(true);
            UUID entityId = (UUID) typeField.get(packet);
            Entity entity = null;
            for (WorldServer worldServer : MinecraftServer.getServer().F()) {
                entity = worldServer.O.d().a(entityId);
                if (entity != null)
                    break;
            }
            if (entity != null) {
                if (entity instanceof EntityItem) {
                    EntityItem item = (EntityItem) entity;
                    if (item.h() == null) {
                        return;
                    }
                    if (!item.h().r()) {
                        return;
                    }
                    INbtTagCompound tag = new NbtTagCompound(item.h().t());
                    String itemName = item.h().c().a();
                    FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
                    if (FailedNbt.fails(failedNbt)) {
                        throw new EntityNbtNotPermittedException(packet.getClass().getSimpleName(), false, failedNbt, entityId, entity.W().getWorld().getName());
                    }
                }
            }
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) Entity(net.minecraft.world.entity.Entity) EntityNbtNotPermittedException(com.ruinscraft.panilla.api.exception.EntityNbtNotPermittedException) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_18_R2.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) WorldServer(net.minecraft.server.level.WorldServer) Field(java.lang.reflect.Field) PacketPlayOutSpawnEntity(net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) UUID(java.util.UUID) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt) EntityItem(net.minecraft.world.entity.item.EntityItem)

Example 4 with FailedNbt

use of com.ruinscraft.panilla.api.exception.FailedNbt in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().activeContainer;
    for (int slot = 0; slot < container.c.size(); slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : Container(net.minecraft.server.v1_8_R3.Container) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_8_R3.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Example 5 with FailedNbt

use of com.ruinscraft.panilla.api.exception.FailedNbt in project Panilla by ds58.

the class InventoryCleaner method clean.

@Override
public void clean(IPanillaPlayer player) {
    CraftPlayer craftPlayer = (CraftPlayer) player.getHandle();
    Container container = craftPlayer.getHandle().bV;
    for (int slot = 0; slot < container.i.size(); slot++) {
        ItemStack itemStack = container.getSlot(slot).getItem();
        if (itemStack == null || !itemStack.hasTag()) {
            continue;
        }
        NBTTagCompound nmsTag = itemStack.getTag();
        INbtTagCompound tag = new NbtTagCompound(nmsTag);
        String itemName = itemStack.getItem().getName();
        if (nmsTag == null || itemName == null) {
            continue;
        }
        FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
        if (FailedNbt.failsThreshold(failedNbt)) {
            container.getSlot(slot).getItem().setTag(null);
        } else if (FailedNbt.fails(failedNbt)) {
            nmsTag.remove(failedNbt.key);
            container.getSlot(slot).getItem().setTag(nmsTag);
        }
    }
}
Also used : Container(net.minecraft.world.inventory.Container) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_17_R1.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) ItemStack(net.minecraft.world.item.ItemStack) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Aggregations

FailedNbt (com.ruinscraft.panilla.api.exception.FailedNbt)25 INbtTagCompound (com.ruinscraft.panilla.api.nbt.INbtTagCompound)24 Field (java.lang.reflect.Field)12 EntityNbtNotPermittedException (com.ruinscraft.panilla.api.exception.EntityNbtNotPermittedException)10 UUID (java.util.UUID)10 INbtTagList (com.ruinscraft.panilla.api.nbt.INbtTagList)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 PacketPlayOutSpawnEntity (net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity)3 WorldServer (net.minecraft.server.level.WorldServer)3 Entity (net.minecraft.world.entity.Entity)3 EntityItem (net.minecraft.world.entity.item.EntityItem)3 Container (net.minecraft.world.inventory.Container)3 ItemStack (net.minecraft.world.item.ItemStack)3 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_12_R1.nbt.NbtTagCompound)2 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_13_R2.nbt.NbtTagCompound)2 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_14_R1.nbt.NbtTagCompound)2 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_15_R1.nbt.NbtTagCompound)2 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_16_R1.nbt.NbtTagCompound)2 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_16_R2.nbt.NbtTagCompound)2 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_16_R3.nbt.NbtTagCompound)2