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 1bab6e7e..47a822e5 100644 --- a/src/main/java/com/songoda/skyblock/challenge/player/PlayerManager.java +++ b/src/main/java/com/songoda/skyblock/challenge/player/PlayerManager.java @@ -43,7 +43,10 @@ public class PlayerManager { public HashMap getPlayer(UUID uuid) { if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() .getBoolean("Island.Challenge.PerIsland", true)) { - uuid = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)).getOwnerUUID(); + Island is = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)); + if(is != null){ + uuid = is.getOwnerUUID(); + } } return islands.get(uuid); } @@ -57,7 +60,10 @@ public class PlayerManager { public void loadPlayer(UUID uuid) { if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() .getBoolean("Island.Challenge.PerIsland", true)) { - uuid = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)).getOwnerUUID(); + Island is = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)); + if(is != null){ + uuid = is.getOwnerUUID(); + } } Config config = skyblock.getFileManager().getConfig(new File(playersDirectory, uuid.toString() + ".yml")); @@ -121,8 +127,10 @@ public class PlayerManager { UUID uuid = p.getUniqueId(); if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() .getBoolean("Island.Challenge.PerIsland", true)) { - uuid = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)).getOwnerUUID(); - + Island is = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)); + if(is != null){ + uuid = is.getOwnerUUID(); + } } HashMap done = islands.get(uuid); if (done == null) { @@ -155,7 +163,10 @@ public class PlayerManager { UUID uuid = p.getUniqueId(); if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() .getBoolean("Island.Challenge.PerIsland", true)) { - uuid = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)).getOwnerUUID(); + Island is = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)); + if(is != null){ + uuid = is.getOwnerUUID(); + } } HashMap done = islands.get(uuid); int count = done.getOrDefault(c, 0); @@ -181,8 +192,10 @@ public class PlayerManager { public void addChallenge(UUID uuid, Challenge c) { if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() .getBoolean("Island.Challenge.PerIsland", true)) { - uuid = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)).getOwnerUUID(); - + Island is = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)); + if(is != null){ + uuid = is.getOwnerUUID(); + } } Config config = skyblock.getFileManager().getConfig(new File(playersDirectory, uuid.toString() + ".yml")); @@ -218,7 +231,10 @@ public class PlayerManager { } else { if (skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() .getBoolean("Island.Challenge.PerIsland", true)) { - uuid = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)).getOwnerUUID(); + Island is = skyblock.getIslandManager().getIsland(Bukkit.getOfflinePlayer(uuid)); + if(is != null){ + uuid = is.getOwnerUUID(); + } } // Not connected, check in file diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/ChallengeCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/ChallengeCommand.java index b33caff9..87a2b4f4 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/ChallengeCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/ChallengeCommand.java @@ -3,6 +3,7 @@ package com.songoda.skyblock.command.commands.island; import java.io.File; import com.songoda.core.compatibility.CompatibleSound; +import com.songoda.skyblock.island.IslandManager; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -24,6 +25,7 @@ public class ChallengeCommand extends SubCommand { SoundManager soundManager = skyblock.getSoundManager(); FileManager fileManager = skyblock.getFileManager(); FabledChallenge fabledChallenge = skyblock.getFabledChallenge(); + IslandManager islandManager = skyblock.getIslandManager(); Config langConfig = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); FileConfiguration langConfigLoad = langConfig.getFileConfiguration(); @@ -36,6 +38,15 @@ public class ChallengeCommand extends SubCommand { return; } if (args.length == 0) { + if (fileManager.getConfig(new File(skyblock.getDataFolder(), "config.yml")).getFileConfiguration() + .getBoolean("Island.Challenge.PerIsland")){ + if(islandManager.getIsland(player) == null){ + messageManager.sendMessage(player, langConfigLoad.getString("Command.Island.Challenge.NoIsland.Message")); + soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); + return; + } + } + // Open challenge inventory ChallengeCategory cc = fabledChallenge.getChallengeManager().getChallenge(1); if (cc == null) { diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 40494212..d4f45456 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -990,6 +990,8 @@ Command: Message: '&bSkyBlock &8| &cError&8: &eCategory not found.' ChallengeNotFound: Message: '&bSkyBlock &8| &cError&8: &eChallenge not found.' + NoIsland: + Message: '&bSkyBlock &8| &cError&8: &eYou don''t have an island.' Preview: Info: Message: '&f&oAllows you to preview island before choosing'