Exception handling and don't kill everything
This commit is contained in:
@@ -24,7 +24,7 @@ public class BackpackConverter implements Converter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int run(CommandSender initiator, ServiceProvider uuidProvider) {
|
public int run(CommandSender initiator, ServiceProvider uuidProvider) {
|
||||||
if(uuidProvider == null)throw new IllegalArgumentException();
|
if (uuidProvider == null) throw new IllegalArgumentException();
|
||||||
|
|
||||||
PlayerVaults plugin = PlayerVaults.getInstance();
|
PlayerVaults plugin = PlayerVaults.getInstance();
|
||||||
File destination = new File(plugin.getDataFolder().getParentFile(), "Backpack" + File.separator + "backpacks");
|
File destination = new File(plugin.getDataFolder().getParentFile(), "Backpack" + File.separator + "backpacks");
|
||||||
@@ -52,37 +52,43 @@ public class BackpackConverter implements Converter {
|
|||||||
File[] files = worldFolder.listFiles();
|
File[] files = worldFolder.listFiles();
|
||||||
for (File file : files != null ? files : new File[0]) {
|
for (File file : files != null ? files : new File[0]) {
|
||||||
if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) {
|
if (file.isFile() && file.getName().toLowerCase().endsWith(".yml")) {
|
||||||
PlayerRecord player = uuidProvider.doLookup(file.getName().substring(0,file.getName().lastIndexOf('.')));
|
try {
|
||||||
if (player == null || player.getUuid() == null) {
|
PlayerRecord player = uuidProvider.doLookup(file.getName().substring(0, file.getName().lastIndexOf('.')));
|
||||||
plugin.getLogger().warning("Unable to convert Backpack for player: " + (player != null ? player.getName() : file.getName()));
|
if (player == null || player.getUuid() == null) {
|
||||||
} else {
|
plugin.getLogger().warning("Unable to convert Backpack for player: " + (player != null ? player.getName() : file.getName()));
|
||||||
UUID uuid = player.getUuid();
|
} else {
|
||||||
FileConfiguration yaml = YamlConfiguration.loadConfiguration(file);
|
UUID uuid = player.getUuid();
|
||||||
ConfigurationSection section = yaml.getConfigurationSection("backpack");
|
FileConfiguration yaml = YamlConfiguration.loadConfiguration(file);
|
||||||
if (section.getKeys(false).size() <= 0) continue; // No slots
|
ConfigurationSection section = yaml.getConfigurationSection("backpack");
|
||||||
|
if (section.getKeys(false).size() <= 0) continue; // No slots
|
||||||
|
|
||||||
Inventory vault = vaults.getVault(uuid, intoVaultNum);
|
Inventory vault = vaults.getVault(uuid, intoVaultNum);
|
||||||
if (vault == null) vault = plugin.getServer().createInventory(null, section.getKeys(false).size());
|
if (vault == null)
|
||||||
for (String key : section.getKeys(false)) {
|
vault = plugin.getServer().createInventory(null, section.getKeys(false).size());
|
||||||
ConfigurationSection slotSection = section.getConfigurationSection(key);
|
for (String key : section.getKeys(false)) {
|
||||||
ItemStack item = slotSection.getItemStack("ItemStack");
|
ConfigurationSection slotSection = section.getConfigurationSection(key);
|
||||||
if (item == null) continue;
|
ItemStack item = slotSection.getItemStack("ItemStack");
|
||||||
|
if (item == null) continue;
|
||||||
|
|
||||||
// Overwrite
|
// Overwrite
|
||||||
vault.setItem(Integer.parseInt(key.split(" ")[1]), item);
|
vault.setItem(Integer.parseInt(key.split(" ")[1]), item);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
vaults.saveVault(vault, uuid, intoVaultNum);
|
vaults.saveVault(vault, uuid, intoVaultNum);
|
||||||
converted++;
|
converted++;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
plugin.getLogger().severe("Error converting Backpack: " + file.getName());
|
plugin.getLogger().severe("Error converting Backpack: " + file.getName());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (System.currentTimeMillis() - lastUpdate >= 1500) {
|
if (System.currentTimeMillis() - lastUpdate >= 1500) {
|
||||||
plugin.getLogger().info(converted + " backpacks have been converted in " + worldFolder.getAbsolutePath());
|
plugin.getLogger().info(converted + " backpacks have been converted in " + worldFolder.getAbsolutePath());
|
||||||
lastUpdate = System.currentTimeMillis();
|
lastUpdate = System.currentTimeMillis();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
plugin.getLogger().warning("Error converting " + file.getAbsolutePath());
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user