Java Code Examples for org.bukkit.event.player.PlayerItemConsumeEvent#setCancelled()

The following examples show how to use org.bukkit.event.player.PlayerItemConsumeEvent#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: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerConsumeItem(PlayerItemConsumeEvent event) {
    final Player player = event.getPlayer();
    final ItemStack itemInUse = event.getItem();
    GDCauseStackManager.getInstance().pushCause(player);
    if (!GDFlags.ITEM_USE || !GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUID())) {
        return;
    }
    if (GriefDefenderPlugin.isTargetIdBlacklisted(Flags.ITEM_USE.toString(), itemInUse, player.getWorld().getUID())) {
        return;
    }

    GDTimings.PLAYER_USE_ITEM_EVENT.startTiming();
    Location location = player.getLocation();
    GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(location.getWorld(), player.getUniqueId());
    GDClaim claim = this.dataStore.getClaimAtPlayer(playerData, location);

    final Tristate result = GDPermissionManager.getInstance().getFinalPermission(event, location, claim, Flags.ITEM_USE, player, itemInUse, player, TrustTypes.ACCESSOR, true);
    if (result == Tristate.FALSE) {
        final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.PERMISSION_ITEM_USE,
                ImmutableMap.of("item", ItemTypeRegistryModule.getInstance().getNMSKey(itemInUse)));
        GriefDefenderPlugin.sendClaimDenyMessage(claim, player,  message);
        event.setCancelled(true);
    }
    GDTimings.PLAYER_USE_ITEM_EVENT.stopTiming();
}
 
Example 2
Source File: AutoEat.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler
public void onConsume(PlayerItemConsumeEvent event)
{
    final User user = UserManager.getUser(event.getPlayer().getUniqueId());

    // Not bypassed
    if (User.isUserInvalid(user, this.getModuleType())) {
        return;
    }

    // After half a second check if it was the last interaction ticks check if this
    Bukkit.getScheduler().runTaskLater(AACAdditionPro.getInstance(), () -> {
        if (user.getTimestampMap().getTimeStamp(TimestampKey.LAST_RIGHT_CLICK_CONSUMABLE_ITEM_EVENT) < user.getTimestampMap().getTimeStamp(TimestampKey.LAST_CONSUME_EVENT)) {
            vlManager.flag(user.getPlayer(), cancelVl, () -> user.getTimestampMap().updateTimeStamp(TimestampKey.AUTOEAT_TIMEOUT), () -> {});
        }
    }, 10);

    if (user.getTimestampMap().recentlyUpdated(TimestampKey.AUTOEAT_TIMEOUT, timeout)) {
        event.setCancelled(true);
    }
}
 
Example 3
Source File: Compat19.java    From RedProtect with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onConsume(PlayerItemConsumeEvent e) {
    if (e.getItem() == null) {
        return;
    }

    Player p = e.getPlayer();
    //deny potion
    if (p == null) {
        return;
    }

    Region r = RedProtect.get().rm.getTopRegion(p.getLocation());
    if (r != null && e.getItem().getType().equals(Material.CHORUS_FRUIT) && !r.canTeleport(p)) {
        RedProtect.get().lang.sendMessage(p, "playerlistener.region.cantuse");
        e.setCancelled(true);
    }
}
 
Example 4
Source File: PlayerListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOW) 
public void onConsume(PlayerItemConsumeEvent event) {
	if (ItemManager.getId(event.getItem()) == CivData.GOLDEN_APPLE) {
		CivMessage.sendError(event.getPlayer(), "You cannot use golden apples.");
		event.setCancelled(true);
		return;
	}
	
	if (event.getItem().getType().equals(Material.POTION)) {
		ConfigTechPotion pot = CivSettings.techPotions.get(Integer.valueOf(event.getItem().getDurability()));
		if (pot != null) {
			if (!pot.hasTechnology(event.getPlayer())) {
				CivMessage.sendError(event.getPlayer(), "You cannot use "+pot.name+" potions. You do not have the technology yet.");
				event.setCancelled(true);
				return;
			}
			if (pot.hasTechnology(event.getPlayer())) {
				event.setCancelled(false);
			}
		} else {
			CivMessage.sendError(event.getPlayer(), "You cannot use this type of potion.");
			event.setCancelled(true);
		}
	}
}
 
Example 5
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void OnPlayerConsumeEvent(PlayerItemConsumeEvent event) {
	ItemStack stack = event.getItem();

	/* Disable notch apples */
	if (ItemManager.getId(event.getItem()) == ItemManager.getId(Material.GOLDEN_APPLE)) {
		if (event.getItem().getDurability() == (short)0x1) {
			CivMessage.sendError(event.getPlayer(), "You cannot use notch apples. Sorry.");
			event.setCancelled(true);
			return;
		}
	}	

	if (stack.getType().equals(Material.POTION)) {
		int effect = event.getItem().getDurability() & 0x000F;			
		if (effect == 0xE) {
			event.setCancelled(true);
			CivMessage.sendError(event.getPlayer(), "You cannot use invisibility potions for now... Sorry.");
			return;
		}
	}
}
 
Example 6
Source File: SlimefunItemConsumeListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onConsume(PlayerItemConsumeEvent e) {
    Player p = e.getPlayer();
    ItemStack item = e.getItem();
    SlimefunItem sfItem = SlimefunItem.getByItem(item);

    if (sfItem != null) {
        if (Slimefun.hasUnlocked(p, sfItem, true)) {
            if (sfItem instanceof Juice) {
                // Fix for Saturation on potions is no longer working

                for (PotionEffect effect : ((PotionMeta) item.getItemMeta()).getCustomEffects()) {
                    if (effect.getType().equals(PotionEffectType.SATURATION)) {
                        p.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, effect.getDuration(), effect.getAmplifier()));
                        break;
                    }
                }

                removeGlassBottle(p, item);
            }
            else {
                sfItem.callItemHandler(ItemConsumptionHandler.class, handler -> handler.onConsume(e, p, item));
            }
        }
        else {
            e.setCancelled(true);
        }
    }
}
 
Example 7
Source File: AcidInventory.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Checks to see if a player is drinking acid
 * 
 * @param e - event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onWaterBottleDrink(final PlayerItemConsumeEvent e) {
    if (Settings.acidDamage == 0D || !Settings.acidBottle)
        return;
    if (DEBUG)
        plugin.getLogger().info("DEBUG: " + e.getEventName());
    if (e.getPlayer().getWorld().getName().equalsIgnoreCase(Settings.worldName) && e.getItem().getType().equals(Material.POTION)) {
        if (DEBUG)
            plugin.getLogger().info(e.getEventName() + " called for " + e.getItem().getType());
        NMSAbstraction nms = null;
        try {
            nms = Util.checkVersion();
        } catch (Exception ex) {
            return;
        }
        if (!nms.isPotion(e.getItem())) {
            plugin.getLogger().info(e.getPlayer().getName() + " " + plugin.myLocale().drankAcidAndDied);
            if (!Settings.muteDeathMessages) {
                for (Player p : plugin.getServer().getOnlinePlayers()) {
                    Util.sendMessage(p, e.getPlayer().getName() + " " + plugin.myLocale(p.getUniqueId()).drankAcid);
                }
            }
            final ItemStack item = new ItemStack(Material.GLASS_BOTTLE);
            e.getPlayer().setItemInHand(item);
            e.getPlayer().setHealth(0D);
            e.setCancelled(true);
        }
    }
}
 
Example 8
Source File: PlayerListener.java    From AuthMeReloaded with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerConsumeItem(PlayerItemConsumeEvent event) {
    if (listenerService.shouldCancelEvent(event)) {
        event.setCancelled(true);
    }
}