Potion Detection

Discussion in 'Spigot Plugin Development' started by XKnucklesX, Apr 14, 2017.

  1. Hello,

    I was wondering how you would be able to see what potion a person used?

    static PotionEffectType getByName(String name)
    Gets the effect type specified by the given name

  2. Listen to PlayerItemConsumeEvent, get the consumed Item, get its itemmeta (PotionMeta) and use PotionMeta#getCustomEffects(), which returns to List<PotionEffect>. Then get the PotionEffectType from each PotionEffect through a for loop?
  3. How would you get the consumed item?
  4. Do you mean that?
    Code (Text):
    public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event) {
        ItemStack item = event.getItem();
    #4 kanoxx, Apr 14, 2017
    Last edited: Apr 14, 2017
  5. Does consumption work for dropping potions on other people?
  6. Do you mean using splash potions on players? If so use PotionSplashEvent#getAffectedEntities(), which returns to a Collection<LivingEntity>. Then check if the livingentity is a player, etc.
    Edit: you can also use PotionSplashEvent#getPotion() (returning a ThrownPotion) to check if the potion does have the PotionEffect you want.