mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-10 12:02:36 +01:00
8398e12b34
By: md_5 <git@md-5.net>
62 lines
2.8 KiB
Diff
62 lines
2.8 KiB
Diff
--- a/net/minecraft/world/entity/vehicle/VehicleEntity.java
|
|
+++ b/net/minecraft/world/entity/vehicle/VehicleEntity.java
|
|
@@ -13,6 +13,12 @@
|
|
import net.minecraft.world.level.World;
|
|
import net.minecraft.world.level.gameevent.GameEvent;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.entity.Vehicle;
|
|
+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);
|
|
@@ -29,6 +35,18 @@
|
|
if (this.isInvulnerableTo(damagesource)) {
|
|
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.level().getCraftServer().getPluginManager().callEvent(event);
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ return false;
|
|
+ }
|
|
+ f = (float) event.getDamage();
|
|
+ // CraftBukkit end
|
|
this.setHurtDir(-this.getHurtDir());
|
|
this.setHurtTime(10);
|
|
this.markHurt();
|
|
@@ -38,9 +56,27 @@
|
|
|
|
if ((flag || this.getDamage() <= 40.0F) && !this.shouldSourceDestroy(damagesource)) {
|
|
if (flag) {
|
|
+ // 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();
|
|
}
|
|
} 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(damagesource);
|
|
}
|
|
|