From 6e17b540f52c656bc698b16b459a6573a50edba6 Mon Sep 17 00:00:00 2001 From: Xephi Date: Sat, 30 Aug 2014 04:05:22 +0200 Subject: [PATCH] Fix the Cache --- .../xephi/authme/cache/backup/FileCache.java | 84 ++++++++++--------- .../authme/datasource/FlatFileThread.java | 5 +- 2 files changed, 47 insertions(+), 42 deletions(-) diff --git a/src/main/java/fr/xephi/authme/cache/backup/FileCache.java b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java index fcaf61a11..33ff09aca 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/FileCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java @@ -71,43 +71,47 @@ public class FileCache { file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "inventory" + File.separator + i + ".cache"); file.createNewFile(); writer = new FileWriter(file); - if (item.getType() == Material.AIR) { - writer.write("AIR"); - writer.close(); - continue; - } - writer.write(item.getType().name() + API.newline); - writer.write(item.getDurability() + API.newline); - writer.write(item.getAmount() + API.newline); - writer.flush(); - if (item.hasItemMeta()) { - ItemMeta meta = item.getItemMeta(); - if (meta.hasDisplayName()) - writer.write("name=" + meta.getDisplayName() + API.newline); - if (meta.hasLore()) { - String lores = ""; - for (String lore : meta.getLore()) - lores = lore + "%newline%"; - writer.write("lore=" + lores + API.newline); - } - if (meta.hasEnchants()) { - for (Enchantment ench : meta.getEnchants().keySet()) { - writer.write("metaenchant=" + ench.getName() + ":" + meta.getEnchants().get(ench) + API.newline); - } + if (item != null) { + if (item.getType() == Material.AIR) { + writer.write("AIR"); + writer.close(); + continue; } + writer.write(item.getType().name() + API.newline); + writer.write(item.getDurability() + API.newline); + writer.write(item.getAmount() + API.newline); writer.flush(); - } - for (Enchantment ench : item.getEnchantments().keySet()) { - writer.write("enchant=" + ench.getName() + ":" + item.getEnchantments().get(ench) + API.newline); - } - Attributes attributes = new Attributes(item); - if (attributes != null) - while (attributes.values().iterator().hasNext()) { - Attribute a = attributes.values().iterator().next(); - if (a != null) { - writer.write("attribute=" + a.getName() + ";" + a.getAttributeType().getMinecraftId() + ";" + a.getAmount() + ";" + a.getOperation().getId() + ";" + a.getUUID().toString()); + if (item.hasItemMeta()) { + ItemMeta meta = item.getItemMeta(); + if (meta.hasDisplayName()) + writer.write("name=" + meta.getDisplayName() + API.newline); + if (meta.hasLore()) { + String lores = ""; + for (String lore : meta.getLore()) + lores = lore + "%newline%"; + writer.write("lore=" + lores + API.newline); } + if (meta.hasEnchants()) { + for (Enchantment ench : meta.getEnchants().keySet()) { + writer.write("metaenchant=" + ench.getName() + ":" + meta.getEnchants().get(ench) + API.newline); + } + } + writer.flush(); } + for (Enchantment ench : item.getEnchantments().keySet()) { + writer.write("enchant=" + ench.getName() + ":" + item.getEnchantments().get(ench) + API.newline); + } + Attributes attributes = new Attributes(item); + if (attributes != null) + while (attributes.values().iterator().hasNext()) { + Attribute a = attributes.values().iterator().next(); + if (a != null) { + writer.write("attribute=" + a.getName() + ";" + a.getAttributeType().getMinecraftId() + ";" + a.getAmount() + ";" + a.getOperation().getId() + ";" + a.getUUID().toString()); + } + } + } else { + writer.write("AIR"); + } writer.close(); } @@ -487,11 +491,15 @@ public class FileCache { if (file.exists()) { if (file.isDirectory()) { - for (File f : file.listFiles()) - if (f.isDirectory()) - for (File a : f.listFiles()) + for (File f : file.listFiles()) { + if (f.isDirectory()) { + for (File a : f.listFiles()) { a.delete(); - else f.delete(); + } + f.delete(); + } else f.delete(); + } + file.delete(); } else file.delete(); } } @@ -505,7 +513,7 @@ public class FileCache { } catch (Error e) { path = player.getName(); } - File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path); + File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "playerdatas.cache"); if (!file.exists()) { file = new File("cache/" + player.getName().toLowerCase() + ".cache"); } diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFileThread.java b/src/main/java/fr/xephi/authme/datasource/FlatFileThread.java index 2ea78ddf5..f52f92abd 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFileThread.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFileThread.java @@ -675,10 +675,7 @@ public class FlatFileThread extends Thread implements DataSource { while ((br.readLine()) != null) { result++; } - } catch (FileNotFoundException ex) { - ConsoleLogger.showError(ex.getMessage()); - return result; - } catch (IOException ex) { + } catch (Exception ex) { ConsoleLogger.showError(ex.getMessage()); return result; } finally {