use of org.bukkit.craftbukkit.v1_17_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()));
}
}
}
use of org.bukkit.craftbukkit.v1_17_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);
}
}
}
use of org.bukkit.craftbukkit.v1_17_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;
}
use of org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method damage.
@Override
public void damage(LivingEntity target, float amount, Entity source, EntityDamageEvent.DamageCause cause) {
if (target == null) {
return;
}
net.minecraft.world.entity.LivingEntity nmsTarget = ((CraftLivingEntity) target).getHandle();
net.minecraft.world.entity.Entity nmsSource = source == null ? null : ((CraftEntity) source).getHandle();
CraftEventFactory.entityDamage = nmsSource;
try {
DamageSource src = getSourceFor(nmsSource, cause);
if (src instanceof FakeDamageSrc) {
src = ((FakeDamageSrc) src).real;
EntityDamageEvent ede = fireFakeDamageEvent(target, source, cause, amount);
if (ede.isCancelled()) {
return;
}
}
nmsTarget.hurt(src, amount);
} finally {
CraftEventFactory.entityDamage = null;
}
}
use of org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelperImpl method getDamageTo.
@Override
public double getDamageTo(LivingEntity attacker, Entity target) {
MobType monsterType;
if (target instanceof LivingEntity) {
monsterType = ((CraftLivingEntity) target).getHandle().getMobType();
} else {
monsterType = MobType.UNDEFINED;
}
double damage = 0;
AttributeInstance attrib = attacker.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE);
if (attrib != null) {
damage = attrib.getValue();
}
if (attacker.getEquipment() != null && attacker.getEquipment().getItemInMainHand() != null) {
damage += EnchantmentHelper.getDamageBonus(CraftItemStack.asNMSCopy(attacker.getEquipment().getItemInMainHand()), monsterType);
}
if (damage <= 0) {
return 0;
}
if (target != null) {
DamageSource source;
if (attacker instanceof Player) {
source = DamageSource.playerAttack(((CraftPlayer) attacker).getHandle());
} else {
source = DamageSource.mobAttack(((CraftLivingEntity) attacker).getHandle());
}
net.minecraft.world.entity.Entity nmsTarget = ((CraftEntity) target).getHandle();
if (nmsTarget.isInvulnerableTo(source)) {
return 0;
}
if (!(nmsTarget instanceof net.minecraft.world.entity.LivingEntity)) {
return damage;
}
net.minecraft.world.entity.LivingEntity livingTarget = (net.minecraft.world.entity.LivingEntity) nmsTarget;
damage = CombatRules.getDamageAfterAbsorb((float) damage, (float) livingTarget.getArmorValue(), (float) livingTarget.getAttributeValue(Attributes.ARMOR_TOUGHNESS));
int enchantDamageModifier = EnchantmentHelper.getDamageProtection(livingTarget.getArmorSlots(), source);
if (enchantDamageModifier > 0) {
damage = CombatRules.getDamageAfterMagicAbsorb((float) damage, (float) enchantDamageModifier);
}
}
return damage;
}
Aggregations