001 package org.bukkit.event.vehicle; 002 003 import org.bukkit.entity.Entity; 004 import org.bukkit.entity.Vehicle; 005 import org.bukkit.event.Cancellable; 006 import org.bukkit.event.HandlerList; 007 import org.bukkit.util.NumberConversions; 008 009 /** 010 * Raised when a vehicle receives damage. 011 */ 012 public class VehicleDamageEvent extends VehicleEvent implements Cancellable { 013 private static final HandlerList handlers = new HandlerList(); 014 private final Entity attacker; 015 private double damage; 016 private boolean cancelled; 017 018 @Deprecated 019 public VehicleDamageEvent(final Vehicle vehicle, final Entity attacker, final int damage) { 020 this(vehicle, attacker, (double) damage); 021 } 022 023 public VehicleDamageEvent(final Vehicle vehicle, final Entity attacker, final double damage) { 024 super(vehicle); 025 this.attacker = attacker; 026 this.damage = damage; 027 } 028 029 /** 030 * Gets the Entity that is attacking the vehicle 031 * 032 * @return the Entity that is attacking the vehicle 033 */ 034 public Entity getAttacker() { 035 return attacker; 036 } 037 038 /** 039 * Gets the damage done to the vehicle 040 * 041 * @return the damage done to the vehicle 042 */ 043 public double getDamage() { 044 return damage; 045 } 046 047 /** 048 * This method exists for legacy reasons to provide backwards 049 * compatibility. It will not exist at runtime and should not be used 050 * under any circumstances. 051 */ 052 @Deprecated 053 public int _INVALID_getDamage() { 054 return NumberConversions.ceil(getDamage()); 055 } 056 057 /** 058 * Sets the damage done to the vehicle 059 * 060 * @param damage The damage 061 */ 062 public void setDamage(double damage) { 063 this.damage = damage; 064 } 065 066 /** 067 * This method exists for legacy reasons to provide backwards 068 * compatibility. It will not exist at runtime and should not be used 069 * under any circumstances. 070 */ 071 @Deprecated 072 public void _INVALID_setDamage(int damage) { 073 setDamage(damage); 074 } 075 076 public boolean isCancelled() { 077 return cancelled; 078 } 079 080 public void setCancelled(boolean cancel) { 081 this.cancelled = cancel; 082 } 083 084 @Override 085 public HandlerList getHandlers() { 086 return handlers; 087 } 088 089 public static HandlerList getHandlerList() { 090 return handlers; 091 } 092 }