Added new Configuration classes

This commit is contained in:
Dinnerbone
2011-09-19 20:36:44 +01:00
committed by Nathan Adams
parent 4155a42406
commit 55f405f4a8
31 changed files with 3454 additions and 9 deletions

View File

@@ -1,12 +1,16 @@
package org.bukkit.inventory;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.material.MaterialData;
/**
* Represents a stack of items
*/
public class ItemStack {
public class ItemStack implements Serializable, ConfigurationSerializable {
private int type;
private int amount = 0;
private MaterialData data = null;
@@ -208,4 +212,36 @@ public class ItemStack {
hash = hash * 7 + 23 * getAmount(); // too bad these are mutable values... Q_Q
return hash;
}
public Map<String, Object> serialize() {
Map<String, Object> result = new LinkedHashMap<String, Object>();
result.put("type", getType());
if (durability != 0) {
result.put("damage", durability);
}
if (amount != 1) {
result.put("amount", amount);
}
return result;
}
public static ItemStack deserialize(Map<String, Object> args) {
Material type = Material.getMaterial((String)args.get("type"));
short damage = 0;
int amount = 1;
if (args.containsKey("damage")) {
damage = (Short)args.get("damage");
}
if (args.containsKey("amount")) {
amount = (Integer)args.get("amount");
}
return new ItemStack(type, amount, damage);
}
}