Remove backwards compatibility
This commit is contained in:
@@ -4,22 +4,18 @@ package com.drtshock.playervaults;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.drtshock.playervaults.commands.Commands;
|
import com.drtshock.playervaults.commands.Commands;
|
||||||
import com.drtshock.playervaults.util.BackwardsCompatibility;
|
|
||||||
import com.drtshock.playervaults.util.Lang;
|
import com.drtshock.playervaults.util.Lang;
|
||||||
import com.drtshock.playervaults.util.Metrics;
|
import com.drtshock.playervaults.util.Metrics;
|
||||||
import com.drtshock.playervaults.util.Serialization;
|
|
||||||
import com.drtshock.playervaults.util.Updater;
|
import com.drtshock.playervaults.util.Updater;
|
||||||
|
|
||||||
|
|
||||||
@@ -41,13 +37,6 @@ public class Main extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
try {
|
|
||||||
transferVaults();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.log(Level.SEVERE, "PlayerVaults: Failed to check to transfer vaults.");
|
|
||||||
log.log(Level.SEVERE, "PlayerVaults: Report this stack trace to drtshock and gomeow.");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
loadLang();
|
loadLang();
|
||||||
log = getServer().getLogger();
|
log = getServer().getLogger();
|
||||||
getServer().getPluginManager().registerEvents(new Listeners(this), this);
|
getServer().getPluginManager().registerEvents(new Listeners(this), this);
|
||||||
@@ -81,28 +70,6 @@ public class Main extends JavaPlugin {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void transferVaults() throws IOException {
|
|
||||||
File f = new File(getDataFolder() + File.separator + "vaults.yml");
|
|
||||||
if(f.exists() && !new File(getDataFolder() + File.separator + "vaults").exists()) {
|
|
||||||
YamlConfiguration vaults = YamlConfiguration.loadConfiguration(f);
|
|
||||||
for(String person:vaults.getKeys(false)) {
|
|
||||||
YamlConfiguration yaml = new YamlConfiguration();
|
|
||||||
for(String vault:vaults.getConfigurationSection(person).getKeys(false)) {
|
|
||||||
String data = vaults.getString(person + "." + vault);
|
|
||||||
Inventory inv = BackwardsCompatibility.pre2_0_0ToCurrent(data);
|
|
||||||
List<String> list = Serialization.toString(inv);
|
|
||||||
String[] ser = list.toArray(new String[list.size()]);
|
|
||||||
for(int x = 0; x < ser.length; x++) {
|
|
||||||
if(!ser[x].equalsIgnoreCase("null"))
|
|
||||||
yaml.set(vault + "." + x, ser[x]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
yaml.save(new File(directory + File.separator + person + ".yml"));
|
|
||||||
}
|
|
||||||
getLogger().warning("Found old storage format used! Converting to new format!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startMetrics() {
|
public void startMetrics() {
|
||||||
try {
|
try {
|
||||||
Metrics metrics = new Metrics(this);
|
Metrics metrics = new Metrics(this);
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
package com.drtshock.playervaults.util;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
|
|
||||||
import net.minecraft.server.v1_5_R1.NBTBase;
|
|
||||||
import net.minecraft.server.v1_5_R1.NBTTagCompound;
|
|
||||||
import net.minecraft.server.v1_5_R1.NBTTagList;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.craftbukkit.v1_5_R1.inventory.CraftInventoryCustom;
|
|
||||||
import org.bukkit.craftbukkit.v1_5_R1.inventory.CraftItemStack;
|
|
||||||
import org.bukkit.enchantments.Enchantment;
|
|
||||||
import org.bukkit.inventory.Inventory;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
|
||||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
|
||||||
|
|
||||||
import com.drtshock.playervaults.Main;
|
|
||||||
|
|
||||||
public class BackwardsCompatibility {
|
|
||||||
|
|
||||||
Main plugin;
|
|
||||||
|
|
||||||
public BackwardsCompatibility(Main m) {
|
|
||||||
this.plugin = m;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Inventory pre2_0_0ToCurrent(String invString) {
|
|
||||||
String[] serializedBlocks = invString.split(";");
|
|
||||||
Inventory deserializedInventory = Bukkit.getServer().createInventory(null, 54);
|
|
||||||
|
|
||||||
for (int i = 1; i < serializedBlocks.length; i++) {
|
|
||||||
String[] serializedBlock = serializedBlocks[i].split("#");
|
|
||||||
int stackPosition = Integer.valueOf(serializedBlock[0]).intValue();
|
|
||||||
|
|
||||||
if (stackPosition < deserializedInventory.getSize()) {
|
|
||||||
ItemStack is = null;
|
|
||||||
Boolean createdItemStack = Boolean.valueOf(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]).intValue()));
|
|
||||||
createdItemStack = Boolean.valueOf(true);
|
|
||||||
} else if ((itemAttribute[0].equals("d")) && (createdItemStack.booleanValue())) {
|
|
||||||
is.setDurability(Short.valueOf(itemAttribute[1]).shortValue());
|
|
||||||
} else if ((itemAttribute[0].equals("a")) && (createdItemStack.booleanValue())) {
|
|
||||||
is.setAmount(Integer.valueOf(itemAttribute[1]).intValue());
|
|
||||||
} else if ((itemAttribute[0].equals("e")) && (createdItemStack.booleanValue())) {
|
|
||||||
is.addEnchantment(Enchantment.getById(Integer.valueOf(itemAttribute[1]).intValue()), Integer.valueOf(itemAttribute[2]).intValue());
|
|
||||||
} else {
|
|
||||||
if ((!itemAttribute[0].equals("i")) || (!createdItemStack.booleanValue()))
|
|
||||||
continue;
|
|
||||||
ItemMeta meta = is.getItemMeta();
|
|
||||||
meta.setDisplayName(itemAttribute[1]);
|
|
||||||
is.setItemMeta(meta);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
deserializedInventory.setItem(stackPosition, is);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return deserializedInventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Inventory pre3_0_0ToCurrent(String data) {
|
|
||||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data));
|
|
||||||
NBTTagList itemList = (NBTTagList) NBTBase.b(new DataInputStream(inputStream));
|
|
||||||
Inventory inventory = new CraftInventoryCustom(null, itemList.size(), ChatColor.DARK_RED + "Vault");
|
|
||||||
|
|
||||||
for (int i = 0; i < itemList.size(); i++) {
|
|
||||||
NBTTagCompound inputObject = (NBTTagCompound) itemList.get(i);
|
|
||||||
|
|
||||||
if (!inputObject.isEmpty()) {
|
|
||||||
inventory.setItem(i, CraftItemStack.asCraftMirror(net.minecraft.server.v1_5_R1.ItemStack.createStack(inputObject)));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return inventory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
|
||||||
private static CraftItemStack getCraftVersion(org.bukkit.inventory.ItemStack stack) {
|
|
||||||
if ((stack instanceof CraftItemStack))
|
|
||||||
return (CraftItemStack) stack;
|
|
||||||
if (stack != null) {
|
|
||||||
return CraftItemStack.asCraftCopy(stack);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -52,11 +52,7 @@ public class VaultManager {
|
|||||||
public void loadVault(Player player, String holder, int number) {
|
public void loadVault(Player player, String holder, int number) {
|
||||||
Inventory inv = null;
|
Inventory inv = null;
|
||||||
YamlConfiguration playerFile = playerVaultFile(holder);
|
YamlConfiguration playerFile = playerVaultFile(holder);
|
||||||
if(!playerFile.getString("vault" + number, "~").equals("~") && playerFile.getString("vault" + number, "~").trim().endsWith("=")) {
|
if(playerFile.getConfigurationSection("vault" + number) == null) {
|
||||||
String data = playerFile.getString("vault" + number);
|
|
||||||
inv = BackwardsCompatibility.pre3_0_0ToCurrent(data);
|
|
||||||
}
|
|
||||||
else if(playerFile.getConfigurationSection("vault" + number) == null) {
|
|
||||||
inv = Bukkit.createInventory(player, 54, ChatColor.DARK_RED + "Vault #" + String.valueOf(number));
|
inv = Bukkit.createInventory(player, 54, ChatColor.DARK_RED + "Vault #" + String.valueOf(number));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user