@Override public void consumeItem() { org.bukkit.block.Dispenser disp = (org.bukkit.block.Dispenser) _block.getState(); final Inventory inv = disp.getInventory(); Bukkit.getScheduler().runTask(_plugin, new Runnable() { @Override public void run() { for (int i = 0; i < inv.getSize(); ++i) { ItemStack item = inv.getItem(i); if (item != null && item.isSimilar(_item)) { if (item.getAmount() > 1) { item.setAmount(item.getAmount() - 1); } else { inv.clear(i); } return; } } } }); }
/** * Prevent a dispenser from placing liquid in a region that disables placement */ @EventHandler public void onBlockDispense(BlockDispenseEvent event) { Dispenser dispenser = (Dispenser)event.getBlock().getState().getData(); Block targetBlock = event.getBlock().getRelative(dispenser.getFacing()); if (event.getItem().getType() == Material.LAVA_BUCKET || event.getItem().getType() == Material.WATER_BUCKET) { CuboidRegion region = regionHandler.getApplicableRegion(targetBlock.getLocation()); if (region != null && !region.allows("build")) { event.setCancelled(true); } } }
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onDispense(BlockDispenseEvent dispenseEvent) { //don't track in worlds where claims are not enabled if(!GriefPrevention.instance.claimsEnabledForWorld(dispenseEvent.getBlock().getWorld())) return; //from where? Block fromBlock = dispenseEvent.getBlock(); Dispenser dispenser = new Dispenser(fromBlock.getType(), fromBlock.getData()); //to where? Block toBlock = fromBlock.getRelative(dispenser.getFacing()); Claim fromClaim = this.dataStore.getClaimAt(fromBlock.getLocation(), false, null); Claim toClaim = this.dataStore.getClaimAt(toBlock.getLocation(), false, fromClaim); //into wilderness is NOT OK in creative mode worlds Material materialDispensed = dispenseEvent.getItem().getType(); if((materialDispensed == Material.WATER_BUCKET || materialDispensed == Material.LAVA_BUCKET) && GriefPrevention.instance.creativeRulesApply(dispenseEvent.getBlock().getLocation()) && toClaim == null) { dispenseEvent.setCancelled(true); return; } //wilderness to wilderness is OK if(fromClaim == null && toClaim == null) return; //within claim is OK if(fromClaim == toClaim) return; //everything else is NOT OK dispenseEvent.setCancelled(true); }
/** * Prevents the tipping of liquids over the beacon using a dispenser * @param event */ @EventHandler(priority = EventPriority.LOW, ignoreCancelled=true) public void onDispense(final BlockDispenseEvent event) { if (DEBUG) getLogger().info("DEBUG: " + event.getEventName()); World world = event.getBlock().getWorld(); if (!world.equals(getBeaconzWorld())) { return; } if (DEBUG) getLogger().info("DEBUG: " + event.getItem().getType()); if (!event.getItem().getType().equals(Material.WATER_BUCKET) && !event.getItem().getType().equals(Material.LAVA_BUCKET)) { return; } if (DEBUG) getLogger().info("DEBUG: " + event.getBlock().getType()); if (!event.getBlock().getType().equals(Material.DISPENSER)) { return; } Dispenser dispenser = (Dispenser)event.getBlock().getState().getData(); Block b = event.getBlock().getRelative(dispenser.getFacing()); if (DEBUG) getLogger().info("DEBUG: " + b.getLocation()); if (getRegister().isAboveBeacon(b.getLocation())) { world.playSound(b.getLocation(), Sound.BLOCK_STONE_BREAK, 1F, 2F); event.setCancelled(true); } }
public Location getLocation() { if (_location == null) { BlockFace face = ((Dispenser) _block.getState().getData()).getFacing(); _location = _block.getLocation().add(UtilsMc.faceToDelta(face, 0.2)).add(0, -0.3, 0); } return _location; }
public Dispenser() { }
public Dispenser(BlockFace direction) { }
@Deprecated public Dispenser(int type) { }
public Dispenser(Material type) { }
@Deprecated public Dispenser(int type, byte data) { }
@Deprecated public Dispenser(Material type, byte data) { }
public Dispenser clone() { return null; }