Death message player name doesnt work

Discussion in 'Plugin Development' started by zJanny, Sep 22, 2019.

  1. Offline

    zJanny

    Hello,
    I want to have custom death message
    The code i use for it is:

    Code:
            @EventHandler
            public void onPlayerDeath(PlayerDeathEvent e) {
                       
    
                        e.setDeathMessage("§4The Player" + Bukkit.getName() + " §4has died");

    But Ingame it shows as Name:[​IMG]
     
  2. Offline

    timtower Moderator Moderator

    @zJanny event.getPlayer().getDisplayName()
     
  3. Offline

    zJanny

    I get this error in Console when i died:
    [11:27:57] [Server thread/ERROR]: Could not pass event PlayerDeathEvent to Champ3 v1.5
    org.bukkit.event.EventException: null
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:529) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:514) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:726) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.EntityPlayer.die(EntityPlayer.java:520) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.EntityLiving.damageEntity(EntityLiving.java:1169) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.EntityHuman.damageEntity(EntityHuman.java:769) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.EntityPlayer.damageEntity(EntityPlayer.java:675) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.EntityLiving.killEntity(EntityLiving.java:174) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.CommandKill.a(SourceFile:30) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.CommandKill.a(SourceFile:23) ~[spigot.jar:git-Spigot-9de398a-9c887d4]
    at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:262) [spigot.jar:git-Spigot-9de398a-9c887d4]
    at com.mojang.brigadier.CommandDispatcher.execute(CommandDispatcher.java:176) [spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.CommandDispatcher.a(CommandDispatcher.java:172) [spigot.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.craftbukkit.v1_14_R1.command.VanillaCommandWrapper.execute(VanillaCommandWrapper.java:45) [spigot.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) [spigot.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:710) [spigot.jar:git-Spigot-9de398a-9c887d4]
    at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchServerCommand(CraftServer.java:695) [spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.DedicatedServer.handleCommandQueue(DedicatedServer.java:433) [spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.DedicatedServer.b(DedicatedServer.java:397) [spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:971) [spigot.jar:git-Spigot-9de398a-9c887d4]
    at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:816) [spigot.jar:git-Spigot-9de398a-9c887d4]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
    Caused by: java.lang.NullPointerException
    at at.Champ3.zJanny.listeners.JoinListener.onPlayerDeath(JoinListener.java:72) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_221]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_221]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_221]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_221]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:316) ~[spigot.jar:git-Spigot-9de398a-9c887d4]

    The code now is
    Code:
    @SuppressWarnings("null")
            @EventHandler
            public void onPlayerDeath(PlayerDeathEvent e) {
                      
    
                        OfflinePlayer event = null;
                        e.setDeathMessage("§4The Player" + event.getPlayer().getDisplayName() + " §4has died");
     
  4. Offline

    timtower Moderator Moderator

    @zJanny And why did you add a variable?
     
  5. Offline

    zJanny

    Because i get an error if i dont add one:
    Event cannot be resolved
     
  6. Offline

    timtower Moderator Moderator

    @zJanny Then replace event by something that can represent an event. Like the PlayerDeathEvent
     
  7. Offline

    zJanny

    I alreade use the Death event
    Code:
    public void onPlayerDeath(PlayerDeathEvent e) {
    Sorry i am German and i understand your sentence false because i read it with german gramman

    So what ran represent "event" on PlayerDeathEvent?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 22, 2019
  8. Offline

    timtower Moderator Moderator

  9. Offline

    zJanny

    The method get Player is undefinded for the Type PlayerDeathEvent
     
  10. Offline

    timtower Moderator Moderator

    @zJanny Then find a method that does contain a player.
     
  11. Offline

    zJanny

    If fixed it with entitiy
     

Share This Page