Greetings, I'm new at coding and I need some help, because I don't know why this isn't working. Thanks any help in advance, have a great day! PHP: public function tierSystem(PlayerDeathEvent $event){$kdr = $this->getServer()->getPluginManager()->getPlugin("KDR");$player = $event->getPlayer();$killdata = $kdr->getProvider()->getPlayerKillPoints($player);$firsttier = 5; # Award should be given after the 5th kill$killer = $player->getLastDamageCause()->getDamager();if($player->getLastDamageCause() instanceof EntityDamageByEntityEvent){ if($player->getLastDamageCause()->getDamager() instanceof Player){ if($killdata === $firsttier){ $killer->sendMessage("§8[§b!§8]§7 You are on the first Tier! Your reward:§b 500$"); $killer->sendTitle("§aTier 1 unlocked!"); $killer->sendSubTitle("§7Your reward: §6500$"); $this->getServer()->getPluginManager()->getPlugin("EconomyAPI"); EconomyAPI::getInstance()->addMoney($killer, 500); } }}
You gave no useful information. Are there any errors? Did you register Listener? What's the expected behavior and whats the one you observe?
I would like to make a plugin which rewards the player for every 5th kill. I get the kills data from the KDR plugin. In the current code, if the player has 5 kill, he or she should get 500 dollar after the 5th kill. When I get the 5th kill, nothing happens.
I'll teach you a valuable lesson. Simple output of the data can help you find the cause PHP: public function tierSystem(PlayerDeathEvent $event){# Add log message to see if this code gets executed at all$this->getServer()->getLogger()->notice(__CLASS__."::".__METHOD__." executed (Line: ".__LINE__.")");$kdr = $this->getServer()->getPluginManager()->getPlugin("KDR");$player = $event->getPlayer();$killdata = $kdr->getProvider()->getPlayerKillPoints($player);$firsttier = 5; # Award should be given after the 5th kill$killer = $player->getLastDamageCause()->getDamager();if($player->getLastDamageCause() instanceof EntityDamageByEntityEvent){ # DEBUG $this->getServer()->getLogger()->notice("Last damage cause was caused by entity"); if($player->getLastDamageCause()->getDamager() instanceof Player){ # DEBUG $this->getServer()->getLogger()->notice("Last damager was instanceof Player"); $this->getServer()->getLogger()->notice("Checking: {$killdata} === {$firsttier}"); if($killdata === $firsttier){ $killer->sendMessage("§8[§b!§8]§7 You are on the first Tier! Your reward:§b 500$"); $killer->sendTitle("§aTier 1 unlocked!"); $killer->sendSubTitle("§7Your reward: §6500$"); $this->getServer()->getPluginManager()->getPlugin("EconomyAPI"); EconomyAPI::getInstance()->addMoney($killer, 500); } }} Do you have registered listener? Something like this: PHP: public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this);}
Thanks for teaching me, successfully I found the error, and now everything works. Thanks for your time and help. Have a wonderful day!