2016-12-21 18:21:40 +01:00
|
|
|
From 6b61c540e2b3ce1833af6411ba1627ac98ab08d3 Mon Sep 17 00:00:00 2001
|
2016-04-23 00:01:28 +02:00
|
|
|
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
|
2016-12-21 18:21:40 +01:00
|
|
|
index ae6638d..3e20704 100644
|
2016-04-23 00:01:28 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
2016-12-21 18:21:40 +01:00
|
|
|
@@ -1803,6 +1803,10 @@ public abstract class Entity implements ICommandListener {
|
2016-11-17 03:23:38 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-23 00:01:28 +02:00
|
|
|
|
2016-06-09 05:57:14 +02:00
|
|
|
+ return this.mountEntity(entity, flag, false); // Paper - OBFHELPER
|
2016-04-23 00:01:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
2016-05-12 04:07:46 +02:00
|
|
|
+ public boolean mountEntity(Entity entity, boolean flag, boolean suppressEvents) { // Paper
|
2016-04-23 00:01:28 +02:00
|
|
|
if (!flag && (!this.n(entity) || !entity.q(this))) {
|
|
|
|
return false;
|
|
|
|
} else {
|
2016-12-21 18:21:40 +01:00
|
|
|
@@ -1811,7 +1815,7 @@ public abstract class Entity implements ICommandListener {
|
2016-04-23 00:01:28 +02:00
|
|
|
}
|
|
|
|
|
2016-06-09 05:57:14 +02:00
|
|
|
this.au = entity;
|
|
|
|
- this.au.o(this);
|
|
|
|
+ this.au.addRider(this, suppressEvents); // Paper
|
2016-04-23 00:01:28 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-12-21 18:21:40 +01:00
|
|
|
@@ -1838,12 +1842,20 @@ public abstract class Entity implements ICommandListener {
|
2016-04-23 00:01:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected void o(Entity entity) {
|
2016-06-09 05:57:14 +02:00
|
|
|
+ // Paper start - OBFHELPER
|
2016-04-23 00:01:28 +02:00
|
|
|
+ this.addRider(entity, false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void addRider(Entity entity, boolean suppressEvents) {
|
|
|
|
+ // Paper end
|
2016-06-09 05:57:14 +02:00
|
|
|
if (entity.bB() != this) {
|
2016-04-23 00:01:28 +02:00
|
|
|
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
|
2016-12-21 18:21:40 +01:00
|
|
|
@@ -1866,6 +1878,8 @@ public abstract class Entity implements ICommandListener {
|
2016-04-23 00:01:28 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Spigot end
|
|
|
|
+ // =============================================================
|
|
|
|
+ } // Paper - end suppressible block
|
2016-06-09 05:57:14 +02:00
|
|
|
if (!this.world.isClientSide && entity instanceof EntityHuman && !(this.bw() instanceof EntityHuman)) {
|
2016-04-23 00:01:28 +02:00
|
|
|
this.passengers.add(0, entity);
|
|
|
|
} else {
|
2016-12-21 18:21:40 +01:00
|
|
|
@@ -1891,16 +1905,29 @@ public abstract class Entity implements ICommandListener {
|
2016-04-23 00:01:28 +02:00
|
|
|
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);
|
2016-05-12 04:07:46 +02:00
|
|
|
+ dismounter.mountEntity(this, false, true);
|
2016-04-23 00:01:28 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
+
|
|
|
|
protected boolean q(Entity entity) {
|
2016-06-09 05:57:14 +02:00
|
|
|
return this.bx().size() < 1;
|
2016-04-23 00:01:28 +02:00
|
|
|
}
|
|
|
|
--
|
2016-12-11 00:50:31 +01:00
|
|
|
2.9.3
|
2016-04-23 00:01:28 +02:00
|
|
|
|