Revert "Added ItemFlag support and patch error when loading ItemFlags from file."
This reverts commit 4ba4f5da25.
Should fix #332 and #329
This commit is contained in:
@@ -16,24 +16,18 @@
|
|||||||
*/
|
*/
|
||||||
package com.drtshock.playervaults.vaultmanagement;
|
package com.drtshock.playervaults.vaultmanagement;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemFlag;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.JSONValue;
|
import org.json.simple.JSONValue;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fancy JSON serialization mostly by evilmidget38.
|
* Fancy JSON serialization mostly by evilmidget38.
|
||||||
*
|
*
|
||||||
@@ -104,7 +98,8 @@ public class Serialization {
|
|||||||
if (piece.equalsIgnoreCase("null")) {
|
if (piece.equalsIgnoreCase("null")) {
|
||||||
contents.add(null);
|
contents.add(null);
|
||||||
} else {
|
} else {
|
||||||
contents.add((ItemStack) deserialize(toMap((JSONObject) JSONValue.parse(piece))));
|
ItemStack item = (ItemStack) deserialize(toMap((JSONObject) JSONValue.parse(piece)));
|
||||||
|
contents.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemStack[] items = new ItemStack[contents.size()];
|
ItemStack[] items = new ItemStack[contents.size()];
|
||||||
@@ -147,50 +142,23 @@ public class Serialization {
|
|||||||
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static Map<String, Object> recreateMap(Map<String, Object> original) {
|
public static Map<String, Object> recreateMap(Map<String, Object> original) {
|
||||||
Map<String, Object> map = new HashMap<>();
|
return new HashMap<>(original);
|
||||||
map.putAll(original);
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||||
public static Object deserialize(Map<String, Object> map) {
|
public static Object deserialize(Map<String, Object> map) {
|
||||||
List<?> itemflags = null;
|
|
||||||
for (Entry<String, Object> entry : map.entrySet()) {
|
for (Entry<String, Object> entry : map.entrySet()) {
|
||||||
if (entry.getKey().equals("meta") && entry.getValue() instanceof Map) {
|
|
||||||
itemflags = (List<?>) ((Map) entry.getValue()).get("ItemFlags");
|
|
||||||
|
|
||||||
}
|
|
||||||
if (entry.getValue() instanceof Map) {
|
if (entry.getValue() instanceof Map) {
|
||||||
entry.setValue(deserialize((Map) entry.getValue()));
|
entry.setValue(deserialize((Map) entry.getValue()));
|
||||||
} else if (entry.getValue() instanceof Iterable) {
|
} else if (entry.getValue() instanceof Iterable) {
|
||||||
List<?> templ = convertIterable((Iterable) entry.getValue());
|
entry.setValue(convertIterable((Iterable) entry.getValue()));
|
||||||
if (entry.getKey().equalsIgnoreCase("itemflags")) {
|
|
||||||
map.remove(entry.getKey());
|
|
||||||
} else {
|
|
||||||
entry.setValue(templ);
|
|
||||||
}
|
|
||||||
} else if (entry.getValue() instanceof Number) {
|
} else if (entry.getValue() instanceof Number) {
|
||||||
entry.setValue(convertNumber((Number) entry.getValue()));
|
entry.setValue(convertNumber((Number) entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (map.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
|
return map.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY) ? ConfigurationSerialization.deserializeObject(map) : map;
|
||||||
Object obj = ConfigurationSerialization.deserializeObject(map);
|
|
||||||
if (itemflags != null && obj instanceof ItemStack) {
|
|
||||||
ItemStack tempitem = (ItemStack) obj;
|
|
||||||
ItemMeta meta = tempitem.getItemMeta();
|
|
||||||
for (Object flag : itemflags) {
|
|
||||||
|
|
||||||
meta.addItemFlags(ItemFlag.valueOf(flag.toString()));
|
|
||||||
}
|
|
||||||
tempitem.setItemMeta(meta);
|
|
||||||
}
|
|
||||||
return obj;
|
|
||||||
} else {
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private static List<?> convertIterable(Iterable<?> iterable) {
|
private static List<?> convertIterable(Iterable<?> iterable) {
|
||||||
List<Object> newList = new ArrayList<>();
|
List<Object> newList = new ArrayList<>();
|
||||||
for (Object object : iterable) {
|
for (Object object : iterable) {
|
||||||
@@ -206,12 +174,11 @@ public class Serialization {
|
|||||||
return newList;
|
return newList;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
private static Number convertNumber(Number number) {
|
private static Number convertNumber(Number number) {
|
||||||
if (number instanceof Long) {
|
if (number instanceof Long) {
|
||||||
Long longObj = (Long) number;
|
Long longObj = (Long) number;
|
||||||
if (longObj.longValue() == longObj.intValue()) {
|
if (longObj == longObj.intValue()) {
|
||||||
return new Integer(longObj.intValue());
|
return longObj.intValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return number;
|
return number;
|
||||||
|
|||||||
Reference in New Issue
Block a user