Search in sources :

Example 31 with CraftEntity

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

the class PlatformHelper method entityToTag.

@Override
public TagCompound entityToTag(Entity bukkitEntity) {
    net.minecraft.server.v1_16_R1.Entity entity = ((CraftEntity) bukkitEntity).getHandle();
    NBTTagCompound vanillaNBT = new NBTTagCompound();
    if (entity instanceof EntityLiving) {
        ((EntityLiving) entity).saveData(vanillaNBT);
    } else {
        Method b = ReflectionUtil.getMethod(entity.getClass(), "b", NBTTagCompound.class);
        try {
            b.invoke(entity, vanillaNBT);
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
    }
    return (TagCompound) ItemStackNBTConverter.vanillaCompoundToCompound(vanillaNBT);
}
Also used : net.minecraft.server.v1_16_R1(net.minecraft.server.v1_16_R1) CraftEntity(org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity) Method(java.lang.reflect.Method) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 32 with CraftEntity

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

the class PlatformHelper method applyTagToEntity.

@Override
public void applyTagToEntity(TagCompound tag, Entity bukkitEntity) {
    net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkitEntity).getHandle();
    CompoundTag vanillaNBT = (CompoundTag) ItemStackNBTConverter.compoundToVanillaCompound(tag);
    if (vanillaNBT != null) {
        if (bukkitEntity instanceof Villager) {
            net.minecraft.world.entity.npc.Villager villager = (net.minecraft.world.entity.npc.Villager) entity;
            villager.readAdditionalSaveData(vanillaNBT);
        } else if (bukkitEntity instanceof net.minecraft.world.entity.npc.WanderingTrader) {
            net.minecraft.world.entity.npc.WanderingTrader villager = (net.minecraft.world.entity.npc.WanderingTrader) entity;
            villager.addAdditionalSaveData(vanillaNBT);
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) org.bukkit.entity(org.bukkit.entity) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 33 with CraftEntity

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

the class PlatformHelper method entityToTag.

@Override
public TagCompound entityToTag(Entity bukkitEntity) {
    net.minecraft.world.entity.Entity entity = ((CraftEntity) bukkitEntity).getHandle();
    CompoundTag vanillaNBT = new CompoundTag();
    if (entity instanceof net.minecraft.world.entity.LivingEntity) {
        ((net.minecraft.world.entity.LivingEntity) entity).addAdditionalSaveData(vanillaNBT);
    } else {
        Method b = ReflectionUtil.getMethod(entity.getClass(), "b", CompoundTag.class);
        try {
            b.invoke(entity, vanillaNBT);
        } catch (IllegalAccessException | InvocationTargetException e) {
            e.printStackTrace();
        }
    }
    return (TagCompound) ItemStackNBTConverter.vanillaCompoundToCompound(vanillaNBT);
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity) Method(java.lang.reflect.Method) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) CraftLivingEntity(org.bukkit.craftbukkit.v1_18_R1.entity.CraftLivingEntity) org.bukkit.entity(org.bukkit.entity) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 34 with CraftEntity

use of org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_8_R3 method hideEntity.

@Override
public void hideEntity(Player player, Entity entity, boolean keepInTabList) {
    // Use Bukkit API for Player entities
    if (entity instanceof Player) {
        player.hidePlayer((Player) entity);
        return;
    }
    CraftPlayer craftPlayer = (CraftPlayer) player;
    EntityPlayer entityPlayer = craftPlayer.getHandle();
    UUID playerUUID = player.getUniqueId();
    if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity)) {
        if (!hiddenEntities.containsKey(playerUUID)) {
            hiddenEntities.put(playerUUID, new HashSet<UUID>());
        }
        Set hidden = hiddenEntities.get(playerUUID);
        UUID entityUUID = entity.getUniqueId();
        if (!hidden.contains(entityUUID)) {
            hidden.add(entityUUID);
            EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker;
            net.minecraft.server.v1_8_R3.Entity other = ((CraftEntity) entity).getHandle();
            EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId());
            if (entry != null) {
                entry.clear(entityPlayer);
            }
        }
    }
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) HashSet(java.util.HashSet) Set(java.util.Set) CraftEntity(org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) UUID(java.util.UUID) CompoundTag_v1_8_R3(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_8_R3) net.minecraft.server.v1_8_R3(net.minecraft.server.v1_8_R3)

Example 35 with CraftEntity

use of org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.

the class EntityHelper_v1_11_R1 method unhideEntity.

@Override
public void unhideEntity(Player player, Entity entity) {
    // Use Bukkit API for Player entities
    if (entity instanceof Player) {
        player.showPlayer((Player) entity);
        return;
    }
    CraftPlayer craftPlayer = (CraftPlayer) player;
    EntityPlayer entityPlayer = craftPlayer.getHandle();
    UUID playerUUID = player.getUniqueId();
    if (entityPlayer.playerConnection != null && !craftPlayer.equals(entity) && hiddenEntities.containsKey(playerUUID)) {
        Set hidden = hiddenEntities.get(playerUUID);
        UUID entityUUID = entity.getUniqueId();
        if (hidden.contains(entityUUID)) {
            hidden.remove(entityUUID);
            EntityTracker tracker = ((WorldServer) craftPlayer.getHandle().world).tracker;
            net.minecraft.server.v1_11_R1.Entity other = ((CraftEntity) entity).getHandle();
            EntityTrackerEntry entry = tracker.trackedEntities.get(other.getId());
            if (entry != null && !entry.trackedPlayers.contains(entityPlayer)) {
                entry.updatePlayer(entityPlayer);
            }
        }
    }
}
Also used : CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) HashSet(java.util.HashSet) Set(java.util.Set) CompoundTag_v1_11_R1(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_11_R1) net.minecraft.server.v1_11_R1(net.minecraft.server.v1_11_R1) CraftEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) UUID(java.util.UUID)

Aggregations

Entity (org.bukkit.entity.Entity)29 Iterator (java.util.Iterator)21 List (java.util.List)21 LivingEntity (org.bukkit.entity.LivingEntity)16 UUID (java.util.UUID)12 CraftEntity (org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity)10 CraftEntity (org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity)10 HashSet (java.util.HashSet)8 Set (java.util.Set)8 CraftEntity (org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity)8 CraftEntity (org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity)7 EntityAttachmentHelper (com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper)6 Location (org.bukkit.Location)6 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)6 net.minecraft.server.v1_10_R1 (net.minecraft.server.v1_10_R1)5 net.minecraft.server.v1_11_R1 (net.minecraft.server.v1_11_R1)5 Entity (net.minecraft.world.entity.Entity)5 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)5 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)5 Vector (org.bukkit.util.Vector)5