#Addon for Turning Chests into BackPacks #Written by Einlanzers import esm import os from esm import items from java import io from org.bukkit.inventory import ItemStack def save_backpack(): output = io.ObjectOutputStream(io.FileOutputStream("backpack.dat")) output.writeObject(backpacks) output.close() def load_backpack(): if not os.path.exists("backpack.dat"): return {} input = io.ObjectInputStream(io.FileInputStream("backpack.dat")) obj = input.readObject() input.close() return obj backpacks = load_backpack() def block_break(ev): block = ev.getBlock() player = ev.getPlayer() name = player.getName() blocktype = block.getTypeId() if blocktype != esm.items.chest: return True state = block.getState() inventory = state.getInventory() contents = inventory.getContents() pack = [] for itemstack in contents: itemtype = itemstack.getTypeId() amount = itemstack.getAmount() durability = itemstack.getDurability() slot = [itemtype, amount, durability] pack.append(slot) if name not in backpacks: backpacks[name] = [] backpacks[name].append(pack) inventory.clear() save_backpack() return True def block_placed(ev): block = ev.getBlock() player = ev.getPlayer() name = player.getName() blocktype = block.getTypeId() if blocktype != esm.items.chest: return True if name not in backpacks: return True if len(backpacks[name]) == 0: return True pack = backpacks[name].pop(0) state = block.getState() inventory = state.getInventory() contents = [] for slot in pack: if len(slot) < 3: continue itemtype = slot[0] amount = slot[1] durability = slot[2] itemstack = ItemStack(itemtype, amount, durability) contents.append(itemstack) inventory.setContents(contents) save_backpack() return True