Search in sources :

Example 41 with BlockState

use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.

the class PrismMiscEvents method onPrismBlocksDrainEvent.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPrismBlocksDrainEvent(final PrismBlocksDrainEvent event) {
    // Get all block changes for this event
    final ArrayList<BlockStateChange> blockStateChanges = event.getBlockStateChanges();
    if (!blockStateChanges.isEmpty()) {
        // Create an entry for the rollback as a whole
        final Handler primaryAction = ActionFactory.createPrismProcess("prism-process", PrismProcessType.DRAIN, event.onBehalfOf(), "" + event.getRadius());
        final int id = RecordingTask.insertActionIntoDatabase(primaryAction);
        if (id == 0) {
            return;
        }
        for (final BlockStateChange stateChange : blockStateChanges) {
            final BlockState orig = stateChange.getOriginalBlock();
            final BlockState newBlock = stateChange.getNewBlock();
            // Build the action
            RecordingQueue.addToQueue(ActionFactory.createPrismRollback("prism-drain", orig, newBlock, event.onBehalfOf().getName(), id));
        }
    // ActionQueue.save();
    }
}
Also used : BlockStateChange(me.botsko.prism.events.BlockStateChange) BlockState(org.bukkit.block.BlockState) Handler(me.botsko.prism.actions.Handler) EventHandler(org.bukkit.event.EventHandler) EventHandler(org.bukkit.event.EventHandler)

Example 42 with BlockState

use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.

the class PrismBlockEvents method onBlockFade.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockFade(final BlockFadeEvent event) {
    if (!Prism.getIgnore().event("block-fade", event.getBlock()))
        return;
    final Block b = event.getBlock();
    if (b.getType().equals(Material.FIRE))
        return;
    final BlockState s = event.getNewState();
    RecordingQueue.addToQueue(ActionFactory.createBlockChange("block-fade", 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 43 with BlockState

use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.

the class PrismBlockEvents method onBlockSpread.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockSpread(final BlockSpreadEvent event) {
    // If fire, do we track fire spread? If not, do we track block-spread
    String type = "block-spread";
    if (event.getNewState().getType().equals(Material.FIRE)) {
        if (!Prism.getIgnore().event("fire-spread"))
            return;
        type = "fire-spread";
    } else {
        if (!Prism.getIgnore().event("block-spread", event.getBlock()))
            return;
    }
    final Block b = event.getBlock();
    final BlockState s = event.getNewState();
    RecordingQueue.addToQueue(ActionFactory.createBlockChange(type, 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 44 with BlockState

use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.

the class PrismEntityEvents method onEntityBlockForm.

/**
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEntityBlockForm(final EntityBlockFormEvent event) {
    if (!Prism.getIgnore().event("entity-form", event.getBlock()))
        return;
    final Block block = event.getBlock();
    final Location loc = block.getLocation();
    final BlockState newState = event.getNewState();
    final String entity = event.getEntity().getType().name().toLowerCase();
    RecordingQueue.addToQueue(ActionFactory.createBlockChange("entity-form", loc, block.getTypeId(), block.getData(), newState.getTypeId(), newState.getRawData(), entity));
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 45 with BlockState

use of org.bukkit.block.BlockState in project Prism-Bukkit by prism.

the class PrismInventoryEvents method onInventoryDrag.

/**
     * Handle inventory transfers
     * 
     * @param event
     */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryDrag(final InventoryDragEvent event) {
    if (!plugin.getConfig().getBoolean("prism.tracking.item-insert") && !plugin.getConfig().getBoolean("prism.tracking.item-remove"))
        return;
    // Get container
    final InventoryHolder ih = event.getInventory().getHolder();
    Location containerLoc = null;
    if (ih instanceof BlockState) {
        final BlockState eventChest = (BlockState) ih;
        containerLoc = eventChest.getLocation();
    }
    // Store some info
    final Player player = (Player) event.getWhoClicked();
    final Map<Integer, ItemStack> newItems = event.getNewItems();
    for (final Entry<Integer, ItemStack> entry : newItems.entrySet()) {
        recordInvAction(player, containerLoc, entry.getValue(), entry.getKey(), "item-insert");
    }
}
Also used : Player(org.bukkit.entity.Player) BlockState(org.bukkit.block.BlockState) ItemStack(org.bukkit.inventory.ItemStack) InventoryHolder(org.bukkit.inventory.InventoryHolder) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BlockState (org.bukkit.block.BlockState)62 Block (org.bukkit.block.Block)27 EventHandler (org.bukkit.event.EventHandler)16 Location (org.bukkit.Location)12 MaterialData (org.bukkit.material.MaterialData)12 BlockFace (org.bukkit.block.BlockFace)8 Material (org.bukkit.Material)7 World (org.bukkit.World)6 Player (org.bukkit.entity.Player)6 ArrayList (java.util.ArrayList)5 ItemStack (org.bukkit.inventory.ItemStack)5 BlockStateChange (me.botsko.prism.events.BlockStateChange)4 GlowBlockState (net.glowstone.block.GlowBlockState)4 CreatureSpawner (org.bukkit.block.CreatureSpawner)4 Sign (org.bukkit.block.Sign)4 Vector (org.bukkit.util.Vector)4 GlowBlock (net.glowstone.block.GlowBlock)3 TreeType (org.bukkit.TreeType)3 InventoryHolder (org.bukkit.inventory.InventoryHolder)3 HashMap (java.util.HashMap)2