Permanent Item Attributes - How to Solve?

Discussion in 'Spigot Plugin Development' started by KingOfTheNerds, May 20, 2016.

  1. Hey people,

    So I'm making a plugin which involves people wearing armor with custom attributes (like more health, armor, and attack damage). The problem is, when they log out while wearing a piece of armor with a certain attribute, that attribute is permanently applied.
    You can even take off the armor after they relog, and they still have the attribute. If they are still wearing the armor, they get double the benefits, as shown here.

    BEFORE LOGGING OUT:
    Notice I have 4 extra hearts, and my chestplate gives me +2 health (or 1 extra heart)
    2016-05-20_16.00.02.png

    AFTER LOGGING IN:
    Notice I have the same gear, but I now have 5 hearts instead of 4. The armor has re-applied its effect. 2016-05-20_16.00.38.png


    This really breaks my plugin, since people can just relog and get more powerful. I've tried lots of stuff to try and fix this, but nothing has worked.

    Help would be much appreciated.

    A fellow nerd,

    - KingOfTheNerds
     
  2. lower max hp when they log off?
     
  3. I tried clearing their armor right before they log off so that their max health would be lowered, but it didn't work. I guess the attribute becomes permanent right when they log, and if that's the case I can't do anything to lower their hp before they log :/
     
  4. When do you apply the armor effect in the first place? It sounds to me like it's getting reapplied upon player login. I think that if you listen to InventoryClickEvent and, every time it's called, update the player's attributes based on the armor they are wearing, that will prevent the effect from being reapplied when the player logs in.

    To prevent the four-hearts issue, you'll need your algorithm to remember what a player's attributes are normally (i.e. without the special armor effects) so that it can update the player's attributes based on these norms.

    If that doesn't help you, mind showing some code?
     
  5. Why not just apply permanent attributes on itemstack creation, or change name/lore to indicate the item has been modified?