Solved Custom death message not working

Discussion in 'Plugin Help/Development/Requests' started by BizarrePlatinum, Apr 5, 2015.

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

    BizarrePlatinum

    Code:
    public void onPlayerDeath(PlayerDeathEvent e) {
            Entity entity = e.getEntity();
           
            e.setDeathMessage((String)null);
           
            if(e.getEntityType().equals(EntityType.PLAYER)) {
                entity.sendMessage(ChatColor.DARK_RED + "DESYNCHRONIZED");
            }
        }
    
    I am attempting to create a custom death message, but it appears not to be working (the reason I am not using setDeathMessage for it is I only want the player dying to receive the message). If someone could help out, that'd be most appreciated, thanks :).
     
  2. Offline

    nverdier

    @BizarrePlatinum PlayerDeathEvent#getEntity returns a Player, do you don't need to check the EntityType. There is no need to cast 'null' to String. You don't have an @EventHandler over the method, it seems. Also, have you registered your events?
     
  3. Offline

    BizarrePlatinum

    - I assumed since I could only get the entity, that I needed to get the entity type.
    - Whoops, thought I needed to cast null to a String.
    - That may be my problem, I just noticed that I had forgotten to annotate a few of the events.
    - I have registered my events.

    The problem has been fixed, I had forgotten the annotations, thanks :).
     
  4. Offline

    HCMatt

    Hey @BizarrePlatinum !

    How to go about fixing this:

    You will obviously need an @EventHandler above your onPlayerDeath(), and will also need to register your events by putting in your onEnable()
    Code:
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    Onces you have done this, you will want your onPlayerDeath() to look like this:


    Code:
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e){
            Player p = e.getEntity();
            e.setDeathMessage(null);
            p.sendMessage(ChatColor.DARK_RED + "DESYNCHRONISED");
            return;
        }
    I know that your problem has been resolved, but this is just a more efficient way of doing this.

    ~Matty.
     
  5. Offline

    nverdier

    @HCMatt So basically exactly what I said, but with spoonfeeding added?
     
  6. Offline

    HCMatt

    @nverdier So basically I was trying to help as much as I can. I was not talking to you, so your rude input towards me was not needed.
     
  7. Offline

    nverdier

    @HCMatt This is offtopic, but you said everything that I did, but you put spoonfeeding in it as well. So I think that it is the contrary, you were being rude. But we shouldn't be posting here, this is getting quite offtopic.
     
  8. Offline

    BizarrePlatinum

    I'd also like to mention that the problem had already been solved, although I appreciate you trying to help me out, it wasn't necessary.
     
Thread Status:
Not open for further replies.

Share This Page