From eccf82b7335dfb0723e3cd37a57df1a968ea7842 Mon Sep 17 00:00:00 2001 From: Frank Baumann Date: Mon, 24 Feb 2014 15:00:50 +0100 Subject: [PATCH] Delete corrupt saveplayer data --- src/com/dre/dungeonsxl/DSavePlayer.java | 75 ++++++++++++++----------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/src/com/dre/dungeonsxl/DSavePlayer.java b/src/com/dre/dungeonsxl/DSavePlayer.java index 99b3aa73..c0c7cb91 100644 --- a/src/com/dre/dungeonsxl/DSavePlayer.java +++ b/src/com/dre/dungeonsxl/DSavePlayer.java @@ -60,45 +60,52 @@ public class DSavePlayer { public void reset() { Player onlinePlayer = p.getServer().getPlayer(this.playerName); - if (onlinePlayer != null) { - /* Player is online */ - onlinePlayer.getInventory().setContents(this.oldInventory); - onlinePlayer.getInventory().setArmorContents(this.oldArmor); - onlinePlayer.setTotalExperience(this.oldExp); - onlinePlayer.setLevel(this.oldLvl); - onlinePlayer.setHealth(this.oldHealth); - onlinePlayer.setFoodLevel(this.oldFoodLevel); - onlinePlayer.setGameMode(this.oldGamemode); - onlinePlayer.setFireTicks(this.oldFireTicks); - for (PotionEffect effect : onlinePlayer.getActivePotionEffects()) { - onlinePlayer.removePotionEffect(effect.getType()); - } - onlinePlayer.addPotionEffects(this.oldPotionEffects); - - DUtility.secureTeleport(onlinePlayer, this.oldLocation); - } else { - /* Player is offline */ - Player offlinePlayer = p.getOfflinePlayer(this.playerName, this.uuid, this.oldLocation); - if (offlinePlayer != null) { - offlinePlayer.getInventory().setContents(this.oldInventory); - offlinePlayer.getInventory().setArmorContents(this.oldArmor); - offlinePlayer.setTotalExperience(this.oldExp); - offlinePlayer.setLevel(this.oldLvl); - offlinePlayer.setHealth(this.oldHealth); - offlinePlayer.setFoodLevel(this.oldFoodLevel); - offlinePlayer.setGameMode(this.oldGamemode); - offlinePlayer.setFireTicks(this.oldFireTicks); - for (PotionEffect effect : offlinePlayer.getActivePotionEffects()) { - offlinePlayer.removePotionEffect(effect.getType()); + + try{ + if (onlinePlayer != null) { + /* Player is online */ + onlinePlayer.getInventory().setContents(this.oldInventory); + onlinePlayer.getInventory().setArmorContents(this.oldArmor); + onlinePlayer.setTotalExperience(this.oldExp); + onlinePlayer.setLevel(this.oldLvl); + onlinePlayer.setHealth(this.oldHealth); + onlinePlayer.setFoodLevel(this.oldFoodLevel); + onlinePlayer.setGameMode(this.oldGamemode); + onlinePlayer.setFireTicks(this.oldFireTicks); + for (PotionEffect effect : onlinePlayer.getActivePotionEffects()) { + onlinePlayer.removePotionEffect(effect.getType()); + } + onlinePlayer.addPotionEffects(this.oldPotionEffects); + + DUtility.secureTeleport(onlinePlayer, this.oldLocation); + } else { + /* Player is offline */ + Player offlinePlayer = p.getOfflinePlayer(this.playerName, this.uuid, this.oldLocation); + if (offlinePlayer != null) { + offlinePlayer.getInventory().setContents(this.oldInventory); + offlinePlayer.getInventory().setArmorContents(this.oldArmor); + offlinePlayer.setTotalExperience(this.oldExp); + offlinePlayer.setLevel(this.oldLvl); + offlinePlayer.setHealth(this.oldHealth); + offlinePlayer.setFoodLevel(this.oldFoodLevel); + offlinePlayer.setGameMode(this.oldGamemode); + offlinePlayer.setFireTicks(this.oldFireTicks); + for (PotionEffect effect : offlinePlayer.getActivePotionEffects()) { + offlinePlayer.removePotionEffect(effect.getType()); + } + //causes NP + //offlinePlayer.addPotionEffects(this.oldPotionEffects); + + offlinePlayer.saveData(); } - //causes NP - //offlinePlayer.addPotionEffects(this.oldPotionEffects); - - offlinePlayer.saveData(); } + } catch (NullPointerException exception) { + P.p.log("Corrupt playerdata detected and removed!"); } + savePlayers.remove(this); save(); + } // Static