Solved Update item's lore globally

Discussion in 'Plugin Development' started by quumi, May 25, 2023.

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

    quumi

    So i have a configuration file where you can set item's lore like this:
    Code:
    lore-overrides:
      - id: 1
        lore: "Hello world"
      - id: 2
        lore: "this is test lore message"
    
    And a command that writes lore to item using ItemMeta and sets "custom_lore_id" nbt tag.

    Now, how do i globally update item's lore when configuration values change?

    • Every item that has custom lore has "custom_lore_id": <number> NBT.
    • There is a HashMap<Integer, String> of these ids mapped to lore messages.

    I've thought about modifying outgoing packets and setting item's lore there instead of using ItemMeta, but not sure on how do i modify packets.

    I have also thought about overriding CraftMetaItem#getLore method but CraftMetaItem is private class and i cannot override it.

    So i would like to know:
    • is it really possible & worth it to modify packets?
    • are package-private classes really not override'able?
    • maybe other hints on how do i implement this?
     
  2. Offline

    timtower Administrator Administrator Moderator

    @quumi When do you want to override the lore?
     
  3. Offline

    quumi

    Sorry, do you mean how fast should it update the lore?
     
  4. Offline

    timtower Administrator Administrator Moderator

    Yes
     
  5. Offline

    quumi

    Okay, so looking at features i have planned for this plugin - not slower than 1.5sec to update.
     
  6. Offline

    timtower Administrator Administrator Moderator

    How often are you reloading the config?
     
  7. Offline

    quumi

    Currently its reloaded maybe about 1-2 times a day, but one of the planned features of the plugin might cause configuration to update up to 20 times a minute.
     
  8. Offline

    timtower Administrator Administrator Moderator

    You might want to reconsider that amount, or the place where you are storing the lores.

    Loop through the inventories of the players, find the item, replace the lore.
    Do this with a runTaskTimer
    For inventories: replace when players open them.
     
  9. Offline

    quumi

    Oh, forgot about that, thanks for help!
     
Thread Status:
Not open for further replies.

Share This Page