Custom death messages help

Discussion in 'Spigot Plugin Development' started by ProJoosh, May 29, 2015.

  1. Code (Text):
        //Player on death
        @EventHandler
        public void death(PlayerDeathEvent e) {
            Player dead = e.getEntity().getPlayer(); //get the guy who was killed
            Player killer = e.getEntity().getKiller(); //Get killer
            e.getDrops().clear(); //Clear drops
            e.setDroppedExp(0);
           
            if(TournamentPVP.INSTANCE.getConfig().getBoolean("Settings.killHearts")){
                int heartsGain = TournamentPVP.INSTANCE.getConfig().getInt("Settings.killHeartsGain") * 2;
                if(killer.getHealth() <= killer.getMaxHealth() - heartsGain){
                    killer.setHealth(killer.getHealth() + heartsGain);
                }else{
                    killer.setHealth(killer.getMaxHealth());
                }
            }
           
            if(e.getDeathMessage().contains("drown")) {
                e.setDeathMessage(ChatColor.RED + dead.getName() + ChatColor.GOLD + " drowned.");
                sendTitle(dead, ChatColor.GOLD + "-" + pointsDeath + " Points", ChatColor.GOLD + "You died from drowning.", 2,2,1);
                dead.getWorld().playEffect(dead.getLocation(), Effect.EXPLOSION, 10);
                dead.playSound(dead.getLocation(), Sound.BLAZE_DEATH, 30, 30);
                e.getEntity().getPlayer().getLocation().getWorld().playEffect(e.getEntity().getPlayer().getLocation(), Effect.EXPLOSION_HUGE, 50);
                changePointsSuicide(dead);
            }
            //Fell from fall damage
            if(e.getDeathMessage().contains("high place") || e.getDeathMessage().contains("fell from") || e.getDeathMessage().contains("fell")) {
                    e.setDeathMessage(ChatColor.RED + dead.getName() + ChatColor.GOLD + " hit the ground too hard.");
                    sendTitle(dead, ChatColor.GOLD + "-" + pointsDeath + " Points", ChatColor.GOLD + "You died from fall damage.", 2,2,1);
                    changePointsSuicide(dead);
            //Shot by player
            }
            if(e.getDeathMessage().contains("shot by") || e.getDeathMessage().contains("shot")) {
                    e.setDeathMessage(ChatColor.RED + dead.getName() + ChatColor.GOLD + " was shot by " + ChatColor.RED + killer.getName() + ChatColor.GOLD + ".");
                    sendTitle(killer, ChatColor.GOLD + "+" + pointsKill + " Points", ChatColor.GOLD + "You shot to death " + dead.getName(), 2,2,1);
                    sendTitle(dead, ChatColor.GOLD + "-" + pointsDeath + " Points", ChatColor.GOLD + "You were shot to death by " + killer.getName(), 2,2,1);
                    changePoints(dead, killer);
            }
            if(e.getDeathMessage().contains("slain by") || e.getDeathMessage().contains("killed")) {
                    e.setDeathMessage(ChatColor.RED + dead.getName() + ChatColor.GOLD + " has been slain by " + ChatColor.RED + killer.getName() + ChatColor.GOLD + ".");
                    sendTitle(killer, ChatColor.GOLD + "+" + pointsKill + " Points", ChatColor.GOLD + "You killed " + dead.getName(), 2,2,1);
                    sendTitle(dead, ChatColor.GOLD + "-" + pointsDeath + " Points", ChatColor.GOLD + "You were killed by " + killer.getName(), 2,2,1);
                    dead.playSound(dead.getLocation(), Sound.BLAZE_DEATH, 30, 30);
                    killer.playSound(dead.getLocation(), Sound.BLAZE_DEATH, 30, 30);
                    changePoints(dead, killer);
                //Pricket to death
            }
            if(e.getDeathMessage().contains("pricked")) {
                e.setDeathMessage(ChatColor.RED + dead.getName() + ChatColor.GOLD + " was pricked to dead.");
                sendTitle(dead, ChatColor.GOLD + "-" + pointsDeath + " Points", ChatColor.GOLD + "You died from a cactus.", 2,2,1);
                dead.getWorld().playEffect(dead.getLocation(), Effect.EXPLOSION, 10);
                dead.playSound(dead.getLocation(), Sound.BLAZE_DEATH, 30, 30);
                e.getEntity().getPlayer().getLocation().getWorld().playEffect(e.getEntity().getPlayer().getLocation(), Effect.EXPLOSION_HUGE, 50);
                changePointsSuicide(dead);
            }
           
            updateScoreboard();
            doValidCheck();
        }
       
    So i have this code in my plugin to do custom drown messages but 100% of the time and sometimes the fell from a high place message dosnt work, Any way to fix this or alternatives.
     
  2. I use the EntityDamageEvent and get the Damage Cause :)

    Edit: Also in your currect code you can check the last damage cause it should be the same :):)
     
  3. I mean maybe it could better got stabbed and player got skydiving without down by now well i like player death or chopped also be for a funny if you said like played also be it was on but down by now well i messages. I mean maybe it want there that had that and in half. it could and player well i mean maybe funny if you said liked think it could betty funny reason you said like player went that you said like player well i there was actually one of my first minecraft skydiving without a funny if yo
     
  4. Whats o_O
     
  5. Inkzzz

    Resource Staff

    #getLastDamageCause()
     
  6. It's what I actually just said :cool:
     
  7. Inkzzz

    Resource Staff

    Sorry bud, didn't see that haha
     
  8. so like if(dead.getLastDamageCause() == DamageCause.DROWNING)
     
  9. Inkzzz

    Resource Staff

    Yes!
     
  10. Check if (e.getEntity().getKiller() != null), that means that killer is a player, if it was null it was either a Mob or something like Fall damage, drowning, etc
     
  11. whats the DamageCause.<name> for sword damage?
     
  12. That would just count as the player killing them I believe.
     
  13. There is no such thing you can test if killer item in hand is a sword
     
  14. Yes actually, you can.

    Code (Text):
    if (e.getEntity().getKiller().getItemInHand().getType().toString().endsWith("SWORD")) {


    // killer used sword to kill


    }
     
  15. couldnt i just do if(dead.getLastDamageCause() == killer)
     
  16. I have never tried that, but both should work the same way.
     
  17. the get last damage cause dosnt work.
     
  18. Don't access your configuration this way... Use a constructor..
     
  19. this still works though.
     
  20. Yes, but the way you are doing it is wrong. You should only use static in certain cases. This is not one of them.