2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/commands/CommandTeleport.java
+++ b/net/minecraft/server/commands/CommandTeleport.java
2023-03-14 17:30:00 +01:00
@@ -33,6 +33,13 @@
2021-03-15 23:00:00 +01:00
import net.minecraft.world.phys.Vec2F;
import net.minecraft.world.phys.Vec3D;
2021-03-08 22:47:33 +01:00
2018-09-07 12:32:57 +02:00
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.event.entity.EntityTeleportEvent;
2023-03-14 17:30:00 +01:00
+import org.bukkit.event.player.PlayerTeleportEvent;
2018-09-07 12:32:57 +02:00
+// CraftBukkit end
2021-03-08 22:47:33 +01:00
+
2018-09-07 12:32:57 +02:00
public class CommandTeleport {
2022-06-07 18:00:00 +02:00
private static final SimpleCommandExceptionType INVALID_POSITION = new SimpleCommandExceptionType(IChatBaseComponent.translatable("commands.teleport.invalidPosition"));
2023-06-07 17:30:00 +02:00
@@ -155,7 +162,30 @@
2023-03-14 17:30:00 +01:00
float f2 = MathHelper.wrapDegrees(f);
float f3 = MathHelper.wrapDegrees(f1);
2017-06-04 00:39:36 +02:00
2023-03-14 17:30:00 +01:00
- if (entity.teleportTo(worldserver, d0, d1, d2, set, f2, f3)) {
+ // CraftBukkit start - Teleport event
+ boolean result;
+ if (entity instanceof EntityPlayer player) {
+ result = player.teleportTo(worldserver, d0, d1, d2, set, f2, f3, PlayerTeleportEvent.TeleportCause.COMMAND);
+ } else {
+ Location to = new Location(worldserver.getWorld(), d0, d1, d2, f2, f3);
2020-06-25 02:00:00 +02:00
+ EntityTeleportEvent event = new EntityTeleportEvent(entity.getBukkitEntity(), entity.getBukkitEntity().getLocation(), to);
2021-06-11 13:33:49 +02:00
+ worldserver.getCraftServer().getPluginManager().callEvent(event);
2020-06-25 02:00:00 +02:00
+ if (event.isCancelled()) {
+ return;
+ }
2018-09-07 12:32:57 +02:00
+
2020-06-25 02:00:00 +02:00
+ d0 = to.getX();
+ d1 = to.getY();
+ d2 = to.getZ();
+ f2 = to.getYaw();
2023-03-14 17:30:00 +01:00
+ f3 = to.getPitch();
2020-06-25 02:00:00 +02:00
+ worldserver = ((CraftWorld) to.getWorld()).getHandle();
2023-03-14 17:30:00 +01:00
+
+ result = entity.teleportTo(worldserver, d0, d1, d2, set, f2, f3);
+ }
+
+ if (result) {
2020-06-25 02:00:00 +02:00
+ // CraftBukkit end
2023-03-14 17:30:00 +01:00
if (commandteleport_a != null) {
commandteleport_a.perform(commandlistenerwrapper, entity);
}