Search in sources :

Example 1 with EventHandler

use of org.bukkit.event.EventHandler in project Core by iConomy.

the class players method onPlayerJoin.

@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
    Accounts accounts = new Accounts();
    Player player = event.getPlayer();
    if (player != null)
        if (!accounts.exists(player.getName()))
            accounts.create(player.getName());
}
Also used : Player(org.bukkit.entity.Player) Accounts(com.iCo6.system.Accounts) EventHandler(org.bukkit.event.EventHandler)

Example 2 with EventHandler

use of org.bukkit.event.EventHandler in project HawkEye by oliverwoodings.

the class ToolListener method onBlockPlace.

@EventHandler(priority = EventPriority.HIGHEST)
public void onBlockPlace(BlockPlaceEvent event) {
    Player player = event.getPlayer();
    Block block = event.getBlock();
    if (BlockUtil.getBlockString(block).equals(Config.ToolBlock) && SessionManager.getSession(player).isUsingTool()) {
        ToolManager.toolSearch(player, block.getLocation());
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) EventHandler(org.bukkit.event.EventHandler)

Example 3 with EventHandler

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

the class PrismEntityEvents method onPotionSplashEvent.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPotionSplashEvent(final PotionSplashEvent event) {
    final ProjectileSource source = event.getPotion().getShooter();
    // Ignore from non-players for the time being
    if (!(source instanceof Player))
        return;
    final Player player = (Player) source;
    if (!Prism.getIgnore().event("potion-splash", player))
        return;
    // What type?
    // Right now this won't support anything with multiple effects
    final Collection<PotionEffect> potion = event.getPotion().getEffects();
    String name = "";
    for (final PotionEffect eff : potion) {
        name = eff.getType().getName().toLowerCase();
    }
    RecordingQueue.addToQueue(ActionFactory.createPlayer("potion-splash", player, name));
}
Also used : PotionEffect(org.bukkit.potion.PotionEffect) ProjectileSource(org.bukkit.projectiles.ProjectileSource) EventHandler(org.bukkit.event.EventHandler)

Example 4 with EventHandler

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

the class PrismEntityEvents method onEntityChangeBlock.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityChangeBlock(final EntityChangeBlockEvent event) {
    final String entity = MiscUtils.getEntityName(event.getEntity());
    // Technically I think that I really should name it "entity-eat" for
    // better consistency and
    // in case other mobs ever are made to eat. But that's not as fun
    Material to = event.getTo();
    Material from = event.getBlock().getType();
    if (from == Material.GRASS && to == Material.DIRT) {
        if (event.getEntityType() != EntityType.SHEEP)
            return;
        if (!Prism.getIgnore().event("sheep-eat", event.getBlock()))
            return;
        RecordingQueue.addToQueue(ActionFactory.createBlock("sheep-eat", event.getBlock(), entity));
    } else if (to == Material.AIR ^ from == Material.AIR && event.getEntity() instanceof Enderman) {
        if (from == Material.AIR) {
            if (!Prism.getIgnore().event("enderman-place", event.getBlock()))
                return;
            BlockState state = event.getBlock().getState();
            state.setType(to);
            RecordingQueue.addToQueue(ActionFactory.createBlock("enderman-place", state, entity));
        } else {
            if (!Prism.getIgnore().event("enderman-pickup", event.getBlock()))
                return;
            final Enderman enderman = (Enderman) event.getEntity();
            if (enderman.getCarriedMaterial() != null) {
                BlockState state = event.getBlock().getState();
                state.setData(enderman.getCarriedMaterial());
                RecordingQueue.addToQueue(ActionFactory.createBlock("enderman-pickup", state, entity));
            }
        }
    } else if (to == Material.AIR && event.getEntity() instanceof Wither) {
        if (!Prism.getIgnore().event("entity-break", event.getBlock()))
            return;
        RecordingQueue.addToQueue(ActionFactory.createBlock("block-break", event.getBlock(), event.getEntityType().getName()));
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Material(org.bukkit.Material) EventHandler(org.bukkit.event.EventHandler)

Example 5 with EventHandler

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

the class PrismInventoryEvents method onInventoryClick.

/**
     * Handle inventory transfers
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryClick(final InventoryClickEvent event) {
    if (!plugin.getConfig().getBoolean("prism.tracking.item-insert") && !plugin.getConfig().getBoolean("prism.tracking.item-remove"))
        return;
    Location containerLoc = null;
    // Store some info
    final Player player = (Player) event.getWhoClicked();
    final ItemStack currentitem = event.getCurrentItem();
    final ItemStack cursoritem = event.getCursor();
    // Get location
    if (event.getInventory().getHolder() instanceof BlockState) {
        final BlockState b = (BlockState) event.getInventory().getHolder();
        containerLoc = b.getLocation();
    } else if (event.getInventory().getHolder() instanceof Entity) {
        final Entity e = (Entity) event.getInventory().getHolder();
        containerLoc = e.getLocation();
    } else if (event.getInventory().getHolder() instanceof DoubleChest) {
        final DoubleChest chest = (DoubleChest) event.getInventory().getHolder();
        containerLoc = chest.getLocation();
    }
    // Double chests report 27 default size, though they actually
    // have 6 rows of 9 for 54 slots
    int defaultSize = event.getView().getType().getDefaultSize();
    if (event.getInventory().getHolder() instanceof DoubleChest) {
        defaultSize = event.getView().getType().getDefaultSize() * 2;
    }
    // slot count of the inventory. At that point, they represent the player inv.
    if (event.getSlot() == event.getRawSlot() && event.getRawSlot() <= defaultSize) {
        ItemStack addStack = null;
        ItemStack removeStack = null;
        if (currentitem != null && !currentitem.getType().equals(Material.AIR) && cursoritem != null && !cursoritem.getType().equals(Material.AIR)) {
            if (currentitem.isSimilar(cursoritem)) {
                // Items are similar enough to stack
                int amount = cursoritem.getAmount();
                if (event.isRightClick()) {
                    amount = 1;
                }
                int remaining = (currentitem.getMaxStackSize() - currentitem.getAmount());
                int inserted = (amount <= remaining) ? amount : remaining;
                if (inserted > 0) {
                    addStack = cursoritem.clone();
                    addStack.setAmount(inserted);
                }
            } else {
                // Items are not similar
                addStack = cursoritem.clone();
                removeStack = currentitem.clone();
            }
        } else if (currentitem != null && !currentitem.getType().equals(Material.AIR)) {
            removeStack = currentitem.clone();
        } else if (cursoritem != null && !cursoritem.getType().equals(Material.AIR)) {
            addStack = cursoritem.clone();
        }
        // Record events
        if (addStack != null) {
            recordInvAction(player, containerLoc, addStack, event.getRawSlot(), "item-insert", event);
        }
        if (removeStack != null) {
            recordInvAction(player, containerLoc, removeStack, event.getRawSlot(), "item-remove", event);
        }
        return;
    }
    if (event.isShiftClick() && cursoritem != null && cursoritem.getType().equals(Material.AIR)) {
        recordInvAction(player, containerLoc, currentitem, -1, "item-insert", event);
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) BlockState(org.bukkit.block.BlockState) ItemStack(org.bukkit.inventory.ItemStack) DoubleChest(org.bukkit.block.DoubleChest) Location(org.bukkit.Location) 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