Search in sources :

Example 36 with CraftEntity

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

the class EntityHelper_v1_9_R2 method follow.

@Override
public void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander) {
    if (target == null || follower == null) {
        return;
    }
    final net.minecraft.server.v1_9_R2.Entity nmsEntityFollower = ((CraftEntity) follower).getHandle();
    if (!(nmsEntityFollower instanceof EntityInsentient)) {
        return;
    }
    final EntityInsentient nmsFollower = (EntityInsentient) nmsEntityFollower;
    final NavigationAbstract followerNavigation = nmsFollower.getNavigation();
    UUID uuid = follower.getUniqueId();
    if (followTasks.containsKey(uuid)) {
        followTasks.get(uuid).cancel();
    }
    final int locationNearInt = (int) Math.floor(lead);
    final boolean hasMax = maxRange > lead;
    followTasks.put(follower.getUniqueId(), new BukkitRunnable() {

        private boolean inRadius = false;

        public void run() {
            if (!target.isValid() || !follower.isValid()) {
                this.cancel();
            }
            followerNavigation.a(2F);
            Location targetLocation = target.getLocation();
            PathEntity path;
            if (hasMax && !Utilities.checkLocation(targetLocation, follower.getLocation(), maxRange) && !target.isDead() && target.isOnGround()) {
                if (!inRadius) {
                    follower.teleport(Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
                } else {
                    inRadius = false;
                    path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
                    if (path != null) {
                        followerNavigation.a(path, 1D);
                        followerNavigation.a(2D);
                    }
                }
            } else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
                path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
                if (path != null) {
                    followerNavigation.a(path, 1D);
                    followerNavigation.a(2D);
                }
            } else {
                inRadius = true;
            }
            if (inRadius && !allowWander) {
                followerNavigation.o();
            }
            nmsFollower.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
        }
    }.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
Also used : net.minecraft.server.v1_9_R2(net.minecraft.server.v1_9_R2) CompoundTag_v1_9_R2(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_9_R2) CraftEntity(org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) UUID(java.util.UUID) Location(org.bukkit.Location)

Example 37 with CraftEntity

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

the class EntityHelper_v1_9_R2 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_9_R2.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_9_R2.entity.CraftPlayer) HashSet(java.util.HashSet) Set(java.util.Set) CraftEntity(org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) net.minecraft.server.v1_9_R2(net.minecraft.server.v1_9_R2) CompoundTag_v1_9_R2(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_9_R2) UUID(java.util.UUID)

Example 38 with CraftEntity

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

the class EntityHelper_v1_10_R1 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_10_R1.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_10_R1.entity.CraftPlayer) HashSet(java.util.HashSet) Set(java.util.Set) CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) net.minecraft.server.v1_10_R1(net.minecraft.server.v1_10_R1) CompoundTag_v1_10_R1(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_10_R1) UUID(java.util.UUID)

Example 39 with CraftEntity

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

the class PlatformHelper method applyTagToEntity.

@Override
public void applyTagToEntity(TagCompound tag, Entity bukkitEntity) {
    net.minecraft.server.v1_10_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("bJ", villager, vanillaNBT.getInt("Career"));
        ReflectionUtil.setFieldValue("bK", villager, vanillaNBT.getInt("CareerLevel"));
        ReflectionUtil.setFieldValue("bG", 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 = ItemStack.createStack(invTag.get(i));
            if (itemstack != null) {
                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_10_R1.entity.CraftEntity) Villager(org.bukkit.entity.Villager) net.minecraft.server.v1_10_R1(net.minecraft.server.v1_10_R1) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)

Example 40 with CraftEntity

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

the class PlatformHelper method applyTagToEntity.

@Override
public void applyTagToEntity(TagCompound tag, Entity bukkitEntity) {
    net.minecraft.server.v1_11_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("bJ", villager, vanillaNBT.getInt("Career"));
        ReflectionUtil.setFieldValue("bK", villager, vanillaNBT.getInt("CareerLevel"));
        ReflectionUtil.setFieldValue("bG", 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_11_R1.entity.CraftEntity) net.minecraft.server.v1_11_R1(net.minecraft.server.v1_11_R1) Villager(org.bukkit.entity.Villager) CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)

Aggregations

Entity (org.bukkit.entity.Entity)30 Iterator (java.util.Iterator)21 List (java.util.List)21 LivingEntity (org.bukkit.entity.LivingEntity)14 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 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)8 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)7 CraftEntity (org.bukkit.craftbukkit.v1_9_R2.entity.CraftEntity)7 Location (org.bukkit.Location)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 CompoundTag_v1_10_R1 (net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_10_R1)4 CompoundTag_v1_11_R1 (net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_11_R1)4 CompoundTag_v1_8_R3 (net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_8_R3)4 CompoundTag_v1_9_R2 (net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_9_R2)4