Custom death messages?

Discussion in 'Plugin Development' started by AppleMC, Feb 18, 2013.

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

    AppleMC

    Anyone know how to set custom death messages for different events? lava death, player killing player, fell?
     
  2. Offline

    CubixCoders

    Listen for PlayerDeathEvent and check if event.getCause == DamageCause.LAVA or something then use
    event.setDeathMessage("");
     
  3. Offline

    AppleMC

    CubixCoders Ok thanks! Bee-tee-dubs do you know how to set & color codes for chat and configuration files? Ive been trying to figure it out..
     
  4. Offline

    CubixCoders

    I believe it is
    ChatColor.translateAlternateColorCodes("&", string);
    So through the config, you would just have to do this
    player.sendMessage(ChatColor.translateAlternateColorCodes("&", getConfig().getString(yourpath)));
     
  5. Offline

    david_rosales

    Or u can listen for death and do this:

    Code:java
    1.  
    2. if(event.getDeathMessage().contains("hit the ground to hard")
    3. {
    4. event.setDeathMessage(ChatColor.DARK_GRAY + event.getEntity() + ChatColor.GRAY + " fell a very long distance");
    5. }
    6.  
     
  6. Offline

    AppleMC

    CubixCoders where would I put it?.. If possible can you show me a example in a whole code?... just a simple one..

    david_rosales Ok thanks, if the other doesnt work, I'll always have your code xD

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

    CubixCoders

    AppleMC
    Code:java
    1.  
    2. if(cmd.getName().equalsIgnoreCase("clan")){
    3. if(args[0].equalsIgnoreCase("list")){
    4. for(String s: getConfig().getStringList("Clan.List")){
    5. sender.sendMessage(ChatColor.Blue + "The clans are: " + ChatColor.translateAlternateColorCodes("&", s));
    6. }
    7. }
    8. }
    9.  

    That will check if they sent "clan" as their command, then if their arg is "list", then it will get a list from the config named Clan.List and then translate the codes to them
     
  8. Offline

    AppleMC

    CubixCoders I mean players chatting with & codes, and can give me whole thing starting from @EventHandler for death message please?
     
  9. Offline

    CubixCoders

    Code:java
    1.  
    2. @EventHandler
    3. public void onDeath(PlayerDeathEvent e){
    4. if(e.getDeathMessage().contains("hit the ground")){
    5. e.setDeathMessage("Whatever");
    6. }
    7. }
    8.  

    And for chatting
    Code:java
    1.  
    2. @EventHandler
    3. public void onTalk(PlayerChatEvent e){
    4. e.setMessage(ChatColor.translateAlternateColorCodes("&", e.getMessage()));
    5. }
    6.  
     
  10. Offline

    AppleMC

    CubixCoders the color code is for ALL codes? 123456789abcdef

    CubixCoders can you tell me whats wrong with this? sender is getting error
    Code:
        @EventHandler
        public void onDeath(PlayerDeathEvent e) {
            if(e.getDeathMessage().contains("hit the ground too hard")) {
                Player player = (Player) sender;
                e.setDeathMessage(ChatColor.GOLD + player.getName() + ChatColor.DARK_RED + " didn't see where he was going and fell off a cliff.")
            }
    CubixCoders and the color code is giving me error at translateAlternativeColorCodes
    Code:
        @EventHandler
        public void onTalk(PlayerChatEvent e){
            e.setMessage(ChatColor.translateAlternateColorCodes("&", e.getMessage()));
        }
    Btw how do u insert java code so it looks like that xD

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

    CubixCoders

    Code:java
    1.  
    2.  
    3. e.setMessage(ChatColor.translateAlternateColorCodes('&', e.getMessage()));
    4.  
    5.  

    There is no sender, you have to use Player player = e.getEntity();
    And for the cool writing use (syntax=java) (/syntax) but replace () with []
     
  12. Offline

    AppleMC

    @CubixCodes thanks, but im getting this thing with yellow line saying add supression and stuff for translatecodes
     
  13. Offline

    CubixCoders

    It doesn't matter Go ahead and add it if you want
     
  14. Offline

    AppleMC

    @CubixCodes OMG THANK YOU they all work, does color code work for configuration files? Also how would I use config file for death message? and color code &k does it to my name too, possible to change?
     
  15. Offline

    CubixCoders

    just change the string you set it to, to plugin.getConfig().getString(path);
     
  16. Offline

    AppleMC

    CubixCoders but if I use the & codes for message, does it show up with color ? and when i use &k, &l it changes my name too any way to stop that?
     
  17. Offline

    CubixCoders

    Code:java
    1.  
    2. @EventHandler
    3. public void onTalk(PlayerChatEvent e){
    4. e.setMessage(e.getPlayer().getDisplayName() + ChatColor.translateAlternateColorCodes("&", e.getMessage()));
    5. }
    6.  
     
  18. Offline

    AppleMC

    CubixCoders lets say i have config lava death: &4died from lava. does that show as DARK_RED died from lava?
    and the alternativeTranslateColor is getting error for the new one..

    @CubixCodes i fixed the error but it shows my name twice when msging with color now..

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

    CubixCoders

    Sorry, i keep doing "&" it's '&', then if you get rid of the event.getPlayer().getDisplayName() isn't that what your old prblem was?
     
  20. Offline

    AppleMC

    CubixCoders i mean it shows name but if i use &k and &l it does random / bold to my name too
     
  21. Offline

    CubixCoders

    Try
    player.setDisplayName(ChatColor.WHITE + player.getDisplayName());
    But that will automatically set it to white no matter what
     
  22. Offline

    AppleMC

    CubixCoders thanks :3 but the death messages arent working with config..
     
  23. Offline

    CubixCoders

    You have to get the message from the config and translate the codes
     
  24. Offline

    AppleMC

    CubixCoders I tried without the & codes from config but didnt work..
     
  25. Offline

    CubixCoders

    Show code please
     
  26. Offline

    AppleMC

    Code:java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent e) {
    3. if(e.getDeathMessage().contains("hit the ground too hard")) {
    4. Player player = e.getEntity();
    5. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    6. } else if (e.getDeathMessage().contains("drowned")) {
    7. Player player = e.getEntity();
    8. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    9. } else if (e.getDeathMessage().contains("swim in lava")) {
    10. Player player = e.getEntity();
    11. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    12. } else if (e.getDeathMessage().contains("struck by lightning")) {
    13. Player player = e.getEntity();
    14. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    15. } else if (e.getDeathMessage().contains("blew up") || e.getDeathMessage().contains("blown up")) {
    16. Player player = e.getEntity();
    17. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    18. } else if (e.getDeathMessage().contains("went up in flames") || e.getDeathMessage().contains("burned to death")) {
    19. Player player = e.getEntity();
    20. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    21. } else if (e.getDeathMessage().contains("shot")) {
    22. Player player = e.getEntity();
    23. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    24. } else if (e.getDeathMessage().contains("pricked to death") || e.getDeathMessage().contains("walked into a cactus")) {
    25. Player player = e.getEntity();
    26. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    27. } else if (e.getDeathMessage().contains("falling anvil")) {
    28. Player player = e.getEntity();
    29. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    30. } else if (e.getDeathMessage().contains("starved")) {
    31. Player player = e.getEntity();
    32. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    33. } else if (e.getDeathMessage().contains("suffocated in")) {
    34. Player player = e.getEntity();
    35. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    36. } else if (e.getDeathMessage().contains("was killed while trying")) {
    37. Player player = e.getEntity();
    38. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    39. } else if (e.getDeathMessage().contains("fell out of the world")) {
    40. Player player = e.getEntity();
    41. e.setDeathMessage(ChatColor.GOLD + player.getName() + " " + ChatColor.DARK_RED + plugin.getConfig().getString("Lava death"));
    42. }

    LOL first time using - fail... and do u know how to set up alias commands in plugin.yml? alias: [alias] isnt workign for me
     
  27. Offline

    CubixCoders

    Code:java
    1.  
    2. ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("Lava death"));
    3.  
     
  28. Offline

    AppleMC

    CubixCoders I tried just without the & code though, chatcolor already in code and just message, it gave error... do u know how to set alias for command? i tried alias: [alias] didnt work..
     
  29. Offline

    CubixCoders

    You didn't translate the codes from the config, and does the String "Lava death" exist in the config? and sorry idk about alias's D:
     
  30. Offline

    AppleMC

    CubixCoders yeah i have Lava death in my config file.. :/
     
Thread Status:
Not open for further replies.

Share This Page