Nicely done! Just a tip, but instead of using a variable like {backpacks.open::%player's uuid%} to determine whether or not a player's backpack is open, try using a metadata tag like metadata value "backpacks-open" of player. Metadata tags are much better in a case like this because they do not take up valuable variable space, and are deleted automatically when the server stops, so you don't have to worry about deleting it yourself if the server shuts down unexpectedly. You can also pack an effect and condition into one line, for example:
if {god::%victim's uuid%} is true:
cancel event
turns into:
cancel event if {god::%victim's uuid%} is true
Also, you don't need to make every single argument in a command optional, so instead of having command /retrieve [<integer>] [<integer>], you can have command /retrieve <integer> <integer>, and then in your code, you wouldn't have to check if each argument is set.