# ##############################################################################################################
# Inventory See for Online/Offline Players
# Made by AsuDev
# Report bugs by messaging me on discord: AsuDev#0714
# There is one CAVEAT:
# I did not use NBT inventory editing for this, rather it goes by saving a players inventories.
# This means that to edit a player's offline inventory, they have to have joined and left the server
# at least once after this script has been loaded.
# ##############################################################################################################
# Save a players inventory when they leave the server
function saveInventoryPlayer(p: player):
set {_uuid} to uuid of {_p}
delete {offlineInventory.%{_uuid}%::*}
set {_counter} to 0
loop 36 times:
add slot {_counter} of {_p}'s inventory to {offlineInventory.%{_uuid}%::*}
add 1 to {_counter}
# Save the offline player's inventory after edits
function saveInventoryOfflinePlayer(inv: inventory, p: offline player):
set {_uuid} to uuid of {_p}
delete {offlineInventory.%{_uuid}%::*}
set {_counter} to 0
loop 36 times:
add slot {_counter} of {_inv} to {offlineInventory.%{_uuid}%::*}
add 1 to {_counter}
# Retrieve the offline players inventory when they join
function retrievePlayerInventory(inv: inventory, p: offline player):
set {_uuid} to uuid of {_p}
set {_counter} to 1
loop 36 times:
set slot {_counter}-1 of {_inv} to {offlineInventory.%{_uuid}%::%{_counter}%}
add 1 to {_counter}
# Join event for updating a players inventory and also checks to see if someone is editing their offline inventory
on join:
size of {offlineInventory.%uuid of player%::*} is not 0
retrievePlayerInventory(player's inventory, player)
loop all players:
if metadata value "Invsee" of loop-player is "%player%":
set metadata value "CancelInvsee" of loop-player to "True"
send "&c%player% &7just logged in, your invsee has been updated." to loop-player
wait 10 ticks
close loop-player's inventory
open player's inventory to loop-player
# Quit event for saving the players inventory and also checks to see if someone is editing their live inventory
on quit:
saveInventoryPlayer(player)
loop all players:
if loop-player's current inventory is player's inventory:
set metadata value "CancelInvsee" of loop-player to "True"
send "&c%player% &7just logged in, your invsee has been updated." to loop-player
wait 10 ticks
close loop-player's inventory
make loop-player execute command "iv %player%"
# Inventory close event for editing offline player inventories
on inventory close:
metadata value "Invsee" of player is set
if metadata value "CancelInvsee" of player is not set:
set {_p} to metadata value "Invsee" of player
set {_p} to "%{_p}%" parsed as offline player
saveInventoryOfflinePlayer(player's current inventory, {_p})
delete metadata value "Invsee" of player
delete metadata value "CancelInvsee" of player
# Main invsee command for players/offline players
command /iv [<offline player>]:
aliases: invsee
permission: invsee.use
permission message: &cYou do not have permission to execute this command.
trigger:
if arg 1 is set:
if arg 1 is online:
open arg 1's inventory to player
else:
if arg 1 has played before:
if size of {offlineInventory.%uuid of arg 1%::*} is not 0:
set metadata value "Invsee" of player to "%arg 1%"
open chest with 4 rows named "%arg 1%'s Inventory" to player
retrievePlayerInventory(player's current inventory, arg 1)
while name of player's current inventory is "%arg 1%'s Inventory":
saveInventoryOfflinePlayer(player's current inventory, arg 1)
wait 3 ticks
else:
message "&cThat player has played before, but they haven't joined since this script was added so there is no saved inventory data..."
else:
message "&cThat player has not played before."
else:
message "&fView a player or offline player's inventory."
message "&f/invsee <player>"