DeathMessage View Permission

Discussion in 'Plugin Development' started by ItsBlockFighter, Jun 10, 2017.

Thread Status:
Not open for further replies.
  1. Hi!
    How can I do it just to see who has the right to die? Who killed him
     
  2. Offline

    Desle

    you could cancel the default message and loop through the players to check which one has the right permissions. if so, send the message.
     
  3. @Desle
    So? Or how should it be?
    Code:
        @EventHandler
        public void onDeath(PlayerDeathEvent e) {
                Player player = e.getEntity();
                if(player.hasPermission("ghostrealms.deathlog")) {
                    Player p = e.getEntity().getPlayer();
                    Player k = e.getEntity().getKiller();
                    player.sendMessage(ChatColor.RED + p.getName() + ChatColor.GRAY + "-t megölte " + ChatColor.GREEN + k.getName());
            }
        }
    }
    
     
  4. @ItsBlockFighter
    Yes, you just have to cancel the previous death message by setting it to null. (e.setDeathMessage(null))
     
  5. @AlvinB
    I did what you said but it does not specify who killed you
     
  6. @AlvinB
    Code:
        @EventHandler
        public void onDeath(PlayerDeathEvent e) {
                Player player = e.getEntity();
                if(player.hasPermission("ghostrealms.deathlog")) {
                    Player p = e.getEntity().getPlayer();
                    Player k = e.getEntity().getKiller();
                    e.setDeathMessage(null);
                    player.sendMessage(ChatColor.RED + p.getName() + ChatColor.GRAY + "-t megölte " + ChatColor.GREEN + k.getName());
            }
        }
    }
    
     
  7. @ItsBlockFighter
    PlayerDeathEvent is fired before the player is actually dead, so e.getEntity().getKiller() is not yet set. If you set the death message, and then in a delayed task do the message and getting the player variables, you should be set.

    Also, you don't need the "getPlayer()" bit of "e.getEntity().getPlayer()". "e.getEntity()" already returns the player. You also already have a player variable, so no need to introduce a new one.
     
  8. @AlvinB
    You can not enter it in code because I do not understand it anymore
     
  9. @ItsBlockFighter
    Just create a new task, and run the sendMessage code 1 tick later.
    Code:java
    1. // The permission check and null-setting of the deathmessage here
    2. e.setDeath....
    3. new BukkitRunnable() {
    4. // Run the sendMessage code here!
    5. }.runTask(yourPluginInstance);
     
  10. @AlvinB
    But I just want the one who killed the player so that the Admin can see who killed him
     
  11. @ItsBlockFighter
    Yes, but you can only use getKiller() one tick after the event is fired, because events are fired before the actual action happens.
     
  12. @AlvinB
    But Who Ordinates Who Killed Him Only Everybody Sees Me And I Just Want It Who Has Right To
     
Thread Status:
Not open for further replies.

Share This Page