· · Question · · Player Dies/Dead

Discussion in 'Plugin Development' started by IcyRelic, Jan 30, 2012.

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

    IcyRelic

    Is there a better event/method to do player death events instead of onPlayerRespawnEvent?
    Player respawn has bugs Example: when the player would hit title screen and rejoin it wont do the code no errors or anything just doesnt do it but is there another way?
     
  2. Offline

    Digi

    EntityDeathEvent and check if entity instanceof Player.
     
  3. Offline

    coldandtired

    Or just use the PlayerDeathEvent.
     
  4. Offline

    IcyRelic

    thank you both ill try them both and see what one works best for me
    i must of skipped over those
     
  5. Offline

    coldandtired

    You can ignore the playerdeathevent - seems it isn't fully implemented yet.
     
  6. Offline

    IcyRelic

    ok PlayerDeathEvent is going to give me the best options but 1 question it doesnt have event.getPlayer().sendMessage(""); or anything with getplayer what do i have to do to make it sendmessages or do anything else like that that i was able to do on player respawn

    lol i got this message after i sent the one before do u know anything about any of them? they dont have event.getPlayer is there a replacement for it?

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

    coldandtired

    All entity events have the method getEntity().

    You can use this to find out what it is - if (event.getEntity() instanceof Player) - and if it matches whichever type of entity you want you can cast it - Player p = (Player)event.getEntity();
     
  8. Offline

    IcyRelic

    thanks so much thats what i was looking for

    ok since im new to this event will this message say You were killed by a Creeper if the player was killed by a creeper
    p.sendMessage("You were killed by a " + event.getEntity().getEntityId());
    or would it give a long number if so how do i get the entity name

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

    coldandtired

    No. There are a few problems there.

    First, getEntityId() would indeed be a long unique number.
    Second, event.getEntity() will give you the dead entity, not the killer. To get the killer you'd need to do ((LivingEntity)event.getEntity()).getKiller(); but I don't think it will work if the player was killed by an explosion (so you'd have to mess with the damage event instead)
    Thirdly, there is no simple way to turn the entity into a name. Internally, creeper is called CraftCreeper, and Mooshroom is called CraftMushroomCow, etc. so you would have to create a lookup table to turn the internal name to whatever you need.
     
  10. Offline

    IcyRelic

    coldandtired so here let me revise that

    p.sendMessage("You were killed by a " + ((LivingEntity)event.getEntity()).getKiller()).replaceAll("CraftCreeper", "Creeper");
    would that work or no because i do that for configs to change a message like {player} into the playername
     
  11. Offline

    coldandtired

    Almost.

    p.sendMessage("You were killed by a " + ((LivingEntity)event.getEntity()).getKiller().toString().replaceAll("CraftCreeper", "Creeper"));

    But I'm not sure whether it will work - it depends whether the explosion gets counted as the killer or the creeper.
     
  12. Offline

    IcyRelic

    Error: LivingEntity cannot be resolved to a type

    Edit:
    NVM fixed it

    ok here is what i did:
    Code:
                        if(((LivingEntity)event.getEntity()).getKiller().toString() == "CraftCreeper"){
                            p.sendMessage("You were killed by a " + ((LivingEntity)event.getEntity()).getKiller().toString().replaceAll("CraftCreeper", "Creeper"));
                        }
                        if(((LivingEntity)event.getEntity()).getKiller().toString() == "CraftSkeleton"){
                            p.sendMessage("You were killed by a " + ((LivingEntity)event.getEntity()).getKiller().toString().replaceAll("CraftSkeleton", "Skeleton"));
                        }
                        if(((LivingEntity)event.getEntity()).getKiller().toString() == "CraftZombie"){
                            p.sendMessage("You were killed by a " + ((LivingEntity)event.getEntity()).getKiller().toString().replaceAll("CraftZombie", "Zombie"));
                        }
    i get an internal error here it is
    Code:
    C:\Users\IcyRelic\Desktop\Test Server>java -Xms1024M -Xmx1024M -jar craftbukkit.
    jar
    174 recipes
    27 achievements
    17:22:25 [INFO] Starting minecraft server version 1.1
    17:22:25 [INFO] Loading properties
    17:22:25 [INFO] Starting Minecraft server on *:25565
    17:22:26 [INFO] This server is running Craftbukkit version git-Bukkit-1.1-R1-b18
    18jnks (MC: 1.1) (Implementing API version 1.1-R1)
    17:22:27 [INFO] [PermissionsEx] sql backend registered!
    17:22:27 [INFO] [PermissionsEx] file backend registered!
    17:22:27 [INFO] [PermissionsEx] PermissionEx plugin initialized.
    17:22:27 [INFO] [PermissionsEx] p2compat backend registered!
    17:22:27 [INFO] [PermissionsCompat] Compatibility Layer Initalized!
    17:22:27 [INFO] [PermissionsEx] Initializing file backend
    17:22:27 [INFO] [Vault] Loading Vault v1.2.6-b70.
    17:22:27 [INFO] [Vault][Economy] iConomy 6 found: Waiting
    17:22:27 [INFO] [Vault][Permission] PermissionsEx found: Waiting
    17:22:27 [INFO] [Vault][Permission] SuperPermissions loaded as backup permission
    system.
    17:22:27 [INFO] [Vault][Chat] PermissionsEx found: Waiting
    17:22:27 [INFO] [Vault] Enabled Version 1.2.6-b70
    17:22:28 [INFO] Preparing level "world"
    17:22:28 [INFO] Default game type: 0
    17:22:30 [INFO] Preparing start region for level 0 (Seed: 1353636894111224568)
    17:22:31 [INFO] Preparing spawn area: 0%
    17:22:32 [INFO] Preparing spawn area: 32%
    17:22:33 [INFO] Preparing spawn area: 93%
    17:22:33 [INFO] Preparing start region for level 1 (Seed: 1353636894111224568)
    17:22:34 [INFO] Preparing spawn area: 73%
    17:22:34 [INFO] Preparing start region for level 2 (Seed: 1353636894111224568)
    17:22:35 [INFO] Preparing spawn area: 48%
    17:22:35 [INFO] [PermissionsEx] Loading PermissionsEx v1.17.
    17:22:36 [INFO] [PermissionsEx] Superperms support enabled.
    17:22:36 [INFO] [PermissionsEx] v1.17 enabled
    17:22:36 [INFO] [Vault][Permission] PermissionsEx hooked.
    17:22:36 [INFO] [Vault][Permission] PermissionsEx_Chat hooked.
    17:22:36 [INFO] [iConomy] Loading iConomy v6.0.8b.
    17:22:36 [INFO] [iConomy - Celty] Enabled (181 ms)
    17:22:36 [INFO] [Vault][Economy] iConomy 6 hooked.
    17:22:36 [INFO] [Paid2Level] Loading Paid2Level v1.0.
    17:22:36 [INFO] [Paid2Level] Enabled!
    17:22:36 [INFO] [MOTD With Death Message] Loading MOTD With Death Message v1.0.
    17:22:36 [INFO] [MOTD] Enabled!
    17:22:36 [INFO] [Permissions] Loading Permissions v2.7.7.
    17:22:36 [INFO] [PermissionsCompat] Compatibility layer enabled.
    17:22:36 [INFO] [Paid2Kill] Loading Paid2Kill v1.0.
    17:22:36 [INFO] [Paid2Kill] Enabled!
    17:22:37 [INFO] [ChatManager] Loading ChatManager v1.15.
    17:22:37 [INFO] [ChatManager] ChatManager disabled. Check config.yml!
    17:22:37 [INFO] [ChatManager] Unloading ChatManager v1.15.
    17:22:37 [INFO] [ChatManager] ChatManager disabled!
    17:22:37 [INFO] Server permissions file permissions.yml is empty, ignoring it
    17:22:37 [INFO] Done (9.111s)! For help, type "help" or "?"
    >deop icyrelic
    17:22:38 [INFO] CONSOLE: De-opping icyrelic
    17:22:40 [WARNING] Can't keep up! Did the system time change, or is the server o
    verloaded?
    17:22:43 [WARNING] Can't keep up! Did the system time change, or is the server o
    verloaded?
    17:23:29 [INFO] /127.0.0.1:59668 lost connection
    17:23:34 [INFO] IcyRelic [/127.0.0.1:59674] logged in with entity id 629 at ([wo
    rld] 204.0625, 63.0, 225.0)
    17:23:49 [INFO] Placed stronghold in INVALID biome at (-52, 41)
    >time set 24
    17:24:42 [INFO] CONSOLE: Set time to 24
    17:25:07 [WARNING] Can't keep up! Did the system time change, or is the server o
    verloaded?
    17:25:12 [WARNING] Can't keep up! Did the system time change, or is the server o
    verloaded?
    >give icyrelic 276
    17:25:57 [INFO] CONSOLE: Giving IcyRelic some 276 (DIAMOND_SWORD)
    >give icyrelic bow
    17:26:15 [INFO] CONSOLE: Giving IcyRelic some 261 (BOW)
    >give icyrelic arrow 64
    17:26:21 [INFO] CONSOLE: Giving IcyRelic some 262 (ARROW)
    >pex group admin add Paid2Kill.Collect
    17:27:13 [INFO] Permission "Paid2Kill.Collect" added to admin !
    17:28:12 [WARNING] Can't keep up! Did the system time change, or is the server o
    verloaded?
    17:30:23 [SEVERE] Could not pass event org.bukkit.event.entity.PlayerDeathEvent
    to Paid2Kill
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.
    java:1026)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:57)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:453)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerDeathEvent(C
    raftEventFactory.java:370)
            at net.minecraft.server.EntityPlayer.die(EntityPlayer.java:171)
            at net.minecraft.server.EntityLiving.damageEntity(EntityLiving.java:544)
     
            at net.minecraft.server.EntityHuman.damageEntity(EntityHuman.java:612)
            at net.minecraft.server.EntityPlayer.damageEntity(EntityPlayer.java:213)
     
            at net.minecraft.server.EntityArrow.y_(EntityArrow.java:208)
            at net.minecraft.server.World.entityJoinedWorld(World.java:1256)
            at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:1
    10)
            at net.minecraft.server.World.playerJoinedWorld(World.java:1238)
            at net.minecraft.server.World.tickEntities(World.java:1145)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:527)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:434)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.
    java:1024)
            ... 15 more
    Caused by: java.lang.NullPointerException
            at me.icyrelic.com.ptk.PListener.PlayerDied(PListener.java:38)
            ... 20 more
    17:32:01 [SEVERE] Could not pass event org.bukkit.event.entity.PlayerDeathEvent
    to Paid2Kill
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.
    java:1026)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:57)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:453)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerDeathEvent(C
    raftEventFactory.java:370)
            at net.minecraft.server.EntityPlayer.die(EntityPlayer.java:171)
            at net.minecraft.server.EntityLiving.damageEntity(EntityLiving.java:544)
     
            at net.minecraft.server.EntityHuman.damageEntity(EntityHuman.java:612)
            at net.minecraft.server.EntityPlayer.damageEntity(EntityPlayer.java:213)
     
            at net.minecraft.server.EntityMonster.d(EntityMonster.java:105)
            at net.minecraft.server.EntityMonster.a(EntityMonster.java:111)
            at net.minecraft.server.EntityCreature.m_(EntityCreature.java:70)
            at net.minecraft.server.EntityLiving.d(EntityLiving.java:944)
            at net.minecraft.server.EntityMonster.d(EntityMonster.java:27)
            at net.minecraft.server.EntityZombie.d(EntityZombie.java:47)
            at net.minecraft.server.EntityLiving.y_(EntityLiving.java:339)
            at net.minecraft.server.EntityMonster.y_(EntityMonster.java:31)
            at net.minecraft.server.World.entityJoinedWorld(World.java:1256)
            at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:1
    10)
            at net.minecraft.server.World.playerJoinedWorld(World.java:1238)
            at net.minecraft.server.World.tickEntities(World.java:1145)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:527)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:434)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.
    java:1024)
            ... 22 more
    Caused by: java.lang.NullPointerException
            at me.icyrelic.com.ptk.PListener.PlayerDied(PListener.java:38)
            ... 27 more
    17:32:37 [SEVERE] Could not pass event org.bukkit.event.entity.PlayerDeathEvent
    to Paid2Kill
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.
    java:1026)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:57)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:453)
            at org.bukkit.craftbukkit.event.CraftEventFactory.callPlayerDeathEvent(C
    raftEventFactory.java:370)
            at net.minecraft.server.EntityPlayer.die(EntityPlayer.java:171)
            at net.minecraft.server.EntityLiving.damageEntity(EntityLiving.java:544)
     
            at net.minecraft.server.EntityHuman.damageEntity(EntityHuman.java:612)
            at net.minecraft.server.EntityPlayer.damageEntity(EntityPlayer.java:213)
     
            at net.minecraft.server.Explosion.a(Explosion.java:150)
            at net.minecraft.server.World.createExplosion(World.java:1526)
            at net.minecraft.server.WorldServer.createExplosion(WorldServer.java:229
    )
            at net.minecraft.server.EntityCreeper.a(EntityCreeper.java:122)
            at net.minecraft.server.EntityCreature.m_(EntityCreature.java:70)
            at net.minecraft.server.EntityLiving.d(EntityLiving.java:944)
            at net.minecraft.server.EntityMonster.d(EntityMonster.java:27)
            at net.minecraft.server.EntityLiving.y_(EntityLiving.java:339)
            at net.minecraft.server.EntityMonster.y_(EntityMonster.java:31)
            at net.minecraft.server.EntityCreeper.y_(EntityCreeper.java:72)
            at net.minecraft.server.World.entityJoinedWorld(World.java:1256)
            at net.minecraft.server.WorldServer.entityJoinedWorld(WorldServer.java:1
    10)
            at net.minecraft.server.World.playerJoinedWorld(World.java:1238)
            at net.minecraft.server.World.tickEntities(World.java:1145)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:527)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:434)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Caused by: java.lang.reflect.InvocationTargetException
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:601)
            at org.bukkit.plugin.java.JavaPluginLoader$103.execute(JavaPluginLoader.
    java:1024)
            ... 24 more
    Caused by: java.lang.NullPointerException
            at me.icyrelic.com.ptk.PListener.PlayerDied(PListener.java:38)
            ... 29 more
    remember there are 3 errores in there 1 for all 2 if statements

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

    Digi

    First of all, store your stuff.

    The reason for those errors is that something is NULL and you're calling a method to it at line 38... check that line and see what might be null and check against null.
     
Thread Status:
Not open for further replies.

Share This Page