1.7 spectator bug fixed.
Placeholderapi is no longer a requirement. /f showclaims lag fixed Scoreboard is now off by default, can be turned on in config. Issue with Flight AutoEnabling when disabled has been fixed. 1.7 itemflag bug fixed
This commit is contained in:
107
src/main/java/com/massivecraft/factions/util/InventoryUtil.java
Normal file
107
src/main/java/com/massivecraft/factions/util/InventoryUtil.java
Normal file
@@ -0,0 +1,107 @@
|
||||
package com.massivecraft.factions.util;
|
||||
|
||||
import com.massivecraft.factions.zcore.nbtapi.NBTItem;
|
||||
import com.massivecraft.factions.zcore.nbtapi.NBTType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class InventoryUtil {
|
||||
|
||||
|
||||
public static String InventoryToString(Inventory invInventory) {
|
||||
// String serialization = invInventory.getSize() + ";";
|
||||
StringBuilder serialization = new StringBuilder(invInventory.getSize() + ";");
|
||||
for (int i = 0; i < invInventory.getSize(); i++) {
|
||||
ItemStack is = invInventory.getItem(i);
|
||||
if (is != null) {
|
||||
// String serializedItemStack = new String();
|
||||
StringBuilder serializedItemStack = new StringBuilder();
|
||||
|
||||
String isType = String.valueOf(is.getType().getId());
|
||||
// serializedItemStack += "t@" + isType;
|
||||
serializedItemStack.append("t@" + isType);
|
||||
|
||||
if (is.getDurability() != 0) {
|
||||
String isDurability = String.valueOf(is.getDurability());
|
||||
//serializedItemStack += ":d@" + isDurability;
|
||||
serializedItemStack.append(":d@" + isDurability);
|
||||
}
|
||||
|
||||
if (is.getAmount() != 1) {
|
||||
String isAmount = String.valueOf(is.getAmount());
|
||||
//serializedItemStack += ":a@" + isAmount;
|
||||
serializedItemStack.append(":a@" + isAmount);
|
||||
}
|
||||
|
||||
Map<Enchantment, Integer> isEnch = is.getEnchantments();
|
||||
if (isEnch.size() > 0) {
|
||||
for (Map.Entry<Enchantment, Integer> ench : isEnch.entrySet()) {
|
||||
// serializedItemStack += ":e@" + ench.getKey().getId() + "@" + ench.getValue();
|
||||
serializedItemStack.append(":e@" + ench.getKey().getId() + "@" + ench.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
NBTItem nbtItem = new NBTItem(is);
|
||||
Set<String> nbtKeySet = nbtItem.getKeys();
|
||||
|
||||
for (String nbtKey : nbtKeySet) {
|
||||
serializedItemStack.append(":n@" + nbtKey + "@" + nbtItem.getType(nbtKey).getId() + "@" + )
|
||||
}
|
||||
*/
|
||||
// serialization += i + "#" + serializedItemStack + ";";
|
||||
serialization.append(i + "#" + serializedItemStack + ";");
|
||||
}
|
||||
}
|
||||
return serialization.toString();
|
||||
}
|
||||
|
||||
public static Inventory StringToInventory(String invString) {
|
||||
String[] serializedBlocks = invString.split(";");
|
||||
String invInfo = serializedBlocks[0];
|
||||
Inventory deserializedInventory = Bukkit.getServer().createInventory(null, Integer.valueOf(invInfo));
|
||||
|
||||
for (int i = 1; i < serializedBlocks.length; i++) {
|
||||
String[] serializedBlock = serializedBlocks[i].split("#");
|
||||
int stackPosition = Integer.valueOf(serializedBlock[0]);
|
||||
|
||||
if (stackPosition >= deserializedInventory.getSize()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack is = null;
|
||||
Boolean createdItemStack = false;
|
||||
|
||||
String[] serializedItemStack = serializedBlock[1].split(":");
|
||||
for (String itemInfo : serializedItemStack) {
|
||||
String[] itemAttribute = itemInfo.split("@");
|
||||
if (itemAttribute[0].equals("t")) {
|
||||
is = new ItemStack(Material.getMaterial(Integer.valueOf(itemAttribute[1])));
|
||||
createdItemStack = true;
|
||||
} else if (itemAttribute[0].equals("d") && createdItemStack) {
|
||||
is.setDurability(Short.valueOf(itemAttribute[1]));
|
||||
} else if (itemAttribute[0].equals("a") && createdItemStack) {
|
||||
is.setAmount(Integer.valueOf(itemAttribute[1]));
|
||||
} else if (itemAttribute[0].equals("e") && createdItemStack) {
|
||||
is.addEnchantment(Enchantment.getById(Integer.valueOf(itemAttribute[1])), Integer.valueOf(itemAttribute[2]));
|
||||
}
|
||||
}
|
||||
deserializedInventory.setItem(stackPosition, is);
|
||||
}
|
||||
|
||||
return deserializedInventory;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user