Skip to content

Commit

Permalink
refactor: remove MovePlayerPacket.TeleportationCause from EntityTelep…
Browse files Browse the repository at this point in the history
…ortEvent.Reason
  • Loading branch information
smartcmd committed Dec 26, 2024
1 parent f5d76f9 commit 29f33c9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.allaymc.api.eventbus.event.CancellableEvent;
import org.allaymc.api.math.location.Location3f;
import org.allaymc.api.math.location.Location3fc;
import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket;

/**
* @author daoge_cmd
Expand Down Expand Up @@ -35,14 +34,12 @@ public boolean isTeleportBetweenWorlds() {
@AllArgsConstructor
public enum Reason {
// Unknown reason, may be caused by plugin
UNKNOWN(MovePlayerPacket.TeleportationCause.UNKNOWN),
UNKNOWN,
// Ender pearl
PROJECTILE(MovePlayerPacket.TeleportationCause.PROJECTILE),
PROJECTILE,
// Chorus fruit
CHORUS_FRUIT(MovePlayerPacket.TeleportationCause.CHORUS_FRUIT),
CHORUS_FRUIT,
// Command
COMMAND(MovePlayerPacket.TeleportationCause.COMMAND);

private final MovePlayerPacket.TeleportationCause networkValue;
COMMAND;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,19 @@ public void sendLocationToSelf(EntityTeleportEvent.Reason reason) {
pk.setPosition(org.cloudburstmc.math.vector.Vector3f.from(location.x(), location.y() + getBaseOffset(), location.z()));
pk.setRotation(org.cloudburstmc.math.vector.Vector3f.from(location.pitch(), location.yaw(), location.headYaw()));
pk.setMode(MovePlayerPacket.Mode.TELEPORT);
pk.setTeleportationCause(reason.getNetworkValue());
pk.setTeleportationCause(convertTeleportReasonToNetworkCause(reason));
networkComponent.sendPacket(pk);
}

protected static MovePlayerPacket.TeleportationCause convertTeleportReasonToNetworkCause(EntityTeleportEvent.Reason reason) {
return switch (reason) {
case PROJECTILE -> MovePlayerPacket.TeleportationCause.PROJECTILE;
case CHORUS_FRUIT -> MovePlayerPacket.TeleportationCause.CHORUS_FRUIT;
case COMMAND -> MovePlayerPacket.TeleportationCause.COMMAND;
default -> MovePlayerPacket.TeleportationCause.UNKNOWN;
};
}

@Override
public boolean isUsingItemInAir() {
return getMetadata().get(EntityFlag.USING_ITEM);
Expand Down

0 comments on commit 29f33c9

Please sign in to comment.