From 5660ccc300e426374d1d2e5a48809aa3eccc77d1 Mon Sep 17 00:00:00 2001 From: Xephi59 Date: Mon, 13 Jul 2015 01:15:18 +0200 Subject: [PATCH] Fix FileCache ... Sleeping is stupid x) --- src/main/java/fr/xephi/authme/api/API.java | 4 +- .../xephi/authme/cache/backup/FileCache.java | 37 ++++++++++--------- .../authme/process/quit/AsyncronousQuit.java | 3 -- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/fr/xephi/authme/api/API.java b/src/main/java/fr/xephi/authme/api/API.java index 516157ad..b3fbaf2b 100644 --- a/src/main/java/fr/xephi/authme/api/API.java +++ b/src/main/java/fr/xephi/authme/api/API.java @@ -10,6 +10,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import fr.xephi.authme.AuthMe; +import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.Utils; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerCache; @@ -104,7 +105,8 @@ public class API { try { player.getInventory().setContents(content); player.getInventory().setArmorContents(armor); - } catch (NullPointerException npe) { + } catch (Exception npe) { + ConsoleLogger.showError("Some error appear while trying to set inventory for " + player.getName()); } } 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 94859806..6e59f47a 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/FileCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/FileCache.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Scanner; import java.util.UUID; -import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; @@ -203,7 +202,7 @@ public class FileCache { path = player.getName(); } try { - File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + ".playerdatas.cache"); + File file = new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "playerdatas.cache"); String playername = player.getName().toLowerCase(); if (!file.exists()) { // OLD METHOD @@ -357,7 +356,7 @@ public class FileCache { for (int i = 0; i < inv.length; i++) { reader = new Scanner(new File(plugin.getDataFolder() + File.separator + "cache" + File.separator + path + File.separator + "inventory" + File.separator + i + ".cache")); ItemStack item = new ItemStack(Material.AIR); - ItemMeta meta = null; + ItemMeta meta = item.getItemMeta(); Attributes attributes = null; count = 1; boolean v = true; @@ -365,22 +364,24 @@ public class FileCache { String line = reader.nextLine(); switch (count) { case 1: - item.setType(Material.getMaterial(line)); + item = new ItemStack(Material.getMaterial(line)); if (item.getType() == Material.AIR) v = false; + meta = item.getItemMeta(); + count++; continue; case 2: - item.setDurability(Short.parseShort(line)); + item.setDurability((short) Integer.parseInt(line)); + count++; continue; case 3: item.setAmount(Integer.parseInt(line)); + count++; continue; - case 4: - meta = Bukkit.getItemFactory().getItemMeta(item.getType()); - break; default: break; } + meta = item.getItemMeta(); if (line.startsWith("name=")) { line = line.substring(5); meta.setDisplayName(line); @@ -399,6 +400,7 @@ public class FileCache { if (line.startsWith("enchant=")) { line = line.substring(8); item.addEnchantment(Enchantment.getByName(line.split(":")[0]), Integer.parseInt(line.split(":")[1])); + continue; } if (Settings.customAttributes) { if (line.startsWith("attribute=")) { @@ -429,7 +431,7 @@ public class FileCache { } if (reader != null) reader.close(); - if (attributes != null) + if (Settings.customAttributes && attributes != null) inv[i] = attributes.getStack(); else inv[i] = item; } @@ -444,22 +446,24 @@ public class FileCache { String line = reader.nextLine(); switch (count) { case 1: - item.setType(Material.getMaterial(line)); + item = new ItemStack(Material.getMaterial(line)); if (item.getType() == Material.AIR) v = false; + meta = item.getItemMeta(); + count++; continue; case 2: - item.setDurability(Short.parseShort(line)); + item.setDurability((short) Integer.parseInt(line)); + count++; continue; case 3: item.setAmount(Integer.parseInt(line)); + count++; continue; - case 4: - meta = Bukkit.getItemFactory().getItemMeta(item.getType()); - break; default: break; } + meta = item.getItemMeta(); if (line.startsWith("name=")) { line = line.substring(5); meta.setDisplayName(line); @@ -573,10 +577,7 @@ public class FileCache { file = new File("cache/" + player.getName().toLowerCase() + ".cache"); } - if (file.exists()) { - return true; - } - return false; + return file.exists(); } } diff --git a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java index 6394cac8..953a3c71 100644 --- a/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java +++ b/src/main/java/fr/xephi/authme/process/quit/AsyncronousQuit.java @@ -79,9 +79,6 @@ public class AsyncronousQuit { if (limbo.getMessageTaskId() != null) limbo.getMessageTaskId().cancel(); LimboCache.getInstance().deleteLimboPlayer(name); - if (playerBackup.doesCacheExist(player)) { - playerBackup.removeCache(player); - } } if (Settings.isSessionsEnabled && !isKick) { BukkitTask task = plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {