Java Code Examples for org.bukkit.event.block.BlockDispenseEvent#setCancelled()

The following examples show how to use org.bukkit.event.block.BlockDispenseEvent#setCancelled() . 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: BlockEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@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 2
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@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 3
Source File: IslandGuard.java    From askyblock with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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 4
Source File: CivilianListener.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@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 5
Source File: BookOfSoulsCI.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@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 6
Source File: CustomItemListener.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@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 7
Source File: WorldFreeze.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onBlockDispense(BlockDispenseEvent event) {
    if (!match.isRunning()) {
        event.setCancelled(true);
    }
}
 
Example 8
Source File: CustomFirework.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onDispense(BlockDispenseEvent event, DispenserDetails details) {
	event.setCancelled(true);
}
 
Example 9
Source File: GenericBomb.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onDispense(BlockDispenseEvent event, DispenserDetails details) {
	event.setCancelled(true);
	details.consumeItem();
	trigger(createItem(details.getLocation(), event.getVelocity()));
}
 
Example 10
Source File: TimeFirework.java    From NBTEditor with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onDispense(BlockDispenseEvent event, DispenserDetails details) {
	event.setCancelled(true);
	details.consumeItem();
	fire(details.getLocation(), details, null);
}