org.bukkit.event.block.BlockDispenseEvent Java Examples
The following examples show how to use
org.bukkit.event.block.BlockDispenseEvent.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlockTransformListener.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventWrapper public void onDispenserDispense(final BlockDispenseEvent event) { if (Materials.isBucket(event.getItem())) { // Yes, the location the dispenser is facing is stored in "velocity" for some ungodly reason Block targetBlock = event.getVelocity().toLocation(event.getBlock().getWorld()).getBlock(); Material contents = Materials.materialInBucket(event.getItem()); if (Materials.isLiquid(contents) || (contents == Material.AIR && targetBlock.isLiquid())) { callEvent( event, targetBlock.getState(), BlockStates.cloneWithMaterial(targetBlock, contents), Trackers.getOwner(event.getBlock())); } } }
Example #2
Source File: IslandGuard.java From askyblock with GNU General Public License v2.0 | 6 votes |
/** * Prevents water from being dispensed in hell biomes * * @param e - event */ @EventHandler(priority = EventPriority.LOW) public void onNetherDispenser(final BlockDispenseEvent e) { if (DEBUG) { plugin.getLogger().info(e.getEventName()); } if (e.getBlock().getWorld().getEnvironment().equals(Environment.NETHER) || !inWorld(e.getBlock().getLocation()) || !e.getBlock().getBiome().equals(Biome.HELL)) { return; } // plugin.getLogger().info("DEBUG: Item being dispensed is " + // e.getItem().getType().toString()); if (e.getItem().getType().equals(Material.WATER_BUCKET)) { e.setCancelled(true); if (plugin.getServer().getVersion().contains("(MC: 1.8") || plugin.getServer().getVersion().contains("(MC: 1.7")) { e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.valueOf("FIZZ"), 1F, 2F); } else { e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.ENTITY_CREEPER_PRIMED, 1F, 2F); } } }
Example #3
Source File: DispenserListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onBlockDispensing(BlockDispenseEvent e) { Block b = e.getBlock(); if (b.getType() == Material.DISPENSER && b.getRelative(BlockFace.DOWN).getType() != Material.HOPPER) { SlimefunItem machine = BlockStorage.check(b); if (machine != null) { machine.callItemHandler(BlockDispenseHandler.class, handler -> { Dispenser dispenser = (Dispenser) b.getState(); BlockFace face = ((Directional) b.getBlockData()).getFacing(); Block block = b.getRelative(face); handler.onBlockDispense(e, dispenser, block, machine); }); } } }
Example #4
Source File: BlockListener.java From civcraft with GNU General Public License v2.0 | 6 votes |
@EventHandler(priority = EventPriority.NORMAL) public void onBlockDispenseEvent(BlockDispenseEvent event) { ItemStack stack = event.getItem(); if (stack != null) { if (event.getItem().getType().equals(Material.POTION)) { int effect = event.getItem().getDurability() & 0x000F; if (effect == 0xE) { event.setCancelled(true); return; } } if (event.getItem().getType().equals(Material.INK_SACK)) { //if (event.getItem().getDurability() == 15) { event.setCancelled(true); return; //} } } }
Example #5
Source File: BlockEventHandler.java From GriefDefender with MIT License | 6 votes |
@EventHandler(priority = EventPriority.LOWEST) public void onBlockDispense(BlockDispenseEvent event) { final Block block = event.getBlock(); final World world = event.getBlock().getWorld(); if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(world.getUID())) { return; } final Location location = block.getLocation(); final GDClaimManager claimWorldManager = GriefDefenderPlugin.getInstance().dataStore.getClaimWorldManager(world.getUID()); final GDChunk gpChunk = claimWorldManager.getChunk(block.getChunk()); final GDPermissionUser user = gpChunk.getBlockOwner(location); if (user != null) { final BlockFace face = NMSUtil.getInstance().getFacing(block); final Location faceLocation = BlockUtil.getInstance().getBlockRelative(location, face); final GDClaim targetClaim = this.storage.getClaimAt(faceLocation); final ItemStack activeItem = user != null && user.getOnlinePlayer() != null ? NMSUtil.getInstance().getActiveItem(user.getOnlinePlayer()) : null; final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, targetClaim, Flags.INTERACT_BLOCK_SECONDARY, activeItem, event.getBlock(), user, TrustTypes.BUILDER, true); if (result == Tristate.FALSE) { event.setCancelled(true); } else { GDCauseStackManager.getInstance().pushCause(user); } } }
Example #6
Source File: InventoryGui.java From InventoryGui with MIT License | 5 votes |
public void unregister() { InventoryClickEvent.getHandlerList().unregister(this); InventoryDragEvent.getHandlerList().unregister(this); InventoryCloseEvent.getHandlerList().unregister(this); InventoryMoveItemEvent.getHandlerList().unregister(this); BlockDispenseEvent.getHandlerList().unregister(this); BlockBreakEvent.getHandlerList().unregister(this); EntityDeathEvent.getHandlerList().unregister(this); }
Example #7
Source File: CustomItemListener.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
@EventHandler private void blockDispense(BlockDispenseEvent event) { if (event.getBlock().getType() != Material.DISPENSER) { return; } CustomItem customItem = CustomItemManager.getCustomItem(event.getItem()); if (customItem != null) { if (verifyCustomItem(customItem, event.getBlock().getWorld())) { customItem.onDispense(event, new DispenserDetails(event, customItem._owner)); } else { event.setCancelled(true); } } }
Example #8
Source File: BookOfSoulsCI.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
@Override public void onDispense(BlockDispenseEvent event, DispenserDetails details) { BookOfSouls bos = BookOfSouls.getFromBook(event.getItem()); if (bos != null) { bos.getEntityNBT().spawn(details.getLocation()); } event.setCancelled(true); }
Example #9
Source File: ItemModifyMatchModule.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler public void onArmorDispense(BlockDispenseEvent event) { // This covers armor being equipped by a dispenser, which does not call any of the other events ItemStack stack = event.getItem(); if (applyRules(stack)) { event.setItem(stack); } }
Example #10
Source File: CivilianListener.java From Civs with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onCivilianDispense(BlockDispenseEvent event) { ItemStack is = event.getItem(); if (!CVItem.isCivsItem(is)) { return; } CivItem civItem = CivItem.getFromItemStack(is); if (!civItem.isPlaceable()) { event.setCancelled(true); return; } }
Example #11
Source File: ItemModifyMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler public void onArmorDispense(BlockDispenseEvent event) { // This covers armor being equipped by a dispenser, which does not call any of the other events ItemStack stack = event.getItem(); if(applyRules(stack)) { event.setItem(stack); } }
Example #12
Source File: BlockTransformListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventWrapper public void onDispenserDispense(final BlockDispenseEvent event) { if(Materials.isBucket(event.getItem())) { // Yes, the location the dispenser is facing is stored in "velocity" for some ungodly reason Block targetBlock = event.getVelocity().toLocation(event.getBlock().getWorld()).getBlock(); Material contents = Materials.materialInBucket(event.getItem()); if(Materials.isLiquid(contents) || (contents == Material.AIR && targetBlock.isLiquid())) { callEvent(event, targetBlock.getState(), BlockStateUtils.cloneWithMaterial(targetBlock, contents), blockResolver.getOwner(event.getBlock())); } } }
Example #13
Source File: CoreMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void breakCheck(final BlockTransformEvent event) { if (event.getWorld() != this.match.getWorld()) return; ParticipantState player = ParticipantBlockTransformEvent.getPlayerState(event); Vector blockVector = BlockVectors.center(event.getNewState()).toVector(); for (Core core : this.cores) { if (!core.hasLeaked() && core.getCasingRegion().contains(blockVector)) { if (event.getNewState().getType() == Material.AIR) { if (player != null) { Competitor team = player.getParty(); if (team == core.getOwner()) { event.setCancelled(true, TranslatableComponent.of("core.damageOwn")); } else if (event.getOldState().getData().equals(core.getMaterial())) { this.match.callEvent(new CoreBlockBreakEvent(core, player, event.getOldState())); core.touch(player); // Note: team may not have touched a broken core if a different team broke it if (!core.isCompleted(team) && !core.hasTouched(team)) { this.match.callEvent(new GoalStatusChangeEvent(this.match, core)); } } } else if (event.getCause() instanceof EntityExplodeEvent) { // this is a temp fix until there is a tracker for placed minecarts (only dispensed are // tracked right now) if (((EntityExplodeEvent) event.getCause()).getEntity() instanceof ExplosiveMinecart) { event.setCancelled(true); } } else if (event.getCause() instanceof BlockPistonRetractEvent) { event.setCancelled(true); } } else if (event.getCause() instanceof BlockPistonExtendEvent) { event.setCancelled(true); } else if (event.getCause() instanceof BlockDispenseEvent) { event.setCancelled(true); } break; } } }
Example #14
Source File: CoreMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void breakCheck(final BlockTransformEvent event) { if(event.getWorld() != this.match.getWorld()) return; ParticipantState player = ParticipantBlockTransformEvent.getPlayerState(event); Vector blockVector = BlockUtils.center(event.getNewState()).toVector(); for(Core core : this.cores) { if(!core.hasLeaked() && core.getCasingRegion().contains(blockVector)) { if(event.getNewState().getType() == Material.AIR) { if(player != null) { Competitor team = player.getParty(); if(team == core.getOwner()) { event.setCancelled(true, new TranslatableComponent("match.core.damageOwn")); } else if (event.getOldState().getData().equals(core.getMaterial())) { this.match.getPluginManager().callEvent(new CoreBlockBreakEvent(core, player, event.getOldState())); core.touch(player); // Note: team may not have touched a broken core if a different team broke it if(!core.isCompleted(team) && !core.hasTouched(team)) { this.match.getPluginManager().callEvent(new GoalStatusChangeEvent(core)); } } } else if(event.getCause() instanceof EntityExplodeEvent) { // this is a temp fix until there is a tracker for placed minecarts (only dispensed are tracked right now) if(((EntityExplodeEvent) event.getCause()).getEntity() instanceof ExplosiveMinecart) { event.setCancelled(true); } } else if(event.getCause() instanceof BlockPistonRetractEvent) { event.setCancelled(true); } } else if(event.getCause() instanceof BlockPistonExtendEvent) { event.setCancelled(true); } else if(event.getCause() instanceof BlockDispenseEvent) { event.setCancelled(true); } break; } } }
Example #15
Source File: WorldFreeze.java From CardinalPGM with MIT License | 4 votes |
@EventHandler public void onBlockDispense(BlockDispenseEvent event) { if (!match.isRunning()) { event.setCancelled(true); } }
Example #16
Source File: CustomFirework.java From NBTEditor with GNU General Public License v3.0 | 4 votes |
@Override public void onDispense(BlockDispenseEvent event, DispenserDetails details) { event.setCancelled(true); }
Example #17
Source File: DispenserDetails.java From NBTEditor with GNU General Public License v3.0 | 4 votes |
DispenserDetails(BlockDispenseEvent event, Plugin plugin) { super(event.getItem()); _block = event.getBlock(); _plugin = plugin; }
Example #18
Source File: InventoryGui.java From InventoryGui with MIT License | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void onDispense(BlockDispenseEvent event) { if (hasRealOwner() && owner.equals(event.getBlock().getState())) { plugin.getServer().getScheduler().runTask(plugin, (Runnable) gui::draw); } }
Example #19
Source File: GenericBomb.java From NBTEditor with GNU General Public License v3.0 | 4 votes |
@Override public void onDispense(BlockDispenseEvent event, DispenserDetails details) { event.setCancelled(true); details.consumeItem(); trigger(createItem(details.getLocation(), event.getVelocity())); }
Example #20
Source File: TimeFirework.java From NBTEditor with GNU General Public License v3.0 | 4 votes |
@Override public void onDispense(BlockDispenseEvent event, DispenserDetails details) { event.setCancelled(true); details.consumeItem(); fire(details.getLocation(), details, null); }
Example #21
Source File: BlockDispenseHandler.java From Slimefun4 with GNU General Public License v3.0 | votes |
void onBlockDispense(BlockDispenseEvent e, Dispenser dispenser, Block facedBlock, SlimefunItem machine);
Example #22
Source File: CustomItem.java From NBTEditor with GNU General Public License v3.0 | votes |
public void onDispense(BlockDispenseEvent event, DispenserDetails details) { }