Java Code Examples for org.bukkit.event.hanging.HangingPlaceEvent#isCancelled()

The following examples show how to use org.bukkit.event.hanging.HangingPlaceEvent#isCancelled() . 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: ProtectionHandler.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onPaintingPlace(HangingPlaceEvent event) {
    boolean setCancelled = event.isCancelled() ||
            shouldBlockAction(event.getBlock(), event.getPlayer(), "block_build");
    if (setCancelled) {
        event.setCancelled(true);
    }
    if (event.isCancelled() && event.getPlayer() != null) {
        event.getPlayer().sendMessage(Civs.getPrefix() +
                LocaleManager.getInstance().getTranslationWithPlaceholders(event.getPlayer(), LocaleConstants.REGION_PROTECTED));
    }
}
 
Example 2
Source File: ItemHanging.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean interactWith(ItemStack itemstack, EntityHuman entityhuman, World world, int i, int j, int k, int l, float f, float f1, float f2) {
	if (l == 0) {
		return false;
	}
	if (l == 1) {
		return false;
	}
	int i1 = Direction.e[l];
	EntityHanging entityhanging = a(world, i, j, k, i1);
	if (!entityhuman.a(i, j, k, l, itemstack)) {
		return false;
	}
	if ((entityhanging != null) && (entityhanging.survives())) {
		if (!world.isStatic) {
			Player who = entityhuman == null ? null : (Player) entityhuman.getBukkitEntity();
			Block blockClicked = world.getWorld().getBlockAt(i, j, k);
			BlockFace blockFace = CraftBlock.notchToBlockFace(l);

			HangingPlaceEvent event = new HangingPlaceEvent((Hanging) entityhanging.getBukkitEntity(), who, blockClicked, blockFace);
			world.getServer().getPluginManager().callEvent(event);

			PaintingPlaceEvent paintingEvent = null;
			if ((entityhanging instanceof EntityPainting)) {
				paintingEvent = new PaintingPlaceEvent((Painting) entityhanging.getBukkitEntity(), who, blockClicked, blockFace);
				paintingEvent.setCancelled(event.isCancelled());
				world.getServer().getPluginManager().callEvent(paintingEvent);
			}
			if ((event.isCancelled()) || ((paintingEvent != null) && (paintingEvent.isCancelled()))) {
				return false;
			}
			world.addEntity(entityhanging);
		}
		itemstack.count -= 1;
	}
	return true;
}