DurabilityAlert

Discussion in 'Plugin Requests' started by Dark_Serpent, Mar 30, 2016.

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

    Dark_Serpent

    Plugin category: Mechanic, Informational

    Suggested name: DurabilityAlert

    What I want: I'd like a plugin that warned you via chat how much durability an item has left in percentage when it reached a certain point. (Armor, Swords, Bows, Pickaxes, Axes, Hoes, Shovels, Fishing Pole)

    Image for example:
    Show Spoiler

    [​IMG]


    The alert should pop up at 30%, 15%, and 5%.

    As well, an alert should be sent if your item has broken.

    Image for example:
    Show Spoiler

    [​IMG]


    Ideas for commands: None needed.

    Ideas for permissions: None needed.

    When I'd like it by: Whenever possible! Thank you to anyone who picks this up! :D

    Additional Notes: This plugin must be compatible for 1.7.10. In addition, while there are other plugins like or similar to this, they are no longer operational and being maintained.
     
    Last edited: Mar 30, 2016
  2. Offline

    StarRocket

    I can do this.
     
  3. Offline

    Dark_Serpent

    Alright, thank you so much! If you need any information I'll be happy to supply it of course :)
     
  4. Offline

    StarRocket

    @Dark_Serpent Made good progress today with the time I had to code, armor, tools, and swords all give alerts and I worked on fishing rods but they are pretty buggy, so I need to find a better way to handle them. Should be done tomorrow hopefully.

    EDIT: Finished, here is link. Fishing rods are still somewhat buggy even though I have improved the rate of it sending a message. All other items you requested appear to be working smoothly. Although not requested, there is a command with which you can reload the plugin config because I decided to make the [Alert] part of the message configurable. The command is /durablityalert reload. Aliases of /da or /duraalert. Permission for reloading is durabilityalert.admin, which defaults to OP. Also, if you do not mind, I would like to put this on bukkitdev because I like how it works, and as you said there are currently no working ones.

    One more note - I tested this on a 1.8 server and it should be totally compatible with your 1.7, but if not, I can rewrite with a 1.7 api. If I get fishing rods working better than they currently are, I'll update this.
     
    Last edited: Mar 31, 2016
  5. Offline

    Dark_Serpent

    Thank you so much! I'll begin testing it out ASAP, and to answer your question, I don't mind at all! Feel free to do whatever you'd like with it!

    EDIT: @StarRocket Do you think you could make it so each percentage warning only shows up once per armor?
     
    Last edited: Mar 31, 2016
  6. Offline

    StarRocket

    @Dark_Serpent I am unsure what you mean by that. Do you mean only one percentage warning (the first one that shows up is the only one that goes off)? Or something else?
     
  7. Offline

    I Al Istannen

    @StarRocket
    Hey,

    I have quickly looked at your plugin and may be able to help you with some things. First, this check is probably uneeded, the console should be able to use the command:
    Code:
          if (!(sender instanceof Player))
          {
            sender.sendMessage(ChatColor.RED + "You must be a player to use this command!");
            return true;
          }
    Just use CommandSenderr#sendMessage(String). You never use methods exclusive to player, so it is a good idea to "go as far up" as possible (in this case the class containing the methods you need is CommandSender, so use that).

    Then in your listeners you violate the DRY (Don't repeat yourself) priciple. You basically have the same code lots of times, when just small things change. Instead of hardcoding all the durabilities, the Material#getMaxDurability() method may come in handy. Then I would move all the checking code in a method like this:

    "private short getPercent(short maxDurability, short currentDurability)" and perform the logic there.
    Then you could move the percentage values into the config and just check if the config contains the percent and react accordingly.

    Apart from that you could probably use just one Interact listener on MONITOR priority (so that it definitly knows if the event was cancelled) then check if the getMaxDurability() is equal to zero (if it is, the item has no durability and you can just return from the method). Otherwise you can do the things described above.

    I haven't tested any of the things I said, but they should work and greatly improve the readability and maintainability of the code as well as cut the size down :)
     
    Last edited: Apr 1, 2016
  8. Offline

    StarRocket

    @I Al Istannen When first beginning the project I planned to simply get the max durability of the item in hand and then calculate it that way, but for some reason I was unable to find it. Thank you very much for pointing it out to me. And yeah, for the command I could have done so, but I was lazy and just copied the command structure from a different plugin that did need the console to be unable to use the command and just didn't remove it. When I get more time I'll do a rewrite to make it more efficient using these suggestions.
     
    I Al Istannen likes this.
  9. Offline

    Dark_Serpent

    Sorry! I wasn't really clear when I asked.
    This is what shows up when an armor set reaches low durability:
    Show Spoiler

    [​IMG]

    The text is spammed in the chat multiple times. I would prefer it if for each durability level it reaches, 30%, 15%, and 5%, it only showed up once per armor, sword, bow, etc. As to look more like this:
    Show Spoiler

    [​IMG]

    In this example, the gold helmet reaches 5% durability, but is only shown once. The boots drop from 30% to 5%, and as such, both 30% and 5% are shown when it happens, but it isn't shown multiple times (spammed in the chat).
     
  10. Offline

    I Al Istannen

    @StarRocket

    So I have looked into it and created a decent and small working version. I also found out that I was dumb, because the InteractEvent is useless :D (The rest of the points is still valid though.) You will have to use a few other events.

    For fishing:
    • Catching a Fish ==> 1 Durability lost
    • In Ground ==> 2 Durability lost
    • Catching an Entity ==> 3 Durability lost
    • "FISHING" ==> 0 Durability lost
    • "FAILED_ATTEMPT" ==> 0 Durability lost.

    I think you can also extract most of the logic to some methods, needing not much space and time for each indvidual event. If you are annoyed by me, feel free to say so and I apologize in advance. Accordingly, if you need help feel free to message me in some way ;)
     
  11. Offline

    Dark_Serpent

    Bump

    In addition, @StarRocket there seems to be some debug code left in the plugin, every time a fishing rod is used a number is returned in the chat
     
Thread Status:
Not open for further replies.

Share This Page