Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-4505

Force-update entity's item attribute modifiers

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • This server is running CraftBukkit version git-Spigot-eb21557-4a47be6 (MC: 1.13.2) (Implementing API version 1.13.2-R0.1-SNAPSHOT)
    • Yes

      Example usecase:

      A minigame plugin stores and restores a player's inventory and health. The player was wearing an item with a health boost modifier previously, and his health was larger than the default 20. When restoring, the plugin first restores the inventory contents, and then attempts to restore the player's health.

      This will currently fail, because it takes 1 tick before a LivingEntity updates its active attribute modifiers due to changed items.

       

      Current workarounds all have their flaws:

      • Waiting 1 tick between restoring the inventory and the health: This may conflict with anything that happens in that 1 tick and that may affect or use the player's health (taking damage, other plugins using the player's current health for some purpose, player leaving, ..).
      • Manually checking for and applying item attribute modifiers: It isn't possible to access the current internal 'cached/last-held' items of an entity, so it's not possible to know which of the entity's currently active modifiers are supposed to be removed (which modifiers are getting replaced).
      • Storing, clearing and later restoring all modifiers: Plugins may add and remove custom modifiers in arbitrary conditions. If those conditions are no longer fulfilled when later restoring those modifiers, the entity may end up (persistently) with modifiers it is no longer supposed to have.

      One workaround that may (mostly) work in this specific usecase:

      When restoring, clear all attribute modifiers, and then manually check and apply item modifiers, before restoring the health. This depends on being able to safely remove all current modifiers without risking removing any modifiers that the entity is supposed to keep having, and which it might not automatically regain by some other mechanism.

      This will not work if there is some other plugin that applies modifiers only once when a certain condition is met (some probably non-realistic example: a plugin applying a health boost once every 5 minecraft days, and remove it again afterwards, without checking in-between if the entities/players still have it).

      This would still require the plugin to manually check and update the modifiers for held/weared items. (For reference, this is what I actual use right now: https://pastebin.com/F2Dpry2s)

       

      Proposal:

      Would it be possible to add a method to LivingEntity with which this 'update equipment items' (and therefore the active item attribute modifiers) can be forced to happen immediately? Alternatively, the entity could also adjust its active attribute modifiers immediately when any of its equipment changes.

            Unassigned Unassigned
            blablubbabc blablubbabc
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: