I want to make a plugin when life is low, I get some effects like: Class Main extends PluginBase implements Listener { public function onEnable() { $this->getLogger()->info ("§aAtivado"); $this->getServer()->getPluginManager()->registerEvents($this,$this); } public function onDisable() { $this->getLogger()->info('§aDesativado'); } public function execute(Listener $listener, Event $event){ $p = $ev->getPlayer(); $health = getHealth(); if ($health <= 7) { $p->sendTip('§dVocê usou o §aTOTEM'); $ev->getPlayer()->getInvenTory()->removeItem(Item::Get(341,0,1)); $p->addEffect(Effect::getEffect(10)->setAmplifier(3)->setDuration(10 * 3)->setVisible(true)); $p->addEffect(Effect::getEffect(11)->setAmplifier(1)->setDuration(5 * 1)->setVisible(true)); $p->addEffect(Effect::getEffect(12)->setAmplifier(1)->setDuration(5 * 1)->setVisible(true)); } } }but i don't know how to load even the public function
In my opinion there are two ways of doing that, if you want to check every second if a player has a specific number of hearts just create a Task and get all players of the server and check if they have x amount of hearts and if they have, for example lower than 3 hearts then give the player the effect you want to.
to track when damage is dealt use EntityDamageEvent, and make a request for execute() function onDamage(EntityDamageEvent $event){ $entity = $event->getEntity(); if($event instanceof EntityDamageByEntityEvent){ if(($entity->getHealth() - $event->getFinalDamage()) <= 7){ $this->execute($entity); } } } function execute($p){ $p->sendTip('§dVocê usou o §aTOTEM'); $p->getInventory()->removeItem(Item::get(341, 0, 1)); $p->addEffect(Effect::getEffect(10)->setAmplifier(3)->setDuration(10 * 3)->setVisible(true)); $p->addEffect(Effect::getEffect(11)->setAmplifier(1)->setDuration(5 * 1)->setVisible(true)); $p->addEffect(Effect::getEffect(12)->setAmplifier(1)->setDuration(5 * 1)->setVisible(true)); }