summaryrefslogtreecommitdiffstats
path: root/nms-patches/ItemChorusFruit.patch
blob: c05c10b56b15a34fdc3b4f456fa7ec6cbe2d31d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
--- a/net/minecraft/server/ItemChorusFruit.java
+++ b/net/minecraft/server/ItemChorusFruit.java
@@ -1,5 +1,11 @@
 package net.minecraft.server;
 
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerTeleportEvent;
+// CraftBukkit end
+
 public class ItemChorusFruit extends ItemFood {
 
     public ItemChorusFruit(int i, float f) {
@@ -19,6 +25,20 @@
                 double d4 = MathHelper.a(entityliving.locY + (double) (entityliving.getRandom().nextInt(16) - 8), 0.0D, (double) (world.ab() - 1));
                 double d5 = entityliving.locZ + (entityliving.getRandom().nextDouble() - 0.5D) * 16.0D;
 
+                // CraftBukkit start
+                if (entityliving instanceof EntityPlayer) {
+                    Player player = ((EntityPlayer) entityliving).getBukkitEntity();
+                    PlayerTeleportEvent teleEvent = new PlayerTeleportEvent(player, player.getLocation(), new Location(player.getWorld(), d3, d4, d5), PlayerTeleportEvent.TeleportCause.CHORUS_FRUIT);
+                    world.getServer().getPluginManager().callEvent(teleEvent);
+                    if (teleEvent.isCancelled()) {
+                        break;
+                    }
+                    d3 = teleEvent.getTo().getX();
+                    d4 = teleEvent.getTo().getY();
+                    d5 = teleEvent.getTo().getZ();
+                }
+                // CraftBukkit end
+
                 if (entityliving.isPassenger()) {
                     entityliving.stopRiding();
                 }