From b4599e74f3bb59c09b2ec43ba4087f7097d72bb9 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Wed, 26 Aug 2015 21:35:15 +0200 Subject: [PATCH] keepInventory split --- src/com/dre/dungeonsxl/DConfig.java | 22 +++++++++++------- src/com/dre/dungeonsxl/DPlayer.java | 17 ++++++++++---- src/com/dre/dungeonsxl/DSavePlayer.java | 31 +++++++++++++------------ 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/com/dre/dungeonsxl/DConfig.java b/src/com/dre/dungeonsxl/DConfig.java index e5ecfe27..a9244ca5 100644 --- a/src/com/dre/dungeonsxl/DConfig.java +++ b/src/com/dre/dungeonsxl/DConfig.java @@ -155,11 +155,21 @@ public class DConfig { /* Keep Inventory */ if (configFile.contains("keepInventory")) { - keepInventoryOnEnter = configFile.getBoolean("keepInventory"); - keepInventoryOnEscape = configFile.getBoolean("keepInventory"); - keepInventoryOnFinish = configFile.getBoolean("keepInventory"); + if (!configFile.contains("keepInventoryOnEnter")) { + keepInventoryOnEnter = configFile.getBoolean("keepInventory"); + } + if (!configFile.contains("keepInventoryOnEscape")) { + keepInventoryOnEscape = configFile.getBoolean("keepInventory"); + } + if (!configFile.contains("keepInventoryOnFinish")) { + keepInventoryOnFinish = configFile.getBoolean("keepInventory"); + } } else { - keepInventory = mainConfig.keepInventory; + if (mainConfig.keepInventory) { + keepInventoryOnEnter = mainConfig.keepInventory; + keepInventoryOnEscape = mainConfig.keepInventory; + keepInventoryOnFinish = mainConfig.keepInventory; + } } if (configFile.contains("keepInventoryOnEnter")) { @@ -342,10 +352,6 @@ public class DConfig { return tmpSecureObjects; } - public boolean getKeepInventory() { - return keepInventory; - } - public boolean getKeepInventoryOnEnter() { return keepInventoryOnEnter; } diff --git a/src/com/dre/dungeonsxl/DPlayer.java b/src/com/dre/dungeonsxl/DPlayer.java index e54b83e0..4df29995 100644 --- a/src/com/dre/dungeonsxl/DPlayer.java +++ b/src/com/dre/dungeonsxl/DPlayer.java @@ -76,10 +76,11 @@ public class DPlayer { this.clearPlayerData(); } else { this.player.setGameMode(GameMode.SURVIVAL); - if (!(GameWorld.get(world).config.getKeepInventoryOnEnter())) { + DConfig dConfig = GameWorld.get(world).config; + if (!(dConfig.getKeepInventoryOnEnter())) { this.clearPlayerData(); } - if (GameWorld.get(world).config.isLobbyDisabled()) { + if (dConfig.isLobbyDisabled()) { this.ready(); } initialLives = GameWorld.get(world).config.getInitialLives(); @@ -105,7 +106,7 @@ public class DPlayer { public void escape() { remove(this); - this.savePlayer.reset(); + this.savePlayer.reset(false); } public void leave() { @@ -114,7 +115,13 @@ public class DPlayer { // Lives p.lives.remove(player); - this.savePlayer.reset(); + DConfig dConfig = GameWorld.get(world).config; + if (this.isFinished) { + this.savePlayer.reset(dConfig.getKeepInventoryOnFinish()); + } + else { + this.savePlayer.reset(dConfig.getKeepInventoryOnEscape()); + } if (this.isEditing) { EditWorld eworld = EditWorld.get(this.world); @@ -218,7 +225,7 @@ public class DPlayer { } // Respawn Items - if (!(GameWorld.get(world).config.getKeepInventoryOnDeath())) { + if (GameWorld.get(world).config.getKeepInventoryOnDeath()) { if (this.respawnInventory != null || this.respawnArmor != null) { this.player.getInventory().setContents(this.respawnInventory); this.player.getInventory().setArmorContents(this.respawnArmor); diff --git a/src/com/dre/dungeonsxl/DSavePlayer.java b/src/com/dre/dungeonsxl/DSavePlayer.java index 47c72297..d59e70c2 100644 --- a/src/com/dre/dungeonsxl/DSavePlayer.java +++ b/src/com/dre/dungeonsxl/DSavePlayer.java @@ -59,30 +59,31 @@ public class DSavePlayer { save(); } - public void reset() { + public void reset(boolean keepInventory) { Player onlinePlayer = p.getServer().getPlayer(this.playerName); 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()); + if (!keepInventory) { + 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); } - onlinePlayer.addPotionEffects(this.oldPotionEffects); - DUtility.secureTeleport(onlinePlayer, this.oldLocation); } else { /* Player is offline */ Player offlinePlayer = p.getOfflinePlayer(this.playerName, UUID.fromString(uuid), this.oldLocation); - if (offlinePlayer != null) { + if (offlinePlayer != null && !keepInventory) { offlinePlayer.getInventory().setContents(this.oldInventory); offlinePlayer.getInventory().setArmorContents(this.oldArmor); offlinePlayer.setTotalExperience(this.oldExp); @@ -174,7 +175,7 @@ public class DSavePlayer { // Create Player DSavePlayer savePlayer = new DSavePlayer(playerName, uuid, oldLocation, oldInventory, oldArmor, oldLvl, oldExp, oldHealth, oldFoodLevel, oldFireTicks, oldGamemode, oldPotionEffects); - savePlayer.reset(); + savePlayer.reset(false); } }