Search in sources :

Example 16 with EventHandler

use of org.bukkit.event.EventHandler in project Prism-Bukkit by prism.

the class PrismBlockEvents method onBlockBurn.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBurn(final BlockBurnEvent event) {
    if (!Prism.getIgnore().event("block-burn", event.getBlock()))
        return;
    Block block = event.getBlock();
    RecordingQueue.addToQueue(ActionFactory.createBlock("block-burn", block, "Environment"));
    // Change handling a bit if it's a long block
    final Block sibling = me.botsko.elixr.BlockUtils.getSiblingForDoubleLengthBlock(block);
    if (sibling != null && !block.getType().equals(Material.CHEST) && !block.getType().equals(Material.TRAPPED_CHEST)) {
        block = sibling;
    }
    // check for block relationships
    logBlockRelationshipsForBlock("Environment", block);
}
Also used : Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 17 with EventHandler

use of org.bukkit.event.EventHandler in project Prism-Bukkit by prism.

the class PrismBlockEvents method onBlockForm.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockForm(final BlockFormEvent event) {
    if (!Prism.getIgnore().event("block-form", event.getBlock()))
        return;
    final Block b = event.getBlock();
    final BlockState s = event.getNewState();
    RecordingQueue.addToQueue(ActionFactory.createBlockChange("block-form", b.getLocation(), b.getTypeId(), b.getData(), s.getTypeId(), s.getRawData(), "Environment"));
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 18 with EventHandler

use of org.bukkit.event.EventHandler in project Prism-Bukkit by prism.

the class PrismBlockEvents method onBlockFromTo.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFromTo(final BlockFromToEvent event) {
    // Ignore blocks that aren't liquid. @todo what else triggers this?
    if (!event.getBlock().isLiquid())
        return;
    final BlockState from = event.getBlock().getState();
    final BlockState to = event.getToBlock().getState();
    // Watch for blocks that the liquid can break
    if (me.botsko.elixr.BlockUtils.canFlowBreakMaterial(to.getType())) {
        if (from.getType() == Material.STATIONARY_WATER || from.getType() == Material.WATER) {
            if (Prism.getIgnore().event("water-break", event.getBlock())) {
                RecordingQueue.addToQueue(ActionFactory.createBlock("water-break", event.getToBlock(), "Water"));
            }
        } else if (from.getType() == Material.STATIONARY_LAVA || from.getType() == Material.LAVA) {
            if (Prism.getIgnore().event("lava-break", event.getBlock())) {
                RecordingQueue.addToQueue(ActionFactory.createBlock("lava-break", event.getToBlock(), "Lava"));
            }
        }
    }
    // Record water flow
    if (from.getType() == Material.STATIONARY_WATER || from.getType() == Material.WATER) {
        if (Prism.getIgnore().event("water-flow", event.getBlock())) {
            RecordingQueue.addToQueue(ActionFactory.createBlock("water-flow", event.getBlock(), "Water"));
        }
    }
    // Record lava flow
    if (from.getType() == Material.STATIONARY_LAVA || from.getType() == Material.LAVA) {
        if (Prism.getIgnore().event("lava-flow", event.getBlock())) {
            RecordingQueue.addToQueue(ActionFactory.createBlock("lava-flow", event.getBlock(), "Lava"));
        }
    }
    /**
         * Predict the forming of Stone, Obsidian, Cobblestone because of
         * lava/water flowing into each other. Boy, I wish bukkit used
         * block_form for this.
         */
    if (!Prism.getIgnore().event("block-form", event.getBlock()))
        return;
    // Lava flows to water. STONE forms
    if (from.getType().equals(Material.STATIONARY_LAVA) && to.getType().equals(Material.STATIONARY_WATER)) {
        final Block newTo = event.getToBlock();
        newTo.setType(Material.STONE);
        RecordingQueue.addToQueue(ActionFactory.createBlock("block-form", newTo, "Environment"));
    }
// // int id = event.getBlock().getTypeId();
//
// // If moving to air
// Block b = event.getToBlock();
// if(b.getType().equals(Material.AIR)){
//
// // formed sat/lava = cobble
// // formed stationary_water = stone
//
// // Are we moving from a water block
// Material fromM = event.getBlock().getType();
// if(fromM.equals(Material.WATER) ||
// fromM.equals(Material.STATIONARY_WATER)){
// // Check all sides
// for(BlockFace face : BlockFace.values()){
// Block r = b.getRelative(face, 1);
// // If the side is lava, cobble shall form.
// // Note: if stationary_lava, stone will form. Seems to always be
// captured above.
// if(r.getType().equals(Material.LAVA) ||
// r.getType().equals(Material.STATIONARY_LAVA)){
// String coordsKey = r.getX()+":"+r.getY()+":"+r.getZ();
// if(coordsUsed.contains(coordsKey)) continue;
// coordsUsed.add(coordsKey);
// Prism.debug("COBBLE FORMED " + r.getType().name());
// // r.setType(Material.COBBLESTONE);
// plugin.actionsRecorder.addToQueue( new
// BlockAction(ActionType.BLOCK_FORM, r, "Environment") );
// }
// }
// }
// }
//
//
// // Water flowing into lava forms obsidian or cobble
// if ( from.getType().equals(Material.STATIONARY_WATER) &&
// to.getType().equals(Material.STATIONARY_LAVA) ) {
// Prism.debug("FROM WATER to " + to.getType().name());
// BlockState lower =
// event.getToBlock().getRelative(BlockFace.DOWN).getState();
// // Obsidian can form below
// if( lower.getType().equals(Material.OBSIDIAN) ){
// String coordsKey = lower.getX()+":"+lower.getY()+":"+lower.getZ();
// if(coordsUsed.contains(coordsKey)) return;
// // Add coords to list the event has already fired for
// coordsUsed.add(coordsKey);
// Prism.debug("COBBLE/OBY FORMED BELOW " + coordsKey);
// plugin.actionsRecorder.addToQueue( new
// BlockAction(ActionType.BLOCK_FORM, lower.getBlock(), "Environment")
// );
// }
//
// }
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 19 with EventHandler

use of org.bukkit.event.EventHandler in project Prism-Bukkit by prism.

the class PrismBlockEvents method onBlockPlace.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(final BlockPlaceEvent event) {
    final Player player = event.getPlayer();
    final Block block = event.getBlock();
    if (!Prism.getIgnore().event("block-place", player))
        return;
    if (block.getType().equals(Material.AIR))
        return;
    final BlockState s = event.getBlockReplacedState();
    RecordingQueue.addToQueue(ActionFactory.createBlockChange("block-place", block.getLocation(), s.getTypeId(), s.getRawData(), block.getTypeId(), block.getData(), player.getName()));
    // Pass to the placement alerter
    if (!player.hasPermission("prism.alerts.use.place.ignore") && !player.hasPermission("prism.alerts.ignore")) {
        plugin.useMonitor.alertOnBlockPlacement(player, block);
    }
}
Also used : Player(org.bukkit.entity.Player) BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 20 with EventHandler

use of org.bukkit.event.EventHandler in project AuthMeReloaded by AuthMe.

the class EntityListener method onProjectileLaunch.

@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onProjectileLaunch(ProjectileLaunchEvent event) {
    if (event.getEntity() == null) {
        return;
    }
    Projectile projectile = event.getEntity();
    // In the Bukkit API prior to 1.7, getShooter() returns a LivingEntity instead of a ProjectileSource
    Object shooterRaw = null;
    if (shooterIsLivingEntity) {
        try {
            if (getShooter == null) {
                getShooter = Projectile.class.getMethod("getShooter");
            }
            shooterRaw = getShooter.invoke(projectile);
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            ConsoleLogger.logException("Error getting shooter", e);
        }
    } else {
        shooterRaw = projectile.getShooter();
    }
    if (shooterRaw instanceof Player && listenerService.shouldCancelEvent((Player) shooterRaw)) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) InvocationTargetException(java.lang.reflect.InvocationTargetException) Projectile(org.bukkit.entity.Projectile) 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