diff --git a/abstract/pom.xml b/abstract/pom.xml index a7936f3d..924caced 100644 --- a/abstract/pom.xml +++ b/abstract/pom.xml @@ -8,6 +8,6 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT diff --git a/core/pom.xml b/core/pom.xml index d074bf05..6bfb8d3e 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java index edd5a20a..ba6a9560 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/DungeonsXL.java @@ -39,7 +39,6 @@ import io.github.dre2n.dungeonsxl.player.DGamePlayer; import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DPermissions; import io.github.dre2n.dungeonsxl.player.DPlayers; -import io.github.dre2n.dungeonsxl.player.DSavePlayer; import io.github.dre2n.dungeonsxl.requirement.RequirementTypes; import io.github.dre2n.dungeonsxl.reward.DLootInventory; import io.github.dre2n.dungeonsxl.reward.RewardTypes; @@ -280,14 +279,12 @@ public class DungeonsXL extends BRPlugin { // Save and load public void saveData() { protections.saveAll(); - DSavePlayer.save(); dWorlds.saveAll(); } public void loadData() { protections.loadAll(); dPlayers.loadAll(); - DSavePlayer.load(); dWorlds.check(); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java index ff60988d..290304cd 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/command/ReloadCommand.java @@ -23,7 +23,6 @@ import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.player.DPermissions; -import java.io.File; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; import org.bukkit.plugin.PluginManager; diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java index 31e5dbe3..47f3445c 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/DMessages.java @@ -140,6 +140,7 @@ public enum DMessages implements Messages { LOG_ERROR_SIGN_SETUP("Log_Error_SignSetup", "&4A sign at &6&v1&4 is erroneous!"), LOG_GENERATE_NEW_WORLD("Log_GenerateNewWorld", "&6Generating new world..."), LOG_IMPORT_WORLD("Log_ImportWorld", "&6Importing world..."), + LOG_KILLED_CORRUPTED_PLAYER("Log_KilledCorruptedPlayer", "&4Killed player &6&v1 &4because the data to restore his main inventory is corrupted :("), LOG_NEW_MAP("Log_NewDungeon", "&6Creating new map."), LOG_NEW_PLAYER_DATA("Log_NewPlayerData", "&6A new player data file has been created and saved as &v1."), LOG_WORLD_GENERATION_FINISHED("Log_WorldGenerationFinished", "&6World generation finished!"), diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java b/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java index 9d238163..880e04c3 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/config/PlayerData.java @@ -17,12 +17,22 @@ package io.github.dre2n.dungeonsxl.config; import io.github.dre2n.commons.config.BRConfig; +import io.github.dre2n.commons.util.EnumUtil; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; /** * @author Daniel Saukel @@ -31,8 +41,25 @@ public class PlayerData extends BRConfig { DungeonsXL plugin = DungeonsXL.getInstance(); - public static final int CONFIG_VERSION = 1; + public static final int CONFIG_VERSION = 2; + public static final String PREFIX_STATE_PERSISTENCE = "savePlayer."; + public static final String PREFIX_STATS = "stats."; + + // State persistence + private Location oldLocation; + private List oldInventory; + private List oldArmor; + private ItemStack oldOffHand; + private int oldLvl; + private float oldExp; + private double oldHealth; + private int oldFoodLevel; + private int oldFireTicks; + private GameMode oldGameMode; + private Collection oldPotionEffects; + + // Stats private Map timeLastPlayed = new HashMap<>(); public PlayerData(File file) { @@ -44,6 +71,179 @@ public class PlayerData extends BRConfig { load(); } + /* Getters and setters */ + /** + * @return if the player was in a game when he left the game + */ + public boolean wasInGame() { + return config.contains(PREFIX_STATE_PERSISTENCE); + } + + /** + * @return the old location + */ + public Location getOldLocation() { + return oldLocation; + } + + /** + * @param location + * the location to set + */ + public void setOldLocation(Location location) { + oldLocation = location; + } + + /** + * @return the items in the old inventory + */ + public List getOldInventory() { + return oldInventory; + } + + /** + * @param inventory + * the inventory to set + */ + public void setOldInventory(List inventory) { + oldInventory = inventory; + } + + /** + * @return the items in the old armor slots + */ + public List getOldArmor() { + return oldArmor; + } + + /** + * @param inventory + * the inventory to set + */ + public void setOldArmor(List inventory) { + oldArmor = inventory; + } + + /** + * @return the items in the old off-hand slot + */ + public ItemStack getOldOffHand() { + return oldOffHand; + } + + /** + * @param offHand + * the off hand item to set + */ + public void setOldOffHand(ItemStack offHand) { + oldOffHand = offHand; + } + + /** + * @return the old level + */ + public int getOldLevel() { + return oldLvl; + } + + /** + * @param level + * the level to set + */ + public void setOldLevel(int level) { + oldLvl = level; + } + + /** + * @return the old exp + */ + public float getOldExp() { + return oldExp; + } + + /** + * @param exp + * the amount of exp to set + */ + public void setOldExp(float exp) { + oldExp = exp; + } + + /** + * @return the old health + */ + public double getOldHealth() { + return oldHealth; + } + + /** + * @param health + * the health to set + */ + public void setOldHealth(double health) { + oldHealth = health; + } + + /** + * @return the old food level + */ + public int getOldFoodLevel() { + return oldFoodLevel; + } + + /** + * @param foodLevel + * the food level to set + */ + public void setOldFoodLevel(int foodLevel) { + oldFoodLevel = foodLevel; + } + + /** + * @return the old fire ticks + */ + public int getOldFireTicks() { + return oldFireTicks; + } + + /** + * @param fireTicks + * the fire ticks to set + */ + public void setFireTicks(int fireTicks) { + oldFireTicks = fireTicks; + } + + /** + * @return the old GameMode + */ + public GameMode getOldGameMode() { + return oldGameMode; + } + + /** + * @param gameMode + * the GameMode to set + */ + public void setOldGameMode(GameMode gameMode) { + oldGameMode = gameMode; + } + + /** + * @return the old potion effects + */ + public Collection getOldPotionEffects() { + return oldPotionEffects; + } + + /** + * @param potionEffects + * the potion effects to set + */ + public void setOldPotionEffects(Collection potionEffects) { + oldPotionEffects = potionEffects; + } + /** * @return a map of the player's finished dungeons with dates. */ @@ -76,6 +276,7 @@ public class PlayerData extends BRConfig { save(); } + /* Actions */ /** * @param dungeon * the finished dungeon @@ -87,8 +288,8 @@ public class PlayerData extends BRConfig { @Override public void initialize() { - if (!config.contains("timeLastPlayed")) { - config.createSection("timeLastPlayed"); + if (!config.contains(PREFIX_STATS + "timeLastPlayed")) { + config.createSection(PREFIX_STATS + "timeLastPlayed"); } if (!file.exists()) { @@ -104,17 +305,99 @@ public class PlayerData extends BRConfig { @Override public void load() { - if (config.isConfigurationSection("timeLastPlayed")) { - for (String key : config.getConfigurationSection("timeLastPlayed").getKeys(false)) { - timeLastPlayed.put(key, config.getLong("timeLastPlayed." + key)); + if (config.isConfigurationSection(PREFIX_STATS + "timeLastPlayed")) { + for (String key : config.getConfigurationSection(PREFIX_STATS + "timeLastPlayed").getKeys(false)) { + timeLastPlayed.put(key, config.getLong(PREFIX_STATS + "timeLastPlayed." + key)); } } + + if (!wasInGame()) { + return; + } + + oldInventory = (List) config.get(PREFIX_STATE_PERSISTENCE + "oldInventory"); + oldArmor = (List) config.get(PREFIX_STATE_PERSISTENCE + "oldArmor"); + oldOffHand = (ItemStack) config.get(PREFIX_STATE_PERSISTENCE + "oldOffHand"); + + oldLvl = config.getInt(PREFIX_STATE_PERSISTENCE + "oldLvl"); + oldExp = config.getInt(PREFIX_STATE_PERSISTENCE + "oldExp"); + oldHealth = config.getInt(PREFIX_STATE_PERSISTENCE + "oldHealth"); + oldFoodLevel = config.getInt(PREFIX_STATE_PERSISTENCE + "oldFoodLevel"); + oldFireTicks = config.getInt(PREFIX_STATE_PERSISTENCE + "oldFireTicks"); + + if (EnumUtil.isValidEnum(GameMode.class, config.getString(PREFIX_STATE_PERSISTENCE + "oldGameMode"))) { + oldGameMode = GameMode.valueOf(config.getString(PREFIX_STATE_PERSISTENCE + "oldGameMode")); + } else { + oldGameMode = GameMode.SURVIVAL; + } + oldPotionEffects = (Collection) config.get(PREFIX_STATE_PERSISTENCE + "oldPotionEffects"); + + oldLocation = (Location) config.get(PREFIX_STATE_PERSISTENCE + "oldLocation"); + if (oldLocation.getWorld() == null) { + oldLocation = plugin.getServer().getWorlds().get(0).getSpawnLocation(); + } } @Override public void save() { - config.set("timeLastPlayed", timeLastPlayed); + config.set(PREFIX_STATS + "timeLastPlayed", timeLastPlayed); super.save(); } + /** + * Saves the player's data to the file. + * + * @param player + * the Player to save + */ + public void savePlayerState(Player player) { + oldGameMode = player.getGameMode(); + oldFireTicks = player.getFireTicks(); + oldFoodLevel = player.getFoodLevel(); + oldHealth = player.getHealth(); + oldExp = player.getExp(); + oldLvl = player.getLevel(); + oldArmor = new ArrayList<>(Arrays.asList(player.getInventory().getArmorContents())); + oldInventory = new ArrayList<>(Arrays.asList(player.getInventory().getContents())); + oldOffHand = player.getInventory().getItemInOffHand(); + oldLocation = player.getLocation(); + oldPotionEffects = player.getActivePotionEffects(); + + config.set(PREFIX_STATE_PERSISTENCE + "oldGameMode", oldGameMode.toString()); + config.set(PREFIX_STATE_PERSISTENCE + "oldFireTicks", oldFireTicks); + config.set(PREFIX_STATE_PERSISTENCE + "oldFoodLevel", oldFoodLevel); + config.set(PREFIX_STATE_PERSISTENCE + "oldHealth", oldHealth); + config.set(PREFIX_STATE_PERSISTENCE + "oldExp", oldExp); + config.set(PREFIX_STATE_PERSISTENCE + "oldLvl", oldLvl); + config.set(PREFIX_STATE_PERSISTENCE + "oldArmor", oldArmor); + config.set(PREFIX_STATE_PERSISTENCE + "oldInventory", oldInventory); + config.set(PREFIX_STATE_PERSISTENCE + "oldOffHand", oldOffHand); + config.set(PREFIX_STATE_PERSISTENCE + "oldLocation", oldLocation); + config.set(PREFIX_STATE_PERSISTENCE + "oldPotionEffects", oldPotionEffects); + + save(); + } + + /** + * Removes the state data from the file + */ + public void clearPlayerState() { + oldGameMode = null; + oldFireTicks = 0; + oldFoodLevel = 0; + oldHealth = 0; + oldExp = 0; + oldLvl = 0; + oldArmor = null; + oldInventory = null; + oldOffHand = null; + oldLocation = null; + oldPotionEffects = null; + + if (wasInGame()) { + config.set("savePlayer", null); + } + save(); + } + } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java index fbc16e4f..73cdbbbe 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/listener/PlayerListener.java @@ -35,7 +35,6 @@ import io.github.dre2n.dungeonsxl.player.DGroup; import io.github.dre2n.dungeonsxl.player.DInstancePlayer; import io.github.dre2n.dungeonsxl.player.DPermissions; import io.github.dre2n.dungeonsxl.player.DPlayers; -import io.github.dre2n.dungeonsxl.player.DSavePlayer; import io.github.dre2n.dungeonsxl.reward.DLootInventory; import io.github.dre2n.dungeonsxl.reward.RewardChest; import io.github.dre2n.dungeonsxl.sign.OpenDoorSign; @@ -45,7 +44,6 @@ import io.github.dre2n.dungeonsxl.trigger.UseItemTrigger; import io.github.dre2n.dungeonsxl.world.DEditWorld; import io.github.dre2n.dungeonsxl.world.DGameWorld; import java.util.ArrayList; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.Material; @@ -486,25 +484,13 @@ public class PlayerListener implements Listener { if (dPlayer != null) { DGroup dGroup = DGroup.getByPlayer(dPlayer.getPlayer()); if (dGroup != null) { - dGroup.getPlayers().remove(dPlayer.getPlayer()); - dGroup.getPlayers().add(player); + dGroup.removePlayer(dPlayer.getPlayer()); + dGroup.addPlayer(player); } dPlayer.setPlayer(player); // Check offlineTime dPlayer.setOfflineTime(0); - - } else { - DSavePlayer dSavePlayer = dPlayers.getDSavePlayerByPlayer(player); - - Location target = Bukkit.getServer().getWorlds().get(0).getSpawnLocation(); - if (dSavePlayer != null) { - target = dSavePlayer.getOldLocation(); - } - - if (DEditWorld.getByWorld(player.getWorld()) != null || DGameWorld.getByWorld(player.getWorld()) != null) { - player.teleport(target); - } } // Tutorial Mode @@ -547,7 +533,7 @@ public class PlayerListener implements Listener { } if (dGroup.getGameWorld() == null) { - dGroup.setGameWorld(plugin.getDWorlds().getResourceByName(DGroup.getByPlayer(player).getMapName()).instantiateAsGameWorld());// TO DO + dGroup.setGameWorld(plugin.getDWorlds().getResourceByName(DGroup.getByPlayer(player).getMapName()).instantiateAsGameWorld()); dGroup.getGameWorld().setTutorial(true); } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java index 8e5bfbab..5afc050e 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DEditPlayer.java @@ -106,7 +106,7 @@ public class DEditPlayer extends DInstancePlayer { */ public void escape() { delete(); - getSavePlayer().reset(false); + reset(false); } public void poke(Block block) { @@ -142,7 +142,7 @@ public class DEditPlayer extends DInstancePlayer { public void leave() { delete(); - getSavePlayer().reset(false); + reset(false); DEditWorld editWorld = DEditWorld.getByWorld(getWorld()); if (editWorld != null) { diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java index 17e9f175..10c84ff1 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGamePlayer.java @@ -381,9 +381,9 @@ public class DGamePlayer extends DInstancePlayer { delete(); if (finished) { - getSavePlayer().reset(rules.getKeepInventoryOnFinish()); + reset(rules.getKeepInventoryOnFinish()); } else { - getSavePlayer().reset(rules.getKeepInventoryOnEscape()); + reset(rules.getKeepInventoryOnEscape()); } // Permission bridge diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java index c90270b0..0e164d46 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DGlobalPlayer.java @@ -16,12 +16,19 @@ */ package io.github.dre2n.dungeonsxl.player; +import io.github.dre2n.commons.compatibility.CompatibilityHandler; +import io.github.dre2n.commons.compatibility.Version; +import io.github.dre2n.commons.util.messageutil.MessageUtil; +import io.github.dre2n.commons.util.playerutil.PlayerUtil; import io.github.dre2n.dungeonsxl.DungeonsXL; +import io.github.dre2n.dungeonsxl.config.DMessages; import io.github.dre2n.dungeonsxl.config.PlayerData; import io.github.dre2n.dungeonsxl.global.DPortal; import java.io.File; +import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; /** * Represents a player in the non-DXL worlds of the server. @@ -45,8 +52,16 @@ public class DGlobalPlayer { private ItemStack[] respawnArmor; public DGlobalPlayer(Player player) { + this(player, false); + } + + public DGlobalPlayer(Player player, boolean reset) { this.player = player; + loadPlayerData(new File(DungeonsXL.PLAYERS, player.getUniqueId().toString() + ".yml")); + if (reset && data.wasInGame()) { + reset(false); + } plugin.getDPlayers().addPlayer(this); } @@ -63,6 +78,7 @@ public class DGlobalPlayer { plugin.getDPlayers().addPlayer(this); } + /* Getters and setters */ /** * @return the Bukkit player */ @@ -213,4 +229,47 @@ public class DGlobalPlayer { return DPermissions.hasPermission(player, permission); } + /* Actions */ + /** + * Respawns the player at his old position before he was in a dungeon + */ + public void reset(boolean keepInventory) { + try { + if (!keepInventory) { + while (data.getOldInventory().size() > 36) { + data.getOldInventory().remove(36); + } + player.getInventory().setContents(data.getOldInventory().toArray(new ItemStack[36])); + player.getInventory().setArmorContents(data.getOldArmor().toArray(new ItemStack[4])); + if (Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) { + player.getInventory().setItemInOffHand(data.getOldOffHand()); + } + player.setLevel(data.getOldLevel()); + player.setExp(data.getOldExp()); + player.setHealth(data.getOldHealth()); + player.setFoodLevel(data.getOldFoodLevel()); + player.setGameMode(data.getOldGameMode()); + player.setFireTicks(data.getOldFireTicks()); + for (PotionEffect effect : player.getActivePotionEffects()) { + player.removePotionEffect(effect.getType()); + } + + player.addPotionEffects(data.getOldPotionEffects()); + } + + if (data.getOldLocation().getWorld() != null) { + PlayerUtil.secureTeleport(player, data.getOldLocation()); + } else { + PlayerUtil.secureTeleport(player, Bukkit.getWorlds().get(0).getSpawnLocation()); + } + + } catch (NullPointerException exception) { + exception.printStackTrace(); + player.setHealth(0); + MessageUtil.log(plugin, DMessages.LOG_KILLED_CORRUPTED_PLAYER.getMessage(player.getName())); + } + + data.clearPlayerState(); + } + } diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java index 8acdc41d..275e6c70 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DInstancePlayer.java @@ -16,8 +16,6 @@ */ package io.github.dre2n.dungeonsxl.player; -import io.github.dre2n.commons.compatibility.CompatibilityHandler; -import io.github.dre2n.commons.compatibility.Version; import org.bukkit.World; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; @@ -27,41 +25,16 @@ import org.bukkit.potion.PotionEffect; */ public abstract class DInstancePlayer extends DGlobalPlayer { - private DSavePlayer savePlayer; private World world; private boolean inDungeonChat = false; DInstancePlayer(Player player, World world) { - super(player); - - double health = player.getHealth(); - if (!Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) { - savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), null, player.getLevel(), - player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects()); - } else { - savePlayer = new DSavePlayer(player.getName(), player.getUniqueId(), player.getLocation(), player.getInventory().getContents(), player.getInventory().getArmorContents(), player.getInventory().getItemInOffHand(), player.getLevel(), - player.getTotalExperience(), (int) health, player.getFoodLevel(), player.getFireTicks(), player.getGameMode(), player.getActivePotionEffects()); - } - + super(player, false); this.world = world; + getData().savePlayerState(player); } /* Getters and setters */ - /** - * @return the savePlayer - */ - public DSavePlayer getSavePlayer() { - return savePlayer; - } - - /** - * @param savePlayer - * the savePlayer to set - */ - public void setSavePlayer(DSavePlayer savePlayer) { - this.savePlayer = savePlayer; - } - /** * @return * the instance diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java index d632be1c..9619af11 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DPlayers.java @@ -28,7 +28,6 @@ import org.bukkit.entity.Player; public class DPlayers { private CopyOnWriteArrayList dGlobalPlayers = new CopyOnWriteArrayList<>(); - private CopyOnWriteArrayList dSavePlayers = new CopyOnWriteArrayList<>(); /** * @return the DGlobalPlayer which represents the player @@ -111,42 +110,6 @@ public class DPlayers { dGlobalPlayers.remove(player); } - /** - * @return the DSavePlayer that represents the player - */ - public DSavePlayer getDSavePlayerByPlayer(Player player) { - for (DSavePlayer dSavePlayer : dSavePlayers) { - if (dSavePlayer.getName().equals(player.getName())) { - return dSavePlayer; - } - } - - return null; - } - - /** - * @return the dSavePlayers - */ - public List getDSavePlayers() { - return dSavePlayers; - } - - /** - * @param dSavePlayer - * the dSavePlayer to add - */ - public void addDSavePlayer(DSavePlayer dSavePlayer) { - dSavePlayers.add(dSavePlayer); - } - - /** - * @param dSavePlayer - * the dSavePlayer to remove - */ - public void removeDSavePlayer(DSavePlayer dSavePlayer) { - dSavePlayers.remove(dSavePlayer); - } - /** * Load all players */ diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DSavePlayer.java b/core/src/main/java/io/github/dre2n/dungeonsxl/player/DSavePlayer.java deleted file mode 100644 index d6fef445..00000000 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/player/DSavePlayer.java +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright (C) 2012-2016 Frank Baumann - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package io.github.dre2n.dungeonsxl.player; - -import io.github.dre2n.commons.compatibility.CompatibilityHandler; -import io.github.dre2n.commons.compatibility.Version; -import io.github.dre2n.commons.util.EnumUtil; -import io.github.dre2n.commons.util.playerutil.PlayerUtil; -import io.github.dre2n.dungeonsxl.DungeonsXL; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.World; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; - -/** - * Represents a player in a GameWorld who went offline. - * - * @author Frank Baumann, Tobias Schmitz, Milan Albrecht, Daniel Saukel - */ -public class DSavePlayer { - - static DungeonsXL plugin = DungeonsXL.getInstance(); - static DPlayers dPlayers = plugin.getDPlayers(); - - // Variables - private String name; - private String uuid; - - private Location oldLocation; - private List oldInventory; - private List oldArmor; - private ItemStack oldOffHand; - private int oldLvl; - private int oldExp; - private double oldHealth; - private int oldFoodLevel; - private int oldFireTicks; - private GameMode oldGameMode; - private Collection oldPotionEffects; - - public DSavePlayer(String name, UUID uuid, Location oldLocation, ArrayList oldInventory, ArrayList oldArmor, ItemStack oldOffHand, int oldLvl, int oldExp, double oldHealth, int oldFoodLevel, int oldFireTicks, - GameMode oldGameMode, Collection oldPotionEffects) { - this.name = name; - this.uuid = uuid.toString(); - - this.oldLocation = oldLocation; - this.oldInventory = oldInventory; - this.oldArmor = oldArmor; - this.oldOffHand = oldOffHand; - this.oldExp = oldExp; - this.oldHealth = oldHealth; - this.oldFoodLevel = oldFoodLevel; - this.oldGameMode = oldGameMode; - this.oldLvl = oldLvl; - this.oldFireTicks = oldFireTicks; - this.oldPotionEffects = oldPotionEffects; - - save(); - dPlayers.addDSavePlayer(this); - } - - public DSavePlayer(String name, UUID uuid, Location oldLocation, ItemStack[] oldInventory, ItemStack[] oldArmor, ItemStack oldOffHand, int oldLvl, int oldExp, double oldHealth, int oldFoodLevel, int oldFireTicks, - GameMode oldGameMode, Collection oldPotionEffects) { - this(name, uuid, oldLocation, new ArrayList<>(Arrays.asList(oldInventory)), new ArrayList<>(Arrays.asList(oldArmor)), oldOffHand, oldLvl, oldExp, oldHealth, oldFoodLevel, oldFireTicks, oldGameMode, oldPotionEffects); - } - - /* Getters and setters */ - /** - * @return the name - */ - public String getName() { - return name; - } - - /** - * @return the uuid - */ - public UUID getUniqueId() { - return UUID.fromString(uuid); - } - - /** - * @return the old location - */ - public Location getOldLocation() { - return oldLocation; - } - - /** - * @param location - * the location to set - */ - public void setOldLocation(Location location) { - oldLocation = location; - } - - /** - * @return the items in the old inventory - */ - public List getOldInventory() { - return oldInventory; - } - - /** - * @param inventory - * the inventory to set - */ - public void setOldInventory(List inventory) { - oldInventory = inventory; - } - - /** - * @return the items in the old armor slots - */ - public List getOldArmor() { - return oldArmor; - } - - /** - * @param inventory - * the inventory to set - */ - public void setOldArmor(List inventory) { - oldArmor = inventory; - } - - /** - * @return the items in the old off-hand slot - */ - public ItemStack getOldOffHand() { - return oldOffHand; - } - - /** - * @param offHand - * the off hand item to set - */ - public void setOldOffHand(ItemStack offHand) { - oldOffHand = offHand; - } - - /** - * @return the old level - */ - public int getOldLevel() { - return oldLvl; - } - - /** - * @param level - * the level to set - */ - public void setOldLevel(int level) { - oldLvl = level; - } - - /** - * @return the old exp - */ - public int getOldExp() { - return oldExp; - } - - /** - * @param exp - * the amount of exp to set - */ - public void setOldExp(int exp) { - oldExp = exp; - } - - /** - * @return the old health - */ - public double getOldHealth() { - return oldHealth; - } - - /** - * @param health - * the health to set - */ - public void setOldHealth(double health) { - oldHealth = health; - } - - /** - * @return the old food level - */ - public int getOldFoodLevel() { - return oldFoodLevel; - } - - /** - * @param foodLevel - * the food level to set - */ - public void setOldFoodLevel(int foodLevel) { - oldFoodLevel = foodLevel; - } - - /** - * @return the old fire ticks - */ - public int getOldFireTicks() { - return oldFireTicks; - } - - /** - * @param fireTicks - * the fire ticks to set - */ - public void setFireTicks(int fireTicks) { - oldFireTicks = fireTicks; - } - - /** - * @return the old GameMode - */ - public GameMode getOldGameMode() { - return oldGameMode; - } - - /** - * @param gameMode - * the GameMode to set - */ - public void setOldGameMode(GameMode gameMode) { - oldGameMode = gameMode; - } - - /** - * @return the old potion effects - */ - public Collection getOldPotionEffects() { - return oldPotionEffects; - } - - /** - * @param potionEffects - * the potion effects to set - */ - public void setOldPotionEffects(Collection potionEffects) { - oldPotionEffects = potionEffects; - } - - /* Actions */ - public void reset(boolean keepInventory) { - Player player = plugin.getServer().getPlayer(name); - boolean offline = false; - if (player == null) { - player = PlayerUtil.getOfflinePlayer(name, UUID.fromString(uuid), oldLocation); - offline = true; - } - if (player == null) { - return; - } - - try { - if (!keepInventory) { - while (oldInventory.size() > 36) { - oldInventory.remove(36); - } - player.getInventory().setContents(oldInventory.toArray(new ItemStack[36])); - player.getInventory().setArmorContents(oldArmor.toArray(new ItemStack[4])); - if (Version.andHigher(Version.MC1_9).contains(CompatibilityHandler.getInstance().getVersion())) { - player.getInventory().setItemInOffHand(oldOffHand); - } - player.setTotalExperience(oldExp); - player.setLevel(oldLvl); - player.setHealth(oldHealth); - player.setFoodLevel(oldFoodLevel); - player.setGameMode(oldGameMode); - player.setFireTicks(oldFireTicks); - for (PotionEffect effect : player.getActivePotionEffects()) { - player.removePotionEffect(effect.getType()); - } - // Causes NPE if offline - if (!offline) { - player.addPotionEffects(oldPotionEffects); - - } else { - player.saveData(); - } - } - - if (!offline && oldLocation.getWorld() != null) { - PlayerUtil.secureTeleport(player, oldLocation); - } else { - PlayerUtil.secureTeleport(player, Bukkit.getWorlds().get(0).getSpawnLocation()); - } - - } catch (NullPointerException exception) { - plugin.getLogger().info("Corrupted playerdata detected and removed!"); - } - - save(); - dPlayers.removeDSavePlayer(this); - } - - /* Statics */ - @Deprecated - public static void save() { - FileConfiguration configFile = new YamlConfiguration(); - - for (DSavePlayer savePlayer : dPlayers.getDSavePlayers()) { - configFile.set(savePlayer.name + ".uuid", savePlayer.uuid); - configFile.set(savePlayer.name + ".oldGameMode", savePlayer.oldGameMode.toString()); - configFile.set(savePlayer.name + ".oldFireTicks", savePlayer.oldFireTicks); - configFile.set(savePlayer.name + ".oldFoodLevel", savePlayer.oldFoodLevel); - configFile.set(savePlayer.name + ".oldHealth", savePlayer.oldHealth); - configFile.set(savePlayer.name + ".oldExp", savePlayer.oldExp); - configFile.set(savePlayer.name + ".oldLvl", savePlayer.oldLvl); - configFile.set(savePlayer.name + ".oldArmor", savePlayer.oldArmor); - configFile.set(savePlayer.name + ".oldInventory", savePlayer.oldInventory); - configFile.set(savePlayer.name + ".oldOffHand", savePlayer.oldOffHand); - configFile.set(savePlayer.name + ".oldLocation.x", savePlayer.oldLocation.getX()); - configFile.set(savePlayer.name + ".oldLocation.y", savePlayer.oldLocation.getY()); - configFile.set(savePlayer.name + ".oldLocation.z", savePlayer.oldLocation.getZ()); - configFile.set(savePlayer.name + ".oldLocation.yaw", savePlayer.oldLocation.getYaw()); - configFile.set(savePlayer.name + ".oldLocation.pitch", savePlayer.oldLocation.getPitch()); - configFile.set(savePlayer.name + ".oldLocation.world", savePlayer.oldLocation.getWorld().getName()); - configFile.set(savePlayer.name + ".oldPotionEffects", savePlayer.oldPotionEffects); - } - - try { - configFile.save(new File(plugin.getDataFolder(), "savePlayers.yml")); - } catch (IOException e) { - e.printStackTrace(); - } - } - - @Deprecated - public static void load() { - FileConfiguration configFile = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder(), "savePlayers.yml")); - - for (String name : configFile.getKeys(false)) { - // Load uuid - UUID uuid = UUID.fromString(configFile.getString(name + ".uuid")); - - // Load inventory data - ArrayList oldInventory = (ArrayList) configFile.get(name + ".oldInventory"); - ArrayList oldArmor = (ArrayList) configFile.get(name + ".oldArmor"); - ItemStack oldOffHand = (ItemStack) configFile.get(name + ".oldOffHand"); - - // Load other data - int oldLvl = configFile.getInt(name + ".oldLvl"); - int oldExp = configFile.getInt(name + ".oldExp"); - int oldHealth = configFile.getInt(name + ".oldHealth"); - int oldFoodLevel = configFile.getInt(name + ".oldFoodLevel"); - int oldFireTicks = configFile.getInt(name + ".oldFireTicks"); - GameMode oldGameMode = GameMode.SURVIVAL; - if (EnumUtil.isValidEnum(GameMode.class, configFile.getString(name + ".oldGameMode"))) { - oldGameMode = GameMode.valueOf(configFile.getString(name + ".oldGameMode")); - } - Collection oldPotionEffects = (Collection) configFile.get(name + ".oldPotionEffects"); - - // Location - World world = plugin.getServer().getWorld(configFile.getString(name + ".oldLocation.world")); - if (world == null) { - world = plugin.getServer().getWorlds().get(0); - } - - Location oldLocation = new Location(world, configFile.getDouble(name + ".oldLocation.x"), configFile.getDouble(name + ".oldLocation.y"), configFile.getDouble(name - + ".oldLocation.z"), configFile.getInt(name + ".oldLocation.yaw"), configFile.getInt(name + ".oldLocation.pitch")); - - // Create Player - DSavePlayer savePlayer = new DSavePlayer(name, uuid, oldLocation, oldInventory, oldArmor, oldOffHand, oldLvl, oldExp, oldHealth, oldFoodLevel, oldFireTicks, oldGameMode, oldPotionEffects); - savePlayer.reset(false); - } - } - -} diff --git a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java index a40af95e..5688d087 100644 --- a/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java +++ b/core/src/main/java/io/github/dre2n/dungeonsxl/requirement/FeeLevelRequirement.java @@ -18,8 +18,8 @@ package io.github.dre2n.dungeonsxl.requirement; import io.github.dre2n.commons.util.messageutil.MessageUtil; import io.github.dre2n.dungeonsxl.config.DMessages; +import io.github.dre2n.dungeonsxl.config.PlayerData; import io.github.dre2n.dungeonsxl.player.DGamePlayer; -import io.github.dre2n.dungeonsxl.player.DSavePlayer; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -70,8 +70,9 @@ public class FeeLevelRequirement extends Requirement { if (dPlayer == null) { return; } - DSavePlayer dSavePlayer = dPlayer.getSavePlayer(); - dSavePlayer.setOldLevel(dSavePlayer.getOldLevel() - fee); + + PlayerData data = dPlayer.getData(); + data.setOldLevel(data.getOldLevel() - fee); MessageUtil.sendMessage(player, plugin.getMessageConfig().getMessage(DMessages.REQUIREMENT_FEE, fee + " levels")); } diff --git a/craftbukkit_1_10_R1/pom.xml b/craftbukkit_1_10_R1/pom.xml index ea1a5bd9..df616a42 100644 --- a/craftbukkit_1_10_R1/pom.xml +++ b/craftbukkit_1_10_R1/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT diff --git a/craftbukkit_1_9_R1/pom.xml b/craftbukkit_1_9_R1/pom.xml index f9edf9f0..d3be7605 100644 --- a/craftbukkit_1_9_R1/pom.xml +++ b/craftbukkit_1_9_R1/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT diff --git a/craftbukkit_1_9_R2/pom.xml b/craftbukkit_1_9_R2/pom.xml index 99459d94..b1e69498 100644 --- a/craftbukkit_1_9_R2/pom.xml +++ b/craftbukkit_1_9_R2/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT diff --git a/pom.xml b/pom.xml index a6b4dfd8..bff956df 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ 4.0.0 io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT pom DungeonsXL https://dre2n.github.io diff --git a/shade/pom.xml b/shade/pom.xml index d67cf276..23b07e46 100644 --- a/shade/pom.xml +++ b/shade/pom.xml @@ -8,7 +8,7 @@ io.github.dre2n dungeonsxl - 0.14.4 + 0.15-SNAPSHOT dungeonsxl-${project.version}${buildNo}