Search in sources :

Example 96 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project Panilla by ds58.

the class PacketInspector method stripNbtFromItemEntity.

@Override
public void stripNbtFromItemEntity(UUID entityId) {
    org.bukkit.entity.Entity bukkitEntity = Bukkit.getServer().getEntity(entityId);
    if (bukkitEntity instanceof CraftEntity) {
        CraftEntity craftEntity = (CraftEntity) bukkitEntity;
        Entity entity = craftEntity.getHandle();
        if (entity instanceof EntityItem) {
            EntityItem item = (EntityItem) entity;
            if (item.getItemStack() == null) {
                return;
            }
            if (!item.getItemStack().hasTag()) {
                return;
            }
            item.getItemStack().setTag(null);
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity) CraftEntity(org.bukkit.craftbukkit.v1_13_R2.entity.CraftEntity)

Example 97 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project Panilla by ds58.

the class PacketInspector method stripNbtFromItemEntity.

@Override
public void stripNbtFromItemEntity(UUID entityId) {
    org.bukkit.entity.Entity bukkitEntity = Bukkit.getServer().getEntity(entityId);
    if (bukkitEntity instanceof CraftEntity) {
        CraftEntity craftEntity = (CraftEntity) bukkitEntity;
        Entity entity = craftEntity.getHandle();
        if (entity instanceof EntityItem) {
            EntityItem item = (EntityItem) entity;
            if (item.getItemStack() == null) {
                return;
            }
            if (!item.getItemStack().hasTag()) {
                return;
            }
            item.getItemStack().setTag(null);
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R2.entity.CraftEntity)

Example 98 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity 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("b");
            typeField.setAccessible(true);
            UUID entityId = (UUID) typeField.get(packet);
            org.bukkit.entity.Entity bukkitEntity = org.bukkit.Bukkit.getEntity(entityId);
            CraftEntity craftEntity = (CraftEntity) bukkitEntity;
            if (craftEntity == null) {
                return;
            }
            Entity entity = craftEntity.getHandle();
            if (entity != null) {
                if (entity instanceof EntityItem) {
                    EntityItem item = (EntityItem) entity;
                    if (item.getItemStack() == null) {
                        return;
                    }
                    if (!item.getItemStack().hasTag()) {
                        return;
                    }
                    INbtTagCompound tag = new NbtTagCompound(item.getItemStack().getTag());
                    String itemName = item.getItemStack().getItem().getName();
                    FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
                    if (FailedNbt.fails(failedNbt)) {
                        throw new EntityNbtNotPermittedException(packet.getClass().getSimpleName(), false, failedNbt, entityId, bukkitEntity.getWorld().getName());
                    }
                }
            }
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) EntityNbtNotPermittedException(com.ruinscraft.panilla.api.exception.EntityNbtNotPermittedException) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_16_R3.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) Field(java.lang.reflect.Field) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) UUID(java.util.UUID) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Example 99 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity 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("b");
            typeField.setAccessible(true);
            UUID entityId = (UUID) typeField.get(packet);
            org.bukkit.entity.Entity bukkitEntity = org.bukkit.Bukkit.getEntity(entityId);
            CraftEntity craftEntity = (CraftEntity) bukkitEntity;
            if (craftEntity == null) {
                return;
            }
            Entity entity = craftEntity.getHandle();
            if (entity != null) {
                if (entity instanceof EntityItem) {
                    EntityItem item = (EntityItem) entity;
                    if (item.getItemStack() == null) {
                        return;
                    }
                    if (!item.getItemStack().hasTag()) {
                        return;
                    }
                    INbtTagCompound tag = new NbtTagCompound(item.getItemStack().getTag());
                    String itemName = item.getItemStack().getItem().getName();
                    FailedNbt failedNbt = NbtChecks.checkAll(tag, itemName, panilla);
                    if (FailedNbt.fails(failedNbt)) {
                        throw new EntityNbtNotPermittedException(packet.getClass().getSimpleName(), false, failedNbt, entityId, bukkitEntity.getWorld().getName());
                    }
                }
            }
        } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) EntityNbtNotPermittedException(com.ruinscraft.panilla.api.exception.EntityNbtNotPermittedException) NbtTagCompound(com.ruinscraft.panilla.craftbukkit.v1_14_R1.nbt.NbtTagCompound) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) CraftEntity(org.bukkit.craftbukkit.v1_14_R1.entity.CraftEntity) Field(java.lang.reflect.Field) INbtTagCompound(com.ruinscraft.panilla.api.nbt.INbtTagCompound) UUID(java.util.UUID) FailedNbt(com.ruinscraft.panilla.api.exception.FailedNbt)

Example 100 with CraftEntity

use of org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity in project MyPet by xXKeyleXx.

the class PlatformHelper method applyTagToEntity.

@Override
public void applyTagToEntity(TagCompound tag, Entity bukkitEntity) {
    net.minecraft.server.v1_12_R1.Entity entity = ((CraftEntity) bukkitEntity).getHandle();
    NBTTagCompound vanillaNBT = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
    // Just a temporary fix until I come up with a better solution
    if (bukkitEntity instanceof Villager) {
        EntityVillager villager = (EntityVillager) entity;
        villager.setProfession(vanillaNBT.getInt("Profession"));
        villager.riches = vanillaNBT.getInt("Riches");
        ReflectionUtil.setFieldValue("bK", villager, vanillaNBT.getInt("Career"));
        ReflectionUtil.setFieldValue("bL", villager, vanillaNBT.getInt("CareerLevel"));
        ReflectionUtil.setFieldValue("bH", villager, vanillaNBT.getBoolean("Willing"));
        if (vanillaNBT.hasKeyOfType("Offers", 10)) {
            NBTTagCompound nbttaglist = vanillaNBT.getCompound("Offers");
            ReflectionUtil.setFieldValue("trades", villager, new MerchantRecipeList(nbttaglist));
        }
        NBTTagList invTag = vanillaNBT.getList("Inventory", 10);
        for (int i = 0; i < invTag.size(); ++i) {
            ItemStack itemstack = new ItemStack(invTag.get(i));
            villager.inventory.a(itemstack);
        }
        villager.m(true);
        if (villager.isBaby()) {
            villager.goalSelector.a(8, new PathfinderGoalPlay(villager, 0.32D));
        } else if (villager.getProfession() == 0) {
            villager.goalSelector.a(6, new PathfinderGoalVillagerFarm(villager, 0.6D));
        }
    }
// can not be used in 1.10
// entity.f(vanillaNBT);
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity) net.minecraft.server.v1_12_R1(net.minecraft.server.v1_12_R1) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)

Aggregations

Location (org.bukkit.Location)40 Entity (org.bukkit.entity.Entity)38 LivingEntity (org.bukkit.entity.LivingEntity)33 Entity (net.minecraft.world.entity.Entity)25 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)25 CraftEntity (org.bukkit.craftbukkit.v1_18_R2.entity.CraftEntity)24 Iterator (java.util.Iterator)21 List (java.util.List)21 CraftEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)21 UUID (java.util.UUID)20 CraftEntity (org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity)20 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)17 Player (org.bukkit.entity.Player)16 CraftEntity (org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity)14 Vector (org.bukkit.util.Vector)14 EntityAttachmentHelper (com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper)12 Vec3 (net.minecraft.world.phys.Vec3)12 SkinnableEntity (net.citizensnpcs.npc.skin.SkinnableEntity)11 EntityDamageSource (net.minecraft.world.damagesource.EntityDamageSource)11 EnteredStateTracker (com.elmakers.mine.bukkit.utility.EnteredStateTracker)10