mirror of
https://github.com/garbagemule/MobArena.git
synced 2024-11-27 04:55:25 +01:00
Remove obsolete item storing for RepairableContainer.
This commit is contained in:
parent
96870e826b
commit
a527c4a842
@ -1,7 +1,7 @@
|
||||
name: MobArena
|
||||
author: garbagemule
|
||||
main: com.garbagemule.MobArena.MobArena
|
||||
version: 0.96.2.8
|
||||
version: 0.96.2.9
|
||||
softdepend: [Multiverse-Core,Towny,Heroes,MagicSpells,Vault]
|
||||
commands:
|
||||
ma:
|
||||
|
@ -4,20 +4,18 @@ import org.bukkit.block.BlockState;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import com.garbagemule.MobArena.util.inventory.SerializableInventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class RepairableContainer extends RepairableBlock
|
||||
{
|
||||
private SerializableInventory inv;
|
||||
private ItemStack[] contents;
|
||||
|
||||
public RepairableContainer(BlockState state, boolean clear) {
|
||||
super(state);
|
||||
|
||||
// Grab the inventory of the block
|
||||
Inventory inv = ((InventoryHolder) state).getInventory();
|
||||
|
||||
// Make a SerializableInventory
|
||||
this.inv = new SerializableInventory(inv);
|
||||
contents = inv.getContents();
|
||||
|
||||
// Clear the inventory if prompted
|
||||
if (clear) inv.clear();
|
||||
@ -36,7 +34,7 @@ public class RepairableContainer extends RepairableBlock
|
||||
// Grab the inventory
|
||||
InventoryHolder cb = (InventoryHolder) getWorld().getBlockAt(getX(),getY(),getZ()).getState();
|
||||
Inventory chestInv = cb.getInventory();
|
||||
|
||||
SerializableInventory.loadContents(chestInv, this.inv);
|
||||
|
||||
chestInv.setContents(contents);
|
||||
}
|
||||
}
|
||||
|
@ -7,20 +7,6 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class InventoryUtils
|
||||
{
|
||||
public static SerializableItem parseItemStack(ItemStack stack) {
|
||||
return SerializableItem.parseSerializableItem(stack);
|
||||
}
|
||||
|
||||
public static SerializableItem[] parseItemStacks(ItemStack... stacks) {
|
||||
SerializableItem[] items = new SerializableItem[stacks.length];
|
||||
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i] = parseItemStack(stacks[i]);
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
public static List<ItemStack> extractAll(int id, List<ItemStack> items) {
|
||||
List<ItemStack> result = new ArrayList<ItemStack>();
|
||||
|
||||
|
@ -1,73 +0,0 @@
|
||||
package com.garbagemule.MobArena.util.inventory;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
public class SerializableInventory implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = 5816986232508437560L;
|
||||
|
||||
private SerializableItem[] items, armor;
|
||||
|
||||
public SerializableInventory(PlayerInventory inv) {
|
||||
ItemStack[] stackItems = inv.getContents();
|
||||
ItemStack[] stackArmor = inv.getArmorContents();
|
||||
|
||||
this.items = new SerializableItem[stackItems.length];
|
||||
this.armor = new SerializableItem[stackArmor.length];
|
||||
|
||||
for (int i = 0; i < stackItems.length; i++) {
|
||||
this.items[i] = SerializableItem.parseSerializableItem(stackItems[i]);
|
||||
}
|
||||
|
||||
for (int i = 0; i < stackArmor.length; i++) {
|
||||
this.armor[i] = SerializableItem.parseSerializableItem(stackArmor[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public SerializableInventory(Inventory inv) {
|
||||
ItemStack[] stacks = inv.getContents();
|
||||
this.items = new SerializableItem[stacks.length];
|
||||
|
||||
for (int i = 0; i < stacks.length; i++) {
|
||||
this.items[i] = SerializableItem.parseSerializableItem(stacks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack[] getItems() {
|
||||
ItemStack[] result = new ItemStack[items.length];
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
result[i] = (items[i] == null ? null : items[i].toItemStack());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ItemStack[] getArmor() {
|
||||
ItemStack[] result = new ItemStack[armor.length];
|
||||
for (int i = 0; i < armor.length; i++) {
|
||||
result[i] = (armor[i] == null ? null : armor[i].toItemStack());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void loadContents(Player p, SerializableInventory inv) {
|
||||
if (inv == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
p.getInventory().setContents(inv.getItems());
|
||||
p.getInventory().setArmorContents(inv.getArmor());
|
||||
}
|
||||
|
||||
public static void loadContents(Inventory chestInv, SerializableInventory inv) {
|
||||
if (inv == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
chestInv.setContents(inv.getItems());
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
package com.garbagemule.MobArena.util.inventory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
public class SerializableItem implements Serializable
|
||||
{
|
||||
private static final long serialVersionUID = -2855528738291283052L;
|
||||
|
||||
private int id;
|
||||
private int amount;
|
||||
private short damage;
|
||||
private Byte data;
|
||||
private Map<Integer,Integer> enchantments;
|
||||
|
||||
private SerializableItem(ItemStack stack) {
|
||||
this.id = stack.getTypeId();
|
||||
this.amount = stack.getAmount();
|
||||
this.damage = stack.getDurability();
|
||||
|
||||
MaterialData md = stack.getData();
|
||||
this.data = (md == null ? null : md.getData());
|
||||
|
||||
this.enchantments = new HashMap<Integer,Integer>();
|
||||
for (Entry<Enchantment,Integer> entry : stack.getEnchantments().entrySet()) {
|
||||
this.enchantments.put(entry.getKey().getId(), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
public ItemStack toItemStack() {
|
||||
ItemStack stack = new ItemStack(id, amount, damage);
|
||||
if (data != null) stack.setData(new MaterialData(data));
|
||||
|
||||
if (!enchantments.isEmpty()) {
|
||||
for (Entry<Integer,Integer> entry : this.enchantments.entrySet()) {
|
||||
stack.addUnsafeEnchantment(Enchantment.getById(entry.getKey()), entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static SerializableItem parseSerializableItem(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new SerializableItem(stack);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user