Death Messages

Discussion in 'Spigot Plugin Development' started by Carloswasthere, Jun 7, 2015.

  1. I have a error when the player death, nothing how do:

    If player death by fall:
    Code (Text):
                e.setDeathMessage(""+name+"" + ChatColor.GRAY + "cayó de muy alto" + ChatColor.BLUE + " (" + ChatColor.GRAY + Math.round(e.getEntity().getFallDistance()) / 1L + " bloques" + ChatColor.BLUE + ")" );
    If player death fall by killer:
    Code (Text):
                e.setDeathMessage(""+killer+"" + ChatColor.GRAY + "empujó de muy alto a " + ChatColor.RESET + ""+name+"" + ChatColor.BLUE + " (" + ChatColor.GRAY + Math.round(e.getEntity().getFallDistance()) / 1L + " bloques" + ChatColor.BLUE + ")" );
    Here the code of use for death messages:

    Code (Text):
            if(cause == EntityDamageEvent.DamageCause.FALL)
            {
                e.setDeathMessage(""+name+"" + ChatColor.GRAY + "cayó de muy alto" + ChatColor.BLUE + " (" + ChatColor.GRAY + Math.round(e.getEntity().getFallDistance()) / 1L + " bloques" + ChatColor.BLUE + ")" );
            }
            else if(cause == EntityDamageEvent.DamageCause.FALL){
                e.setDeathMessage(""+killer+"" + ChatColor.GRAY + "empujó de muy alto a " + ChatColor.RESET + ""+name+"" + ChatColor.BLUE + " (" + ChatColor.GRAY + Math.round(e.getEntity().getFallDistance()) / 1L + " bloques" + ChatColor.BLUE + ")" );
            }
     
  2. What is the error?
     
  3. Error console and shows no message.
     
  4. Omnivion

    Patron

    But what is the error to console?
     
  5. New code:
    Code (Text):
    package carlos.was.there.gmail.com;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Sound;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.PlayerDeathEvent;

    public final class MensajesDeMuerte implements Listener
    {
       
              @EventHandler
      public void deathEvent(PlayerDeathEvent e)
      {
          Player p = e.getEntity().getPlayer();
          Player k = p.getKiller();
          String name = p.getName();
          String killer = p.getKiller().getName();
          EntityDamageEvent de = p.getLastDamageCause();
          EntityDamageEvent.DamageCause cause = de.getCause();
          p.playSound(p.getLocation(), Sound.ENDERDRAGON_GROWL, 5, 5);
          k.playSound(k.getLocation(), Sound.LEVEL_UP, 5, 5);
         
          if (k instanceof Player){
          e.setDeathMessage(ChatColor.GRAY + "[" + ChatColor.DARK_RED + Math.round(k.getHealth()) / 1L + "❤" + ChatColor.GRAY + "] " + ChatColor.RESET + p.getName() + ChatColor.GRAY + " fue asesinado por " + ChatColor.RESET + k.getName());
            }
            if(cause == EntityDamageEvent.DamageCause.FALL)
            {
                e.setDeathMessage(""+name+"" + ChatColor.GRAY + " cayó de muy alto" + ChatColor.BLUE + " (" + ChatColor.GRAY + Math.round(e.getEntity().getFallDistance()) / 1L + " bloques" + ChatColor.BLUE + ")" );
            }
            else if(cause == EntityDamageEvent.DamageCause.STARVATION){
                e.setDeathMessage(""+name+"" + ChatColor.GRAY + " no le compró arepas a Tiflayn");
            }
            else if (cause == EntityDamageEvent.DamageCause.VOID){
                e.setDeathMessage(""+name+"" + ChatColor.GRAY + " cayó al vacio.");
            }
            else if (cause == EntityDamageEvent.DamageCause.PROJECTILE){
                e.setDeathMessage(ChatColor.GRAY + "[" + ChatColor.DARK_RED + Math.round(k.getHealth()) / 1L + "❤" + ChatColor.GRAY + "] " + ChatColor.RESET + ""+name+"" + ChatColor.GRAY + " fue impactado por un proyectíl de " + ChatColor.RESET + k.getName() + ".");
            }
            else if (cause == EntityDamageEvent.DamageCause.BLOCK_EXPLOSION){
                e.setDeathMessage(""+name+"" + ChatColor.GRAY + " fue alcanzado por una explosión");
            }
            else if (cause == EntityDamageEvent.DamageCause.LAVA){
                e.setDeathMessage(""+name+"" + ChatColor.GRAY + " nadó el lava pero se derritió");
            }
            else if (cause == EntityDamageEvent.DamageCause.SUICIDE){
                e.setDeathMessage(""+name+"" + ChatColor.GRAY + " se suicidó.");
            }
            else if (cause == EntityDamageEvent.DamageCause.DROWNING){
                e.setDeathMessage(""+name+"" + ChatColor.GRAY + "olvidó respirar.");
            }
         
        }
       
    }
     

    This error:
    Code (Text):
    2015-06-07 19:45:41 [SEVERE] Could not pass event PlayerDeathEvent to EsencialPlugin v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:478)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:463)
        at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:361)
        at net.minecraft.server.v1_5_R3.EntityPlayer.die(EntityPlayer.java:294)
        at net.minecraft.server.v1_5_R3.EntityLiving.damageEntity(EntityLiving.java:764)
        at net.minecraft.server.v1_5_R3.EntityHuman.damageEntity(EntityHuman.java:684)
        at net.minecraft.server.v1_5_R3.EntityPlayer.damageEntity(EntityPlayer.java:359)
        at net.minecraft.server.v1_5_R3.EntityLiving.x(EntityLiving.java:355)
        at net.minecraft.server.v1_5_R3.Entity.l_(Entity.java:262)
        at net.minecraft.server.v1_5_R3.EntityLiving.l_(EntityLiving.java:511)
        at net.minecraft.server.v1_5_R3.EntityHuman.l_(EntityHuman.java:158)
        at net.minecraft.server.v1_5_R3.EntityPlayer.g(EntityPlayer.java:225)
        at net.minecraft.server.v1_5_R3.PlayerConnection.a(PlayerConnection.java:354)
        at net.minecraft.server.v1_5_R3.Packet10Flying.handle(SourceFile:136)
        at org.spigotmc.netty.NettyNetworkManager.b(NettyNetworkManager.java:239)
        at net.minecraft.server.v1_5_R3.PlayerConnection.d(PlayerConnection.java:115)
        at net.minecraft.server.v1_5_R3.ServerConnection.b(SourceFile:35)
        at org.spigotmc.MultiplexingServerConnection.b(MultiplexingServerConnection.java:61)
        at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:583)
        at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:233)
        at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:472)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:404)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NullPointerException
        at carlos.was.there.gmail.com.MensajesDeMuerte.deathEvent(MensajesDeMuerte.java:22)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 25 more
    2015-06-07 19:45:41 [INFO] Carloswasthere drowned
     
  6. Omnivion

    Patron

    Make sure p.getKiller() isn't null, and is actually a player.
     
  7. Use:
    e.getEntity().getPlayer().getKiller()
    ?
     
  8. Revisa la línea 22 de tu código, ese es el error que manda.
     
  9. Si, gracias :D
    Solucionado.


    Code (Text):
                p.playSound(p.getLocation(), Sound.ENDERDRAGON_GROWL, 5, 5);
                k.playSound(k.getLocation(), Sound.LEVEL_UP, 5, 5);
     
  10. Como hago para agregar dos mensajes de muerte, uno por el asesino y otro natural..
    How do for add two death messages, one for the killer and other natural


    Only have the natural death:

    Code (Text):
            else if(cause == EntityDamageEvent.DamageCause.FALL)
            {
                e.setDeathMessage(p.getName() + ChatColor.GRAY + " cayó de muy alto" + ChatColor.BLUE + " (" + ChatColor.GRAY + Math.round(e.getEntity().getFallDistance()) / 1L + " bloques" + ChatColor.BLUE + ")" );
            }
     
  11. Trata esto:
    Code (Text):

    @EventHandler
        public void ondied (PlayerDeathEvent e) {
            // Un jugador cualquiera
            if(e.getEntity().getKiller() instanceof Player) {
                e.setDeathMessage(e.getEntity().getName() + " fue asesinado brutalmente por " + e.getEntity().getKiller().getName());
                return;
            }
            // Una muerte cualquiera
            if(!(e.getEntity().getKiller() instanceof Player)) {
                e.setDeathMessage(e.getEntity().getName() + " fue asesinado brutalmente por una razón desconocida");
                return;
            }
        }
    }

     
     
  12. It is always a Player.
     
  13. Omnivion

    Patron

    Code (Text):
    @EventHandler
      public void deathEvent(PlayerDeathEvent e)
      {
          Player p = e.getEntity().getPlayer();
          Player k = p.getKiller();
    I don't think so... And that was the code I was quoting.
     
  14. It's return type is always Player. Hence instanceof bears no meaning. A null check is all you need.
     
  15. Omnivion

    Patron

    Oh, you're right. My bad.
     
  16. Not work ):
    When a player have a STONE_SWORD in inventory and pickup other STONE_SWORD, remove one STONE_SWORD.
    Code (Text):
          public void onPickupItem(PlayerPickupItemEvent e)
          {
              Player p = e.getPlayer();
              Inventory inventory = e.getPlayer().getInventory();
            if(p.getInventory().contains(Material.STONE_SWORD, 1)){
                inventory.removeItem(new ItemStack (Material.STONE_SWORD, 1));
            }
          }
     
  17. I assume this would work:
    Code (Java):
        public void onPickupItem(PlayerPickupItemEvent e) {
            Player p = e.getPlayer();
            PlayerInventory inventory = p.getInventory();
            if (e.getItem() != null) {
                if (e.getItem().getItemStack().getType() == Material.STONE_SWORD) {
                    if (inventory.containsAtLeast(new ItemStack(
                            Material.STONE_SWORD), 1)) {
                        e.setCancelled(true);
                    }
                }
            }
        }
     
  18. Not work ):
     
  19. Asegúrate de que registras sus eventos en el onEnable() método; proximo asegúrate usando el "Player p" en el evento. Yo veo que hablas en espanol y un poco ingles. xD

    English: Make sure that you register your events in the onEnable() method; next make sure you're using el "Player p" en the event (that you use to send the messages). I see that you speak Spanish and little English. xD
     
  20. Jajaja, correcto, ya está hecho, aún así, los usuarios continúan recogiendo los items.