Added new Configuration classes

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot
2011-09-19 20:36:44 +01:00
parent e99e39ee62
commit 6c7412d365
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);
}
}