Search in sources :

Example 31 with CraftEntity

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

the class DenizenNetworkManagerImpl method tryProcessMovePacketForAttach.

public void tryProcessMovePacketForAttach(ClientboundMoveEntityPacket packet, Entity e) throws IllegalAccessException {
    EntityAttachmentHelper.EntityAttachedToMap attList = EntityAttachmentHelper.toEntityToData.get(e.getUUID());
    if (attList != null) {
        for (EntityAttachmentHelper.PlayerAttachMap attMap : attList.attachedToMap.values()) {
            EntityAttachmentHelper.AttachmentData att = attMap.getAttachment(player.getUUID());
            if (attMap.attached.isValid() && att != null) {
                ClientboundMoveEntityPacket pNew;
                int newId = att.attached.getBukkitEntity().getEntityId();
                if (packet instanceof ClientboundMoveEntityPacket.Pos) {
                    pNew = new ClientboundMoveEntityPacket.Pos(newId, packet.getXa(), packet.getYa(), packet.getZa(), packet.isOnGround());
                } else if (packet instanceof ClientboundMoveEntityPacket.Rot) {
                    pNew = new ClientboundMoveEntityPacket.Rot(newId, packet.getyRot(), packet.getxRot(), packet.isOnGround());
                } else if (packet instanceof ClientboundMoveEntityPacket.PosRot) {
                    pNew = new ClientboundMoveEntityPacket.PosRot(newId, packet.getXa(), packet.getYa(), packet.getZa(), packet.getyRot(), packet.getxRot(), packet.isOnGround());
                } else {
                    if (Debug.verbose) {
                        Debug.echoError("Impossible move-entity packet class: " + packet.getClass().getCanonicalName());
                    }
                    return;
                }
                if (att.positionalOffset != null && (packet instanceof ClientboundMoveEntityPacket.Pos || packet instanceof ClientboundMoveEntityPacket.PosRot)) {
                    boolean isRotate = packet instanceof ClientboundMoveEntityPacket.PosRot;
                    byte yaw, pitch;
                    if (att.noRotate) {
                        Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
                        yaw = EntityAttachmentHelper.compressAngle(attachedEntity.getYRot());
                        pitch = EntityAttachmentHelper.compressAngle(attachedEntity.getXRot());
                    } else if (isRotate) {
                        yaw = packet.getyRot();
                        pitch = packet.getxRot();
                    } else {
                        yaw = EntityAttachmentHelper.compressAngle(e.getYRot());
                        pitch = EntityAttachmentHelper.compressAngle(e.getXRot());
                    }
                    if (att.noPitch) {
                        Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
                        pitch = EntityAttachmentHelper.compressAngle(attachedEntity.getXRot());
                    }
                    byte newYaw = yaw;
                    if (isRotate) {
                        newYaw = EntityAttachmentHelper.adaptedCompressedAngle(newYaw, att.positionalOffset.getYaw());
                        pitch = EntityAttachmentHelper.adaptedCompressedAngle(pitch, att.positionalOffset.getPitch());
                    }
                    Vector goalPosition = att.fixedForOffset(new Vector(e.getX(), e.getY(), e.getZ()), e.getYRot(), e.getXRot());
                    Vector oldPos = att.visiblePositions.get(player.getUUID());
                    boolean forceTele = false;
                    if (oldPos == null) {
                        oldPos = att.attached.getLocation().toVector();
                        forceTele = true;
                    }
                    Vector moveNeeded = goalPosition.clone().subtract(oldPos);
                    att.visiblePositions.put(player.getUUID(), goalPosition.clone());
                    int offX = (int) (moveNeeded.getX() * (32 * 128));
                    int offY = (int) (moveNeeded.getY() * (32 * 128));
                    int offZ = (int) (moveNeeded.getZ() * (32 * 128));
                    if (forceTele || offX < Short.MIN_VALUE || offX > Short.MAX_VALUE || offY < Short.MIN_VALUE || offY > Short.MAX_VALUE || offZ < Short.MIN_VALUE || offZ > Short.MAX_VALUE) {
                        ClientboundTeleportEntityPacket newTeleportPacket = new ClientboundTeleportEntityPacket(e);
                        ENTITY_ID_PACKTELENT.setInt(newTeleportPacket, att.attached.getBukkitEntity().getEntityId());
                        POS_X_PACKTELENT.setDouble(newTeleportPacket, goalPosition.getX());
                        POS_Y_PACKTELENT.setDouble(newTeleportPacket, goalPosition.getY());
                        POS_Z_PACKTELENT.setDouble(newTeleportPacket, goalPosition.getZ());
                        YAW_PACKTELENT.setByte(newTeleportPacket, newYaw);
                        PITCH_PACKTELENT.setByte(newTeleportPacket, pitch);
                        if (NMSHandler.debugPackets) {
                            Debug.log("Attach Move-Tele Packet: " + newTeleportPacket.getClass().getCanonicalName() + " for " + att.attached.getUUID() + " sent to " + player.getName() + " with original yaw " + yaw + " adapted to " + newYaw);
                        }
                        oldManager.send(newTeleportPacket);
                    } else {
                        POS_X_PACKENT.setShort(pNew, (short) Mth.clamp(offX, Short.MIN_VALUE, Short.MAX_VALUE));
                        POS_Y_PACKENT.setShort(pNew, (short) Mth.clamp(offY, Short.MIN_VALUE, Short.MAX_VALUE));
                        POS_Z_PACKENT.setShort(pNew, (short) Mth.clamp(offZ, Short.MIN_VALUE, Short.MAX_VALUE));
                        if (isRotate) {
                            YAW_PACKENT.setByte(pNew, yaw);
                            PITCH_PACKENT.setByte(pNew, pitch);
                        }
                        if (NMSHandler.debugPackets) {
                            Debug.log("Attach Move Packet: " + pNew.getClass().getCanonicalName() + " for " + att.attached.getUUID() + " sent to " + player.getName() + " with original yaw " + yaw + " adapted to " + newYaw);
                        }
                        oldManager.send(pNew);
                    }
                } else {
                    if (NMSHandler.debugPackets) {
                        Debug.log("Attach Replica-Move Packet: " + pNew.getClass().getCanonicalName() + " for " + att.attached.getUUID() + " sent to " + player.getName());
                    }
                    oldManager.send(pNew);
                }
            }
        }
    }
    if (e.passengers != null && !e.passengers.isEmpty()) {
        for (Entity ent : e.passengers) {
            tryProcessMovePacketForAttach(packet, ent);
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Entity(net.minecraft.world.entity.Entity) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) SectionPos(net.minecraft.core.SectionPos) BlockPos(net.minecraft.core.BlockPos) EntityAttachmentHelper(com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper) Vector(org.bukkit.util.Vector)

Example 32 with CraftEntity

use of org.bukkit.craftbukkit.v1_6_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 33 with CraftEntity

use of org.bukkit.craftbukkit.v1_6_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)

Example 34 with CraftEntity

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

the class EntityHelper_v1_11_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_11_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 : 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) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) UUID(java.util.UUID) Location(org.bukkit.Location)

Example 35 with CraftEntity

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

the class EntityHelper_v1_11_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_11_R1.Entity handle = ((CraftEntity) entity).getHandle();
        handle.yaw = yaw;
        handle.pitch = pitch;
    }
}
Also used : CraftLivingEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftLivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftLivingEntity) CraftEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity) Entity(org.bukkit.entity.Entity) CraftPlayer(org.bukkit.craftbukkit.v1_11_R1.entity.CraftPlayer) Location(org.bukkit.Location)

Aggregations

Entity (org.bukkit.entity.Entity)30 Iterator (java.util.Iterator)21 List (java.util.List)21 LivingEntity (org.bukkit.entity.LivingEntity)17 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 EntityAttachmentHelper (com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper)6 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 Entity (net.minecraft.world.entity.Entity)5 Vector (org.bukkit.util.Vector)5 CompoundTag_v1_11_R1 (net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_11_R1)4