0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2024-11-22 04:16:17 +00:00
craftbukkit/nms-patches/net/minecraft/server/commands/CommandTeleport.patch
2024-10-23 02:15:00 +11:00

50 lines
2.1 KiB
Diff

--- a/net/minecraft/server/commands/CommandTeleport.java
+++ b/net/minecraft/server/commands/CommandTeleport.java
@@ -31,6 +31,14 @@
import net.minecraft.world.phys.Vec2F;
import net.minecraft.world.phys.Vec3D;
+// CraftBukkit start
+import net.minecraft.server.level.EntityPlayer;
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.event.entity.EntityTeleportEvent;
+import org.bukkit.event.player.PlayerTeleportEvent;
+// CraftBukkit end
+
public class CommandTeleport {
private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType(IChatBaseComponent.translatable("commands.teleport.invalidPosition"));
@@ -167,7 +175,30 @@
float f4 = MathHelper.wrapDegrees(f2);
float f5 = MathHelper.wrapDegrees(f3);
- if (entity.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true)) {
+ // CraftBukkit start - Teleport event
+ boolean result;
+ if (entity instanceof EntityPlayer player) {
+ result = player.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true, PlayerTeleportEvent.TeleportCause.COMMAND);
+ } else {
+ Location to = new Location(worldserver.getWorld(), d3, d4, d5, f4, f5);
+ EntityTeleportEvent event = new EntityTeleportEvent(entity.getBukkitEntity(), entity.getBukkitEntity().getLocation(), to);
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) {
+ return;
+ }
+
+ d3 = to.getX();
+ d4 = to.getY();
+ d5 = to.getZ();
+ f4 = to.getYaw();
+ f5 = to.getPitch();
+ worldserver = ((CraftWorld) to.getWorld()).getHandle();
+
+ result = entity.teleportTo(worldserver, d3, d4, d5, set, f4, f5, true);
+ }
+
+ if (result) {
+ // CraftBukkit end
if (lookat != null) {
lookat.perform(commandlistenerwrapper, entity);
}