I need to use setHealth() in my Plugin. I´m using $player->setHealth(20); 20, because the Player has 20 half hearts. But when the setHealth method gets called, it removes 2 hearts from the player instead of adding them. How do I need to use this method? Thanks
I already tried that. Has the same effect. I could try to use setMaxHealth() or wait some time until it gets fixed. I'll report it as a bug.
$event->getPlayer()->setHealth(0) This is you want to kill the person Let's say your making like a badword plugin PHP: public function onChat(PlayerChatEvent $event) { $msg = $event->getMessage(); $fuckword = "fuck"; // Your fucked lol if(strpos($msg, $fuckword) !==false) { $event->getPlayer()->sendMessage("DONT EVER SAY THAT AGAIN YOU DIE NOW"); $event->getPlayer()->setHealth(0);// That's the part you use setHealth()}}
if(strolower($msg, $fuckword) ??? Thats not how you use strtolower. I think you meant stripos($msg, $fuckword)
Use stripos() !== false And you should use attack(), otherwise it will cause other issues e.g. no EntityDamageEvent fired (hence no update in getLastDamageCause, hence breaks some other plugins e.g. plugins that announce who killed who).