Solved Making shulker box only usable by the crafter

Discussion in 'Spigot Plugin Development' started by SplitYoSis, Jul 13, 2021.

  1. Hello! Whats the best way to make it so only the person who crafted the shulker box can place/open/break it?
    and after its placed do I have to save the player who placed it so when its broken i can check for it?

    Im asking because the way im thinking of doing it seems long and requires 3 events, and im wondering if there is a simple way to do it. thanks! :)
  2. I believe there is no short way, you'd have to store the crafter in the persistent data container or lore of the item; listen for when it's placed and if it's the crafter, store that information by location (have listeners for when it's opened) and finally have a listener for when it's broken and if it is broken by the crafter add that stored information back to the item.
    • Agree Agree x 1
  3. In addition to what is said above, note that ShulkerBox also implements PersistentDataHolder so you can use its PersistentDataContainer as well as the ItemMeta's container.
    • Like Like x 2
  4. Oh you're completely right, hadn't realised it was a block entity. Yeah, no need to store by location when placing it, can just store it in its own PersistentDataHolder.
  5. Storing the location seem irrelevant here tho, the uuid inside PersistentDataContainer will do the job.

    Edit: my bad didn’t read the whole thread
  6. While PersistentDataContainer is absolutely the way to go in newer versions, people seem to be reading over the version number here (PDC was only added 1.13+). For outdated versions, you can utilize NBT to store information in the itemstack version of the shulkerbox. Storing information in the placed version is going to be difficult. I am fairly certain tile-entities won't keep custom NBT stored, meaning there is no way to store persistent information in them in outdated versions (Spigot rewrote NBT saving for PDC to be saved on tile-entities). So you will have to use an external solution (file or database) to store information about who placed which shulkerbox if you care about storage across restarts. If storing it just while the server is running is enough for you, it is possible to use metadata too (but this does get cleared at restart).
  7. I still want it to work across restarts, so im just gonna use an external file with 3 listeners. Thanks to everyone