Search in sources :

Example 1 with CraftEntity

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

the class EntityHelper_v1_10_R1 method walkTo.

@Override
public void walkTo(final Entity entity, Location location, double speed, final Runnable callback) {
    if (entity == null || location == null) {
        return;
    }
    net.minecraft.server.v1_10_R1.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
    if (!(nmsEntityEntity instanceof EntityInsentient)) {
        return;
    }
    final EntityInsentient nmsEntity = (EntityInsentient) nmsEntityEntity;
    final NavigationAbstract entityNavigation = nmsEntity.getNavigation();
    final PathEntity path;
    final boolean aiDisabled = isAIDisabled(entity);
    if (aiDisabled) {
        toggleAI(entity, true);
        nmsEntity.onGround = true;
    }
    path = entityNavigation.a(location.getX(), location.getY(), location.getZ());
    if (path != null) {
        entityNavigation.a(path, 1D);
        entityNavigation.a(2D);
        final double oldSpeed = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).b();
        nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
        new BukkitRunnable() {

            @Override
            public void run() {
                if (entityNavigation.n() || path.b()) {
                    if (callback != null) {
                        callback.run();
                    }
                    nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
                    if (aiDisabled) {
                        toggleAI(entity, false);
                    }
                    cancel();
                }
            }
        }.runTaskTimer(NMSHandler.getJavaPlugin(), 1, 1);
    } else //if (!Utilities.checkLocation(location, entity.getLocation(), 20)) {
    // TODO: generate waypoints to the target location?
    {
        entity.teleport(location);
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) 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) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable)

Example 2 with CraftEntity

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

the class EntityHelper_v1_10_R1 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_10_R1.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 : CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) 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) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) UUID(java.util.UUID) Location(org.bukkit.Location)

Example 3 with CraftEntity

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

the class EntityHelper_v1_10_R1 method rotate.

@Override
public void rotate(Entity entity, float yaw, float pitch) {
    // it will appear to be online
    if (entity instanceof Player && ((Player) entity).isOnline()) {
        Location location = entity.getLocation();
        location.setYaw(yaw);
        location.setPitch(pitch);
        entity.teleport(location);
    } else if (entity instanceof LivingEntity) {
        if (entity instanceof EnderDragon) {
            yaw = normalizeYaw(yaw - 180);
        }
        look(entity, yaw, pitch);
    } else {
        net.minecraft.server.v1_10_R1.Entity handle = ((CraftEntity) entity).getHandle();
        handle.yaw = yaw;
        handle.pitch = pitch;
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftLivingEntity) CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftLivingEntity) Entity(org.bukkit.entity.Entity) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) Location(org.bukkit.Location)

Example 4 with CraftEntity

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

the class EntityHelper_v1_10_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_10_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_10_R1.entity.CraftPlayer) HashSet(java.util.HashSet) Set(java.util.Set) CraftEntity(org.bukkit.craftbukkit.v1_10_R1.entity.CraftEntity) 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) CraftPlayer(org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer) UUID(java.util.UUID)

Example 5 with CraftEntity

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

the class EntityHelper_v1_9_R2 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_9_R2.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_9_R2.entity.CraftPlayer) HashSet(java.util.HashSet) Set(java.util.Set) 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) CraftPlayer(org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer) UUID(java.util.UUID)

Aggregations

Location (org.bukkit.Location)41 Entity (org.bukkit.entity.Entity)38 LivingEntity (org.bukkit.entity.LivingEntity)37 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 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)22 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 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