So i am working on a plugin that needs to detect whether a player is holding an item or wearing it...
PlayerItemHeldEvent. You can save the player's previous effects in an array and then do checks whenever the event gets called. WARNING: I'm not sure if this event gets called when the held item is moved to cursor inventory. If it doesn't get called, the player can be stuck with an infinite effect. But you can verify that fact... maybe? Confirmed, it works with every transaction. It's the best option to use in your case. PHP: /** @var int[] */private $enchantFx = [];public function onItemHold(PlayerItemHeldEvent $event) : void{ $item = $event->getItem(); $player = $event->getPlayer(); if(isset($this->enchantFx[$id = $player->getId()])){//remove effects if any foreach($this->enchantFx[$id] as $effectId){ $player->removeEffect($effectId); } unset($this->enchantFx[$id]); } if($item->hasEnchantment(Enchantment::SHARPNESS)){ $effect = Effect::getEffect(Effect::HASTE)->setDuration(INT32_MAX); if($player->addEffect($effect)){ $this->enchantFx[$id][] = $effect->getId(); }else{ //unsuccessful attempt to give player an effect, probably because they already have the same effect with a better level of amplifier } }}
You can listen to the EntityArmorChangeEvent Source: https://forums.pmmp.io/threads/wearing-item.4836/ Other reference: PHP: Player->getInventory()->getHelmet() # orgetChestplate() # orgetLeggings() # orgetBoots() returns an Item object.