1.12.2 Ender Crystal Get Killer

Discussion in 'Spigot Plugin Development' started by Hellinduction, Nov 27, 2020.

  1. So i own a small anarchy server and the common way of pvp on anarchy servers is crystal pvp. I have a command that tell you how many people you killed. Would there be any way in getting the killer in the scenario that:
    Player1 kills Player2 with an ender crystal
    (The killer should be player1) but the problem i have is, in chat it just says the player name has been blown up or along those lines.
     
  2. Code (Java):
    public void PlayerDead(PlayerDeathEvent e){
            Player dead = e.getEntity().getKiller();
            if(e.getEntity().getKiller() instanceof EnderCrystal) {
                // yourcode
            }
        }
    I can only tell you how to find out who killed the player. I just don't understand what you want to do.
     
  3. Essentially what i am trying to do is:
    When a player uses an end crystal to blow another player up, i am trying to get the player that used an end crystal to blow the other player up.
     
  4. Joshb_

    Supporter

    You need to get who blew up the ender crystal and store it and if player b died from it get the stored info. IIRC you need to use
    EntityDamageByEntityEvent and get the last entity damager for player b
     
  5. This will return null 100% of the time since getKiller() can be null and you don't null check that so it'll error but also your code is so wrong since getKiller() is always a Player not an Entity (which wouldn't even make sense since in any case only a LivingEntity should be a killer even though it's a Player only but never an Entity) so it can't be checked as an EnderCrystal lol.

    As stated above the best shot you have is probably to check EntityDamageByEntityEvent by checking if the getEntity() is a Player and getDamager() is an EnderCrystal and then store the damaged Player in a map to retrieve that later on in another event, though likely you can use the same event here for all you need to do.
     
    • Like Like x 1
  6. Oh, that was very stupid. Thank you for the correction.