use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.
the class ItemMergesScriptEvent method onItemMerges.
@EventHandler
public void onItemMerges(ItemMergeEvent event) {
Item entity = event.getEntity();
Item target = event.getTarget();
location = new dLocation(target.getLocation());
item = new dItem(entity.getItemStack());
this.entity = new dEntity(entity);
cancelled = event.isCancelled();
this.event = event;
fire();
event.setCancelled(cancelled);
}
use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.
the class ProjectileHitsScriptEvent method onProjectileHits.
@EventHandler
public void onProjectileHits(ProjectileHitEvent event) {
projectile = new dEntity(event.getEntity());
if (projectile.getLocation() == null) {
// No, I can't explain how or why this would ever happen... nonetheless, it appears it does happen sometimes.
return;
}
if (Double.isNaN(projectile.getLocation().getDirection().normalize().getX())) {
// I can't explain this one either. It also chooses to happen whenever it pleases.
return;
}
Block block = null;
try {
BlockIterator bi = new BlockIterator(projectile.getLocation().getWorld(), projectile.getLocation().toVector(), projectile.getLocation().getDirection().normalize(), 0, 4);
while (bi.hasNext()) {
block = bi.next();
if (block.getTypeId() != 0) {
break;
}
}
} catch (IllegalStateException ex) {
// As this error happens on no fault of the user, display no error message... just cancel the event.
return;
}
if (block == null) {
return;
}
material = dMaterial.getMaterialFrom(block.getType(), block.getData());
shooter = projectile.getShooter();
location = new dLocation(block.getLocation());
this.event = event;
fire();
}
use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.
the class ProjectileLaunchedScriptEvent method onProjectileLaunched.
@EventHandler
public void onProjectileLaunched(ProjectileLaunchEvent event) {
Entity projectile = event.getEntity();
dEntity.rememberEntity(projectile);
this.projectile = new dEntity(projectile);
location = new dLocation(event.getEntity().getLocation());
cancelled = event.isCancelled();
this.event = event;
fire();
dEntity.forgetEntity(projectile);
event.setCancelled(cancelled);
}
use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.
the class PlayerFillsBucketScriptEvent method onBucketFill.
@EventHandler
public void onBucketFill(PlayerBucketFillEvent event) {
entity = new dEntity(event.getPlayer());
location = new dLocation(event.getBlockClicked().getLocation());
item = new dItem(event.getItemStack());
material = dMaterial.getMaterialFrom(event.getBlockClicked().getType(), event.getBlockClicked().getData());
cancelled = event.isCancelled();
this.event = event;
fire();
event.setCancelled(cancelled);
}
use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.
the class PlayerItemTakesDamageScriptEvent method onPlayerItemTakesDamage.
@EventHandler
public void onPlayerItemTakesDamage(PlayerItemDamageEvent event) {
if (dEntity.isNPC(event.getPlayer())) {
return;
}
item = new dItem(event.getItem());
damage = new Element(event.getDamage());
location = new dLocation(event.getPlayer().getLocation());
cancelled = event.isCancelled();
this.event = event;
fire();
event.setCancelled(cancelled);
event.setDamage(damage.asInt());
final Player p = event.getPlayer();
if (cancelled) {
Bukkit.getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), new Runnable() {
@Override
public void run() {
p.updateInventory();
}
}, 1);
}
}
Aggregations