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:
Trent Hensler
2018-03-02 10:10:46 -08:00
parent 13cf69b3fc
commit 6bdb2212ec
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2013 drtshock
*
* This program is free software: you can redistribute it and/or modify
@@ -16,24 +16,18 @@
*/
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.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.JSONValue;
import java.util.*;
import java.util.Map.Entry;
/**
* Fancy JSON serialization mostly by evilmidget38.
*
@@ -104,7 +98,8 @@ public class Serialization {
if (piece.equalsIgnoreCase("null")) {
contents.add(null);
} 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()];
@@ -147,50 +142,23 @@ public class Serialization {
@Deprecated
public static Map<String, Object> recreateMap(Map<String, Object> original) {
Map<String, Object> map = new HashMap<>();
map.putAll(original);
return map;
return new HashMap<>(original);
}
@Deprecated
@SuppressWarnings({"unchecked", "rawtypes"})
public static Object deserialize(Map<String, Object> map) {
List<?> itemflags = null;
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) {
entry.setValue(deserialize((Map) entry.getValue()));
} else if (entry.getValue() instanceof Iterable) {
List<?> templ = convertIterable((Iterable) entry.getValue());
if (entry.getKey().equalsIgnoreCase("itemflags")) {
map.remove(entry.getKey());
} else {
entry.setValue(templ);
}
entry.setValue(convertIterable((Iterable) entry.getValue()));
} else if (entry.getValue() instanceof Number) {
entry.setValue(convertNumber((Number) entry.getValue()));
}
}
if (map.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
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;
}
return map.containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY) ? ConfigurationSerialization.deserializeObject(map) : map;
}
@Deprecated
private static List<?> convertIterable(Iterable<?> iterable) {
List<Object> newList = new ArrayList<>();
for (Object object : iterable) {
@@ -206,12 +174,11 @@ public class Serialization {
return newList;
}
@Deprecated
private static Number convertNumber(Number number) {
if (number instanceof Long) {
Long longObj = (Long) number;
if (longObj.longValue() == longObj.intValue()) {
return new Integer(longObj.intValue());
if (longObj == longObj.intValue()) {
return longObj.intValue();
}
}
return number;