Vehicle Dismount Event Improvements
player.getVehicle() was returning null during the event. Paper had added lots of code to cause the player to remount the entity on cancel. I've simplified the diff and made player.getVehicle() work during the event by setting the vehicle back during the event, and only set it to null if the event is not cancelled.
This commit is contained in:
@@ -5,88 +5,39 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
index ae6638d39..0818ff854 100644
|
||||
--- a/src/main/java/net/minecraft/server/Entity.java
|
||||
+++ b/src/main/java/net/minecraft/server/Entity.java
|
||||
@@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener {
|
||||
}
|
||||
}
|
||||
|
||||
+ return this.mountEntity(entity, flag, false); // Paper - OBFHELPER
|
||||
+ }
|
||||
+
|
||||
+ public boolean mountEntity(Entity entity, boolean flag, boolean suppressEvents) { // Paper
|
||||
if (!flag && (!this.n(entity) || !entity.q(this))) {
|
||||
return false;
|
||||
} else {
|
||||
public boolean i;
|
||||
public final List<Entity> passengers;
|
||||
protected int j;
|
||||
- private Entity au;
|
||||
+ private Entity au;public void setVehicle(Entity entity) { this.au = entity; } // Paper // OBFHELPER
|
||||
public boolean attachedToPlayer;
|
||||
public World world;
|
||||
public double lastX;
|
||||
@@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener {
|
||||
}
|
||||
|
||||
this.au = entity;
|
||||
- this.au.o(this);
|
||||
+ this.au.addRider(this, suppressEvents); // Paper
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener {
|
||||
}
|
||||
|
||||
protected void o(Entity entity) {
|
||||
+ // Paper start - OBFHELPER
|
||||
+ this.addRider(entity, false);
|
||||
+ }
|
||||
+
|
||||
+ private void addRider(Entity entity, boolean suppressEvents) {
|
||||
+ // Paper end
|
||||
if (entity.bB() != this) {
|
||||
throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)");
|
||||
throw new IllegalStateException("Use x.stopRiding(y), not y.removePassenger(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
|
||||
+ // =============================================================
|
||||
+ entity.setVehicle(this); // Paper - Set the vehicle back for the event
|
||||
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
|
||||
if (getBukkitEntity() instanceof Vehicle && entity.getBukkitEntity() instanceof LivingEntity) {
|
||||
@@ -0,0 +0,0 @@ public abstract class Entity implements ICommandListener {
|
||||
return;
|
||||
}
|
||||
// Spigot end
|
||||
+ // =============================================================
|
||||
+ } // Paper - end suppressible block
|
||||
if (!this.world.isClientSide && entity instanceof EntityHuman && !(this.bw() instanceof EntityHuman)) {
|
||||
this.passengers.add(0, entity);
|
||||
} else {
|
||||
@@ -0,0 +0,0 @@ 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;
|
||||
+ }
|
||||
+ entity.setVehicle(null);
|
||||
+ // 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.bx().size() < 1;
|
||||
}
|
||||
--
|
||||
Reference in New Issue
Block a user