Bow Leveling Problem

Discussion in 'Plugin Development' started by nathanthesnooper, Oct 8, 2017.

Thread Status:
Not open for further replies.
  1. Hello, I am an experienced plugin developer, but I have reached a problem I don't know how to solve...

    When an arrow hits something, it's bow gains some XP
    However, when an arrow hits something, the players bow might be charging. My problem is that I don't know how to increase the XP on the Bow without reseting the ItemStack and thus, reseting the charge.

    The only way I know to solve this would be to store new XP in a HashMap, and whenever the Player switches their hand or moves it in their inventory, it updates the ItemStack. The only problem is that there are so many different ways items are moved, dropped, swapped in hand, disconnected, etc. And I'm sure there must be an easier way.

    I appreciate all help!
     
  2. Offline

    mine2012craft

    @nathanthesnooper how are you showing the xp display of the bow? Are you doing it by XP bars, scoreboards, BossBars, or durability?

    If you are doing it by durability, which I am assuming you are, I recommend you do not for this matter. Trying to update a charging bow with the new durability will reset its charge no matter what, I'm pretty sure. You will most likely need to find a different way to show XP. If you have multiple weapons that show XP (Swords, Shovels, etc) by durability, maybe you could try to show XP by the XP bar, and whenever someone switches to an XP weapon, the bar updates. Or perhaps by Bossbar?
     
  3. @mine2012craft I am using Lores to store the XP. Is the only solution to record when the bow moves or slot changes to update it? (Can you change an ItemStack without updating it?)
     
  4. Offline

    MightyOne

    I can not imagine of what would be wrong about just setting the lore in the item meta and - done. Is there any problem? Do you need to update the item to show the new lore?
     
  5. Offline

    Side8StarLite

  6. Offline

    MightyOne

    Weeeeeell if you do not want to interrupt a player while shooting then only update his/her bow after the bow shoot event or how its called (in case the player already charges it again)

    EDIT
    aaah now I understand, there are so many ways how a bow charging can end. Like in slot swich and inventory open event and everything. mhhhh

    EDIT
    since you can only see the lore if you are in an inventory i would just take the InventoryOpenEvent @nathanthesnooper
     
    Last edited: Oct 8, 2017
  7. Offline

    mine2012craft

    @nathanthesnooper like MightyOne said, the best way to probably do this is to update the lore whenever someone opens their inventory.
     
  8. But what do I update the lore from? Will a
    Code:
    HashMap<ItemStack, Integer>
    work?

    I got it all working fine. I have it only update the lore when there is a levelup, And the real level is stored in a hashmap.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 8, 2017
Thread Status:
Not open for further replies.

Share This Page