diff --git a/src/main/java/com/songoda/skyblock/api/event/island/IslandOpenEvent.java b/src/main/java/com/songoda/skyblock/api/event/island/IslandOpenEvent.java index 9af50890..5ff44b97 100644 --- a/src/main/java/com/songoda/skyblock/api/event/island/IslandOpenEvent.java +++ b/src/main/java/com/songoda/skyblock/api/event/island/IslandOpenEvent.java @@ -4,17 +4,20 @@ import com.songoda.skyblock.api.island.Island; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; +@Deprecated public class IslandOpenEvent extends IslandEvent implements Cancellable { private static final HandlerList HANDLERS = new HandlerList(); private final boolean open; private boolean cancelled = false; - + + @Deprecated public IslandOpenEvent(Island island, boolean open) { super(island); this.open = open; } - + + @Deprecated public boolean isOpen() { return open; } diff --git a/src/main/java/com/songoda/skyblock/api/event/island/IslandStatusChangeEvent.java b/src/main/java/com/songoda/skyblock/api/event/island/IslandStatusChangeEvent.java new file mode 100644 index 00000000..cc60daed --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/event/island/IslandStatusChangeEvent.java @@ -0,0 +1,41 @@ +package com.songoda.skyblock.api.event.island; + +import com.songoda.skyblock.api.island.Island; +import com.songoda.skyblock.api.island.IslandStatus; +import org.bukkit.event.Cancellable; +import org.bukkit.event.HandlerList; + +public class IslandStatusChangeEvent extends IslandEvent implements Cancellable { + + private static final HandlerList HANDLERS = new HandlerList(); + private final IslandStatus status; + private boolean cancelled = false; + + public IslandStatusChangeEvent(Island island, IslandStatus status) { + super(island); + this.status = status; + } + + public IslandStatus getStatus() { + return status; + } + + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + + @Override + public HandlerList getHandlers() { + return HANDLERS; + } + + public HandlerList getHandlerList() { + return HANDLERS; + } +} diff --git a/src/main/java/com/songoda/skyblock/api/island/Island.java b/src/main/java/com/songoda/skyblock/api/island/Island.java index 2173931c..67323db3 100644 --- a/src/main/java/com/songoda/skyblock/api/island/Island.java +++ b/src/main/java/com/songoda/skyblock/api/island/Island.java @@ -7,6 +7,7 @@ import com.songoda.skyblock.api.utils.APIUtil; import com.songoda.skyblock.api.visit.Visit; import com.songoda.skyblock.island.IslandCoop; import com.songoda.skyblock.island.IslandPermission; +import com.songoda.skyblock.island.IslandStatus; import org.bukkit.Location; import org.bukkit.OfflinePlayer; import org.bukkit.WeatherType; @@ -372,12 +373,14 @@ public class Island { /** * @return true of conditions met, false otherwise */ + @Deprecated public boolean isOpen() { - return handle.isOpen(); + return handle.getStatus().equals(IslandStatus.OPEN); } - + + @Deprecated public void setOpen(boolean open) { - this.handle.setOpen(open); + this.handle.setStatus(open ? IslandStatus.OPEN : IslandStatus.CLOSED); } /** diff --git a/src/main/java/com/songoda/skyblock/api/island/IslandStatus.java b/src/main/java/com/songoda/skyblock/api/island/IslandStatus.java new file mode 100644 index 00000000..ebc78b32 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/island/IslandStatus.java @@ -0,0 +1,7 @@ +package com.songoda.skyblock.api.island; + +public enum IslandStatus { + OPEN, + CLOSED, + WHITELISTED +} diff --git a/src/main/java/com/songoda/skyblock/api/utils/APIUtil.java b/src/main/java/com/songoda/skyblock/api/utils/APIUtil.java index a1136354..dd4106cb 100644 --- a/src/main/java/com/songoda/skyblock/api/utils/APIUtil.java +++ b/src/main/java/com/songoda/skyblock/api/utils/APIUtil.java @@ -57,6 +57,32 @@ public final class APIUtil { return null; } + + public static com.songoda.skyblock.island.IslandStatus toImplementation(IslandStatus status) { + switch (status) { + case OPEN: + return com.songoda.skyblock.island.IslandStatus.OPEN; + case CLOSED: + return com.songoda.skyblock.island.IslandStatus.CLOSED; + case WHITELISTED: + return com.songoda.skyblock.island.IslandStatus.WHITELISTED; + } + + return null; + } + + public static IslandStatus fromImplementation(com.songoda.skyblock.island.IslandStatus status) { + switch (status) { + case OPEN: + return IslandStatus.OPEN; + case CLOSED: + return IslandStatus.CLOSED; + case WHITELISTED: + return IslandStatus.WHITELISTED; + } + + return null; + } public static com.songoda.skyblock.island.IslandRole toImplementation(IslandRole role) { switch (role) { diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/CloseCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/CloseCommand.java index 117e1bd8..cb4cfd28 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/CloseCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/CloseCommand.java @@ -6,6 +6,7 @@ import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.sound.SoundManager; import org.bukkit.command.ConsoleCommandSender; @@ -33,7 +34,7 @@ public class CloseCommand extends SubCommand { } else if (island.hasRole(IslandRole.Owner, player.getUniqueId()) || (island.hasRole(IslandRole.Operator, player.getUniqueId()) && skyblock.getPermissionManager().hasPermission(island,"Visitor", IslandRole.Operator))) { - if (island.isOpen()) { + if (island.getStatus().equals(IslandStatus.OPEN) || island.getStatus().equals(IslandStatus.WHITELISTED)) { islandManager.closeIsland(island); messageManager.sendMessage(player, configLoad.getString("Command.Island.Close.Closed.Message")); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/ConfirmCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/ConfirmCommand.java index 1d11a8c8..c92b0c2a 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/ConfirmCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/ConfirmCommand.java @@ -10,6 +10,7 @@ import com.songoda.skyblock.cooldown.CooldownType; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; @@ -106,11 +107,11 @@ public class ConfirmCommand extends SubCommand { .getString("Command.Island.Confirmation.Ownership.Member.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } - } else if (confirmation == Confirmation.Reset) { + } else if (confirmation.equals(Confirmation.Reset)) { playerData.setConfirmation(null); playerData.setConfirmationTime(0); - } else if (confirmation == Confirmation.Deletion) { - if (island.isOpen()) { + } else if (confirmation.equals(Confirmation.Deletion)) { + if (island.getStatus().equals(IslandStatus.OPEN)) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Confirmation.Deletion.Open.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/CoopCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/CoopCommand.java index a93e36dc..5ae35b0a 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/CoopCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/CoopCommand.java @@ -4,10 +4,7 @@ import com.songoda.core.compatibility.CompatibleSound; 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.IslandCoop; -import com.songoda.skyblock.island.IslandManager; -import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.island.*; import com.songoda.skyblock.menus.Coop; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.permission.PermissionManager; @@ -85,7 +82,8 @@ public class CoopCommand extends SubCommand { } else if (island.isCoopPlayer(targetPlayerUUID)) { if (targetPlayer != null) { if (islandManager.getVisitorsAtIsland(island).contains(targetPlayerUUID)) { - if (!island.isOpen()) { + if (!(island.getStatus().equals(IslandStatus.OPEN) || + (island.getStatus().equals(IslandStatus.WHITELISTED) && island.isPlayerWhitelisted(player)))) { LocationUtil.teleportPlayerToSpawn(targetPlayer); messageManager.sendMessage(targetPlayer, diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/KickAllCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/KickAllCommand.java index e0f8d686..804dc59e 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/KickAllCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/KickAllCommand.java @@ -8,6 +8,7 @@ import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.sound.SoundManager; import com.songoda.skyblock.utils.world.LocationUtil; @@ -39,7 +40,7 @@ public class KickAllCommand extends SubCommand { } else if (island.hasRole(IslandRole.Owner, player.getUniqueId()) || (island.hasRole(IslandRole.Operator, player.getUniqueId()) && skyblock.getPermissionManager().hasPermission(island, "Kick", IslandRole.Operator))) { - if (island.isOpen()) { + if (!island.getStatus().equals(IslandStatus.CLOSED)) { Set islandVisitors = islandManager.getVisitorsAtIsland(island); if (islandVisitors.size() == 0) { diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java index ee2be148..924810a1 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/KickCommand.java @@ -6,6 +6,7 @@ import java.util.Set; import java.util.UUID; import com.songoda.core.compatibility.CompatibleSound; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.permission.PermissionManager; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -84,7 +85,7 @@ public class KickCommand extends SubCommand { } else if (island.getOwnerUUID().equals(targetPlayerUUID)) { messageManager.sendMessage(player, languageConfig.getFileConfiguration().getString("Command.Island.Kick.Role.Owner.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); - } else if (island.isOpen() && islandVisitors.contains(targetPlayerUUID)) { + } else if (!island.getStatus().equals(IslandStatus.CLOSED) && islandVisitors.contains(targetPlayerUUID)) { if (island.isCoopPlayer(targetPlayerUUID)) { messageManager.sendMessage(player, languageConfig.getFileConfiguration().getString("Command.Island.Kick.Cooped.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); @@ -205,19 +206,27 @@ public class KickCommand extends SubCommand { } } } else { - if (island.isOpen()) { - messageManager.sendMessage(player, languageConfig.getFileConfiguration().getString("Command.Island.Kick.Occupant.Visit.Open.Message")); - } else { - messageManager.sendMessage(player, languageConfig.getFileConfiguration().getString("Command.Island.Kick.Occupant.Visit.Closed.Message")); + switch (island.getStatus()){ + case OPEN: + case WHITELISTED: + messageManager.sendMessage(player, languageConfig.getFileConfiguration().getString("Command.Island.Kick.Occupant.Visit.Open.Message")); + break; + case CLOSED: + messageManager.sendMessage(player, languageConfig.getFileConfiguration().getString("Command.Island.Kick.Occupant.Visit.Closed.Message")); + break; } soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } } else { - if (island.isOpen()) { - messageManager.sendMessage(player, languageConfig.getFileConfiguration().getString("Command.Island.Kick.Permission.Visit.Open.Message")); - } else { - messageManager.sendMessage(player, languageConfig.getFileConfiguration().getString("Command.Island.Kick.Permission.Visit.Closed.Message")); + switch (island.getStatus()){ + case OPEN: + case WHITELISTED: + messageManager.sendMessage(player, languageConfig.getFileConfiguration().getString("Command.Island.Kick.Permission.Visit.Open.Message")); + break; + case CLOSED: + messageManager.sendMessage(player, languageConfig.getFileConfiguration().getString("Command.Island.Kick.Permission.Visit.Closed.Message")); + break; } soundManager.playSound(player, CompatibleSound.ENTITY_VILLAGER_NO.getSound(), 1.0F, 1.0F); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/OpenCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/OpenCommand.java index 9e7fef50..ea7ae61d 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/OpenCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/OpenCommand.java @@ -6,6 +6,7 @@ import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.sound.SoundManager; @@ -35,11 +36,11 @@ public class OpenCommand extends SubCommand { } else if (island.hasRole(IslandRole.Owner, player.getUniqueId()) || (island.hasRole(IslandRole.Operator, player.getUniqueId()) && permissionManager.hasPermission(island, "Visitor", IslandRole.Operator))) { - if (island.isOpen()) { + if (island.getStatus().equals(IslandStatus.OPEN)) { messageManager.sendMessage(player, configLoad.getString("Command.Island.Open.Already.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else { - island.setOpen(true); + island.setStatus(IslandStatus.OPEN); messageManager.sendMessage(player, configLoad.getString("Command.Island.Open.Opened.Message")); soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1.0F, 1.0F); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/PublicCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/PublicCommand.java index 3cf701fa..61ae2c0a 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/PublicCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/PublicCommand.java @@ -6,6 +6,7 @@ import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.sound.SoundManager; import org.bukkit.command.ConsoleCommandSender; @@ -33,16 +34,25 @@ public class PublicCommand extends SubCommand { } else if (island.hasRole(IslandRole.Owner, player.getUniqueId()) || (island.hasRole(IslandRole.Operator, player.getUniqueId()) && skyblock.getPermissionManager().hasPermission(island, "Visitor", IslandRole.Operator))) { - if (island.isOpen()) { - islandManager.closeIsland(island); - - messageManager.sendMessage(player, configLoad.getString("Command.Island.Public.Private.Message")); - soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); - } else { - island.setOpen(true); - - messageManager.sendMessage(player, configLoad.getString("Command.Island.Public.Public.Message")); - soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1.0F, 1.0F); + switch (island.getStatus()) { + case OPEN: + islandManager.whitelistIsland(island); + + messageManager.sendMessage(player, configLoad.getString("Command.Island.Public.Restricted.Message")); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); + break; + case CLOSED: + islandManager.closeIsland(island); + + messageManager.sendMessage(player, configLoad.getString("Command.Island.Public.Private.Message")); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); + break; + case WHITELISTED: + island.setStatus(IslandStatus.OPEN); + + messageManager.sendMessage(player, configLoad.getString("Command.Island.Public.Public.Message")); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1.0F, 1.0F); + break; } } else { messageManager.sendMessage(player, configLoad.getString("Command.Island.Public.Permission.Message")); diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/TeleportCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/TeleportCommand.java index d5f6af4c..88ccc533 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/TeleportCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/TeleportCommand.java @@ -3,10 +3,7 @@ package com.songoda.skyblock.command.commands.island; import com.songoda.core.compatibility.CompatibleSound; import com.songoda.skyblock.command.SubCommand; import com.songoda.skyblock.config.FileManager.Config; -import com.songoda.skyblock.island.Island; -import com.songoda.skyblock.island.IslandEnvironment; -import com.songoda.skyblock.island.IslandManager; -import com.songoda.skyblock.island.IslandWorld; +import com.songoda.skyblock.island.*; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.playerdata.PlayerDataManager; import com.songoda.skyblock.sound.SoundManager; @@ -68,12 +65,17 @@ public class TeleportCommand extends SubCommand { if (islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)).isCoopPlayer(player.getUniqueId())) { isCoopPlayer = true; } - if (islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)).isPlayerWhitelisted(player.getUniqueId())) { + if (visit.getStatus().equals(IslandStatus.WHITELISTED) && islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)).isPlayerWhitelisted(player.getUniqueId())) { isWhitelistedPlayer = true; } } - if (isCoopPlayer || isWhitelistedPlayer || player.hasPermission("fabledskyblock.bypass") || player.hasPermission("fabledskyblock.bypass.*") || player.hasPermission("fabledskyblock.*") || visit.isOpen()) { + if (visit.getStatus().equals(IslandStatus.OPEN) || + isCoopPlayer || + isWhitelistedPlayer || + player.hasPermission("fabledskyblock.bypass") || + player.hasPermission("fabledskyblock.bypass.*") || + player.hasPermission("fabledskyblock.*")) { if (!islandManager.containsIsland(islandOwnerUUID)) { islandManager.loadIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)); } diff --git a/src/main/java/com/songoda/skyblock/command/commands/island/VoteCommand.java b/src/main/java/com/songoda/skyblock/command/commands/island/VoteCommand.java index f2ac88a0..19fea256 100644 --- a/src/main/java/com/songoda/skyblock/command/commands/island/VoteCommand.java +++ b/src/main/java/com/songoda/skyblock/command/commands/island/VoteCommand.java @@ -9,6 +9,7 @@ import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.playerdata.PlayerData; import com.songoda.skyblock.playerdata.PlayerDataManager; @@ -68,13 +69,13 @@ public class VoteCommand extends SubCommand { soundManager.playSound(player, CompatibleSound.BLOCK_ANVIL_LAND.getSound(), 1.0F, 1.0F); } else { Visit visit = visitManager.getIsland(islandOwnerUUID); + if (!islandManager.containsIsland(islandOwnerUUID)) { + islandManager.loadIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)); + } + + Island island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)); - if (visit.isOpen()) { - if (!islandManager.containsIsland(islandOwnerUUID)) { - islandManager.loadIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)); - } - - Island island = islandManager.getIsland(Bukkit.getServer().getOfflinePlayer(islandOwnerUUID)); + if (visit.getStatus().equals(IslandStatus.OPEN)) { if (island.hasRole(IslandRole.Member, player.getUniqueId()) || island.hasRole(IslandRole.Operator, player.getUniqueId()) diff --git a/src/main/java/com/songoda/skyblock/gui/permissions/GuiPermissions.java b/src/main/java/com/songoda/skyblock/gui/permissions/GuiPermissions.java index 55c499dc..3a5825dd 100644 --- a/src/main/java/com/songoda/skyblock/gui/permissions/GuiPermissions.java +++ b/src/main/java/com/songoda/skyblock/gui/permissions/GuiPermissions.java @@ -12,6 +12,7 @@ import com.songoda.skyblock.gui.GuiWelcomeEditor; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandPermission; import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.permission.BasicPermission; import com.songoda.skyblock.permission.PermissionManager; import com.songoda.skyblock.permission.PermissionType; @@ -78,10 +79,19 @@ public class GuiPermissions extends Gui { } Visit visit = island.getVisit(); - List welcomeLore = TextUtils.formatText(configLoad.getStringList( - island.isOpen() - ? "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Closed.Lore" - : "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Open.Lore")); + String configAddress = ""; + switch (island.getStatus()) { + case OPEN: + configAddress = "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Open.Lore"; + break; + case CLOSED: + configAddress = "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Closed.Lore"; + break; + case WHITELISTED: + configAddress = "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Whitelisted.Lore"; + break; + } + List welcomeLore = TextUtils.formatText(configLoad.getStringList(configAddress)); List welcomeFinal = new ArrayList<>(); @@ -95,12 +105,19 @@ public class GuiPermissions extends Gui { TextUtils.formatText(configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname")), welcomeFinal), (event -> { - if (island.isOpen()) { - plugin.getIslandManager().closeIsland(island); - soundManager.playSound(event.player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1f, 1f); - } else { - island.setOpen(true); - soundManager.playSound(event.player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1f, 1f); + switch (island.getStatus()) { + case OPEN: + plugin.getIslandManager().whitelistIsland(island); + soundManager.playSound(event.player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1f, 1f); + break; + case CLOSED: + plugin.getIslandManager().closeIsland(island); + soundManager.playSound(event.player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1f, 1f); + break; + case WHITELISTED: + island.setStatus(IslandStatus.OPEN); + soundManager.playSound(event.player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1f, 1f); + break; } paint(); })); diff --git a/src/main/java/com/songoda/skyblock/island/Island.java b/src/main/java/com/songoda/skyblock/island/Island.java index 30aceaed..91868415 100644 --- a/src/main/java/com/songoda/skyblock/island/Island.java +++ b/src/main/java/com/songoda/skyblock/island/Island.java @@ -45,6 +45,7 @@ public class Island { private UUID islandUUID; private UUID ownerUUID; private IslandLevel level; + private IslandStatus status; private int size; private int maxMembers; private boolean deleted = false; @@ -193,11 +194,33 @@ public class Island { whitelistedPlayers.add(UUID.fromString(whitelistedUUID)); } } + + if(configLoad.getString("Visitor.Open", null).equalsIgnoreCase("true") || + configLoad.getString("Visitor.Open", null).equalsIgnoreCase("false")) { + if(configLoad.getBoolean("Visitor.Open")) { + status = IslandStatus.OPEN; + } else { + status = IslandStatus.CLOSED; + } + configLoad.set("Visitor.Open", null); + } else { + IslandStatus status = IslandStatus.valueOf(configLoad.getString("Visitor.Status")); + switch (status){ + case OPEN: + case CLOSED: + case WHITELISTED: + this.status = status; + break; + default: + this.status = IslandStatus.WHITELISTED; + break; + } + } } else { FileConfiguration configLoad = config.getFileConfiguration(); configLoad.set("UUID", islandUUID.toString()); - configLoad.set("Visitor.Open", mainConfigLoad.getBoolean("Island.Visitor.Open")); + configLoad.set("Visitor.Status", mainConfigLoad.getString("Island.Visitor.Status")); configLoad.set("Border.Enable", mainConfig.getFileConfiguration().getBoolean("Island.WorldBorder.Default", false)); configLoad.set("Border.Color", WorldBorder.Color.Blue.name()); configLoad.set("Biome.Type", mainConfigLoad.getString("Island.Biome.Default.Type").toUpperCase()); @@ -742,22 +765,24 @@ public class Island { public void removeFromBank(double value) { addToBank(-value); } - - public boolean isOpen() { - return skyblock.getFileManager().getConfig( - new File(new File(skyblock.getDataFolder().toString() + "/island-data"), ownerUUID.toString() + ".yml")) - .getFileConfiguration().getBoolean("Visitor.Open"); + + public IslandStatus getStatus() { + return this.status; } - - public void setOpen(boolean open) { - IslandOpenEvent islandOpenEvent = new IslandOpenEvent(getAPIWrapper(), open); + + public void setStatus(IslandStatus status) { + IslandOpenEvent islandOpenEvent = new IslandOpenEvent(getAPIWrapper(), status.equals(IslandStatus.OPEN)); Bukkit.getServer().getPluginManager().callEvent(islandOpenEvent); - - if (!islandOpenEvent.isCancelled()) { - skyblock.getFileManager().getConfig( - new File(new File(skyblock.getDataFolder().toString() + "/island-data"), ownerUUID.toString() + ".yml")) - .getFileConfiguration().set("Visitor.Open", open); - getVisit().setOpen(open); + if(islandOpenEvent.isCancelled()) { + return; + } + + IslandStatusChangeEvent islandStatusChangeEvent = new IslandStatusChangeEvent(getAPIWrapper(), APIUtil.fromImplementation(status)); + Bukkit.getServer().getPluginManager().callEvent(islandStatusChangeEvent); + if(!islandStatusChangeEvent.isCancelled()) { + this.status = status; + getVisit().setStatus(status); + // TODO Save to config } } diff --git a/src/main/java/com/songoda/skyblock/island/IslandManager.java b/src/main/java/com/songoda/skyblock/island/IslandManager.java index a631ab50..b979d027 100644 --- a/src/main/java/com/songoda/skyblock/island/IslandManager.java +++ b/src/main/java/com/songoda/skyblock/island/IslandManager.java @@ -239,7 +239,7 @@ public class IslandManager { new IslandLocation[]{island.getIslandLocation(IslandWorld.Normal, IslandEnvironment.Island), island.getIslandLocation(IslandWorld.Nether, IslandEnvironment.Island), island.getIslandLocation(IslandWorld.End, IslandEnvironment.Island)}, island.getSize(), island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1, island.getBankBalance(), visitManager.getIslandSafeLevel(island.getOwnerUUID()), island.getLevel(), - island.getMessage(IslandMessage.Signature), island.isOpen()); + island.getMessage(IslandMessage.Signature), island.getStatus()); } if (!banManager.hasIsland(island.getOwnerUUID())) banManager.createIsland(island.getOwnerUUID()); @@ -743,7 +743,7 @@ public class IslandManager { new IslandLocation[]{island.getIslandLocation(IslandWorld.Normal, IslandEnvironment.Island), island.getIslandLocation(IslandWorld.Nether, IslandEnvironment.Island), island.getIslandLocation(IslandWorld.End, IslandEnvironment.Island)}, island.getSize(), island.getRole(IslandRole.Member).size() + island.getRole(IslandRole.Operator).size() + 1, island.getBankBalance(), visitManager.getIslandSafeLevel(island.getOwnerUUID()), - island.getLevel(), island.getMessage(IslandMessage.Signature), island.isOpen()); + island.getLevel(), island.getMessage(IslandMessage.Signature), island.getStatus()); } if (!banManager.hasIsland(island.getOwnerUUID())) { @@ -900,7 +900,7 @@ public class IslandManager { int nonIslandMembers = islandVisitors - getCoopPlayersAtIsland(island).size(); if (nonIslandMembers <= 0) { - if (island.isOpen()) { + if (island.getStatus().equals(IslandStatus.OPEN)) { return; } else if (player != null) { removeCoopPlayers(island, player.getUniqueId()); @@ -1177,7 +1177,7 @@ public class IslandManager { Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")); FileConfiguration configLoad = config.getFileConfiguration(); - island.setOpen(false); + island.setStatus(IslandStatus.CLOSED); UUID islandOwnerUUID = island.getOwnerUUID(); Player islandOwnerPlayer = Bukkit.getServer().getPlayer(islandOwnerUUID); @@ -1190,13 +1190,40 @@ public class IslandManager { } for (UUID visitor : getVisitorsAtIsland(island)) { - if (!island.isCoopPlayer(visitor) && !island.isPlayerWhitelisted(visitor)) { + if (!island.isCoopPlayer(visitor)) { Player targetPlayer = Bukkit.getServer().getPlayer(visitor); LocationUtil.teleportPlayerToSpawn(targetPlayer); messageManager.sendMessage(targetPlayer, configLoad.getString("Island.Visit.Closed.Island.Message").replace("%player", islandOwnerPlayerName)); } } } + + public void whitelistIsland(Island island) { + MessageManager messageManager = skyblock.getMessageManager(); + + Config config = skyblock.getFileManager().getConfig(new File(skyblock.getDataFolder(), "language.yml")); + FileConfiguration configLoad = config.getFileConfiguration(); + + island.setStatus(IslandStatus.WHITELISTED); + + UUID islandOwnerUUID = island.getOwnerUUID(); + Player islandOwnerPlayer = Bukkit.getServer().getPlayer(islandOwnerUUID); + String islandOwnerPlayerName; + + if (islandOwnerPlayer == null) { + islandOwnerPlayerName = new OfflinePlayer(islandOwnerUUID).getName(); + } else { + islandOwnerPlayerName = islandOwnerPlayer.getName(); + } + + for (UUID visitor : getVisitorsAtIsland(island)) { + if (!island.isCoopPlayer(visitor) && !island.isPlayerWhitelisted(visitor)) { + Player targetPlayer = Bukkit.getServer().getPlayer(visitor); + LocationUtil.teleportPlayerToSpawn(targetPlayer); + messageManager.sendMessage(targetPlayer, configLoad.getString("Island.Visit.Whitelisted.Island.Message").replace("%player", islandOwnerPlayerName)); // TODO + } + } + } public Island getIsland(org.bukkit.OfflinePlayer offlinePlayer) { PlayerDataManager playerDataManager = skyblock.getPlayerDataManager(); diff --git a/src/main/java/com/songoda/skyblock/island/IslandStatus.java b/src/main/java/com/songoda/skyblock/island/IslandStatus.java new file mode 100644 index 00000000..f45f3d59 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/island/IslandStatus.java @@ -0,0 +1,7 @@ +package com.songoda.skyblock.island; + +public enum IslandStatus { + OPEN, + CLOSED, + WHITELISTED +} diff --git a/src/main/java/com/songoda/skyblock/listeners/Move.java b/src/main/java/com/songoda/skyblock/listeners/Move.java index 682ae6d0..d568f5d8 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Move.java +++ b/src/main/java/com/songoda/skyblock/listeners/Move.java @@ -179,7 +179,8 @@ public class Move implements Listener { return; } - if(loadedIsland.isOpen() || loadedIsland.isPlayerWhitelisted(player)){ + if(loadedIsland.getStatus().equals(IslandStatus.OPEN) || + (loadedIsland.getStatus().equals(IslandStatus.WHITELISTED) && loadedIsland.isPlayerWhitelisted(player))){ loadedIsland.getVisit().addVisitor(player.getUniqueId()); return; } diff --git a/src/main/java/com/songoda/skyblock/listeners/Teleport.java b/src/main/java/com/songoda/skyblock/listeners/Teleport.java index faac4882..16073290 100644 --- a/src/main/java/com/songoda/skyblock/listeners/Teleport.java +++ b/src/main/java/com/songoda/skyblock/listeners/Teleport.java @@ -10,6 +10,7 @@ import com.songoda.skyblock.api.island.Island; import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.IslandManager; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.island.IslandWorld; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.playerdata.PlayerData; @@ -98,7 +99,9 @@ public class Teleport implements Listener { if (island != null) { if (!island.getOwnerUUID().equals(playerData.getOwner())) { if (!player.hasPermission("fabledskyblock.bypass") && !player.hasPermission("fabledskyblock.bypass.*") && !player.hasPermission("fabledskyblock.*")) { - if (!island.isOpen() && !island.isCoopPlayer(player.getUniqueId()) && !island.isPlayerWhitelisted(player)) { + if (!island.getStatus().equals(IslandStatus.OPEN) && + !island.isCoopPlayer(player.getUniqueId()) && + !(island.getStatus().equals(IslandStatus.WHITELISTED) && island.isPlayerWhitelisted(player))) { event.setCancelled(true); messageManager.sendMessage(player, configLoad.getString("Island.Visit.Closed.Plugin.Message")); diff --git a/src/main/java/com/songoda/skyblock/menus/ControlPanel.java b/src/main/java/com/songoda/skyblock/menus/ControlPanel.java index 9af4c2e4..db91e5f0 100644 --- a/src/main/java/com/songoda/skyblock/menus/ControlPanel.java +++ b/src/main/java/com/songoda/skyblock/menus/ControlPanel.java @@ -39,10 +39,16 @@ public final class ControlPanel { final Island island = SkyBlock.getInstance().getIslandManager().getIsland((Player) player); - if (island.isOpen()) { - Bukkit.getServer().getScheduler().runTaskLater(inst, () -> Bukkit.getServer().dispatchCommand(player, "island close"), 1L); - } else { - Bukkit.getServer().getScheduler().runTaskLater(inst, () -> Bukkit.getServer().dispatchCommand(player, "island open"), 1L); + switch (island.getStatus()) { + case OPEN: + Bukkit.getServer().getScheduler().runTaskLater(inst, () -> Bukkit.getServer().dispatchCommand(player, "island whitelist on"), 1L); + break; + case CLOSED: + Bukkit.getServer().getScheduler().runTaskLater(inst, () -> Bukkit.getServer().dispatchCommand(player, "island open"), 1L); + break; + case WHITELISTED: + Bukkit.getServer().getScheduler().runTaskLater(inst, () -> Bukkit.getServer().dispatchCommand(player, "island close"), 1L); + break; } }); diff --git a/src/main/java/com/songoda/skyblock/menus/Information.java b/src/main/java/com/songoda/skyblock/menus/Information.java index 102ec961..bdb31da7 100644 --- a/src/main/java/com/songoda/skyblock/menus/Information.java +++ b/src/main/java/com/songoda/skyblock/menus/Information.java @@ -8,6 +8,7 @@ import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.placeholder.Placeholder; import com.songoda.skyblock.playerdata.PlayerData; @@ -76,7 +77,7 @@ public class Information { } if (viewer.getType() == Information.Viewer.Type.Visitors) { - if (island.isOpen()) { + if (!island.getStatus().equals(IslandStatus.CLOSED)) { if (islandManager.getVisitorsAtIsland(island).size() == 0) { messageManager.sendMessage(player, configLoad.getString("Island.Information.Visitors.Message")); diff --git a/src/main/java/com/songoda/skyblock/menus/Settings.java b/src/main/java/com/songoda/skyblock/menus/Settings.java index 79772e7a..274a0292 100644 --- a/src/main/java/com/songoda/skyblock/menus/Settings.java +++ b/src/main/java/com/songoda/skyblock/menus/Settings.java @@ -286,12 +286,19 @@ public class Settings { } else if ((is.getType() == Material.PAINTING) && (is.hasItemMeta()) && (is.getItemMeta() .getDisplayName().equals(ChatColor.translateAlternateColorCodes('&', configLoad .getString("Menu.Settings.Visitor.Item.Statistics.Displayname"))))) { - if (island14.isOpen()) { - islandManager.closeIsland(island14); - soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); - } else { - island14.setOpen(true); - soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1.0F, 1.0F); + switch (island14.getStatus()) { + case OPEN: + islandManager.whitelistIsland(island14); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); + break; + case CLOSED: + island14.setStatus(IslandStatus.OPEN); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1.0F, 1.0F); + break; + case WHITELISTED: + islandManager.closeIsland(island14); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); + break; } Bukkit.getServer().getScheduler().runTaskLater(skyblock, () -> open(player, Type.Role, IslandRole.Visitor, null), 1L); @@ -349,46 +356,73 @@ public class Settings { } if (config.getFileConfiguration().getBoolean("Island.Visitor.Vote")) { - if (visit.isOpen()) { - nInv.addItem(nInv.createItem(new ItemStack(Material.PAINTING), - configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname"), - configLoad.getStringList( - "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Open.Lore"), - new Placeholder[]{new Placeholder("%visits", "" + visit.getVisitors().size()), - new Placeholder("%votes", "" + visit.getVoters().size()), - new Placeholder("%visitors", - "" + islandManager.getVisitorsAtIsland(island).size())}, - null, null), 4); - } else { - nInv.addItem(nInv.createItem(new ItemStack(Material.PAINTING), - configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname"), - configLoad.getStringList( - "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Closed.Lore"), - new Placeholder[]{new Placeholder("%visits", "" + visit.getVisitors().size()), - new Placeholder("%votes", "" + visit.getVoters().size()), - new Placeholder("%visitors", - "" + islandManager.getVisitorsAtIsland(island).size())}, - null, null), 4); + switch (visit.getStatus()){ + case OPEN: + nInv.addItem(nInv.createItem(new ItemStack(Material.PAINTING), + configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname"), + configLoad.getStringList( + "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Open.Lore"), + new Placeholder[]{new Placeholder("%visits", "" + visit.getVisitors().size()), + new Placeholder("%votes", "" + visit.getVoters().size()), + new Placeholder("%visitors", + "" + islandManager.getVisitorsAtIsland(island).size())}, + null, null), 4); + break; + case CLOSED: + nInv.addItem(nInv.createItem(new ItemStack(Material.PAINTING), + configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname"), + configLoad.getStringList( + "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Closed.Lore"), + new Placeholder[]{new Placeholder("%visits", "" + visit.getVisitors().size()), + new Placeholder("%votes", "" + visit.getVoters().size()), + new Placeholder("%visitors", + "" + islandManager.getVisitorsAtIsland(island).size())}, + null, null), 4); + break; + case WHITELISTED: + nInv.addItem(nInv.createItem(new ItemStack(Material.PAINTING), + configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname"), + configLoad.getStringList( + "Menu.Settings.Visitor.Item.Statistics.Vote.Enabled.Whitelisted.Lore"), + new Placeholder[]{new Placeholder("%visits", "" + visit.getVisitors().size()), + new Placeholder("%votes", "" + visit.getVoters().size()), + new Placeholder("%visitors", + "" + islandManager.getVisitorsAtIsland(island).size())}, + null, null), 4); + break; } } else { - if (visit.isOpen()) { - nInv.addItem(nInv.createItem(new ItemStack(Material.PAINTING), - configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname"), - configLoad.getStringList( - "Menu.Settings.Visitor.Item.Statistics.Vote.Disabled.Open.Lore"), - new Placeholder[]{new Placeholder("%visits", "" + visit.getVisitors().size()), - new Placeholder("%visitors", - "" + islandManager.getVisitorsAtIsland(island).size())}, - null, null), 4); - } else { - nInv.addItem(nInv.createItem(new ItemStack(Material.PAINTING), - configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname"), - configLoad.getStringList( - "Menu.Settings.Visitor.Item.Statistics.Vote.Disabled.Closed.Lore"), - new Placeholder[]{new Placeholder("%visits", "" + visit.getVisitors().size()), - new Placeholder("%visitors", - "" + islandManager.getVisitorsAtIsland(island).size())}, - null, null), 4); + switch (visit.getStatus()){ + case OPEN: + nInv.addItem(nInv.createItem(new ItemStack(Material.PAINTING), + configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname"), + configLoad.getStringList( + "Menu.Settings.Visitor.Item.Statistics.Vote.Disabled.Open.Lore"), + new Placeholder[]{new Placeholder("%visits", "" + visit.getVisitors().size()), + new Placeholder("%visitors", + "" + islandManager.getVisitorsAtIsland(island).size())}, + null, null), 4); + break; + case CLOSED: + nInv.addItem(nInv.createItem(new ItemStack(Material.PAINTING), + configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname"), + configLoad.getStringList( + "Menu.Settings.Visitor.Item.Statistics.Vote.Disabled.Closed.Lore"), + new Placeholder[]{new Placeholder("%visits", "" + visit.getVisitors().size()), + new Placeholder("%visitors", + "" + islandManager.getVisitorsAtIsland(island).size())}, + null, null), 4); + break; + case WHITELISTED: + nInv.addItem(nInv.createItem(new ItemStack(Material.PAINTING), + configLoad.getString("Menu.Settings.Visitor.Item.Statistics.Displayname"), + configLoad.getStringList( + "Menu.Settings.Visitor.Item.Statistics.Vote.Whitelisted.Closed.Lore"), + new Placeholder[]{new Placeholder("%visits", "" + visit.getVisitors().size()), + new Placeholder("%visitors", + "" + islandManager.getVisitorsAtIsland(island).size())}, + null, null), 4); + break; } } @@ -1049,12 +1083,19 @@ public class Settings { && (is.getItemMeta().getDisplayName().equals( ChatColor.translateAlternateColorCodes('&', configLoad.getString( "Menu.Settings.Visitor.Item.Statistics.Displayname"))))) { - if (island15.isOpen()) { - islandManager.closeIsland(island15); - soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); - } else { - island15.setOpen(true); - soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1.0F, 1.0F); + switch (island15.getStatus()) { + case OPEN: + islandManager.whitelistIsland(island15); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); + break; + case CLOSED: + island15.setStatus(IslandStatus.OPEN); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1.0F, 1.0F); + break; + case WHITELISTED: + islandManager.closeIsland(island15); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); + break; } Bukkit.getServer().getScheduler().runTaskLater(skyblock, @@ -1300,12 +1341,19 @@ public class Settings { && (is.getItemMeta().getDisplayName().equals( ChatColor.translateAlternateColorCodes('&', configLoad.getString( "Menu.Settings.Visitor.Item.Statistics.Displayname"))))) { - if (island12.isOpen()) { - islandManager.closeIsland(island12); - soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); - } else { - island12.setOpen(true); - soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1.0F, 1.0F); + switch (island12.getStatus()) { + case OPEN: + islandManager.whitelistIsland(island12); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); + break; + case CLOSED: + island12.setStatus(IslandStatus.OPEN); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_OPEN.getSound(), 1.0F, 1.0F); + break; + case WHITELISTED: + islandManager.closeIsland(island12); + soundManager.playSound(player, CompatibleSound.BLOCK_WOODEN_DOOR_CLOSE.getSound(), 1.0F, 1.0F); + break; } Bukkit.getServer().getScheduler().runTaskLater(skyblock, diff --git a/src/main/java/com/songoda/skyblock/menus/Visit.java b/src/main/java/com/songoda/skyblock/menus/Visit.java index 9cdc4a9a..38c681f7 100644 --- a/src/main/java/com/songoda/skyblock/menus/Visit.java +++ b/src/main/java/com/songoda/skyblock/menus/Visit.java @@ -9,6 +9,7 @@ import com.songoda.skyblock.config.FileManager.Config; import com.songoda.skyblock.island.Island; import com.songoda.skyblock.island.IslandManager; import com.songoda.skyblock.island.IslandRole; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.placeholder.Placeholder; import com.songoda.skyblock.playerdata.PlayerData; @@ -153,14 +154,15 @@ public class Visit { if (islandManager.getIsland(offlinePlayer).isCoopPlayer(player.getUniqueId())) { isCoopPlayer = true; } - if (islandManager.getIsland(offlinePlayer).isPlayerWhitelisted(player.getUniqueId())) { + if (visit.getStatus().equals(IslandStatus.WHITELISTED) && + islandManager.getIsland(offlinePlayer).isPlayerWhitelisted(player.getUniqueId())) { isWhitelistedPlayer = true; } } - if (isCoopPlayer || isWhitelistedPlayer || player.hasPermission("fabledskyblock.bypass") + if (visit.getStatus().equals(IslandStatus.OPEN) || isCoopPlayer || isWhitelistedPlayer || player.hasPermission("fabledskyblock.bypass") || player.hasPermission("fabledskyblock.bypass.*") - || player.hasPermission("fabledskyblock.*") || visit.isOpen()) { + || player.hasPermission("fabledskyblock.*")) { if (!islandManager.containsIsland(targetPlayerUUID)) { islandManager.loadIsland(Bukkit.getServer().getOfflinePlayer(targetPlayerUUID)); } diff --git a/src/main/java/com/songoda/skyblock/placeholder/PlaceholderManager.java b/src/main/java/com/songoda/skyblock/placeholder/PlaceholderManager.java index 23a84e63..84f4e00c 100644 --- a/src/main/java/com/songoda/skyblock/placeholder/PlaceholderManager.java +++ b/src/main/java/com/songoda/skyblock/placeholder/PlaceholderManager.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.UUID; import com.songoda.core.compatibility.CompatibleMaterial; +import com.songoda.skyblock.island.IslandStatus; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.configuration.file.FileConfiguration; @@ -90,7 +91,7 @@ public class PlaceholderManager { return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.fabledskyblock_island_isopen.Empty.Message")); } else { - if (island.isOpen()) { + if (island.getStatus().equals(IslandStatus.OPEN)) { // TODO Update to Status return ChatColor.translateAlternateColorCodes('&', configLoad.getString("Placeholder.fabledskyblock_island_isopen.Open.Message")); } else { diff --git a/src/main/java/com/songoda/skyblock/playerdata/PlayerDataManager.java b/src/main/java/com/songoda/skyblock/playerdata/PlayerDataManager.java index 7ab1079f..7e3b5c29 100644 --- a/src/main/java/com/songoda/skyblock/playerdata/PlayerDataManager.java +++ b/src/main/java/com/songoda/skyblock/playerdata/PlayerDataManager.java @@ -171,8 +171,8 @@ public class PlayerDataManager { islandManager.updateFlight(player); return; - } else if (island.isOpen() || island.isCoopPlayer(player.getUniqueId())) { - if (!island.isOpen() && island.isCoopPlayer(player.getUniqueId())) { + } else if (!island.getStatus().equals(IslandStatus.CLOSED) || island.isCoopPlayer(player.getUniqueId())) { + if (island.getStatus().equals(IslandStatus.CLOSED) && island.isCoopPlayer(player.getUniqueId())) { if (islandManager.removeCoopPlayers(island, null)) { return; } @@ -253,8 +253,8 @@ public class PlayerDataManager { island = islandManager.getIsland(offlinePlayer); if (island != null) { - if (island.isOpen() || island.isCoopPlayer(player.getUniqueId())) { - if (!island.isOpen() && island.isCoopPlayer(player.getUniqueId())) { + if (!island.getStatus().equals(IslandStatus.CLOSED) || island.isCoopPlayer(player.getUniqueId())) { + if (island.getStatus().equals(IslandStatus.CLOSED) && island.isCoopPlayer(player.getUniqueId())) { if (islandManager.removeCoopPlayers(island, null)) { islandManager.unloadIsland(island, Bukkit.getServer().getOfflinePlayer(visitIslandList)); diff --git a/src/main/java/com/songoda/skyblock/visit/Visit.java b/src/main/java/com/songoda/skyblock/visit/Visit.java index be6facca..958f17f0 100644 --- a/src/main/java/com/songoda/skyblock/visit/Visit.java +++ b/src/main/java/com/songoda/skyblock/visit/Visit.java @@ -5,6 +5,7 @@ import com.songoda.skyblock.ban.Ban; import com.songoda.skyblock.config.FileManager; import com.songoda.skyblock.island.IslandLevel; import com.songoda.skyblock.island.IslandLocation; +import com.songoda.skyblock.island.IslandStatus; import com.songoda.skyblock.island.IslandWorld; import org.bukkit.configuration.file.FileConfiguration; @@ -24,11 +25,11 @@ public class Visit { private int safeLevel; private double islandBankBalance; private List islandSignature; - - private boolean open; + + private IslandStatus status; protected Visit(SkyBlock skyblock, UUID islandOwnerUUID, IslandLocation[] islandLocations, int islandSize, - int islandMembers, double islandBankBalance, int safeLevel, IslandLevel islandLevel, List islandSignature, boolean open) { + int islandMembers, double islandBankBalance, int safeLevel, IslandLevel islandLevel, List islandSignature, IslandStatus status) { this.skyblock = skyblock; this.islandOwnerUUID = islandOwnerUUID; this.islandLocations = islandLocations; @@ -38,7 +39,7 @@ public class Visit { this.safeLevel = safeLevel; this.islandLevel = islandLevel; this.islandSignature = islandSignature; - this.open = open; + this.status = status; } public UUID getOwnerUUID() { @@ -203,14 +204,6 @@ public class Visit { this.islandSignature = islandSignature; } - public boolean isOpen() { - return open; - } - - public void setOpen(boolean open) { - this.open = open; - } - public Ban getBan() { return skyblock.getBanManager().getIsland(getOwnerUUID()); } @@ -225,4 +218,12 @@ public class Visit { e.printStackTrace(); } } + + public IslandStatus getStatus() { + return status; + } + + public void setStatus(IslandStatus status) { + this.status = status; + } } diff --git a/src/main/java/com/songoda/skyblock/visit/VisitManager.java b/src/main/java/com/songoda/skyblock/visit/VisitManager.java index 7e8fc311..c8ec9698 100644 --- a/src/main/java/com/songoda/skyblock/visit/VisitManager.java +++ b/src/main/java/com/songoda/skyblock/visit/VisitManager.java @@ -3,10 +3,7 @@ package com.songoda.skyblock.visit; import com.songoda.core.compatibility.CompatibleSound; import com.songoda.skyblock.SkyBlock; import com.songoda.skyblock.config.FileManager; -import com.songoda.skyblock.island.Island; -import com.songoda.skyblock.island.IslandLevel; -import com.songoda.skyblock.island.IslandLocation; -import com.songoda.skyblock.island.IslandWorld; +import com.songoda.skyblock.island.*; import com.songoda.skyblock.message.MessageManager; import com.songoda.skyblock.sound.SoundManager; import com.songoda.skyblock.utils.world.LocationUtil; @@ -92,7 +89,7 @@ public class VisitManager { + configLoad.getStringList("Operators").size() + 1, configLoad.getDouble("Bank.Balance", 0), getIslandSafeLevel(islandOwnerUUID), new IslandLevel(islandOwnerUUID, skyblock), - islandSignature, configLoad.getBoolean("Visitor.Open")); + islandSignature, IslandStatus.valueOf(configLoad.getString("Visitor.Status"))); } catch (Exception e) { e.printStackTrace(); } @@ -190,7 +187,7 @@ public class VisitManager { UUID islandOwnerUUID = it.next(); Visit visit = visitIslands.get(islandOwnerUUID); - if (!visit.isOpen()) { + if (!visit.getStatus().equals(IslandStatus.OPEN)) { visitIslands.remove(islandOwnerUUID); } } @@ -199,9 +196,9 @@ public class VisitManager { } public void createIsland(UUID islandOwnerUUID, IslandLocation[] islandLocations, int islandSize, int islandMembers, - double islandBankBalance, int safeLevel, IslandLevel islandLevel, List islandSignature, boolean open) { + double islandBankBalance, int safeLevel, IslandLevel islandLevel, List islandSignature, IslandStatus status) { visitStorage.put(islandOwnerUUID, new Visit(skyblock, islandOwnerUUID, islandLocations, islandSize, - islandMembers, islandBankBalance, safeLevel, islandLevel, islandSignature, open)); + islandMembers, islandBankBalance, safeLevel, islandLevel, islandSignature, status)); } public void addIsland(UUID islandOwnerUUID, Visit visit) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2bfe64fb..5f4ac7da 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -145,8 +145,8 @@ Island: # even if it's open. # [!] Enabling will prevent possible memory leak issues affecting performance. Unload: false - # Upon Island creation is the Island open to visit? - Open: false + # The island status upon island creation (Open, Closed, Whitelisted) + Status: Whitelisted # Allow players to vote for Islands. This will filter Islands with more votes first # in the Visit Island menu. Vote: true diff --git a/src/main/resources/language.yml b/src/main/resources/language.yml index 3c40d9cc..b698876f 100644 --- a/src/main/resources/language.yml +++ b/src/main/resources/language.yml @@ -1039,6 +1039,8 @@ Command: Message: '&bSkyBlock &8| &aInfo&8: &eYour Island is now &cPrivate&e.' Public: Message: '&bSkyBlock &8| &aInfo&8: &eYour Island is now &aPublic&e.' + Restricted: + Message: '&bSkyBlock &8| &aInfo&8: &eYour Island is now &eRestricted&e.' Leaderboard: Disabled: Message: '&bSkyBlock &8| &cError&8: &eYou cannot view that leaderboard because it has been disabled.' @@ -1362,13 +1364,19 @@ Menu: - '' - '&7Current Visitors&8: &a%visitors' - '' - - '&eClick to close Island!' + - '&eClick to enable Whitelist!' Closed: Lore: - '&7Island Visits&8: &e%visitors' - '&7Island Votes&8: &e%votes' - '' - '&aClick to open Island!' + Whitelisted: + Lore: + - '&7Island Visits&8: &e%visitors' + - '&7Island Votes&8: &e%votes' + - '' + - '&aClick to close Island!' Disabled: Closed: Lore: @@ -1381,7 +1389,13 @@ Menu: - '' - '&7Current Visitors&8: &a%visitors' - '' - - '&eClick to close Island!' + - '&eClick to enable Whitelist!' + Whitelisted: + Lore: + - '&7Island Visits&8: &e%visitors' + - '&7Island Votes&8: &e%votes' + - '' + - '&aClick to close Island!' Displayname: '&aIsland Visit Statistics' Signature: Displayname: '&bIsland Signature'