Get rid of the ending of a death message

Discussion in 'Plugin Development' started by BajanAmerican, Jul 20, 2014.

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

    BajanAmerican

    Hey guys,

    Short and simple, I need to figure out how to get out the end of a death message. For example, when a player killed another player the death message is "<player> was slain by <player> using [ItemStack]". Everyone knows that, it is how the game is designed. My problem is that I cannot get rid of the ending where it states the ItemStack name. Other than that, I also wanted to make the death message custom without going through every single situation; therefore, making my code a long and unorganized mess. Here is the code I tried to use (please disregard all the object I am using, it is for a minigame):

    Code:java
    1. if(event.getDeathMessage().contains(victim.getName()) && event.getDeathMessage().contains(victim.getKiller().getName()))
    2. {
    3. if(victim.getKiller() instanceof Player)
    4. {
    5. //Player attacker = (Player) victim.getKiller();
    6. String victimName = event.getDeathMessage().substring(0, victim.getName().length());
    7. String deathMSG = event.getDeathMessage().substring(victim.getName().length(), (event.getDeathMessage().length() - victim.getKiller().getName().length()));
    8. String attackerName = event.getDeathMessage().substring((victim.getName().length() + deathMSG.length()), event.getDeathMessage().length());
    9. CWPlayer cwpattacker = CWPlayer.getCWPlayer(victim.getKiller());
    10. cwpattacker.setKills(cwpattacker.getKills() + 1);
    11. if(Methods.isRanked(victim.getKiller()))
    12. cwpattacker.setPoints(cwpattacker.getPoints() + 8);
    13. else
    14. cwpattacker.setPoints(cwpattacker.getPoints() + 5);
    15. if(CW.getInstance().getBlueTeam().contains(victim.getName()))
    16. {
    17. event.setDeathMessage(ChatColor.DARK_BLUE + victimName + ChatColor.YELLOW + deathMSG + ChatColor.DARK_RED + attackerName);
    18. CW.getInstance().getGame().setRedKills(CW.getInstance().getGame().getRedKills() + 1);
    19. }
    20. else
    21. {
    22. event.setDeathMessage(ChatColor.DARK_RED + victimName + ChatColor.YELLOW + deathMSG + ChatColor.DARK_BLUE + attackerName);
    23. CW.getInstance().getGame().setBlueKills(CW.getInstance().getGame().getBlueKills() + 1);
    24. }
    25. CW.getInstance().getPlayerKillStreaks().put(victim.getKiller().getName(), CW.getInstance().getPlayerKillStreaks().get(victim.getKiller().getName()) + 1);
    26. CW.getInstance().getPlayerKillStreaks().put(victim.getName(), 0);
    27. if(CW.getInstance().getPlayerKillStreaks().get(victim.getKiller().getName()) == 3)
    28. {
    29. victim.getKiller().getInventory().addItem(CW.getInstance().getClasses().killStreak3);
    30. if(CW.getInstance().getBlueTeam().contains(victim.getKiller().getName()))
    31. Bukkit.broadcastMessage(ChatColor.DARK_BLUE + "" + ChatColor.BOLD + victim.getKiller().getName() + ChatColor.WHITE + "" + ChatColor.BOLD + " HAS RECIEVED A " + ChatColor.GOLD + "" + ChatColor.BOLD + "BAZOOKA");
    32. else
    33. Bukkit.broadcastMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + victim.getKiller().getName() + ChatColor.WHITE + "" + ChatColor.BOLD + " HAS RECIEVED A " + ChatColor.GOLD + "" + ChatColor.BOLD + "BAZOOKA");
    34. }
    35. else if(CW.getInstance().getPlayerKillStreaks().get(victim.getKiller().getName()) == 5)
    36. {
    37. victim.getKiller().getInventory().addItem(CW.getInstance().getClasses().killStreak5);
    38. if(CW.getInstance().getBlueTeam().contains(victim.getKiller().getName()))
    39. Bukkit.broadcastMessage(ChatColor.DARK_BLUE + "" + ChatColor.BOLD + victim.getKiller().getName() + ChatColor.WHITE + "" + ChatColor.BOLD + " HAS RECIEVED A " + ChatColor.GOLD + "" + ChatColor.BOLD + "" + ChatColor.UNDERLINE + "TnT Strike");
    40. else
    41. Bukkit.broadcastMessage(ChatColor.DARK_RED + "" + ChatColor.BOLD + victim.getKiller().getName() + ChatColor.WHITE + "" + ChatColor.BOLD + " HAS RECIEVED A " + ChatColor.GOLD + "" + ChatColor.BOLD + "" + ChatColor.UNDERLINE + "TnT Strike");
    42. }
    43. }
    44. }
    45. else
    46. {
    47. String deathMSG = event.getDeathMessage().substring(victim.getName().length(), event.getDeathMessage().length());
    48. if(CW.getInstance().getBlueTeam().contains(victim.getName()))
    49. {
    50. event.setDeathMessage(ChatColor.DARK_BLUE + victim.getName() + ChatColor.YELLOW + deathMSG);
    51. CW.getInstance().getGame().setRedKills(CW.getInstance().getGame().getRedKills() + 1);
    52. }
    53. else
    54. {
    55. event.setDeathMessage(ChatColor.DARK_RED + victim.getName() + ChatColor.YELLOW + deathMSG);
    56. CW.getInstance().getGame().setBlueKills(CW.getInstance().getGame().getBlueKills() + 1);
    57. }
    58. CW.getInstance().getPlayerKillStreaks().put(victim.getName(), 0);
    59. }


    If anyone could give me any insight on how to complete this task it would be very appreciated. Thanks guys!
     
  2. Offline

    mine-care

    wait if you want to get rifd of de itemstack you have to set the message to damager killed dead, to cancel it completely use setdeathmessage Null
     
  3. Offline

    Flegyas

    I'm sorry but I didn't understand the real problem, do you want to remove the death message part about the item used to kill?
     
  4. Offline

    Ridgepig

    Is this what you mean?
    Code:
    String deathMSG = event.getDeathMessage();
    String killerName = victim.getKiller().getName();
    deathMSG = deathMSG.substring(0, deathMSG.indexOf(killerName) + killerName.length());
    
     
Thread Status:
Not open for further replies.

Share This Page