From 29f33c915c8115091f01fe270049d81e8067106b Mon Sep 17 00:00:00 2001 From: daoge_cmd <3523206925@qq.com> Date: Thu, 26 Dec 2024 10:42:04 +0800 Subject: [PATCH] refactor: remove MovePlayerPacket.TeleportationCause from EntityTeleportEvent.Reason --- .../eventbus/event/entity/EntityTeleportEvent.java | 11 ++++------- .../player/EntityPlayerBaseComponentImpl.java | 11 ++++++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/api/src/main/java/org/allaymc/api/eventbus/event/entity/EntityTeleportEvent.java b/api/src/main/java/org/allaymc/api/eventbus/event/entity/EntityTeleportEvent.java index 278c0929b..ff326087c 100644 --- a/api/src/main/java/org/allaymc/api/eventbus/event/entity/EntityTeleportEvent.java +++ b/api/src/main/java/org/allaymc/api/eventbus/event/entity/EntityTeleportEvent.java @@ -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 @@ -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; } } diff --git a/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerBaseComponentImpl.java b/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerBaseComponentImpl.java index f3b233a43..10eeb42d9 100644 --- a/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerBaseComponentImpl.java +++ b/server/src/main/java/org/allaymc/server/entity/component/player/EntityPlayerBaseComponentImpl.java @@ -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);