Skip to content

Commit

Permalink
Fix viable not being used for player spawn location in older versions…
Browse files Browse the repository at this point in the history
… of MC
  • Loading branch information
libraryaddict committed Jan 5, 2025
1 parent 3a26a5b commit ea0ab6a
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.github.retrooper.packetevents.protocol.player.Equipment;
import com.github.retrooper.packetevents.protocol.player.EquipmentSlot;
import com.github.retrooper.packetevents.protocol.world.Direction;
import com.github.retrooper.packetevents.protocol.world.Location;
import com.github.retrooper.packetevents.protocol.world.PaintingType;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.util.Vector3i;
Expand All @@ -24,6 +25,7 @@
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnPainting;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSpawnPlayer;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerUpdateAttributes;
import io.github.retrooper.packetevents.util.SpigotConversionUtil;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises;
Expand All @@ -44,7 +46,6 @@
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.reflection.WatcherValue;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Damageable;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -95,15 +96,15 @@ public void handle(Disguise disguise, LibsPackets packets, Player observer, Enti
private void constructSpawnPackets(final Player observer, LibsPackets packets, Entity disguisedEntity) {
Disguise disguise = packets.getDisguise();

Location loc = disguisedEntity.getLocation().clone()
.add(0, DisguiseUtilities.getYModifier(disguise) + disguise.getWatcher().getYModifier(), 0);
Vector loc = disguisedEntity.getLocation().toVector();
loc.setY(loc.getY() + DisguiseUtilities.getYModifier(disguise) + disguise.getWatcher().getYModifier());

Float pitchLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getPitchLock() : null;
Float yawLock = DisguiseConfig.isMovementPacketsEnabled() ? disguise.getWatcher().getYawLock() : null;
int entityId = observer == disguisedEntity ? DisguiseAPI.getSelfDisguiseId() : disguisedEntity.getEntityId();

float yaw = (yawLock == null ? loc.getYaw() : yawLock);
float pitch = (pitchLock == null ? loc.getPitch() : pitchLock);
float yaw = (yawLock == null ? disguisedEntity.getLocation().getYaw() : yawLock);
float pitch = (pitchLock == null ? disguisedEntity.getLocation().getPitch() : pitchLock);

if (DisguiseConfig.isMovementPacketsEnabled()) {
if (yawLock == null) {
Expand Down Expand Up @@ -179,11 +180,11 @@ private void constructSpawnPackets(final Player observer, LibsPackets packets, E
spawnPlayer = constructLivingPacket(observer, packets, disguisedEntity, loc, pitch, yaw);
} else {
// Spawn them in front of the observer
Location spawnAt =
inLineOfSight ? loc : observer.getLocation().add(observer.getLocation().getDirection().normalize().multiply(10));
Location spawnAt = inLineOfSight ? pLoc : SpigotConversionUtil.fromBukkitLocation(
observer.getLocation().add(observer.getLocation().getDirection().normalize().multiply(10)));

// Spawn the player
spawnPlayer = new WrapperPlayServerSpawnPlayer(entityId, playerDisguise.getUUID(), pLoc, new ArrayList<>());
spawnPlayer = new WrapperPlayServerSpawnPlayer(entityId, playerDisguise.getUUID(), spawnAt, new ArrayList<>());

packets.addPacket(spawnPlayer);
}
Expand Down Expand Up @@ -383,7 +384,7 @@ private void constructSpawnPackets(final Player observer, LibsPackets packets, E
}
}

private PacketWrapper constructLivingPacket(Player observer, LibsPackets packets, Entity disguisedEntity, Location loc, float pitch,
private PacketWrapper constructLivingPacket(Player observer, LibsPackets packets, Entity disguisedEntity, Vector loc, float pitch,
float yaw) {
Disguise disguise = packets.getDisguise();
Vector vec = disguisedEntity.getVelocity();
Expand Down

0 comments on commit ea0ab6a

Please sign in to comment.