use of org.bukkit.craftbukkit.v1_6_R2.entity.CraftEntity in project NoCheatPlus by NoCheatPlus.
the class BlockCacheCB2882 method standsOnEntity.
@Override
public boolean standsOnEntity(final Entity entity, final double minX, final double minY, final double minZ, final double maxX, final double maxY, final double maxZ) {
try {
// TODO: Probably check other ids too before doing this ?
final net.minecraft.server.v1_6_R3.Entity mcEntity = ((CraftEntity) entity).getHandle();
final AxisAlignedBB box = useBox.b(minX, minY, minZ, maxX, maxY, maxZ);
@SuppressWarnings("rawtypes") final List list = world.getEntities(mcEntity, box);
@SuppressWarnings("rawtypes") final Iterator iterator = list.iterator();
while (iterator.hasNext()) {
final net.minecraft.server.v1_6_R3.Entity other = (net.minecraft.server.v1_6_R3.Entity) iterator.next();
if (!(other instanceof EntityBoat)) {
// && !(other instanceof EntityMinecart)) continue;
continue;
}
if (minY >= other.locY && minY - other.locY <= 0.7) {
return true;
}
// Still check this for some reason.
final AxisAlignedBB otherBox = other.boundingBox;
if (box.a > otherBox.d || box.d < otherBox.a || box.b > otherBox.e || box.e < otherBox.b || box.c > otherBox.f || box.f < otherBox.c)
continue;
else {
return true;
}
}
} catch (Throwable t) {
// Ignore exceptions (Context: DisguiseCraft).
}
return false;
}
use of org.bukkit.craftbukkit.v1_6_R2.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;
}
}
use of org.bukkit.craftbukkit.v1_6_R2.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()));
}
}
}
use of org.bukkit.craftbukkit.v1_6_R2.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);
}
}
}
use of org.bukkit.craftbukkit.v1_6_R2.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;
}
Aggregations