org.bukkit.event.player.PlayerItemConsumeEvent Java Examples

The following examples show how to use org.bukkit.event.player.PlayerItemConsumeEvent. 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: IndicatorListener.java    From HoloAPI with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onConsumePotion(PlayerItemConsumeEvent event) {
    if (Settings.INDICATOR_ENABLE.getValue("potion")) {
        if (event.getItem().getType() == Material.POTION) {
            Potion potion = Potion.fromItemStack(event.getItem());
            if (potion != null) {
                this.showPotionHologram(event.getPlayer(), potion.getEffects());
            }
        } else if (event.getItem().getType() == Material.GOLDEN_APPLE) {
            String msg = Settings.INDICATOR_FORMAT.getValue("potion", "goldenapple");
            if (event.getItem().getDurability() == 1) {
                msg = Settings.INDICATOR_FORMAT.getValue("potion", "godapple");
            }
            Location l = event.getPlayer().getLocation().clone();
            l.setY(l.getY() + Settings.INDICATOR_Y_OFFSET.getValue("potion"));
            HoloAPI.getManager().createSimpleHologram(l, Settings.INDICATOR_TIME_VISIBLE.getValue("potion"), true, msg.replace("%effect%", "Golden Apple"));
        }
    }
}
 
Example #3
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 #4
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 #5
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 #6
Source File: PlayerListener.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event)
{
	Player player = event.getPlayer();
	
	ItemMeta itemMeta = event.getItem().getItemMeta();
	if (itemMeta instanceof PotionMeta)
	{
		this.plugin.getWorldGuardCommunicator().getSessionManager().get(player).getHandler(GiveEffectsFlagHandler.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
	}
	else
	{
		Material material = event.getItem().getType();
		if (material == Material.MILK_BUCKET)
		{
			this.plugin.getWorldGuardCommunicator().getSessionManager().get(player).getHandler(GiveEffectsFlagHandler.class).drinkMilk(player);
		}
	}
}
 
Example #7
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 #8
Source File: LugolsIodinePotion.java    From CraftserveRadiation with Apache License 2.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
    ItemStack item = event.getItem();
    if (!this.test(item)) {
        return;
    }

    PersistentDataContainer container = item.getItemMeta().getPersistentDataContainer();

    int durationSeconds = 0;
    if (container.has(this.durationSecondsKey, PersistentDataType.INTEGER)) {
        durationSeconds = container.getOrDefault(this.durationSecondsKey, PersistentDataType.INTEGER, 0);
    } else if (container.has(this.durationKey, PersistentDataType.INTEGER)) {
        durationSeconds = (int) TimeUnit.MINUTES.toSeconds(container.getOrDefault(this.durationKey, PersistentDataType.INTEGER, 0)); // legacy
    }

    if (durationSeconds <= 0) {
        return;
    }

    Player player = event.getPlayer();
    this.effect.setEffect(player, durationSeconds);
    this.broadcastConsumption(player, durationSeconds);
}
 
Example #9
Source File: GoldenHeadsModule.java    From UHC with MIT License 5 votes vote down vote up
@EventHandler
public void on(PlayerItemConsumeEvent event) {
    if (isEnabled() && isGoldenHead(event.getItem())) {
        event.getPlayer().addPotionEffect(new PotionEffect(
                PotionEffectType.REGENERATION,
                TICKS_PER_HALF_HEART * healAmount,
                1
        ));
    }
}
 
Example #10
Source File: PlayerListenerTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldHandleSimpleCancelableEvents() {
    withServiceMock(listenerService)
        .check(listener::onPlayerShear, PlayerShearEntityEvent.class)
        .check(listener::onPlayerFish, PlayerFishEvent.class)
        .check(listener::onPlayerBedEnter, PlayerBedEnterEvent.class)
        .check(listener::onPlayerDropItem, PlayerDropItemEvent.class)
        .check(listener::onPlayerHitPlayerEvent, EntityDamageByEntityEvent.class)
        .check(listener::onPlayerConsumeItem, PlayerItemConsumeEvent.class)
        .check(listener::onPlayerInteract, PlayerInteractEvent.class)
        .check(listener::onPlayerPickupItem, PlayerPickupItemEvent.class)
        .check(listener::onPlayerInteractEntity, PlayerInteractEntityEvent.class)
        .check(listener::onPlayerHeldItem, PlayerItemHeldEvent.class);
}
 
Example #11
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 #12
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 #13
Source File: ConsumeObjective.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onConsume(PlayerItemConsumeEvent event) {
    String playerID = PlayerConverter.getID(event.getPlayer());
    if (containsPlayer(playerID) && item.compare(event.getItem()) && checkConditions(playerID)) {
        completeObjective(playerID);
    }
}
 
Example #14
Source File: AbsorptionModule.java    From UHC with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void on(PlayerItemConsumeEvent event) {
    if (isEnabled()) return;

    if (event.getItem().getType() != Material.GOLDEN_APPLE) return;

    // schedule on next tick
    new RemovePotionEffectRunnable(event.getPlayer().getUniqueId(), PotionEffectType.ABSORPTION).runTask(plugin);
}
 
Example #15
Source File: ExtendedSaturationModule.java    From UHC with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void on(PlayerItemConsumeEvent event) {
    if (isEnabled()) {
        new SaturationMultiplierRunnable(
                event.getPlayer().getUniqueId(),
                event.getPlayer().getSaturation(),
                multiplier - 1D
        ).runTask(plugin);
    }
}
 
Example #16
Source File: DataUpdaterEvents.java    From AACAdditionPro with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onConsume(final PlayerItemConsumeEvent event)
{
    final User user = UserManager.getUser(event.getPlayer().getUniqueId());

    if (user != null) {
        user.getTimestampMap().updateTimeStamp(TimestampKey.LAST_CONSUME_EVENT);
        user.getDataMap().setValue(DataKey.LAST_CONSUMED_ITEM_STACK, event.getItem());
    }
}
 
Example #17
Source File: ItemsListener.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent e){
	if (e.getItem() == null) return;

	if (e.getItem().equals(UhcItems.createGoldenHead())){
		e.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, 200, 1));
	}
}
 
Example #18
Source File: ActionListener.java    From ActionHealth with MIT License 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onConsume(PlayerItemConsumeEvent event) {
    if (!main.configStore.actionStore.enabled)
        return;

    ActionStore.ActionType actionType = ActionStore.ActionType.CONSUME;
    Player player = event.getPlayer();

    actionHelper.executeTriggers(actionType, player, event.getItem());
}
 
Example #19
Source File: LugolsIodineEffect.java    From CraftserveRadiation with Apache License 2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMilkBucketConsume(PlayerItemConsumeEvent event) {
    if (event.getItem().getType().equals(Material.MILK_BUCKET)) {
        PersistentDataContainer container = event.getPlayer().getPersistentDataContainer();
        container.remove(this.initialSecondsKey);
        container.remove(this.secondsLeftKey);
    }
}
 
Example #20
Source File: FoodEatenListener.java    From Statz with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEat(final PlayerItemConsumeEvent event) {

    final PlayerStat stat = PlayerStat.FOOD_EATEN;

    // Get player
    final Player player = event.getPlayer();

    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;

    PlayerStatSpecification specification = new FoodEatenSpecification(player.getUniqueId(), 1,
            player.getWorld().getName(), event.getItem().getType());

    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat, specification.constructQuery());

}
 
Example #21
Source File: DiscardPotionBottlesMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onDrinkPotion(final PlayerItemConsumeEvent event) {
    if(event.getItem().getType() == Material.POTION) {
        event.setReplacement(new ItemStack(Material.AIR));
    }
}
 
Example #22
Source File: SlimefunItemTest.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
default void simulateConsumption(Player player, T item) {
    PlayerItemConsumeEvent event = new PlayerItemConsumeEvent(player, item.getItem().clone());
    item.callItemHandler(ItemConsumptionHandler.class, handler -> handler.onConsume(event, player, event.getItem()));
}
 
Example #23
Source File: DiscardPotionBottlesMatchModule.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onDrinkPotion(final PlayerItemConsumeEvent event) {
  if (event.getItem().getType() == Material.POTION) {
    event.setReplacement(new ItemStack(Material.AIR));
  }
}
 
Example #24
Source File: PotionRemover.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
    if (event.getItem().getType().equals(Material.POTION)) {
        event.setReplacement(new ItemStack(Material.AIR));
    }
}
 
Example #25
Source File: ObserverModule.java    From CardinalPGM with MIT License 4 votes vote down vote up
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent event) {
    refreshView(event.getPlayer().getUniqueId());
}
 
Example #26
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);
    }
}
 
Example #27
Source File: ItemConsumptionHandler.java    From Slimefun4 with GNU General Public License v3.0 2 votes vote down vote up
/**
 * This method gets fired whenever a {@link PlayerItemConsumeEvent} involving this
 * {@link SlimefunItem} has been triggered.
 * 
 * @param e
 *            The {@link PlayerItemConsumeEvent} that was fired
 * @param p
 *            The {@link Player} who consumed the given {@link ItemStack}
 * @param item
 *            The {@link ItemStack} that was consumed
 */
void onConsume(PlayerItemConsumeEvent e, Player p, ItemStack item);