Solved How to disable death messages

Discussion in 'Spigot Plugin Development' started by Flyin, Jan 14, 2016.

  1. Alright I am trying to disable the "Killed <Player>" message and this code is not working. Note this code used to work but no longer appears to.
    Code (Text):
        @EventHandler
        public void onDeath(PlayerDeathEvent e)
        {
            e.setDeathMessage(null);
        }
    Thanks in advance,
    ~ Flyin
     
    • Useful Useful x 1
  2. e.setDeathMessage(""); should work. Not sure if that's the correct way though.
     
  3. nope, that does nothing :/

    Thanks for the reply though!
     
  4. In which case I question whether the event is being fired at all.. Perhaps you could put in a debug message to ensure the event is called?
     
  5. Yes, I had tested it with a message and the event is being fired... Now what I find really strange is the fact that the command "/gamerule disableDeathMessages (something like that) false" does not work either... xD Note that I have no other plugins on the server...
     
  6. Do these other plugins modify the death message? If so, increase the priority of your event.
    Code (Text):
    @EventHandler(priority = EventPriority.HIGHEST)
     
  7. Ah alright.. That is definitely wierd. What about if you set the death message to a proper string? Does it do anything then? (sorry for all the questions, I'm stumped)

    And you would want to set the gamerule to true to remove the messages from there.
     
  8. As I had said there are no other plugins on the server but never the less I will try it.
     
  9. Ah. It appears I can't read, my apologies. I read it as you do have other plugins on your server, rather than you don't.
     
  10. Alright so I tested the command "/gamerule showDeathMessages <boolean>", with it true or false it does nothing. There are NO other plugins installed to the server and nothing else in my plugin modifying the death msg. The following has not worked:

    * Setting priority to HIGHEST
    * e.setDeathMessage("")
    * e.setDeathMessage(null)

    EDIT: WHY MUST SPIGOT BE BROKEN xD
     
  11. Actually, LOWEST is called first.
     
  12. Good to know but still does not work :/
     
  13. Do I have to remove this message on the packet level?..
     
  14. HIGHEST is called first. It has the higher priority, which means it is more important, so it goes first. But there is no such thing as "overriding". The only way another plugin could influence this if their PlayerDeathEvent set their own death message, which is where priorities would come in handy (putting yours as LOWEST). But none of that should matter. You're sure you implemented Listener and registered the Listener, and the plugin is actually loaded?
     
    • Optimistic Optimistic x 4
    • Funny Funny x 1
  15. Yes, I send a message to the console on the event, the event is working...
     
  16. http://wiki.bukkit.org/Event_API_Reference#Event_Priorities
    Events are called LOWEST to HIGHEST
     
    • Agree Agree x 1
  17. *scratches head* that doesn't even make any sense... welp, use HIGHEST then xD
     
    • Agree Agree x 1
  18. @Flyin well whatever is breaking your plugin, it surely isn't Minecraft / Spigot.
    Code (Java):
    if ((deathMessage != null) && (deathMessage.length() > 0) && (this.world.getGameRules().getBoolean("showDeathMessages"))) {
        if (deathMessage.equals(deathmessage)) {
            this.server.getPlayerList().sendMessage(chatmessage);
        } else {
            this.server.getPlayerList().sendMessage(CraftChatMessage.fromString(deathMessage));
        }
    }
    I recommend checking all plugins that might be on there (including your own), because it's a plugin causing the so called 'bug'. If it's just one plugin, that's even easier: just do a global text search in your IDE.

    And for everyone still debating EventPriority, stop assuming things and look in the damn code.
    Code (Java):
    package org.bukkit.event;

    public enum EventPriority
        {
        LOWEST(0),
        LOW(1),
        NORMAL(2),
        HIGH(3),
        HIGHEST(4),
        MONITOR(5);

        private final int slot;

        private EventPriority(int slot)
        {
            this.slot = slot;
        }

        public int getSlot()
        {
            return this.slot;
        }
    }
    @Warren1001 It's ambiguous, I know. Just think of the event handler queue as a min-priority queue, lowest priority comes first.
     
  19. It's confusing at first because we all think that something with a high priority should come first. Bukkit's way of doing it does make sense though.
     
    • Agree Agree x 2
  20. Lowest priority - set message "1"
    \/
    Medium priority - set message "2"
    \/
    Highest priority - set message "3"
    \/
    Output would be 3, not 1.
     
    • Agree Agree x 1