From eef0d5f7e8f203f5ce968e5b7595d623727d33fc Mon Sep 17 00:00:00 2001 From: Fabrizio La Rosa Date: Sun, 14 Jun 2020 00:31:21 +0200 Subject: [PATCH] Added per island challenges --- .../challenge/player/PlayerManager.java | 34 ++++++++++++++++--- src/main/resources/config.yml | 2 ++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/songoda/skyblock/challenge/player/PlayerManager.java b/src/main/java/com/songoda/skyblock/challenge/player/PlayerManager.java index 0efb5173..09dc4bf6 100644 --- a/src/main/java/com/songoda/skyblock/challenge/player/PlayerManager.java +++ b/src/main/java/com/songoda/skyblock/challenge/player/PlayerManager.java @@ -44,7 +44,8 @@ public class PlayerManager { * The uuid of specific player */ public void loadPlayer(UUID uuid) { - Config config = skyblock.getFileManager().getConfig(new File(playersDirectory, uuid.toString() + ".yml")); + Config config = skyblock.getFileManager().getConfig(new File(playersDirectory, + skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)).getOwnerUUID() + ".yml")); FileConfiguration fileConfig = config.getFileConfiguration(); HashMap challenges = new HashMap<>(); ConfigurationSection section = fileConfig.getConfigurationSection("challenges"); @@ -77,8 +78,16 @@ public class PlayerManager { * The uuid of specific player */ public void unloadPlayer(UUID uuid) { + UUID challengeUUID; + if(skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() + .getBoolean("Island.Challenge.PerIsland", true)){ + challengeUUID = uuid; + } else { + challengeUUID = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)).getOwnerUUID(); + } players.remove(uuid); - skyblock.getFileManager().unloadConfig(new File(playersDirectory, uuid.toString() + ".yml")); + skyblock.getFileManager().unloadConfig(new File(playersDirectory, + challengeUUID.toString() + ".yml")); } @@ -146,7 +155,15 @@ public class PlayerManager { } public void addChallenge(UUID uuid, Challenge c) { - Config config = skyblock.getFileManager().getConfig(new File(playersDirectory, uuid.toString() + ".yml")); + UUID challengeUUID; + if(skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() + .getBoolean("Island.Challenge.PerIsland", true)){ + challengeUUID = uuid; + } else { + challengeUUID = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)).getOwnerUUID(); + } + Config config = skyblock.getFileManager().getConfig(new File(playersDirectory, + challengeUUID.toString() + ".yml")); FileConfiguration fileConfig = config.getFileConfiguration(); int ccId = c.getCategory().getId(); int cId = c.getId(); @@ -177,8 +194,17 @@ public class PlayerManager { if (challenges != null) { return challenges.getOrDefault(c, 0); } else { + UUID challengeUUID; + if(skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() + .getBoolean("Island.Challenge.PerIsland", true)){ + challengeUUID = uuid; + } else { + challengeUUID = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)).getOwnerUUID(); + } + // Not connected, check in file - Config config = skyblock.getFileManager().getConfig(new File(playersDirectory, uuid.toString() + ".yml")); + Config config = skyblock.getFileManager().getConfig(new File(playersDirectory, + challengeUUID.toString() + ".yml")); FileConfiguration fileConfig = config.getFileConfiguration(); int ccId = c.getCategory().getId(); int cId = c.getId(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e434bfdb..5dd88ef0 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -312,6 +312,8 @@ Island: Challenge: # Enable or disable challenges. Configuration for challenges are in challenges.yml file Enable: true + # Disabling this will make challenges per player + PerIsland: true Teleport: # Enable or disable Fall damage FallDamage: true \ No newline at end of file