Ability to set an island to never unload.

This commit is contained in:
Brianna 2019-08-27 20:51:16 -04:00
parent ec5be54588
commit 2b20e1a794
6 changed files with 124 additions and 5 deletions

View File

@ -103,6 +103,7 @@ public class CommandManager implements CommandExecutor, TabCompleter {
new RemoveHologramCommand(), new RemoveHologramCommand(),
new RemoveUpgradeCommand(), new RemoveUpgradeCommand(),
new SetBiomeCommand(), new SetBiomeCommand(),
new SetAlwaysLoadedCommand(),
new SetHologramCommand(), new SetHologramCommand(),
new SetSizeCommand(), new SetSizeCommand(),
new com.songoda.skyblock.command.commands.admin.SetSpawnCommand(), new com.songoda.skyblock.command.commands.admin.SetSpawnCommand(),

View File

@ -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];
}
}

View File

@ -460,6 +460,18 @@ public class Island {
return coopPlayers.getOrDefault(uuid, null); 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<UUID> getRole(IslandRole role) { public Set<UUID> getRole(IslandRole role) {
Set<UUID> islandRoles = new HashSet<>(); Set<UUID> islandRoles = new HashSet<>();

View File

@ -10,7 +10,6 @@ import com.songoda.skyblock.cooldown.CooldownManager;
import com.songoda.skyblock.cooldown.CooldownType; import com.songoda.skyblock.cooldown.CooldownType;
import com.songoda.skyblock.invite.Invite; import com.songoda.skyblock.invite.Invite;
import com.songoda.skyblock.invite.InviteManager; import com.songoda.skyblock.invite.InviteManager;
import com.songoda.skyblock.levelling.LevelChunkSnapshotWrapper;
import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.message.MessageManager;
import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerData;
import com.songoda.skyblock.playerdata.PlayerDataManager; import com.songoda.skyblock.playerdata.PlayerDataManager;
@ -71,6 +70,10 @@ public class IslandManager {
for (Player all : Bukkit.getOnlinePlayers()) { for (Player all : Bukkit.getOnlinePlayers()) {
loadIsland(all); loadIsland(all);
} }
for (Island island : getIslands().values()) {
if (island.isAlwaysLoaded())
loadIslandAtLocation(island.getLocation(IslandWorld.Normal, IslandEnvironment.Island));
}
} }
public void onDisable() { public void onDisable() {
@ -599,15 +602,14 @@ public class IslandManager {
} }
public void unloadIsland(Island island, org.bukkit.OfflinePlayer player) { public void unloadIsland(Island island, org.bukkit.OfflinePlayer player) {
if (island.isAlwaysLoaded()) return;
ScoreboardManager scoreboardManager = skyblock.getScoreboardManager(); ScoreboardManager scoreboardManager = skyblock.getScoreboardManager();
FileManager fileManager = skyblock.getFileManager(); FileManager fileManager = skyblock.getFileManager();
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml")); Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "language.yml"));
FileConfiguration configLoad = config.getFileConfiguration(); FileConfiguration configLoad = config.getFileConfiguration();
if (island.isDeleted()) { if (island.isDeleted()) return;
return;
}
island.save(); island.save();

View File

@ -202,7 +202,8 @@ public class Move implements Listener {
} }
// Load the island they are now on if one exists // 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()); Island loadedIsland = islandManager.loadIslandAtLocation(player.getLocation());
if (loadedIsland != null) { if (loadedIsland != null) {
playerData.setIsland(loadedIsland.getOwnerUUID()); playerData.setIsland(loadedIsland.getOwnerUUID());

View File

@ -224,6 +224,13 @@ Command:
Message: '&bSkyBlock &8| &cError&8: &eYou must enter a numerical value.' Message: '&bSkyBlock &8| &cError&8: &eYou must enter a numerical value.'
Invalid: Invalid:
Message: '&bSkyBlock &8| &cError&8: &eInvalid: /island admin setsize <player> <size>' Message: '&bSkyBlock &8| &cError&8: &eInvalid: /island admin setsize <player> <size>'
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: AddUpgrade:
Info: Info:
Message: '&f&oAdd an upgrade to a player''s Island.' Message: '&f&oAdd an upgrade to a player''s Island.'