Search in sources :

Example 66 with CraftEntity

use of org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity in project NoCheatPlus by NoCheatPlus.

the class MCAccessCBDev method getHeight.

@Override
public double getHeight(final Entity entity) {
    // (entity.getHeight() returns the length field, but we access nms anyway.)
    final net.minecraft.server.v1_12_R1.Entity mcEntity = ((CraftEntity) entity).getHandle();
    final AxisAlignedBB boundingBox = mcEntity.getBoundingBox();
    final double entityHeight = Math.max(mcEntity.length, Math.max(mcEntity.getHeadHeight(), boundingBox.e - boundingBox.b));
    if (entity instanceof LivingEntity) {
        return Math.max(((LivingEntity) entity).getEyeHeight(), entityHeight);
    } else {
        return entityHeight;
    }
}
Also used : AxisAlignedBB(net.minecraft.server.v1_12_R1.AxisAlignedBB) LivingEntity(org.bukkit.entity.LivingEntity) CraftEntity(org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)

Example 67 with CraftEntity

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

the class DenizenNetworkManagerImpl method tryProcessTeleportPacketForAttach.

public void tryProcessTeleportPacketForAttach(Packet<?> packet, Entity e, Vector relative) throws IllegalAccessException {
    EntityAttachmentHelper.EntityAttachedToMap attList = EntityAttachmentHelper.toEntityToData.get(e.getUniqueID());
    if (attList != null) {
        for (EntityAttachmentHelper.PlayerAttachMap attMap : attList.attachedToMap.values()) {
            EntityAttachmentHelper.AttachmentData att = attMap.getAttachment(player.getUniqueID());
            if (attMap.attached.isValid() && att != null) {
                Packet pNew = (Packet) duplo(packet);
                ENTITY_ID_PACKTELENT.setInt(pNew, att.attached.getBukkitEntity().getEntityId());
                Vector resultPos = new Vector(POS_X_PACKTELENT.getDouble(pNew), POS_Y_PACKTELENT.getDouble(pNew), POS_Z_PACKTELENT.getDouble(pNew)).add(relative);
                if (att.positionalOffset != null) {
                    resultPos = att.fixedForOffset(resultPos, e.yaw, e.pitch);
                    byte yaw, pitch;
                    if (att.noRotate) {
                        Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
                        yaw = EntityAttachmentHelper.compressAngle(attachedEntity.yaw);
                        pitch = EntityAttachmentHelper.compressAngle(attachedEntity.pitch);
                    } else {
                        yaw = YAW_PACKTELENT.getByte(packet);
                        pitch = PITCH_PACKTELENT.getByte(packet);
                    }
                    byte newYaw = EntityAttachmentHelper.adaptedCompressedAngle(yaw, att.positionalOffset.getYaw());
                    pitch = EntityAttachmentHelper.adaptedCompressedAngle(pitch, att.positionalOffset.getPitch());
                    POS_X_PACKTELENT.setDouble(pNew, resultPos.getX());
                    POS_Y_PACKTELENT.setDouble(pNew, resultPos.getY());
                    POS_Z_PACKTELENT.setDouble(pNew, resultPos.getZ());
                    YAW_PACKTELENT.setByte(pNew, newYaw);
                    PITCH_PACKTELENT.setByte(pNew, pitch);
                    if (NMSHandler.debugPackets) {
                        Debug.log("Attach Teleport Packet: " + pNew.getClass().getCanonicalName() + " for " + att.attached.getUUID() + " sent to " + player.getName() + " with raw yaw " + yaw + " adapted to " + newYaw);
                    }
                }
                att.visiblePositions.put(player.getUniqueID(), resultPos.clone());
                oldManager.sendPacket(pNew);
            }
        }
    }
    if (e.passengers != null && !e.passengers.isEmpty()) {
        for (Entity ent : e.passengers) {
            tryProcessTeleportPacketForAttach(packet, ent, new Vector(ent.locX() - e.locX(), ent.locY() - e.locY(), ent.locZ() - e.locZ()));
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PacketOutSpawnEntity(com.denizenscript.denizen.nms.interfaces.packets.PacketOutSpawnEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) EntityAttachmentHelper(com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper) Vector(org.bukkit.util.Vector)

Example 68 with CraftEntity

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

the class DenizenNetworkManagerImpl method tryProcessMovePacketForAttach.

public void tryProcessMovePacketForAttach(Packet<?> packet, Entity e) throws IllegalAccessException {
    EntityAttachmentHelper.EntityAttachedToMap attList = EntityAttachmentHelper.toEntityToData.get(e.getUniqueID());
    if (attList != null) {
        for (EntityAttachmentHelper.PlayerAttachMap attMap : attList.attachedToMap.values()) {
            EntityAttachmentHelper.AttachmentData att = attMap.getAttachment(player.getUniqueID());
            if (attMap.attached.isValid() && att != null) {
                Packet pNew = (Packet) duplo(packet);
                ENTITY_ID_PACKENT.setInt(pNew, att.attached.getBukkitEntity().getEntityId());
                if (att.positionalOffset != null && (packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMove || packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook)) {
                    boolean isRotate = packet instanceof PacketPlayOutEntity.PacketPlayOutRelEntityMoveLook;
                    byte yaw, pitch;
                    if (att.noRotate) {
                        Entity attachedEntity = ((CraftEntity) att.attached.getBukkitEntity()).getHandle();
                        yaw = EntityAttachmentHelper.compressAngle(attachedEntity.yaw);
                        pitch = EntityAttachmentHelper.compressAngle(attachedEntity.pitch);
                    } else if (isRotate) {
                        yaw = YAW_PACKENT.getByte(packet);
                        pitch = PITCH_PACKENT.getByte(packet);
                    } else {
                        yaw = EntityAttachmentHelper.compressAngle(e.yaw);
                        pitch = EntityAttachmentHelper.compressAngle(e.pitch);
                    }
                    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.locX(), e.locY(), e.locZ()), e.yaw, e.pitch);
                    Vector oldPos = att.visiblePositions.get(player.getUniqueID());
                    boolean forceTele = false;
                    if (oldPos == null) {
                        oldPos = att.attached.getLocation().toVector();
                        forceTele = true;
                    }
                    Vector moveNeeded = goalPosition.clone().subtract(oldPos);
                    att.visiblePositions.put(player.getUniqueID(), 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) {
                        PacketPlayOutEntityTeleport newTeleportPacket = new PacketPlayOutEntityTeleport(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 (" + forceTele + ": " + moveNeeded + " == " + offX + "," + offY + "," + offZ + "): " + newTeleportPacket.getClass().getCanonicalName() + " for " + att.attached.getUUID() + " sent to " + player.getName() + " with original yaw " + yaw + " adapted to " + newYaw);
                        }
                        oldManager.sendPacket(newTeleportPacket);
                    } else {
                        POS_X_PACKENT.setShort(pNew, (short) MathHelper.clamp(offX, Short.MIN_VALUE, Short.MAX_VALUE));
                        POS_Y_PACKENT.setShort(pNew, (short) MathHelper.clamp(offY, Short.MIN_VALUE, Short.MAX_VALUE));
                        POS_Z_PACKENT.setShort(pNew, (short) MathHelper.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.sendPacket(pNew);
                    }
                } else {
                    if (NMSHandler.debugPackets) {
                        Debug.log("Attach Replica-Move Packet: " + pNew.getClass().getCanonicalName() + " for " + att.attached.getUUID() + " sent to " + player.getName());
                    }
                    oldManager.sendPacket(pNew);
                }
            }
        }
    }
    if (e.passengers != null && !e.passengers.isEmpty()) {
        for (Entity ent : e.passengers) {
            tryProcessMovePacketForAttach(packet, ent);
        }
    }
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PacketOutSpawnEntity(com.denizenscript.denizen.nms.interfaces.packets.PacketOutSpawnEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) EntityAttachmentHelper(com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper) Vector(org.bukkit.util.Vector)

Example 69 with CraftEntity

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

the class DenizenNetworkManagerImpl method processDisguiseForPacket.

public boolean processDisguiseForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
    if (DisguiseCommand.disguises.isEmpty() || antiDuplicate) {
        return false;
    }
    try {
        if (packet instanceof PacketPlayOutEntityMetadata) {
            PacketPlayOutEntityMetadata metadataPacket = (PacketPlayOutEntityMetadata) packet;
            int eid = ENTITY_METADATA_EID.getInt(metadataPacket);
            Entity ent = player.world.getEntity(eid);
            if (ent == null) {
                return false;
            }
            HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(ent.getUniqueID());
            if (playerMap == null) {
                return false;
            }
            DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUniqueID());
            if (disguise == null) {
                disguise = playerMap.get(null);
                if (disguise == null) {
                    return false;
                }
            }
            if (ent.getId() == player.getId()) {
                if (!disguise.shouldFake) {
                    return false;
                }
                List<DataWatcher.Item<?>> data = (List<DataWatcher.Item<?>>) ENTITY_METADATA_LIST.get(metadataPacket);
                for (DataWatcher.Item item : data) {
                    DataWatcherObject<?> watcherObject = item.a();
                    int watcherId = watcherObject.a();
                    if (watcherId == 0) {
                        // Entity flags
                        PacketPlayOutEntityMetadata altPacket = new PacketPlayOutEntityMetadata();
                        copyPacket(metadataPacket, altPacket);
                        data = new ArrayList<>(data);
                        ENTITY_METADATA_LIST.set(altPacket, data);
                        data.remove(item);
                        byte flags = (byte) item.b();
                        // Invisible flag
                        flags |= 0x20;
                        data.add(new DataWatcher.Item(watcherObject, flags));
                        PacketPlayOutEntityMetadata updatedPacket = getModifiedMetadataFor(altPacket);
                        oldManager.sendPacket(updatedPacket == null ? altPacket : updatedPacket, genericfuturelistener);
                        return true;
                    }
                }
            } else {
                PacketPlayOutEntityMetadata altPacket = new PacketPlayOutEntityMetadata(ent.getId(), ((CraftEntity) disguise.toOthers.entity.entity).getHandle().getDataWatcher(), true);
                oldManager.sendPacket(altPacket, genericfuturelistener);
                return true;
            }
            return false;
        }
        int ider = -1;
        if (packet instanceof PacketPlayOutNamedEntitySpawn) {
            ider = ENTITY_ID_NAMEDENTSPAWN.getInt(packet);
        } else if (packet instanceof PacketPlayOutSpawnEntity) {
            ider = ENTITY_ID_SPAWNENT.getInt(packet);
        } else if (packet instanceof PacketPlayOutSpawnEntityLiving) {
            ider = ENTITY_ID_SPAWNENTLIVING.getInt(packet);
        }
        if (ider != -1) {
            Entity e = player.getWorld().getEntity(ider);
            if (e == null) {
                return false;
            }
            HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(e.getUniqueID());
            if (playerMap == null) {
                return false;
            }
            DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUniqueID());
            if (disguise == null) {
                disguise = playerMap.get(null);
                if (disguise == null) {
                    return false;
                }
            }
            antiDuplicate = true;
            disguise.sendTo(Collections.singletonList(new PlayerTag(player.getBukkitEntity())));
            antiDuplicate = false;
            return true;
        }
    } catch (Throwable ex) {
        antiDuplicate = false;
        Debug.echoError(ex);
    }
    return false;
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PacketOutSpawnEntity(com.denizenscript.denizen.nms.interfaces.packets.PacketOutSpawnEntity) DisguiseCommand(com.denizenscript.denizen.scripts.commands.player.DisguiseCommand) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity)

Example 70 with CraftEntity

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

the class DenizenNetworkManagerImpl method processDisguiseForPacket.

public boolean processDisguiseForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
    if (DisguiseCommand.disguises.isEmpty() || antiDuplicate) {
        return false;
    }
    try {
        if (packet instanceof ClientboundSetEntityDataPacket) {
            ClientboundSetEntityDataPacket metadataPacket = (ClientboundSetEntityDataPacket) packet;
            int eid = metadataPacket.getId();
            Entity ent = player.level.getEntity(eid);
            if (ent == null) {
                return false;
            }
            HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(ent.getUUID());
            if (playerMap == null) {
                return false;
            }
            DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUUID());
            if (disguise == null) {
                disguise = playerMap.get(null);
                if (disguise == null) {
                    return false;
                }
            }
            if (ent.getId() == player.getId()) {
                if (!disguise.shouldFake) {
                    return false;
                }
                List<SynchedEntityData.DataItem<?>> data = metadataPacket.getUnpackedData();
                for (SynchedEntityData.DataItem item : data) {
                    EntityDataAccessor<?> watcherObject = item.getAccessor();
                    int watcherId = watcherObject.getId();
                    if (watcherId == 0) {
                        // Entity flags
                        ClientboundSetEntityDataPacket altPacket = new ClientboundSetEntityDataPacket(copyPacket(metadataPacket));
                        data = new ArrayList<>(data);
                        ENTITY_METADATA_LIST.set(altPacket, data);
                        data.remove(item);
                        byte flags = (byte) item.getValue();
                        // Invisible flag
                        flags |= 0x20;
                        data.add(new SynchedEntityData.DataItem(watcherObject, flags));
                        ClientboundSetEntityDataPacket updatedPacket = getModifiedMetadataFor(altPacket);
                        oldManager.send(updatedPacket == null ? altPacket : updatedPacket, genericfuturelistener);
                        return true;
                    }
                }
            } else {
                ClientboundSetEntityDataPacket altPacket = new ClientboundSetEntityDataPacket(ent.getId(), ((CraftEntity) disguise.toOthers.entity.entity).getHandle().getEntityData(), true);
                oldManager.send(altPacket, genericfuturelistener);
                return true;
            }
            return false;
        }
        int ider = -1;
        if (packet instanceof ClientboundAddPlayerPacket) {
            ider = ((ClientboundAddPlayerPacket) packet).getEntityId();
        } else if (packet instanceof ClientboundAddEntityPacket) {
            ider = ((ClientboundAddEntityPacket) packet).getId();
        } else if (packet instanceof ClientboundAddMobPacket) {
            ider = ((ClientboundAddMobPacket) packet).getId();
        }
        if (ider != -1) {
            Entity e = player.getLevel().getEntity(ider);
            if (e == null) {
                return false;
            }
            HashMap<UUID, DisguiseCommand.TrackedDisguise> playerMap = DisguiseCommand.disguises.get(e.getUUID());
            if (playerMap == null) {
                return false;
            }
            DisguiseCommand.TrackedDisguise disguise = playerMap.get(player.getUUID());
            if (disguise == null) {
                disguise = playerMap.get(null);
                if (disguise == null) {
                    return false;
                }
            }
            antiDuplicate = true;
            disguise.sendTo(Collections.singletonList(new PlayerTag(player.getBukkitEntity())));
            antiDuplicate = false;
            return true;
        }
    } catch (Throwable ex) {
        antiDuplicate = false;
        Debug.echoError(ex);
    }
    return false;
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity) Entity(net.minecraft.world.entity.Entity) DisguiseCommand(com.denizenscript.denizen.scripts.commands.player.DisguiseCommand) SynchedEntityData(net.minecraft.network.syncher.SynchedEntityData) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) CraftEntity(org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)

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