Search in sources :

Example 96 with EventHandler

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);
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) Item(org.bukkit.entity.Item) net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) EventHandler(org.bukkit.event.EventHandler)

Example 97 with EventHandler

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();
}
Also used : BlockIterator(org.bukkit.util.BlockIterator) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Block(org.bukkit.block.Block) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) EventHandler(org.bukkit.event.EventHandler)

Example 98 with EventHandler

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);
}
Also used : Entity(org.bukkit.entity.Entity) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) EventHandler(org.bukkit.event.EventHandler)

Example 99 with EventHandler

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);
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) EventHandler(org.bukkit.event.EventHandler)

Example 100 with EventHandler

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);
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) EventHandler(org.bukkit.event.EventHandler)

Aggregations

EventHandler (org.bukkit.event.EventHandler)409 Player (org.bukkit.entity.Player)126 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)67 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)62 Entity (org.bukkit.entity.Entity)58 Block (org.bukkit.block.Block)47 Location (org.bukkit.Location)43 Element (net.aufdemrand.denizencore.objects.Element)38 ItemStack (org.bukkit.inventory.ItemStack)33 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)31 Minigame (au.com.mineauz.minigames.minigame.Minigame)29 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)29 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)28 LivingEntity (org.bukkit.entity.LivingEntity)24 Projectile (org.bukkit.entity.Projectile)19 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)18 FPlayer (me.totalfreedom.totalfreedommod.player.FPlayer)15 BlockState (org.bukkit.block.BlockState)15 User (com.earth2me.essentials.User)14 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)14