Skip to content

Commit

Permalink
[Bleeding] Added EntityShootBowEvent. Thanks Zeerix.
Browse files Browse the repository at this point in the history
  • Loading branch information
grum committed Jan 17, 2012
1 parent 4d7a141 commit d57776f
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/org/bukkit/event/Event.java
Expand Up @@ -793,6 +793,12 @@ public enum Type {
* @see org.bukkit.event.entity.EntityCreatePortalEvent
*/
ENTITY_CREATE_PORTAL(Category.LIVING_ENTITY, EntityCreatePortalEvent.class),
/**
* Called when a LivingEntity shoots a bow firing an arrow
*
* @see org.bukkit.event.entity.EntityShootBowEvent
*/
ENTITY_SHOOT_BOW(Category.LIVING_ENTITY, EntityShootBowEvent.class),

/**
* WEATHER EVENTS
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/bukkit/event/entity/EntityListener.java
Expand Up @@ -157,6 +157,13 @@ public void onEndermanPlace(EndermanPlaceEvent event) {}
*/
public void onFoodLevelChange(FoodLevelChangeEvent event) {}

/**
* Called when a LivingEntity shoots a bow firing an arrow
*
* @param event Relevant event details
*/
public void onEntityShootBow(EntityShootBowEvent event) {}

/**
* Called when a Slime splits into smaller Slimes upon death
*
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/org/bukkit/event/entity/EntityShootBowEvent.java
@@ -0,0 +1,81 @@
package org.bukkit.event.entity;

import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Projectile;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;

/**
* Called when a LivingEntity shoots a bow firing an arrow
*/
@SuppressWarnings("serial")
public class EntityShootBowEvent extends EntityEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();

private ItemStack bow;
private Entity projectile;
private float force;
private boolean cancelled;

public EntityShootBowEvent(LivingEntity shooter, ItemStack bow, Projectile projectile, float force) {
super(Type.ENTITY_SHOOT_BOW, shooter);
this.bow = bow;
this.projectile = projectile;
this.force = force;
}

/**
* Gets the bow ItemStack used to fire the arrow; is null if the shooter is a skeleton
*
* @return the bow involved in this event, or null
*/
public ItemStack getBow() {
return bow;
}

/**
* Gets the projectile which will be launched by this event
*
* @return the launched projectile
*/
public Entity getProjectile() {
return projectile;
}

/**
* Replaces the projectile which will be launched
*
* @param projectile the new projectile
*/
public void setProjectile(Entity projectile) {
this.projectile = projectile;
}

/**
* Gets the force the arrow was launched with
*
* @return bow shooting force, up to 1.0
*/
public float getForce() {
return force;
}

public boolean isCancelled() {
return cancelled;
}

public void setCancelled(boolean cancel) {
cancelled = cancel;
}

@Override
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}
}

1 comment on commit d57776f

@feildmaster
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing

 return new EventExecutor() {
  public void execute(Listener listener, Event event) {
   ((EntityListener) listener).onEntityShootBow((EntityShootBowEvent) event);
  }
 };

in JavaPluginLoader. Otherwise there was no need to add it to PlayerListener.

Please sign in to comment.