Hello all Im using the Weapons plugin, and it uses a custom item of your choice, combined with a custom ammunition item (mine being Inc Sac). In my core, onDeath I have a few lines of code intended to reward players with $10 for every kill. PHP: $cause = $event->getEntity()->getLastDamageCause(); if($cause instanceof EntityDamageByEntityEvent){ if($cause->getDamager() instanceof Player) { $killer = $cause->getDamager(); $this->eco = $this->getServer()->getPluginManager()->getPlugin("EconomyAPI"); $this->eco->addMoney($killer, 10); $killer->sendTip("§eYou earned $10 for killing " . $name . "!"); } } } If I'm understanding it correctly however, this would ignore a player who killed another player, with a gun, as that Gun fires (in my case) an Inc Sac, similar to how a Bow fires an Arrow. Would simply removing the line of PHP: if($cause->getDamage() instanceof Player){ allow it to recognize the death by inc sac? Or do I need to check for death by projectile? Extremely confused in regards to this.... Thanks in advance for any help you can give!
Well, if player did die from a Projectile then it must have reference to the shooter entity (Player in this case). I've been away for a while, but I'm not sure if you can actually use an item such as inc sac for a projectile, or can you? Also: why are you re-assigning the economy plugin to class property on each death?
@Primus not sure about the Inc Sac being the projectile either, all I know is, the weapons plugin allowed it. I could make Diamond Swords be the "bullet" for all it cares. Guess I'll try with the instanceof Player, just seems odd, but if what you said is true, it should work. As for the economy thing, I could edit it, but I've been using that exact method for months on another server, so I'm using it here. May not be the best, but it works for me.
https://github.com/InfinityGamers/Weapons/blob/master/src/xBeastMode/Weapons/BulletEntity.php#39 looks like there are no reference to the player who fired the bullet, unless it's inside the compoundtag which I doubt, but too lazy to make sure
In my opinion, a better method of implementing the "Bullet" would be extending a Projectile class and overriding sendDataPacket. That one override easily defeats extending ItemEntity and half-implementing projectile mechanisms to the class.