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

PlayerEditBookEvent is never called for edits

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • CraftBukkit commit 6fd677caf2dfa6212b11122e9b41b584e1ef314c
    • Yes

      I noticed this while updating (insert fork name) to 1.16.4.

      In `PlayerConnection#a(String s, List<String> list, int i)`, the event is called as one expects. This method's name could be `bookSigningCallback`.

      In `PlayerConnection#a(List<String> list, int i)`, the event is never called at all. This method's name could be `bookEditCallback`.

      My solution to this issue was the following, though you may come up with something more future proof:

      if (itemstack.getItem() == Items.WRITABLE_BOOK) {
        NBTTagList nbttaglist = new NBTTagList();
      
        list.stream().map(NBTTagString::a).forEach(nbttaglist::add);
        // Edits start - call PlayerEditBookEvent for non-signing
        ItemStack cloned = itemstack.cloneItemStack();
        cloned.getOrCreateTagAndSet("pages", (NBTBase) nbttaglist); // ItemStack#a(String, NBTBase)
        this.player.inventory.setItem(i, CraftEventFactory.handleEditBookEvent(player, i, itemstack, 
      cloned));
        this.player.updateInventory(this.player.activeContainer);
        // Edits end
      }
      

      I apologise for not wanting to go through with the effort of compiling Spigot for this when the issue is that the behaviour doesn't exist in the code.

            Unassigned Unassigned
            Proximyst Mariell Hoversholm
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: