From 2b20e1a79487344d1c95dbfa9c8e1726298eba02 Mon Sep 17 00:00:00 2001 From: Brianna Date: Tue, 27 Aug 2019 20:51:16 -0400 Subject: [PATCH] Ability to set an island to never unload. --- .../skyblock/command/CommandManager.java | 1 + .../admin/SetAlwaysLoadedCommand.java | 96 +++++++++++++++++++ .../com/songoda/skyblock/island/Island.java | 12 +++ .../skyblock/island/IslandManager.java | 10 +- .../com/songoda/skyblock/listeners/Move.java | 3 +- .../Core/src/main/resources/language.yml | 7 ++ 6 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/command/commands/admin/SetAlwaysLoadedCommand.java diff --git a/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/command/CommandManager.java b/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/command/CommandManager.java index fcb7dae3..56d369c8 100644 --- a/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/command/CommandManager.java +++ b/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/command/CommandManager.java @@ -103,6 +103,7 @@ public class CommandManager implements CommandExecutor, TabCompleter { new RemoveHologramCommand(), new RemoveUpgradeCommand(), new SetBiomeCommand(), + new SetAlwaysLoadedCommand(), new SetHologramCommand(), new SetSizeCommand(), new com.songoda.skyblock.command.commands.admin.SetSpawnCommand(), diff --git a/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/command/commands/admin/SetAlwaysLoadedCommand.java b/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/command/commands/admin/SetAlwaysLoadedCommand.java new file mode 100644 index 00000000..ac7146ef --- /dev/null +++ b/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/command/commands/admin/SetAlwaysLoadedCommand.java @@ -0,0 +1,96 @@ +package com.songoda.skyblock.command.commands.admin; + +import com.songoda.skyblock.command.SubCommand; +import com.songoda.skyblock.config.FileManager; +import com.songoda.skyblock.config.FileManager.Config; +import com.songoda.skyblock.island.Island; +import com.songoda.skyblock.island.IslandManager; +import com.songoda.skyblock.message.MessageManager; +import com.songoda.skyblock.playerdata.PlayerDataManager; +import com.songoda.skyblock.sound.SoundManager; +import com.songoda.skyblock.utils.player.OfflinePlayer; +import com.songoda.skyblock.utils.version.Sounds; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +public class SetAlwaysLoadedCommand extends SubCommand { + + @Override + public void onCommandByPlayer(Player player, String[] args) { + onCommand(player, args); + } + + @Override + public void onCommandByConsole(ConsoleCommandSender sender, String[] args) { + onCommand(sender, args); + } + + public void onCommand(CommandSender sender, String[] args) { + PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); + MessageManager messageManager = skyblock.getMessageManager(); + IslandManager islandManager = skyblock.getIslandManager(); + SoundManager soundManager = skyblock.getSoundManager(); + FileManager fileManager = skyblock.getFileManager(); + + Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + if (args.length == 1) { + Player targetPlayer = Bukkit.getServer().getPlayer(args[0]); + UUID islandOwnerUUID; + + if (targetPlayer == null) { + OfflinePlayer targetPlayerOffline = new OfflinePlayer(args[0]); + islandOwnerUUID = targetPlayerOffline.getOwner(); + } else { + islandOwnerUUID = playerDataManager.getPlayerData(targetPlayer).getOwner(); + } + + if (islandManager.containsIsland(islandOwnerUUID)) { + Island island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)); + + if (island.isAlwaysLoaded()) { + messageManager.sendMessage(sender, + configLoad.getString("Command.Island.Admin.SetAlwaysLoaded.IsOff.Message")); + soundManager.playSound(sender, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); + + island.setAlwaysLoaded(false); + } else { + messageManager.sendMessage(sender, + configLoad.getString("Command.Island.Admin.SetAlwaysLoaded.IsOn.Message")); + soundManager.playSound(sender, Sounds.ANVIL_LAND.bukkitSound(), 1.0F, 1.0F); + + island.setAlwaysLoaded(true); + } + } + } + } + + @Override + public String getName() { + return "setalwaysloaded"; + } + + @Override + public String getInfoMessagePath() { + return "Command.Island.Admin.SetAlwaysLoaded.Info.Message"; + } + + @Override + public String[] getAliases() { + return new String[0]; + } + + @Override + public String[] getArguments() { + return new String[0]; + } +} diff --git a/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/island/Island.java b/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/island/Island.java index 02254bb9..43eea5c6 100644 --- a/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/island/Island.java +++ b/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/island/Island.java @@ -460,6 +460,18 @@ public class Island { return coopPlayers.getOrDefault(uuid, null); } + public void setAlwaysLoaded(boolean alwaysLoaded) { + skyblock.getFileManager().getConfig( + new File(new File(skyblock.getDataFolder().toString() + "/island-data"), ownerUUID.toString() + ".yml")) + .getFileConfiguration().set("AlwaysLoaded", alwaysLoaded); + } + + public boolean isAlwaysLoaded() { + return skyblock.getFileManager().getConfig( + new File(new File(skyblock.getDataFolder().toString() + "/island-data"), ownerUUID.toString() + ".yml")) + .getFileConfiguration().getBoolean("AlwaysLoaded", false); + } + public Set getRole(IslandRole role) { Set islandRoles = new HashSet<>(); diff --git a/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/island/IslandManager.java b/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/island/IslandManager.java index 108bcdc0..b5bf1f99 100644 --- a/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/island/IslandManager.java +++ b/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/island/IslandManager.java @@ -10,7 +10,6 @@ import com.songoda.skyblock.cooldown.CooldownManager; import com.songoda.skyblock.cooldown.CooldownType; import com.songoda.skyblock.invite.Invite; import com.songoda.skyblock.invite.InviteManager; -import com.songoda.skyblock.levelling.LevelChunkSnapshotWrapper; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; @@ -71,6 +70,10 @@ public class IslandManager { for (Player all : Bukkit.getOnlinePlayers()) { loadIsland(all); } + for (Island island : getIslands().values()) { + if (island.isAlwaysLoaded()) + loadIslandAtLocation(island.getLocation(IslandWorld.Normal, IslandEnvironment.Island)); + } } public void onDisable() { @@ -599,15 +602,14 @@ public class IslandManager { } public void unloadIsland(Island island, org.bukkit.OfflinePlayer player) { + if (island.isAlwaysLoaded()) return; ScoreboardManager scoreboardManager = skyblock.getScoreboardManager(); FileManager fileManager = skyblock.getFileManager(); Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); FileConfiguration configLoad = config.getFileConfiguration(); - if (island.isDeleted()) { - return; - } + if (island.isDeleted()) return; island.save(); diff --git a/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/listeners/Move.java b/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/listeners/Move.java index 6df0516e..2f1b11e0 100644 --- a/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/listeners/Move.java +++ b/FabledSkyBlock/Core/src/main/java/com/songoda/skyblock/listeners/Move.java @@ -202,7 +202,8 @@ public class Move implements Listener { } // Load the island they are now on if one exists - if (player.hasPermission("fabledskyblock.bypass")) { + if (player.hasPermission("fabledskyblock.bypass") + || islandManager.getIslandAtLocation(player.getLocation()).isAlwaysLoaded()) { Island loadedIsland = islandManager.loadIslandAtLocation(player.getLocation()); if (loadedIsland != null) { playerData.setIsland(loadedIsland.getOwnerUUID()); diff --git a/FabledSkyBlock/Core/src/main/resources/language.yml b/FabledSkyBlock/Core/src/main/resources/language.yml index f0929bd8..c555b996 100644 --- a/FabledSkyBlock/Core/src/main/resources/language.yml +++ b/FabledSkyBlock/Core/src/main/resources/language.yml @@ -224,6 +224,13 @@ Command: Message: '&bSkyBlock &8| &cError&8: &eYou must enter a numerical value.' Invalid: Message: '&bSkyBlock &8| &cError&8: &eInvalid: /island admin setsize ' + SetAlwaysLoaded: + IsOn: + Message: '&bSkyBlock &8| &aInfo&8: &eThis island will not unload.' + IsOff: + Message: '&bSkyBlock &8| &aInfo&8: &eThis island will unload.' + Info: + Message: '&f&oKeeps an island from unloading.' AddUpgrade: Info: Message: '&f&oAdd an upgrade to a player''s Island.'