Skip to content

Commit

Permalink
add 'context.damage' to vehicle damaged event
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Feb 29, 2020
1 parent 7860a47 commit d65e0db
Showing 1 changed file with 5 additions and 4 deletions.
Expand Up @@ -32,6 +32,7 @@ public class VehicleDamagedScriptEvent extends BukkitScriptEvent implements List
// @Context
// <context.vehicle> returns the EntityTag of the vehicle.
// <context.entity> returns the EntityTag of the attacking entity.
// <context.damage> returns the amount of damage to be received.
//
// @Determine
// ElementTag(Decimal) to set the value of the damage received by the vehicle.
Expand All @@ -49,7 +50,6 @@ public VehicleDamagedScriptEvent() {
public static VehicleDamagedScriptEvent instance;
public EntityTag vehicle;
public EntityTag entity;
private double damage;
public VehicleDamageEvent event;

@Override
Expand Down Expand Up @@ -91,7 +91,7 @@ public String getName() {
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isDouble()) {
damage = ((ElementTag) determinationObj).asDouble();
event.setDamage(((ElementTag) determinationObj).asDouble());
return true;
}
return super.applyDetermination(path, determinationObj);
Expand All @@ -113,16 +113,17 @@ public ObjectTag getContext(String name) {
else if (name.equals("entity") && entity != null) {
return entity.getDenizenObject();
}
else if (name.equals("damage")) {
return new ElementTag(event.getDamage());
}
return super.getContext(name);
}

@EventHandler
public void onVehicleDestroyed(VehicleDamageEvent event) {
vehicle = new EntityTag(event.getVehicle());
entity = event.getAttacker() != null ? new EntityTag(event.getAttacker()) : null;
damage = event.getDamage();
this.event = event;
fire(event);
event.setDamage(damage);
}
}

0 comments on commit d65e0db

Please sign in to comment.