Filled KillHeart [1.10]

Discussion in 'Plugin Requests' started by BlockHeads36, Jul 26, 2016.

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


    Plugin category: Mechanics

    Minecraft version: Minecraft 1.10

    Suggested name: KillerHearts

    What I want: When you kill a player you will receive 2 temporary golden hearts. The hearts will stay for 15 seconds, if you kill another player within the 15 seconds, you get 2 more hearts and the timer resets again. I would not like having the effect icon show in the top right corner by the way!

    Ideas for commands and permissions:
    ~ /gheart set <player> <amount> [time] - gives the player gold hearts, if no time is given its set to 15 seconds.

    When I'd like it by: As soon as you have time.
  2. Offline

    I Al Istannen


    I am not doing this plugin, just asking some questions that came to my mind and might benefit somebody who wants to do this.

    The golden hearts can only be given through an effect. This means the client will know it has an effect and display the icon in the top right.
    I am quite sure you can't do anything against that, but I am fine with being contradicted :p

    You could add red hearts without making them appear, by modifying the attributes of the armor or the item in hand, but that would be unnecessarily complex.

    Why do you want to hide the icon?

    Should the golden hearts regenerate naturally?
    I am quite sure the normal absorption hearts do not, but I haven't played minecraft in a while.
  3. Offline


    @I Al Istannen, you're completely right on everything but adding red hearts. That's done through the player itself, not its armor with only 2 method calls. You just have to change the player displayed heart and health max up 4 points each.
    I Al Istannen likes this.
  4. Offline


    @I Al Istannen @Tecno_Wizard I wasn't sure if you could hide the effect, I am fine with the icon showing in the top right corner, I didn't no if you could make the hearts red, and no the hearts should not regenerate
  5. Last edited: Jul 30, 2016
  6. Offline


    @Jezzerdo4 Thanks!

    Edit: I didn't get the hearts when I killed someone :p
    Last edited: Jul 31, 2016
  7. Offline

    I Al Istannen

    Hey, thanks for doing the plugin :)
    As always, there are a few things worth improving.

    "logger = Logger.getLogger("Minecraft");"
    Do you watch the BcBroz? If yes, stop right here. In the offtopic are enough thread to the why, here is one. They just teach bad practises, like this one.
    You don't need minecrafts logger. Just using "getLogger()" in the onEnable will result in a nice logger, just for you!

    final PluginDescriptionFile pdFile = this.getDescription(); + " has been enabled!");
    Enable and Disable messages are already logged by Bukkit, even with the version. You don't need to log these.

    final PluginDescriptionFile pdFile = this.getDescription(); + " has been disabled!");
    Same as above.

    sender.sendMessage(ChatColor.DARK_AQUA + "Incorrect arguments!");
    sender.sendMessage(ChatColor.AQUA + "/gheart set <player> <level> [length] - Add Golden Hearts to a player!");
    sender.sendMessage(ChatColor.AQUA + "/gheart - Display this help menu!");
    You are sending these messages so often, that moving it in a method may be nicer.

    As you are only checking the name, using "Bukkit#getPlayer(name)" should work too. And is a bit more concise. If the result is null, the player was not found, else he was.

    int args2 = Integer.valueOf(args[2]);
    (the level of the effect)
    This can cause a "NumberFormatException", if the integer is not valid (e.g. "1fdfdf"). Either catch it or check before using some RegEx.
    I would move the conversion in a new method, taking a String and e.g. returning "null" if the exception occured or the number, if all went well.
    Then check that value and send a message accordingly.

    "args.length == 4"
    This will (I think) not be the case when you think it will. You have four arguments:
    "set <player> <level> [length]". If the length is 4, all were specified. If the length is 5, one more is given.

    "args.length == 5"
    Same as above.

    If "args2", "args3" and so on are your real variable names and not replaced by the decompiler, consider renaming them.

    Player killer = e.getEntity().getKiller();
    The killer doesn't have to be a player (zombie, slime, skeleton, ...) or even a player (arrow, potion, fall) and so on.
    You need to handle these cases differently.
    1. Check before casting!
    2. If the killer is an arrow or a potion, check if the shoort is a player and use the shooter, to allow arrows and potions to work.

    if (killer.hasPotionEffect(PotionEffectType.ABSORPTION)) {
        killer.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 300, 2));
    else {
        killer.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, 300, 1));
    This will only work with the first two kills. You can get the current level of Absorption the player has, and just add one to it. This way it will work with any number of kills.
    But, depending on how @BlockHeads36 meant it (and minecraft works. I don't know), you may need to check how many absorption hearts are left and ensure only two are added.

    Have a nice day and good luck :)
  8. @I Al Istannen

    Okay so,

    Thanks for the advice.

    1 and 2. The logger, I know you can do it the way you said and I know bukkit has it but it's just my personal preference.

    3. I know and I need to this.

    4. Again, I know you can do this just I normally do it the way I have as that's the way I normaly do and am use to to typing it and type it faster.

    5. How would I check this is a number?

    6. Well, that's just me failing to count.

    7. I didn't know this could happen, thank you for telling me.

    8. The OP doesn't say about anymore then one time, so I was thinking he/she meant up too 2. Also How do I check what level they have, I couldn't find a way to do this.

    Thanks you!

    Will chabge what your said ASAP


    I don't know why that is. However this will NOT be tested as I have no one to test it with and I will not be testing 1.10 plugins much if at all as I play 1.7/1.8 (as do all my friends) so only have a proper testing server the those versions.
  9. @Jezzerdo4
  10. @AlvinB

    Yep, done that but working on 8, are you able to help with that?
    Last edited: Aug 1, 2016
  11. Offline


  12. Offline

    I Al Istannen

  13. *Facepalm*

    @I Al Istannen

    Sorry point number 8.

    EDIT: I'll have a friend who can help me test it later.
  14. @Jezzerdo4 If by level you mean xp level, Player#getLevel()
  15. @bwfcwalshy

    No, the level of a potion effect (in this case absorrtion.
  16. @Jezzerdo4 Go through the action potion effects and get the absorption then use PotionEffect#getAmplifier()
  17. @bwfcwalshy Thanks but how do I get the absorption?
    Last edited: Aug 1, 2016
  18. Offline


    @Jezzerdo4 Thanks for continuing to work on the plugin!
  19. Offline

    I Al Istannen

  20. Offline


Thread Status:
Not open for further replies.

Share This Page