Private Death Messages?

Discussion in 'Plugin Development' started by aPandaification, Jun 28, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    aPandaification

    So I am making a plugin that disables the public messages of getting killed and logging in and off but I am unsure as to how to make getting killed and killing someone a private message. What I aim to do is have "You have slain " + killed player for the attacker and "You have been slain by " + killer and they would be sent respectively to their players. Can anyone help me out with this.
     
  2. Offline

    ferrybig

    use the respawnEvent for this, and only send the reason to the persons invoked at this
     
  3. Offline

    aPandaification

    Wow thanks I was looking in the PlayerDeathEvent T.T
    EDIT: Wait the PlayerRespawnEvent doesn't have anything to do with who killed you and whatnot...
     
  4. Offline

    ferrybig

    I think I have messed up the death and respawn event, PlayerRespawnDeathEvent is the place to look for, send the deathMesage to only the players invoked, and set it then to null or an empty string
     
  5. Offline

    kkirkfield

    There's probably a lot of ways to do it.
    My way: You will need to overide the player events in bukkit and register them in a listener. You will have to copy all the code from the bukkit events and paste them into your event and then change the text. I don't know if the bukkit is open source and shows that. You may be able to just impliment the bukkit listener and then overide the events you want.

    You can find the events you want to overide here... http://jd.bukkit.org/doxygen/df/d08/namespaceorg_1_1bukkit_1_1event.html

    EDIT: :( ferrybig beat me.
     
  6. Offline

    aPandaification

    well ya I did that, that isn't the problem I'm having because I have the global messages nulled but I want to also send private messages to the player and killer
    EDIT: kkirkfield :confused: sounds scary
    EDIT2: ferrybig I think what I'm having problems with is getting the players involved as there doesn't seem to be any documentation for that :/

    bumpity - still cant get this to work T.T

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  7. Offline

    smilne74

    Try this:


    Code:
    public class PlayerDeathListener implements Listener {
     
        @EventHandler(priority = EventPriority.NORMAL)
        public void onPlayerDeathEvent(PlayerDeathEvent e) {
     
            // Player who died
            Player deadPlayer = (Player) e.getEntity();
     
            // send message to the dead player
            deadPlayer.sendMessage("my message");
     
            // If the killer was a Player
            if (deadPlayer.getKiller() instanceof Player) {
     
                Player killerPlayer = (Player) player.getKiller();
     
            // send message to the killer
                killerPlayer.sendMessage("my message");
        }
        }
    }
    
    Then, in your plugin.enable(), make sure you register the listener:

    Code:
            getServer().getPluginManager().registerEvents(new PlayerDeathListener(), this);
    
     
  8. Offline

    kkirkfield

    player events have a getPlayer() function to get the player that had the event. With the player, you can call sendMessage() to show them your custom death message.
    I didn't know there was a global messages setting that turned off the default.

    EDIT: :( smilne74 beat me
     
Thread Status:
Not open for further replies.

Share This Page