Search in sources :

Example 66 with EventHandler

use of org.bukkit.event.EventHandler in project Minigames by AddstarMC.

the class RegionEvents method itemPickupEvent.

@EventHandler(ignoreCancelled = true)
private void itemPickupEvent(PlayerPickupItemEvent event) {
    final MinigamePlayer ply = pdata.getMinigamePlayer(event.getPlayer());
    if (ply == null)
        return;
    if (ply.isInMinigame()) {
        final Trigger trig = Triggers.getTrigger("ITEM_PICKUP");
        Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

            @Override
            public void run() {
                if (!ply.isInMinigame()) {
                    return;
                }
                for (Node node : getRegionModule(ply.getMinigame()).getNodes()) {
                    node.execute(trig, ply);
                }
                for (Region region : getRegionModule(ply.getMinigame()).getRegions()) {
                    if (region.hasPlayer(ply)) {
                        region.execute(trig, ply);
                    }
                }
            }
        });
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) Trigger(au.com.mineauz.minigamesregions.triggers.Trigger) EventHandler(org.bukkit.event.EventHandler)

Example 67 with EventHandler

use of org.bukkit.event.EventHandler in project Minigames by AddstarMC.

the class RegionEvents method playerJoin.

@EventHandler(ignoreCancelled = true)
private void playerJoin(JoinMinigameEvent event) {
    final MinigamePlayer ply = event.getMinigamePlayer();
    if (ply == null)
        return;
    final Minigame mg = event.getMinigame();
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

        @Override
        public void run() {
            executeRegionChanges(mg, ply);
            for (Node node : RegionModule.getMinigameModule(mg).getNodes()) {
                node.execute(Triggers.getTrigger("GAME_JOIN"), ply);
            }
            for (Region region : RegionModule.getMinigameModule(mg).getRegions()) {
                if (region.hasPlayer(ply))
                    region.execute(Triggers.getTrigger("GAME_JOIN"), ply);
            }
        }
    });
    if (event.getMinigame().getPlayers().size() == 0) {
        for (Region region : RegionModule.getMinigameModule(event.getMinigame()).getRegions()) {
            for (RegionExecutor ex : region.getExecutors()) {
                if (ex.getTrigger().getName().equalsIgnoreCase("TICK")) {
                    region.startTickTask();
                    break;
                }
            }
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) RegionExecutor(au.com.mineauz.minigamesregions.executors.RegionExecutor) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Example 68 with EventHandler

use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.

the class NPCTags method navBegin.

// <--[event]
// @Events
// npc begins navigation
//
// @Warning This event may fire very rapidly.
//
// @Triggers when an NPC begins navigating.
//
// @Context
// None
//
// -->
// <--[action]
// @Actions
// begin navigation
//
// @Triggers when the NPC has received a 'walk' command,
// or is about to follow a path.
//
// @Context
// None
//
// -->
@EventHandler
public void navBegin(NavigationBeginEvent event) {
    dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());
    // Do world script event 'On NPC Completes Navigation'
    if (NPCNavigationSmartEvent.IsActive()) {
        OldEventManager.doEvents(Arrays.asList("npc begins navigation"), new BukkitScriptEntryData(null, npc), null);
    }
    if (!event.getNPC().hasTrait(AssignmentTrait.class)) {
        return;
    }
    npc.action("begin navigation", null);
    if (event.getNPC().getNavigator().getTargetType() == TargetType.ENTITY) {
        LivingEntity entity = (LivingEntity) event.getNPC().getNavigator().getEntityTarget().getTarget();
        // and that entity is not dead, trigger "on attack" command
        if (event.getNPC().getNavigator().getEntityTarget().isAggressive() && !entity.isDead()) {
            dPlayer player = null;
            // Check if the entity attacked by this NPC is a player
            if (entity instanceof Player) {
                player = dPlayer.mirrorBukkitPlayer((Player) entity);
            }
            // <--[action]
            // @Actions
            // attack
            // attack on <entity>
            //
            // @Triggers when the NPC is about to attack an enemy.
            //
            // @Context
            // None
            //
            // -->
            npc.action("attack", player);
            npc.action("attack on " + entity.getType().toString(), player);
        }
        previousLocations.put(event.getNPC().getId(), npc.getLocation());
    }
}
Also used : AssignmentTrait(net.aufdemrand.denizen.npc.traits.AssignmentTrait) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 69 with EventHandler

use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.

the class NPCTags method navComplete.

// <--[event]
// @Events
// npc completes navigation
//
// @Warning This event may fire very rapidly.
//
// @Triggers when an NPC finishes navigating.
//
// @Context
// None
//
// -->
// <--[action]
// @Actions
// complete navigation
//
// @Triggers when the NPC has finished a 'walk' command,
// or has reached a path point.
//
// @Context
// None
//
// -->
@EventHandler
public void navComplete(NavigationCompleteEvent event) {
    dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());
    // Do world script event 'On NPC Completes Navigation'
    if (NPCNavigationSmartEvent.IsActive()) {
        OldEventManager.doEvents(Arrays.asList("npc completes navigation"), new BukkitScriptEntryData(null, npc), null);
    }
    // Do the assignment script action
    if (!event.getNPC().hasTrait(AssignmentTrait.class)) {
        return;
    }
    npc.action("complete navigation", null);
}
Also used : AssignmentTrait(net.aufdemrand.denizen.npc.traits.AssignmentTrait) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) EventHandler(org.bukkit.event.EventHandler)

Example 70 with EventHandler

use of org.bukkit.event.EventHandler in project Denizen-For-Bukkit by DenizenScript.

the class BlockBurnsScriptEvent method onBlockBurns.

@EventHandler
public void onBlockBurns(BlockBurnEvent event) {
    location = new dLocation(event.getBlock().getLocation());
    material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
    cancelled = event.isCancelled();
    this.event = event;
    fire();
    event.setCancelled(cancelled);
}
Also used : net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) EventHandler(org.bukkit.event.EventHandler)

Aggregations

EventHandler (org.bukkit.event.EventHandler)532 Player (org.bukkit.entity.Player)185 Entity (org.bukkit.entity.Entity)70 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)67 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)62 Block (org.bukkit.block.Block)62 ItemStack (org.bukkit.inventory.ItemStack)55 Location (org.bukkit.Location)54 Island (com.wasteofplastic.acidisland.Island)42 Element (net.aufdemrand.denizencore.objects.Element)38 LivingEntity (org.bukkit.entity.LivingEntity)37 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 Projectile (org.bukkit.entity.Projectile)26 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)23 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)22 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)18 ArrayList (java.util.ArrayList)18