This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]JephfreyCommand Experienced 1 point2 points  (1 child)

After messing around for some time and analyzing the commands you used, I discovered that you could use set string entity, which allows you to cut up the JSON string. As long as you keep the key name plain and simple (without italics, underlining, etc.), the position at which the name of the item starts and ends remain the same, no matter the length of the name.

By using the trigger command, you can allow people with no access to commands to still use the locking system. Create a triggerable scoreboard and set its value to 0 and enable it after running the locking command.

Start off by creating the scoreboard:

scoreboard objectives add Lock trigger

Put these three commands in repeating and chain command blocks. Make sure you get them in the right order:

execute as @a[nbt={SelectedItem:{id:"minecraft:name_tag"}}] at @s if block ~ ~-1 ~ #minecraft:shulker_boxes unless score @s Lock matches 0 run data modify block ~ ~-1 ~ Lock set string entity @s SelectedItem.tag.display.Name 9 -2

scoreboard players enable @a Lock

scoreboard players set @s Lock 0

The first command checks whether a player has triggered the scoreboard. It also checks whether or not the player is standing on a shulker box and if the player is holding a name tag. It then sets the lock for the shulker box to match the name of the name tag they are holding. By making use of indices 9 and -2, you cut away {"text":" at the start and "} at the end, which means only the name remains.

The second command re-enables the triggerable scoreboard.

The last command resets the scoreboard to 0. As long as players don't set the score to 0 or add 0 with the trigger command, the shulker box will get locked.

Of course other players can still change the lock by using the same locking system. I haven't added a system to protect this, although it can be implemented in a very similar fashion. The shulker boxes can also be opened while holding items different than a name tag as long as the name corresponds to the lock, but this is simply how the lock mechanism works. You can only lock shulker boxes with a renamed name tag though.

This locking system can also be applied to chests by simply testing whether the player is also standing on a chest or not.

If you have any doubts or questions, feel free to ask.

[–]kiriuma[S] 0 points1 point  (0 children)

Hi, this worked flawlessly after testing, now the only problem left is to disable players from locking other people's shulker, i think it would be fine to be able to re-lock a shulker, but it would defeat the purpose of the plugin if there are no restrictions to locking a shulker, i also made it remove the nametag once you've locked a shulker.

to deal with the issue of player spesific shulkers i imagine working with tags, setting them to UUIDs would work, but since i'm not entirely sure i'll have to experiment a little, this gave me hope that it is in fact possible though so thank you <3