Have to set a killer.

Discussion in 'Plugin Development' started by sajmonks, Jan 26, 2013.

Thread Status:
Not open for further replies.
  1. Hello. I have a problem. I want to set killer of player/entity, but i don't know how.

    Example:
    Code:
       
    @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event){
            event.setDamager(..) // or something like that.
        }
    
    Any ideas ?
     
  2. Offline

    RealDope

    You can't set the killer (with just the Bukkit API), but what do you need to set it for? There are work arounds for nearly anything you can think of.
     
  3. Offline

    evilmidget38

    sajmonks It's certainly possible to do so(reflection sounds like the most versioning-proof way), but why would you need to?
     
  4. Offline

    AbsolutePotato

    How about using
    Code:
     public void onDeath(PlayerDeathEvent event)
      {
        Player player = event.getEntity();
      
        if ((player.getKiller() instanceof Player)) {
          Player p = (Player)player;
          Player killer = p.getKiller();
    
    Where Killer is the player who killed the player.
     
  5. Offline

    RealDope

    He's trying to change the killer, not get it...
     
  6. Offline

    jayserp

    player.damage(int damage, Entity damager);
     
  7. Offline

    iWareWolf

    sajmonks
    You can change the message of the death.
     
  8. Offline

    Cirno

    You might be able to use reflection to edit the killer. Not really recommended, though.
     
  9. Offline

    codename_B

    Here's some old code of mine for just this

    Code:
        private Object getHandle(Player player) {
            try {
                Method getHandle = this.getPlayerHandle==null?this.getPlayerHandle = player.getClass().getDeclaredMethod("getHandle", null):this.getPlayerHandle;
                // I think this is probably the simplest way to do this?
                return getHandle.invoke(player, getHandle);
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        }
        private void setKiller(Player player, Player killer) {
            try {
                Object playerHandle = getHandle(player);
                Object killerHandle = killer == null?null:getHandle(killer);
                Field nmsPlayer = this.getPlayerKiller==null?this.getPlayerKiller = playerHandle.getClass().getDeclaredField("killer"):this.getPlayerKiller;
                nmsPlayer.set(playerHandle, killerHandle);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
     
    Minnymin3 likes this.
  10. Offline

    Minnymin3

Thread Status:
Not open for further replies.

Share This Page