summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityBoat.patch
blob: 8f6ab3b43d371c49c4996e0be7f67c27804a4e27 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
--- a/net/minecraft/server/EntityBoat.java
+++ b/net/minecraft/server/EntityBoat.java
@@ -3,6 +3,15 @@
 import java.util.List;
 import javax.annotation.Nullable;
 
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.entity.Vehicle;
+import org.bukkit.event.vehicle.VehicleDamageEvent;
+import org.bukkit.event.vehicle.VehicleDestroyEvent;
+import org.bukkit.event.vehicle.VehicleEntityCollisionEvent;
+import org.bukkit.event.vehicle.VehicleMoveEvent;
+// CraftBukkit end
+
 public class EntityBoat extends Entity {
 
     private static final DataWatcherObject<Integer> a = DataWatcher.a(EntityBoat.class, DataWatcherRegistry.b);
@@ -37,6 +46,14 @@
     private float aR;
     private float aS;
 
+    // CraftBukkit start
+    // PAIL: Some of these haven't worked since a few updates, and since 1.9 they are less and less applicable.
+    public double maxSpeed = 0.4D;
+    public double occupiedDeceleration = 0.2D;
+    public double unoccupiedDeceleration = -1;
+    public boolean landBoats = false;
+    // CraftBukkit end
+
     public EntityBoat(World world) {
         super(EntityTypes.BOAT, world);
         this.h = new float[2];
@@ -94,6 +111,19 @@
             if (damagesource instanceof EntityDamageSourceIndirect && damagesource.getEntity() != null && this.w(damagesource.getEntity())) {
                 return false;
             } else {
+                // CraftBukkit start
+                Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+                org.bukkit.entity.Entity attacker = (damagesource.getEntity() == null) ? null : damagesource.getEntity().getBukkitEntity();
+
+                VehicleDamageEvent event = new VehicleDamageEvent(vehicle, attacker, (double) f);
+                this.world.getServer().getPluginManager().callEvent(event);
+
+                if (event.isCancelled()) {
+                    return true;
+                }
+                // f = event.getDamage(); // TODO Why don't we do this?
+                // CraftBukkit end
+
                 this.c(-this.o());
                 this.b(10);
                 this.setDamage(this.m() + f * 10.0F);
@@ -101,6 +131,15 @@
                 boolean flag = damagesource.getEntity() instanceof EntityHuman && ((EntityHuman) damagesource.getEntity()).abilities.canInstantlyBuild;
 
                 if (flag || this.m() > 40.0F) {
+                    // CraftBukkit start
+                    VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, attacker);
+                    this.world.getServer().getPluginManager().callEvent(destroyEvent);
+
+                    if (destroyEvent.isCancelled()) {
+                        this.setDamage(40F); // Maximize damage so this doesn't get triggered again right away
+                        return true;
+                    }
+                    // CraftBukkit end
                     if (!flag && this.world.getGameRules().getBoolean("doEntityDrops")) {
                         this.a((IMaterial) this.f());
                     }
@@ -134,9 +173,25 @@
     public void collide(Entity entity) {
         if (entity instanceof EntityBoat) {
             if (entity.getBoundingBox().minY < this.getBoundingBox().maxY) {
+                // CraftBukkit start
+                VehicleEntityCollisionEvent event = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), entity.getBukkitEntity());
+                this.world.getServer().getPluginManager().callEvent(event);
+
+                if (event.isCancelled()) {
+                    return;
+                }
+                // CraftBukkit end
                 super.collide(entity);
             }
         } else if (entity.getBoundingBox().minY <= this.getBoundingBox().minY) {
+            // CraftBukkit start
+            VehicleEntityCollisionEvent event = new VehicleEntityCollisionEvent((Vehicle) this.getBukkitEntity(), entity.getBukkitEntity());
+            this.world.getServer().getPluginManager().callEvent(event);
+
+            if (event.isCancelled()) {
+                return;
+            }
+            // CraftBukkit end
             super.collide(entity);
         }
 
@@ -168,6 +223,7 @@
         return this.getDirection().e();
     }
 
+    private Location lastLocation; // CraftBukkit
     public void tick() {
         this.aM = this.aL;
         this.aL = this.s();
@@ -212,6 +268,22 @@
             this.motZ = 0.0D;
         }
 
+        // CraftBukkit start
+        org.bukkit.Server server = this.world.getServer();
+        org.bukkit.World bworld = this.world.getWorld();
+
+        Location to = new Location(bworld, this.locX, this.locY, this.locZ, this.yaw, this.pitch);
+        Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+
+        server.getPluginManager().callEvent(new org.bukkit.event.vehicle.VehicleUpdateEvent(vehicle));
+
+        if (lastLocation != null && !lastLocation.equals(to)) {
+            VehicleMoveEvent event = new VehicleMoveEvent(vehicle, lastLocation, to);
+            server.getPluginManager().callEvent(event);
+        }
+        lastLocation = vehicle.getLocation();
+        // CraftBukkit end
+
         this.q();
 
         for (int i = 0; i <= 1; ++i) {
@@ -730,6 +802,11 @@
 
                     this.c(this.fallDistance, 1.0F);
                     if (!this.world.isClientSide && !this.dead) {
+                    // CraftBukkit start
+                    Vehicle vehicle = (Vehicle) this.getBukkitEntity();
+                    VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, null);
+                    this.world.getServer().getPluginManager().callEvent(destroyEvent);
+                    if (!destroyEvent.isCancelled()) {
                         this.die();
                         if (this.world.getGameRules().getBoolean("doEntityDrops")) {
                             int i;
@@ -743,6 +820,7 @@
                             }
                         }
                     }
+                    } // CraftBukkit end
                 }
 
                 this.fallDistance = 0.0F;