Skip to content

Instantly share code, notes, and snippets.

@sshh12
Created July 21, 2019 01:27
Show Gist options
  • Save sshh12/5aa5506b842fe896deabc93fa35ab036 to your computer and use it in GitHub Desktop.
Save sshh12/5aa5506b842fe896deabc93fa35ab036 to your computer and use it in GitHub Desktop.
The PerWorldInventory plugin deleted a bunch of items from players, this script manually spawns in the items from the server's config/backup files.
import json
USERNAME = '<adminname>'
BACKUP = '<backup_file>.json'
def parse_item_json(item_json):
name = item_json['item']['type']
amt = item_json['item'].get('amount', 1)
return name, amt
with open(BACKUP, 'r') as f:
data = json.load(f)
items = []
for item in data['ender-chest']:
items.append(parse_item_json(item))
for item in data['inventory']['contents']:
items.append(parse_item_json(item))
for item in data['inventory']['armor']:
items.append(parse_item_json(item))
import keyboard, time
time.sleep(5)
i = 0
for name, amt in items:
if name == 'AIR':
continue
cmd = 'give {} {} {}'.format(USERNAME, name.lower(), amt)
print(cmd)
keyboard.send('/')
time.sleep(0.5)
keyboard.write(cmd + '\n')
time.sleep(0.5)
i += 1
if i % 27 == 0:
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment