0
0
mirror of https://hub.spigotmc.org/stash/scm/spigot/craftbukkit.git synced 2024-11-25 16:16:14 +00:00
craftbukkit/nms-patches/net/minecraft/world/entity/vehicle/VehicleEntity.patch
2024-10-23 02:15:00 +11:00

65 lines
2.8 KiB
Diff

--- a/net/minecraft/world/entity/vehicle/VehicleEntity.java
+++ b/net/minecraft/world/entity/vehicle/VehicleEntity.java
@@ -17,6 +17,13 @@
import net.minecraft.world.level.World;
import net.minecraft.world.level.gameevent.GameEvent;
+// CraftBukkit start
+import org.bukkit.entity.Vehicle;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.vehicle.VehicleDamageEvent;
+import org.bukkit.event.vehicle.VehicleDestroyEvent;
+// CraftBukkit end
+
public abstract class VehicleEntity extends Entity {
protected static final DataWatcherObject<Integer> DATA_ID_HURT = DataWatcher.defineId(VehicleEntity.class, DataWatcherRegistry.INT);
@@ -40,6 +47,18 @@
return false;
} else {
boolean flag;
+ // 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.level().getCraftServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ return false;
+ }
+ f = (float) event.getDamage();
+ // CraftBukkit end
label32:
{
this.setHurtDir(-this.getHurtDir());
@@ -65,9 +84,27 @@
if ((flag1 || this.getDamage() <= 40.0F) && !this.shouldSourceDestroy(damagesource)) {
if (flag1) {
- this.discard();
+ // CraftBukkit start
+ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, attacker);
+ this.level().getCraftServer().getPluginManager().callEvent(destroyEvent);
+
+ if (destroyEvent.isCancelled()) {
+ this.setDamage(40.0F); // Maximize damage so this doesn't get triggered again right away
+ return true;
+ }
+ // CraftBukkit end
+ this.discard(EntityRemoveEvent.Cause.DEATH); // CraftBukkit - add Bukkit remove cause
}
} else {
+ // CraftBukkit start
+ VehicleDestroyEvent destroyEvent = new VehicleDestroyEvent(vehicle, attacker);
+ this.level().getCraftServer().getPluginManager().callEvent(destroyEvent);
+
+ if (destroyEvent.isCancelled()) {
+ this.setDamage(40.0F); // Maximize damage so this doesn't get triggered again right away
+ return true;
+ }
+ // CraftBukkit end
this.destroy(worldserver, damagesource);
}