aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0140-Vehicle-Event-Cancellation-Changes.patch
blob: 93f035051ecc6d27909db7b01400ec34c794c212 (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
From 76ee96877676bceaed80df78b73f2a327b8573c6 Mon Sep 17 00:00:00 2001
From: Zach Brown <zach.brown@destroystokyo.com>
Date: Fri, 22 Apr 2016 18:20:05 -0500
Subject: [PATCH] Vehicle Event Cancellation Changes


diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index b2dc764..2374a35 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1658,6 +1658,10 @@ public abstract class Entity implements ICommandListener {
     }
 
     public boolean a(Entity entity, boolean flag) {
+        return this.mountEntity(entity, flag, false); // Paper - forward
+    }
+
+    public boolean mountEntity(Entity entity, boolean flag, boolean suppressEvents) { // Paper
         if (!flag && (!this.n(entity) || !entity.q(this))) {
             return false;
         } else {
@@ -1666,7 +1670,7 @@ public abstract class Entity implements ICommandListener {
             }
 
             this.at = entity;
-            this.at.o(this);
+            this.at.addRider(this, suppressEvents); // Paper
             return true;
         }
     }
@@ -1693,12 +1697,20 @@ public abstract class Entity implements ICommandListener {
     }
 
     protected void o(Entity entity) {
+        // Paper start - Forward
+        this.addRider(entity, false);
+    }
+
+    private void addRider(Entity entity, boolean suppressEvents) {
+        // Paper end
         if (entity.bz() != this) {
             throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)");
         } else {
             // CraftBukkit start
             com.google.common.base.Preconditions.checkState(!entity.passengers.contains(this), "Circular entity riding! %s %s", this, entity);
 
+            if (!suppressEvents) { // Paper - Make event calls suppressible
+            // =============================================================
             CraftEntity craft = (CraftEntity) entity.getBukkitEntity().getVehicle();
             Entity orig = craft == null ? null : craft.getHandle();
             if (getBukkitEntity() instanceof Vehicle && entity.getBukkitEntity() instanceof LivingEntity && entity.world.isChunkLoaded((int) entity.locX >> 4, (int) entity.locZ >> 4, false)) { // Boolean not used
@@ -1721,6 +1733,8 @@ public abstract class Entity implements ICommandListener {
                 return;
             }
             // Spigot end
+            // =============================================================
+            } // Paper - end suppressible block
             if (!this.world.isClientSide && entity instanceof EntityHuman && !(this.bu() instanceof EntityHuman)) {
                 this.passengers.add(0, entity);
             } else {
@@ -1746,16 +1760,29 @@ public abstract class Entity implements ICommandListener {
                 CraftEntity craftn = (CraftEntity) entity.getBukkitEntity().getVehicle();
                 Entity n = craftn == null ? null : craftn.getHandle();
                 if (event.isCancelled() || n != orig) {
+                    this.cancelDismount(entity); // Paper
                     return;
                 }
             }
             // CraftBukkit end
-            Bukkit.getPluginManager().callEvent( new org.spigotmc.event.entity.EntityDismountEvent(entity.getBukkitEntity(), this.getBukkitEntity())); // Spigot
+            // Paper start - make EntityDismountEvent cancellable
+            if (!new org.spigotmc.event.entity.EntityDismountEvent(entity.getBukkitEntity(), this.getBukkitEntity()).callEvent()) {
+                this.cancelDismount(entity);
+                return;
+            }
+            // Paper end
             this.passengers.remove(entity);
             entity.j = 60;
         }
     }
 
+    // Paper start
+    private void cancelDismount(Entity dismounter) {
+        this.passengers.remove(dismounter);
+        dismounter.mountEntity(this, false, true);
+    }
+    // Paper end
+
     protected boolean q(Entity entity) {
         return this.bv().size() < 1;
     }
-- 
2.8.2