Death Message

Discussion in 'Plugin Requests' started by iNasserDev, Jan 15, 2018.

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

    iNasserDev

    i need plugin death message i can custom it like when player kill another player i want them to say [X] Player Killed By iNasserDev not Player was slain by iNasserDev
     
  2. Have you tried looking this up? If you're having trouble I can google it for you and send you the link... but it should be self-explanatory.

    Basically everyone here doesn't make a plugin for you if exactly what you describe already exists... unless you have a significant enough problem with the existing plugin.
     
  3. Hey iNasserDev,

    i'm a new Developer and i'm trying some things out. So did I with your plugin suggestion, here is your plugin.

    Functions:
    - Customizable death-message with colors
    - normal death-message is disabled

    Placeholder:
    %KILLER - killer
    %VICTIM - victim

    I know it isn't that much, but it was a nice little task for me^^

    EDIT: Changed the death-message only for playerkills!
     
    Last edited: Jan 16, 2018
  4. @FlaveDrake , I was wondering if you could send a link for the source code to that plugin, it's just I'm fairly new to Bukkit and wanted to see how you made the placeholders.
     
  5. @615283, of course but i don't know how to link sources, so i have to send you my code:

    Code:java
    1.  
    2. package com.FlaveDrake.DeathMessage.listener;
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.configuration.file.FileConfiguration;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.entity.PlayerDeathEvent;
    10.  
    11. import com.FlaveDrake.DeathMessage.main.Main;
    12.  
    13. public class DeathMessageListener implements Listener {
    14.  
    15. public static String colorize(String msg) {
    16. String coloredMsg = "";
    17. for (int i = 0; i < msg.length(); i++) {
    18. if (msg.charAt(i) == '&')
    19. coloredMsg += '§';
    20. else
    21. coloredMsg += msg.charAt(i);
    22. }
    23. return coloredMsg;
    24. }
    25.  
    26. @EventHandler
    27. public void onDeath(PlayerDeathEvent e) {
    28. Player victim = e.getEntity();
    29. Player killer = victim.getKiller();
    30. FileConfiguration cfg = Main.getPlugin().getConfig();
    31. String deathmessage = cfg.getString("Messages.death-message");
    32. if (deathmessage != null && killer != null) {
    33. e.setDeathMessage(null);
    34. deathmessage = deathmessage.replaceAll("%KILLER", killer.getName()).replaceAll("%VICTIM", victim.getName()); //This is how i made placeholder
    35. Bukkit.broadcastMessage(colorize(deathmessage));
    36. }
    37. }
    38. }
    39.  


    EDIT

    Hope i could helped you out, if you have any questions pm me.
     
  6. Offline

    Protophite

    @FlaveDrake
    You can use ChatColor#translateAlternateColorCode("§", msg);

    Also it's a good practice to load informartion from config on enable instead of everytime the event triggers.
    Other than that, good logic.
     
Thread Status:
Not open for further replies.

Share This Page