diff --git a/src/main/java/com/songoda/skyblock/api/SkyBlockAPI.java b/src/main/java/com/songoda/skyblock/api/SkyBlockAPI.java index 55a619bc..0c41acca 100644 --- a/src/main/java/com/songoda/skyblock/api/SkyBlockAPI.java +++ b/src/main/java/com/songoda/skyblock/api/SkyBlockAPI.java @@ -5,6 +5,8 @@ import com.songoda.skyblock.api.biome.BiomeManager; import com.songoda.skyblock.api.island.IslandManager; import com.songoda.skyblock.api.levelling.LevellingManager; import com.songoda.skyblock.api.structure.StructureManager; +import com.songoda.skyblock.database.DataManager; +import com.songoda.skyblock.database.DataProvider; public class SkyBlockAPI { @@ -44,17 +46,6 @@ public class SkyBlockAPI { return islandManager; } - /** - * @return The BiomeManager implementation - */ - public static BiomeManager getBiomeManager() { - if (biomeManager == null) { - biomeManager = new BiomeManager(implementation.getBiomeManager()); - } - - return biomeManager; - } - /** * @return The LevellingManager implementation */ @@ -76,4 +67,19 @@ public class SkyBlockAPI { return structureManager; } + + /** + * @return The DataManager implementation + */ + public static DataManager getDataManager() { + return implementation.getDataManager(); + } + + /** + * Use this method to use or modify Island and Player data + * @return The DataProvider implementation + */ + public static DataProvider getDataProvider() { + return implementation.getDataManager().getDataProvider(); + } } diff --git a/src/main/java/com/songoda/skyblock/api/ban/Ban.java b/src/main/java/com/songoda/skyblock/api/ban/Ban.java deleted file mode 100644 index b9d79f22..00000000 --- a/src/main/java/com/songoda/skyblock/api/ban/Ban.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.songoda.skyblock.api.ban; - -import com.google.common.base.Preconditions; -import com.songoda.skyblock.api.island.Island; - -import java.util.Set; -import java.util.UUID; - -public class Ban { - - private final Island handle; - - public Ban(Island handle) { - this.handle = handle; - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean isBanned(UUID uuid) { - Preconditions.checkArgument(uuid != null, "Cannot return condition to null uuid"); - return getBans().contains(uuid); - } - - /** - * @return A Set of players that have banned from the Island - */ - public Set getBans() { - return handle.getIsland().getBan().getBans(); - } - - /** - * Add a player to the banned players for the Island - */ - public void addBan(UUID issuer, UUID banned) { - Preconditions.checkArgument(banned != null, "Cannot add ban to null banned uuid"); - handle.getIsland().getBan().addBan(issuer, banned); - } - - /** - * Remove a player from the banned players for the Island - */ - public void removeBan(UUID uuid) { - Preconditions.checkArgument(uuid != null, "Cannot remove ban to null uuid"); - handle.getIsland().getBan().removeBan(uuid); - } - - /** - * @return Implementation for the Island - */ - public Island getIsland() { - return handle; - } -} diff --git a/src/main/java/com/songoda/skyblock/api/ban/IslandBan.java b/src/main/java/com/songoda/skyblock/api/ban/IslandBan.java new file mode 100644 index 00000000..b5d0515b --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/ban/IslandBan.java @@ -0,0 +1,37 @@ +package com.songoda.skyblock.api.ban; + +import java.util.UUID; + +public interface IslandBan { + + /** + * @return The player's name who was banned + */ + String getPlayerName(); + + /** + * @return The player's UUID who was banned + */ + UUID getPlayerUUID(); + + /** + * @return The player's name who banned the player + */ + String getBannedBy(); + + /** + * @return The player's UUID who banned the player + */ + UUID getBannedByUUID(); + + /** + * @return The reason for the ban + */ + String getReason(); + + /** + * @return The timestamp when the player was banned + */ + long getTime(); + +} diff --git a/src/main/java/com/songoda/skyblock/api/ban/IslandBanManager.java b/src/main/java/com/songoda/skyblock/api/ban/IslandBanManager.java new file mode 100644 index 00000000..11a982a6 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/ban/IslandBanManager.java @@ -0,0 +1,29 @@ +package com.songoda.skyblock.api.ban; + +import java.util.Set; +import java.util.UUID; + +public interface IslandBanManager { + + /** + * @return All records of bans from the island + */ + Set getBans(); + + /** + * Bans the player from the island + */ + void banPlayer(UUID playerUUID); + + /** + * Unbans the player from the island + */ + void unbanPlayer(UUID playerUUID); + + /** + * @param playerUUID The player's UUID to check + * @return true if the player is banned from the island, false otherwise + */ + boolean isBanned(UUID playerUUID); + +} diff --git a/src/main/java/com/songoda/skyblock/api/bank/IslandBankHistory.java b/src/main/java/com/songoda/skyblock/api/bank/IslandBankHistory.java new file mode 100644 index 00000000..fb360b8e --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/bank/IslandBankHistory.java @@ -0,0 +1,132 @@ +package com.songoda.skyblock.api.bank; + +import java.util.Set; +import java.util.UUID; + +public interface IslandBankHistory { + + /** + * @return All transactions that have been made on the island + */ + Set getTransactions(); + + /** + * @param type The TransactionType to filter by + * @return All transactions that matches the TransactionType + */ + Set getTransactions(TransactionType type); + + /** + * @param type The TransactionType to filter by + * @param limit Max amount of transactions to return + * @return All transactions by the TransactionType up to the limit + */ + Set getTransactions(TransactionType type, int limit); + + /** + * @param type The TransactionType to filter by + * @param limit Max amount of transactions to return + * @param offset Offset of the transactions to return + * @return All transactions by the TransactionType up to the limit with an offset + */ + Set getTransactions(TransactionType type, int limit, int offset); + + /** + * @param limit Max amount of transactions to return + * @return All transactions up to the limit + */ + Set getTransactions(int limit); + + /** + * @param limit Max amount of transactions to return + * @param offset Offset of the transactions to return + * @return All transactions up to the limit with an offset + */ + Set getTransactions(int limit, int offset); + + /** + * @param type The TransactionType to filter by + * @param limit Max amount of transactions to return + * @param offset Offset of the transactions to return + * @param from Timestamp to filter transactions from + * @param to Timestamp to filter transactions to + * @return All transactions by the TransactionType up to the limit with an offset between the timestamps + */ + Set getTransactions(TransactionType type, int limit, int offset, long from, long to); + + /** + * @param limit Max amount of transactions to return + * @param offset Offset of the transactions to return + * @param from Timestamp to filter transactions from + * @param to Timestamp to filter transactions to + * @return All transactions up to the limit with an offset between the timestamps + */ + Set getTransactions(int limit, int offset, long from, long to); + + /** + * @param uuid The player's UUID to filter by + * @return All transactions made by the player + */ + Set getTransactionByPlayer(UUID uuid); + + /** + * @param uuid The player's UUID to filter by + * @param limit Max amount of transactions to return + * @return All transactions made by the player by the TransactionType + */ + Set getTransactionByPlayer(UUID uuid, int limit); + + /** + * @param uuid The player's UUID to filter by + * @param limit Max amount of transactions to return + * @param offset Offset of the transactions to return + * @return All transactions made by the player by the TransactionType up to the limit with an offset + */ + Set getTransactionByPlayer(UUID uuid, int limit, int offset); + + /** + * @param uuid The player's UUID to filter by + * @param type The TransactionType to filter by + * @return All transactions made by the player by the TransactionType + */ + Set getTransactionByPlayer(UUID uuid, TransactionType type); + + /** + * @param uuid The player's UUID to filter by + * @param type The TransactionType to filter by + * @param limit Max amount of transactions to return + * @return All transactions made by the player by the TransactionType up to the limit + */ + Set getTransactionByPlayer(UUID uuid, TransactionType type, int limit); + + /** + * @param uuid The player's UUID to filter by + * @param type The TransactionType to filter by + * @param limit Max amount of transactions to return + * @param offset Offset of the transactions to return + * @return All transactions made by the player by the TransactionType up to the limit with an offset + */ + Set getTransactionByPlayer(UUID uuid, TransactionType type, int limit, int offset); + + /** + * @param uuid The player's UUID to filter by + * @param type The TransactionType to filter by + * @param limit Max amount of transactions to return + * @param offset Offset of the transactions to return + * @param from Timestamp to filter transactions from + * @param to Timestamp to filter transactions to + * @return All transactions made by the player up to the limit + */ + Set getTransactionByPlayer(UUID uuid, TransactionType type, int limit, int offset, long from, long to); + + /** + * Delete a transaction from the history + * @param transaction to delete from the database + */ + void deleteTransaction(IslandBankTransaction transaction); + + /** + * Delete all transactions from the history + */ + void deleteAllTransactions(); +} diff --git a/src/main/java/com/songoda/skyblock/api/bank/IslandBankTransaction.java b/src/main/java/com/songoda/skyblock/api/bank/IslandBankTransaction.java new file mode 100644 index 00000000..c844b088 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/bank/IslandBankTransaction.java @@ -0,0 +1,33 @@ +package com.songoda.skyblock.api.bank; + +import com.songoda.skyblock.bank.Transaction; + +import java.util.UUID; + +public interface IslandBankTransaction { + + /** + * @return The player's name who made the transaction + */ + String getPlayerName(); + + /** + * @return The player's UUID who made the transaction + */ + UUID getPlayerUUID(); + + /** + * @return The amount of money that was deposited or withdrawn + */ + int getAmount(); + + /** + * @return The timestamp of the transaction + */ + long getTime(); + + /** + * @return The type of transaction + */ + TransactionType getType(); +} diff --git a/src/main/java/com/songoda/skyblock/api/bank/TransactionLog.java b/src/main/java/com/songoda/skyblock/api/bank/TransactionLog.java deleted file mode 100644 index 6837c2ea..00000000 --- a/src/main/java/com/songoda/skyblock/api/bank/TransactionLog.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.songoda.skyblock.api.bank; - -import com.songoda.skyblock.SkyBlock; -import com.songoda.skyblock.bank.BankManager; -import com.songoda.skyblock.bank.Transaction; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; - -import java.util.List; -import java.util.UUID; - -public class TransactionLog { - - public BankManager getImplementation() { - return SkyBlock.getInstance().getBankManager(); - } - - public List getLogForPlayer(UUID uuid) { - Player player = Bukkit.getPlayer(uuid); - if (player == null) return null; - return getImplementation().getTransactionList(player); - } -} diff --git a/src/main/java/com/songoda/skyblock/api/bank/TransactionType.java b/src/main/java/com/songoda/skyblock/api/bank/TransactionType.java new file mode 100644 index 00000000..0df625c5 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/bank/TransactionType.java @@ -0,0 +1,7 @@ +package com.songoda.skyblock.api.bank; + +public enum TransactionType { + + Deposit, Withdraw + +} diff --git a/src/main/java/com/songoda/skyblock/api/biome/BiomeManager.java b/src/main/java/com/songoda/skyblock/api/biome/BiomeManager.java index a4f3b641..8d6ccaa2 100644 --- a/src/main/java/com/songoda/skyblock/api/biome/BiomeManager.java +++ b/src/main/java/com/songoda/skyblock/api/biome/BiomeManager.java @@ -6,21 +6,16 @@ import com.songoda.skyblock.api.island.Island; import com.songoda.skyblock.island.IslandWorld; import org.bukkit.block.Biome; -public class BiomeManager { - - private final com.songoda.skyblock.biome.BiomeManager biomeManager; - - public BiomeManager(com.songoda.skyblock.biome.BiomeManager biomeManager) { - this.biomeManager = biomeManager; - } +public interface BiomeManager { /** - * Set the Biome of an Island + * Sets the Biome of the island */ - public void setBiome(Island island, Biome biome) { - Preconditions.checkArgument(island != null, "Cannot set biome to null island"); - Preconditions.checkArgument(biome != null, "Cannot set biome to null biome"); + public void setBiome(Biome biome); + + /** + * @return The Biome of the Island + */ + Biome getBiome(); - this.biomeManager.setBiome(island.getIsland(), IslandWorld.Normal, CompatibleBiome.getBiome(biome), null); - } } 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 f5b9ff1d..dedd7258 100644 --- a/src/main/java/com/songoda/skyblock/api/island/Island.java +++ b/src/main/java/com/songoda/skyblock/api/island/Island.java @@ -1,502 +1,655 @@ package com.songoda.skyblock.api.island; -import com.google.common.base.Preconditions; -import com.songoda.skyblock.api.SkyBlockAPI; -import com.songoda.skyblock.api.ban.Ban; -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 com.songoda.skyblock.api.ban.IslandBanManager; import org.bukkit.Location; import org.bukkit.OfflinePlayer; -import org.bukkit.WeatherType; -import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.entity.Player; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.UUID; -public class Island { +public interface Island { - private com.songoda.skyblock.island.Island handle; - public Island(com.songoda.skyblock.island.Island handle) { - this.handle = handle; + /** + * @return The unique id of the Island + */ + UUID getIslandUUID(); + + /** + * @return The Island owner's UUID + */ + UUID getOwnerUUID(); + + /** + * @return All members of the island + */ + Set getMembers(); + + /** + * @param role The role to filter by + * @return All members of the island with the given role + */ + Set getMembersByRole(IslandRole role); + + /** + * Adds a member to the island + * @param player The player to add + * @param role The role to add the player as + */ + default void addMember(Player player, IslandRole role) { + addMember(player.getUniqueId(), role); } /** - * @return The Island UUID + * Adds a member to the island + * @param player The player to add + * @param role The role to add the player as */ - public UUID getIslandUUID() { - return this.handle.getIslandUUID(); + default void addMember(OfflinePlayer player, IslandRole role) { + addMember(player.getUniqueId(), role); } /** - * @return The Island owner UUID + * Adds a member to the island + * @param playerUUID The player's UUID to add */ - public UUID getOwnerUUID() { - return this.handle.getOwnerUUID(); + default void addMember(UUID playerUUID) { + addMember(playerUUID, IslandRole.MEMBER); } /** - * @return The original Island owner UUID + * Adds a member to the island + * @param playerUUID The player's UUID to add + * @param role The role to add the player as */ - public UUID getOriginalOwnerUUID() { - return this.handle.getOriginalOwnerUUID(); + void addMember(UUID playerUUID, IslandRole role); + + /** + * Removes a member from the island + * @param player The player to remove + */ + default void removeMember(Player player) { + removeMember(player.getUniqueId()); } /** - * @return The Island size + * Removes a member from the island + * @param player The player to remove */ - public int getSize() { - return this.handle.getSize(); + default void removeMember(OfflinePlayer player) { + removeMember(player.getUniqueId()); } /** - * Set the size of the Island + * Removes a member from the island + * @param playerUUID The player to remove */ - public void setSize(int size) { - Preconditions.checkArgument(size <= 1000, "Cannot set size to greater than 1000"); - Preconditions.checkArgument(size >= 20, "Cannot set size to less than 20"); - this.handle.setSize(size); + void removeMember(UUID playerUUID); + + /** + * @return All coop players on the island + */ + Set getCoopPlayers(); + + /** + * Adds a coop player to the island + * @param player The player to add + */ + default void addCoopPlayer(Player player) { + addCoopPlayer(player.getUniqueId()); } /** - * @return The Island radius + * Adds a coop player to the island + * @param player The player to add */ - public double getRadius() { - return this.handle.getRadius(); + default void addCoopPlayer(OfflinePlayer player) { + addCoopPlayer(player.getUniqueId()); } /** - * @return true if not null, false otherwise + * Adds a coop player to the island + * @param playerUUID The player's UUID */ - public boolean hasPassword() { - return this.handle.hasPassword(); + void addCoopPlayer(UUID playerUUID); + + /** + * Removes a coop player from the island + * @param player The player to remove + */ + default void removeCoopPlayer(Player player) { + removeCoopPlayer(player.getUniqueId()); } /** - * Set the password for ownership + * Removes a coop player from the island + * @param player The player to remove */ - public void setPassword(String password) { - Preconditions.checkArgument(password != null, "Cannot set password to null password"); - this.handle.setPassword(password); + default void removeCoopPlayer(OfflinePlayer player) { + removeCoopPlayer(player.getUniqueId()); } /** - * Get the Location from the World in island world from World in environment. - * - * @return Location of Island + * Removes a coop player from the island + * @param playerUUID The player's UUID to remove the player by */ - public Location getLocation(IslandWorld world, IslandEnvironment environment) { - Preconditions.checkArgument(world != null, "World in island world null does not exist"); - Preconditions.checkArgument(environment != null, "World in environment null does not exist"); + void removeCoopPlayer(UUID playerUUID); - return handle.getLocation(APIUtil.toImplementation(world), APIUtil.toImplementation(environment)); + + /** + * @return The island's ban manager + */ + IslandBanManager getBanManager(); + + /** + * @return The island's visit manager + */ + IslandVisitManager getVisitManager(); + + int getSize(); + + void setSize(int size); + + double getRadius(); + + boolean hasPassword(); + + void setPassword(String password); + + Location getLocation(); + + void setLocation(Location location); + + boolean isBorderEnabled(); + + void setBorderEnabled(boolean enabled); + + IslandBorderColor getBorderColor(); + + void setBorderColor(IslandBorderColor color); + + Biome getBiome(); + + void setBiome(Biome biome); + + IslandWeather getWeather(); + + IslandStatus getStatus(); + + void setStatus(IslandStatus status); + + IslandLevel getLevel(); + + /** + * Updates the Island border for players occupying an Island + */ + void updateBorder(); + + /** + * Sets the new owner of the island + * @param player The new owner of the island + */ + default void setOwner(Player player) { + setOwner(player.getUniqueId()); } /** - * Set the Location from the World in island world from world in environment - * followed by position + * Sets the new owner of the island + * @param player The new owner of the island */ - public void setLocation(IslandWorld world, IslandEnvironment environment, int x, int y, int z) { - Preconditions.checkArgument(world != null, "World in island world null does not exist"); - Preconditions.checkArgument(environment != null, "World in environment null does not exist"); - - World bukkitWorld = getLocation(world, environment).getWorld(); - this.handle.setLocation(APIUtil.toImplementation(world), APIUtil.toImplementation(environment), - new Location(bukkitWorld, x, y, z)); - } + void setOwner(OfflinePlayer player); /** - * @return true of conditions met, false otherwise + * Sets the new owner of the island + * @param playerUUID The UUID of the new owner */ - public boolean isBorder() { - return this.handle.isBorder(); - } + void setOwner(UUID playerUUID); - /** - * Set the border visible to players for the Island - */ - public void setBorder(boolean border) { - this.handle.setBorder(border); - } + List getOnlineMembers(); - /** - * @return The color of the Island border - */ - public IslandBorderColor getBorderColor() { - return APIUtil.fromImplementation(this.handle.getBorderColor()); - } - - /** - * Set the border color for the Island - */ - public void setBorderColor(IslandBorderColor color) { - Preconditions.checkArgument(color != null, "IslandBorderColor null does not exist"); - this.handle.setBorderColor(APIUtil.toImplementation(color)); - } - - /** - * @return The biome set for the Island - */ - public Biome getBiome() { - return this.handle.getBiome(); - } - - /** - * Set the biome for the Island - */ - public void setBiome(Biome biome) { - Preconditions.checkArgument(biome != null, "Cannot set biome to null biome"); - this.handle.setBiome(biome); - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean isDayCycleSynchronizedSynchronized() { - return this.handle.isWeatherSynchronized(); - } - - /** - * Set the Day Cycle of the Island to be Synchronized with the World cycle - */ - public void setDayCycleSynchronzied(boolean sync) { - this.handle.setWeatherSynchronized(sync); - } - - /** - * @return The WeatherType set for the Island - */ - public WeatherType getWeather() { - return this.handle.getWeather(); - } - - /** - * Set the weather for the Island - */ - public void setWeather(WeatherType weatherType) { - Preconditions.checkArgument(weatherType != null, "Cannot set weather to null weather"); - this.handle.setWeather(weatherType); - } - - /** - * @return The time set for the Island - */ - public int getTime() { - return this.handle.getTime(); - } - - /** - * Set the time for the Island - */ - public void setTime(int time) { - this.handle.setTime(time); - } - - /** - * @return A Set of cooped players - */ - public Map getCoopPlayers() { - return this.handle.getCoopPlayers(); - } - - /** - * Add a player to the coop players for the Island - */ - public void addCoopPlayer(UUID uuid, IslandCoop islandCoop) { - Preconditions.checkArgument(uuid != null, "Cannot add coop player to null uuid"); - this.handle.addCoopPlayer(uuid, islandCoop); - } - - /** - * Add a player to the coop players for the Island - */ - public void addCoopPlayer(OfflinePlayer player, IslandCoop islandCoop) { - Preconditions.checkArgument(player != null, "Cannot add coop player to null player"); - this.handle.addCoopPlayer(player.getUniqueId(), islandCoop); - } - - /** - * Remove a player from the coop players for the Island - */ - public void removeCoopPlayer(UUID uuid) { - Preconditions.checkArgument(uuid != null, "Cannot remove coop player to null uuid"); - this.handle.removeCoopPlayer(uuid); - } - - /** - * Remove a player from the coop players for the Island - */ - public void removeCoopPlayer(OfflinePlayer player) { - Preconditions.checkArgument(player != null, "Cannot remove coop player to null player"); - this.handle.removeCoopPlayer(player.getUniqueId()); - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean isCoopPlayer(UUID uuid) { - Preconditions.checkArgument(uuid != null, "Cannot return condition to null uuid"); - return this.handle.isCoopPlayer(uuid); - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean isCoopPlayer(OfflinePlayer player) { - Preconditions.checkArgument(player != null, "Cannot return condition to null player"); - return this.handle.isCoopPlayer(player.getUniqueId()); - } - - /** - * @return The IslandRole of a player - */ - public IslandRole getRole(OfflinePlayer player) { - Preconditions.checkArgument(player != null, "Cannot get role for null player"); - - for (com.songoda.skyblock.island.IslandRole role : com.songoda.skyblock.island.IslandRole.values()) { - if (this.handle.hasRole(role, player.getUniqueId())) { - return APIUtil.fromImplementation(role); - } - } - - return null; - } - - /** - * @return A Set of players with IslandRole - */ - public Set getPlayersWithRole(IslandRole role) { - Preconditions.checkArgument(role != null, "Cannot get players will null role"); - return this.handle.getRole(APIUtil.toImplementation(role)); - } - - /** - * Set the IslandRole of a player for the Island - * - * @return true of conditions met, false otherwise - */ - public boolean setRole(OfflinePlayer player, IslandRole role) { - Preconditions.checkArgument(player != null, "Cannot set role of null player"); - return setRole(player.getUniqueId(), role); - } - - /** - * Set the IslandRole of a player for the Island - * - * @return true of conditions met, false otherwise - */ - public boolean setRole(UUID uuid, IslandRole role) { - Preconditions.checkArgument(uuid != null, "Cannot set role of null player"); - Preconditions.checkArgument(role != null, "Cannot set role to null role"); - - return this.handle.setRole(APIUtil.toImplementation(role), uuid); - } - - /** - * Remove the IslandRole of a player for the Island - * - * @return true of conditions met, false otherwise - */ - public boolean removeRole(OfflinePlayer player, IslandRole role) { - Preconditions.checkArgument(player != null, "Cannot remove role of null player"); - return removeRole(player.getUniqueId(), role); - } - - /** - * Remove the IslandRole of a player for the Island - * - * @return true of conditions met, false otherwise - */ - public boolean removeRole(UUID uuid, IslandRole role) { - Preconditions.checkArgument(uuid != null, "Cannot remove role of null player"); - Preconditions.checkArgument(role != null, "Cannot remove role to null role"); - - return this.handle.removeRole(APIUtil.toImplementation(role), uuid); - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean hasRole(OfflinePlayer player, IslandRole role) { - Preconditions.checkArgument(player != null, "Cannot check role of null player"); - return handle.hasRole(APIUtil.toImplementation(role), player.getUniqueId()); - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean hasRole(UUID uuid, IslandRole role) { - Preconditions.checkArgument(uuid != null, "Cannot check role of null player"); - Preconditions.checkArgument(role != null, "Cannot check role to null role"); - - return handle.hasRole(APIUtil.toImplementation(role), uuid); - } - - /** - * Set the condition of an IslandUpgrade for the Island - */ - public void setUpgrade(Player player, IslandUpgrade upgrade, boolean status) { - Preconditions.checkArgument(upgrade != null, "Cannot set upgrade to null upgrade"); - this.handle.setUpgrade(player, APIUtil.toImplementation(upgrade), status); - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean hasUpgrade(IslandUpgrade upgrade) { - Preconditions.checkArgument(upgrade != null, "Cannot check upgrade to null upgrade"); - return this.handle.hasUpgrade(APIUtil.toImplementation(upgrade)); - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean isUpgrade(IslandUpgrade upgrade) { - Preconditions.checkArgument(upgrade != null, "Cannot check upgrade to null upgrade"); - return this.handle.isUpgrade(APIUtil.toImplementation(upgrade)); - } - - /** - * @return A List of Settings of an IslandRole for the Island - */ - public List getSettings(IslandRole role) { - Preconditions.checkArgument(role != null, "Cannot get settings to null role"); - return this.handle.getSettings(APIUtil.toImplementation(role)); - } - - /** - * @return true of conditions met, false otherwise - */ - @Deprecated - public boolean isOpen() { - return handle.getStatus().equals(IslandStatus.OPEN); - } - - @Deprecated - public void setOpen(boolean open) { - this.handle.setStatus(open ? IslandStatus.OPEN : IslandStatus.CLOSED); - } - - /** - * @return A List from IslandMessage for the Island - */ - public List getMessage(IslandMessage message) { - Preconditions.checkArgument(message != null, "Cannot get message for null message"); - return this.handle.getMessage(APIUtil.toImplementation(message)); - } - - /** - * @return The author of an IslandMessage for the Island - */ - public String getMessageAuthor(IslandMessage message) { - Preconditions.checkArgument(message != null, "Cannot get message author for null message"); - return this.handle.getMessageAuthor(APIUtil.toImplementation(message)); - } - - /** - * Set the IslandMessage for the Island - */ - public void setMessage(IslandMessage message, String author, List messageLines) { - Preconditions.checkArgument(message != null, "Cannot set message for null message"); - this.handle.setMessage(APIUtil.toImplementation(message), author, messageLines); - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean hasStructure() { - return this.handle.hasStructure(); - } - - /** - * @return The Structure name for the Island - */ - public String getStructure() { - return this.handle.getStructure(); - } - - /** - * Set the Structure for the Island - */ - public void setStructure(String structure) { - Preconditions.checkArgument(structure != null, "Cannot set structure to null structure"); - this.handle.setStructure(structure); - } - - /** - * @return The Visit implementation for the Island - */ - public Visit getVisit() { - return new Visit(this); - } - - /** - * @return The Ban implementation for the Island - */ - public Ban getBan() { - return new Ban(this); - } - - /** - * @return The Level implementation for the Island - */ - public IslandLevel getLevel() { - return new IslandLevel(this); - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean isLoaded() { - return this.handle != null; - } - - /** - * Loads the Island if unloaded - */ - public void load() { - if (this.handle == null) { - SkyBlockAPI.getImplementation().getIslandManager().loadIsland(); - this.handle = SkyBlockAPI.getImplementation().getIslandManager().getIsland(player); - } - } - - /** - * Unloads the Island if loaded - */ - public void unload() { - if (this.handle != null) { - SkyBlockAPI.getImplementation().getIslandManager().unloadIsland(getIsland(), null); - this.handle = null; - } - } - - /** - * Sets the player of the Island - */ - public void setPlayer(OfflinePlayer player) { - this.player = player; - } - - /** - * @return Implementation for the Island - */ - public com.songoda.skyblock.island.Island getIsland() { - return handle; - } - - @Override - public boolean equals(Object object) { - if (!(object instanceof Island)) - return false; - Island other = (Island) object; - return other.getIslandUUID().equals(getIslandUUID()); - } +// private com.songoda.skyblock.island.Island handle; +// public Island(com.songoda.skyblock.island.Island handle) { +// this.handle = handle; +// } +// +// /** +// * @return The Island UUID +// */ +// public UUID getIslandUUID() { +// return this.handle.getIslandUUID(); +// } +// +// /** +// * @return The Island owner UUID +// */ +// public UUID getOwnerUUID() { +// return this.handle.getOwnerUUID(); +// } +// +// /** +// * @return The original Island owner UUID +// */ +// public UUID getOriginalOwnerUUID() { +// return this.handle.getOriginalOwnerUUID(); +// } +// +// /** +// * @return The Island size +// */ +// public int getSize() { +// return this.handle.getSize(); +// } +// +// /** +// * Set the size of the Island +// */ +// public void setSize(int size) { +// Preconditions.checkArgument(size <= 1000, "Cannot set size to greater than 1000"); +// Preconditions.checkArgument(size >= 20, "Cannot set size to less than 20"); +// this.handle.setSize(size); +// } +// +// /** +// * @return The Island radius +// */ +// public double getRadius() { +// return this.handle.getRadius(); +// } +// +// /** +// * @return true if not null, false otherwise +// */ +// public boolean hasPassword() { +// return this.handle.hasPassword(); +// } +// +// /** +// * Set the password for ownership +// */ +// public void setPassword(String password) { +// Preconditions.checkArgument(password != null, "Cannot set password to null password"); +// this.handle.setPassword(password); +// } +// +// /** +// * Get the Location from the World in island world from World in environment. +// * +// * @return Location of Island +// */ +// public Location getLocation(IslandWorld world, IslandEnvironment environment) { +// Preconditions.checkArgument(world != null, "World in island world null does not exist"); +// Preconditions.checkArgument(environment != null, "World in environment null does not exist"); +// +// return handle.getLocation(APIUtil.toImplementation(world), APIUtil.toImplementation(environment)); +// } +// +// /** +// * Set the Location from the World in island world from world in environment +// * followed by position +// */ +// public void setLocation(IslandWorld world, IslandEnvironment environment, int x, int y, int z) { +// Preconditions.checkArgument(world != null, "World in island world null does not exist"); +// Preconditions.checkArgument(environment != null, "World in environment null does not exist"); +// +// World bukkitWorld = getLocation(world, environment).getWorld(); +// this.handle.setLocation(APIUtil.toImplementation(world), APIUtil.toImplementation(environment), +// new Location(bukkitWorld, x, y, z)); +// } +// +// /** +// * @return true of conditions met, false otherwise +// */ +// public boolean isBorder() { +// return this.handle.isBorder(); +// } +// +// /** +// * Set the border visible to players for the Island +// */ +// public void setBorder(boolean border) { +// this.handle.setBorder(border); +// } +// +// /** +// * @return The color of the Island border +// */ +// public IslandBorderColor getBorderColor() { +// return APIUtil.fromImplementation(this.handle.getBorderColor()); +// } +// +// /** +// * Set the border color for the Island +// */ +// public void setBorderColor(IslandBorderColor color) { +// Preconditions.checkArgument(color != null, "IslandBorderColor null does not exist"); +// this.handle.setBorderColor(APIUtil.toImplementation(color)); +// } +// +// /** +// * @return The biome set for the Island +// */ +// public Biome getBiome() { +// return this.handle.getBiome(); +// } +// +// /** +// * Set the biome for the Island +// */ +// public void setBiome(Biome biome) { +// Preconditions.checkArgument(biome != null, "Cannot set biome to null biome"); +// this.handle.setBiome(biome); +// } +// +// /** +// * @return true of conditions met, false otherwise +// */ +// public boolean isDayCycleSynchronizedSynchronized() { +// return this.handle.isWeatherSynchronized(); +// } +// +// /** +// * Set the Day Cycle of the Island to be Synchronized with the World cycle +// */ +// public void setDayCycleSynchronzied(boolean sync) { +// this.handle.setWeatherSynchronized(sync); +// } +// +// /** +// * @return The WeatherType set for the Island +// */ +// public WeatherType getWeather() { +// return this.handle.getWeather(); +// } +// +// /** +// * Set the weather for the Island +// */ +// public void setWeather(WeatherType weatherType) { +// Preconditions.checkArgument(weatherType != null, "Cannot set weather to null weather"); +// this.handle.setWeather(weatherType); +// } +// +// /** +// * @return The time set for the Island +// */ +// public int getTime() { +// return this.handle.getTime(); +// } +// +// /** +// * Set the time for the Island +// */ +// public void setTime(int time) { +// this.handle.setTime(time); +// } +// +// /** +// * @return A Set of cooped players +// */ +// public Map getCoopPlayers() { +// return this.handle.getCoopPlayers(); +// } +// +// /** +// * Add a player to the coop players for the Island +// */ +// public void addCoopPlayer(UUID uuid, IslandCoop islandCoop) { +// Preconditions.checkArgument(uuid != null, "Cannot add coop player to null uuid"); +// this.handle.addCoopPlayer(uuid, islandCoop); +// } +// +// /** +// * Add a player to the coop players for the Island +// */ +// public void addCoopPlayer(OfflinePlayer player, IslandCoop islandCoop) { +// Preconditions.checkArgument(player != null, "Cannot add coop player to null player"); +// this.handle.addCoopPlayer(player.getUniqueId(), islandCoop); +// } +// +// /** +// * Remove a player from the coop players for the Island +// */ +// public void removeCoopPlayer(UUID uuid) { +// Preconditions.checkArgument(uuid != null, "Cannot remove coop player to null uuid"); +// this.handle.removeCoopPlayer(uuid); +// } +// +// /** +// * Remove a player from the coop players for the Island +// */ +// public void removeCoopPlayer(OfflinePlayer player) { +// Preconditions.checkArgument(player != null, "Cannot remove coop player to null player"); +// this.handle.removeCoopPlayer(player.getUniqueId()); +// } +// +// /** +// * @return true of conditions met, false otherwise +// */ +// public boolean isCoopPlayer(UUID uuid) { +// Preconditions.checkArgument(uuid != null, "Cannot return condition to null uuid"); +// return this.handle.isCoopPlayer(uuid); +// } +// +// /** +// * @return true of conditions met, false otherwise +// */ +// public boolean isCoopPlayer(OfflinePlayer player) { +// Preconditions.checkArgument(player != null, "Cannot return condition to null player"); +// return this.handle.isCoopPlayer(player.getUniqueId()); +// } +// +// /** +// * @return The IslandRole of a player +// */ +// public IslandRole getRole(OfflinePlayer player) { +// Preconditions.checkArgument(player != null, "Cannot get role for null player"); +// +// for (com.songoda.skyblock.island.IslandRole role : com.songoda.skyblock.island.IslandRole.values()) { +// if (this.handle.hasRole(role, player.getUniqueId())) { +// return APIUtil.fromImplementation(role); +// } +// } +// +// return null; +// } +// +// /** +// * @return A Set of players with IslandRole +// */ +// public Set getPlayersWithRole(IslandRole role) { +// Preconditions.checkArgument(role != null, "Cannot get players will null role"); +// return this.handle.getRole(APIUtil.toImplementation(role)); +// } +// +// /** +// * Set the IslandRole of a player for the Island +// * +// * @return true of conditions met, false otherwise +// */ +// public boolean setRole(OfflinePlayer player, IslandRole role) { +// Preconditions.checkArgument(player != null, "Cannot set role of null player"); +// return setRole(player.getUniqueId(), role); +// } +// +// /** +// * Set the IslandRole of a player for the Island +// * +// * @return true of conditions met, false otherwise +// */ +// public boolean setRole(UUID uuid, IslandRole role) { +// Preconditions.checkArgument(uuid != null, "Cannot set role of null player"); +// Preconditions.checkArgument(role != null, "Cannot set role to null role"); +// +// return this.handle.setRole(APIUtil.toImplementation(role), uuid); +// } +// +// /** +// * Remove the IslandRole of a player for the Island +// * +// * @return true of conditions met, false otherwise +// */ +// public boolean removeRole(OfflinePlayer player, IslandRole role) { +// Preconditions.checkArgument(player != null, "Cannot remove role of null player"); +// return removeRole(player.getUniqueId(), role); +// } +// +// /** +// * Remove the IslandRole of a player for the Island +// * +// * @return true of conditions met, false otherwise +// */ +// public boolean removeRole(UUID uuid, IslandRole role) { +// Preconditions.checkArgument(uuid != null, "Cannot remove role of null player"); +// Preconditions.checkArgument(role != null, "Cannot remove role to null role"); +// +// return this.handle.removeRole(APIUtil.toImplementation(role), uuid); +// } +// +// /** +// * @return true of conditions met, false otherwise +// */ +// public boolean hasRole(OfflinePlayer player, IslandRole role) { +// Preconditions.checkArgument(player != null, "Cannot check role of null player"); +// return handle.hasRole(APIUtil.toImplementation(role), player.getUniqueId()); +// } +// +// /** +// * @return true of conditions met, false otherwise +// */ +// public boolean hasRole(UUID uuid, IslandRole role) { +// Preconditions.checkArgument(uuid != null, "Cannot check role of null player"); +// Preconditions.checkArgument(role != null, "Cannot check role to null role"); +// +// return handle.hasRole(APIUtil.toImplementation(role), uuid); +// } +// +// /** +// * Set the condition of an IslandUpgrade for the Island +// */ +// public void setUpgrade(Player player, IslandUpgrade upgrade, boolean status) { +// Preconditions.checkArgument(upgrade != null, "Cannot set upgrade to null upgrade"); +// this.handle.setUpgrade(player, APIUtil.toImplementation(upgrade), status); +// } +// +// /** +// * @return true of conditions met, false otherwise +// */ +// public boolean hasUpgrade(IslandUpgrade upgrade) { +// Preconditions.checkArgument(upgrade != null, "Cannot check upgrade to null upgrade"); +// return this.handle.hasUpgrade(APIUtil.toImplementation(upgrade)); +// } +// +// /** +// * @return true of conditions met, false otherwise +// */ +// public boolean isUpgrade(IslandUpgrade upgrade) { +// Preconditions.checkArgument(upgrade != null, "Cannot check upgrade to null upgrade"); +// return this.handle.isUpgrade(APIUtil.toImplementation(upgrade)); +// } +// +// /** +// * @return A List of Settings of an IslandRole for the Island +// */ +// public List getSettings(IslandRole role) { +// Preconditions.checkArgument(role != null, "Cannot get settings to null role"); +// return this.handle.getSettings(APIUtil.toImplementation(role)); +// } +// +// /** +// * @return true of conditions met, false otherwise +// */ +// @Deprecated +// public boolean isOpen() { +// return handle.getStatus().equals(IslandStatus.OPEN); +// } +// +// @Deprecated +// public void setOpen(boolean open) { +// this.handle.setStatus(open ? IslandStatus.OPEN : IslandStatus.CLOSED); +// } +// +// /** +// * @return A List from IslandMessage for the Island +// */ +// public List getMessage(IslandMessage message) { +// Preconditions.checkArgument(message != null, "Cannot get message for null message"); +// return this.handle.getMessage(APIUtil.toImplementation(message)); +// } +// +// /** +// * @return The author of an IslandMessage for the Island +// */ +// public String getMessageAuthor(IslandMessage message) { +// Preconditions.checkArgument(message != null, "Cannot get message author for null message"); +// return this.handle.getMessageAuthor(APIUtil.toImplementation(message)); +// } +// +// /** +// * Set the IslandMessage for the Island +// */ +// public void setMessage(IslandMessage message, String author, List messageLines) { +// Preconditions.checkArgument(message != null, "Cannot set message for null message"); +// this.handle.setMessage(APIUtil.toImplementation(message), author, messageLines); +// } +// +// /** +// * @return true of conditions met, false otherwise +// */ +// public boolean hasStructure() { +// return this.handle.hasStructure(); +// } +// +// /** +// * @return The Structure name for the Island +// */ +// public String getStructure() { +// return this.handle.getStructure(); +// } +// +// /** +// * Set the Structure for the Island +// */ +// public void setStructure(String structure) { +// Preconditions.checkArgument(structure != null, "Cannot set structure to null structure"); +// this.handle.setStructure(structure); +// } +// +// /** +// * @return The Visit implementation for the Island +// */ +// public Visit getVisit() { +// return new Visit(this); +// } +// +// /** +// * @return The Ban implementation for the Island +// */ +// public Ban getBan() { +// return new Ban(this); +// } +// +// /** +// * @return The Level implementation for the Island +// */ +// public IslandLevel getLevel() { +// return new IslandLevel(this); +// } +// +// /** +// * @return Implementation for the Island +// */ +// public com.songoda.skyblock.island.Island getIsland() { +// return handle; +// } +// +// @Override +// public boolean equals(Object object) { +// if (!(object instanceof Island)) +// return false; +// Island other = (Island) object; +// return other.getIslandUUID().equals(getIslandUUID()); +// } } diff --git a/src/main/java/com/songoda/skyblock/api/island/IslandLevel.java b/src/main/java/com/songoda/skyblock/api/island/IslandLevel.java index 7b156013..d5b12b2d 100644 --- a/src/main/java/com/songoda/skyblock/api/island/IslandLevel.java +++ b/src/main/java/com/songoda/skyblock/api/island/IslandLevel.java @@ -6,124 +6,61 @@ import com.songoda.skyblock.SkyBlock; import org.bukkit.Location; import org.bukkit.Material; -public class IslandLevel { - - private final Island handle; - - public IslandLevel(Island handle) { - this.handle = handle; - } +public interface IslandLevel { /** * @return Points of the Island from gathered materials */ - public double getPoints() { - return this.handle.getIsland().getLevel().getPoints(); - } + double getPoints(); /** * @return Level of the Island from points */ - public long getLevel() { - return this.handle.getIsland().getLevel().getLevel(); - } + long getLevel(); /** * @return Last calculated points of the Island */ - public double getLastCalculatedPoints() { - return this.handle.getIsland().getLevel().getLastCalculatedPoints(); - } + double getLastCalculatedPoints(); /** * @return Last calculated level of the Island */ - public long getLastCalculatedLevel() { - return this.handle.getIsland().getLevel().getLastCalculatedLevel(); - } + long getLastCalculatedLevel(); /** * Set the amount of a Material for the Island */ - public void setMaterialAmount(Material material, int amount) { - Preconditions.checkArgument(material != null, "Cannot set material amount to null material"); - this.handle.getIsland().getLevel().setMaterialAmount(CompatibleMaterial.getMaterial(material.name()).name(), amount); - } + void setMaterialAmount(Material material, int amount); /** * Set the amount of a Material for the Island */ - public void setMaterialAmount(Material material, byte data, int amount) { - Preconditions.checkArgument(material != null, "Cannot set material amount to null material"); - //TODO: Add data support - this.handle.getIsland().getLevel().setMaterialAmount(CompatibleMaterial.getMaterial(material.name()).name(), - amount); - } + void setMaterialAmount(Material material, byte data, int amount); /** * @return The amount of a Material from the Island */ - public long getMaterialAmount(Material material) { - Preconditions.checkArgument(material != null, "Cannot get material amount to null material"); - - CompatibleMaterial materials = CompatibleMaterial.getMaterial(material.name()); - com.songoda.skyblock.island.IslandLevel level = this.handle.getIsland().getLevel(); - - if (level.getMaterials().containsKey(materials.name())) { - return level.getMaterials().get(materials.name()); - } - - return 0; - } + long getMaterialAmount(Material material); /** * @return The amount of a Material from the Island */ - public long getMaterialAmount(Material material, byte data) { - Preconditions.checkArgument(material != null, "Cannot get material amount to null material"); - - CompatibleMaterial materials = CompatibleMaterial.getMaterial(material.name()); - //TODO: data support - com.songoda.skyblock.island.IslandLevel level = this.handle.getIsland().getLevel(); - - if (level.getMaterials().containsKey(materials.name())) { - return level.getMaterials().get(materials.name()); - } - - return 0; - } + long getMaterialAmount(Material material, byte data); /** * @return The points earned for a Material from the Island */ - public long getMaterialPoints(Material material) { - Preconditions.checkArgument(material != null, "Cannot get material points to null material"); - return this.handle.getIsland().getLevel().getMaterialPoints(CompatibleMaterial.getMaterial(material.name()).name()); - } + long getMaterialPoints(Material material); /** * @return The points earned for a Material from the Island */ - public long getMaterialPoints(Material material, byte data) { - Preconditions.checkArgument(material != null, "Cannot get material points to null material"); - return this.handle.getIsland().getLevel() - .getMaterialPoints(CompatibleMaterial.getMaterial(material.name()).name()); - //TODO: add data support - } - - /** - * @return Implementation for the Island - */ - public Island getIsland() { - return handle; - } + long getMaterialPoints(Material material, byte data); /** * Update the island level for a determined location - * @param location + * @param location of the island */ - public void updateLevel(Location location){ - Preconditions.checkArgument(location != null, "Cannot update level of a null island"); - SkyBlock.getInstance().getLevellingManager().updateLevel(this.handle.getIsland(), location); - } + void updateLevel(Location location); } diff --git a/src/main/java/com/songoda/skyblock/api/island/IslandManager.java b/src/main/java/com/songoda/skyblock/api/island/IslandManager.java index d35b8d44..83daeb45 100644 --- a/src/main/java/com/songoda/skyblock/api/island/IslandManager.java +++ b/src/main/java/com/songoda/skyblock/api/island/IslandManager.java @@ -14,98 +14,9 @@ import java.util.List; import java.util.Set; import java.util.UUID; -public class IslandManager { +public interface IslandManager { - private final com.songoda.skyblock.island.IslandManager islandManager; - private final PermissionManager permissionManager; - public IslandManager(com.songoda.skyblock.island.IslandManager islandManager) { - this.islandManager = islandManager; - this.permissionManager = SkyBlock.getInstance().getPermissionManager(); - } - - /** - * @return true of conditions met, false otherwise - */ - public static boolean hasIsland(OfflinePlayer player) { - Preconditions.checkArgument(player != null, "Cannot check island to null player"); - return new com.songoda.skyblock.utils.player.OfflinePlayer(player.getUniqueId()).getOwner() != null; - } - - /** - * Updates the Island border for players occupying an Island - */ - public void updateBorder(Island island) { - Preconditions.checkArgument(island != null, "Cannot update border to null island"); - - this.islandManager.updateBorder(island.getIsland()); - } - - /** - * Gives Island ownership to a player of their Island - */ - public void giveOwnership(Island island, OfflinePlayer player) { - Preconditions.checkArgument(player != null, "Cannot give ownership to null island"); - Preconditions.checkArgument(player != null, "Cannot give ownership to null player"); - - this.islandManager.giveOwnership(island.getIsland(), player); - } - - /** - * @return The Visitors occupying an Island - */ - public Set getVisitorsAtIsland(Island island) { - Preconditions.checkArgument(island != null, "Cannot get visitors at island to null island"); - - return this.islandManager.getVisitorsAtIsland(island.getIsland()); - } - - /** - * Makes a player a Visitor of an Island - */ - public void visitIsland(Player player, Island island) { - Preconditions.checkArgument(player != null, "Cannot visit island to null player"); - Preconditions.checkArgument(island != null, "Cannot visit island to null island"); - - this.islandManager.visitIsland(player, island.getIsland()); - } - - /** - * Closes an Island from Visitors - */ - public void closeIsland(Island island) { - Preconditions.checkArgument(island != null, "Cannot closed island to null island"); - - this.islandManager.closeIsland(island.getIsland()); - } - - /** - * @return A Set of Members of an Island that are online - */ - public Set getMembersOnline(Island island) { - Preconditions.checkArgument(island != null, "Cannot get online members to null island"); - - return this.islandManager.getMembersOnline(island.getIsland()); - } - - /** - * @return A List of Players at an Island - */ - public List getPlayersAtIsland(Island island) { - Preconditions.checkArgument(island != null, "Cannot get players at island to null island"); - - return this.islandManager.getPlayersAtIsland(island.getIsland()); - } - - /** - * @return A List of Players at an Island by IslandWorld - */ - public List getPlayersAtIsland(Island island, IslandWorld world) { - Preconditions.checkArgument(island != null, "Cannot get players at island to null island"); - Preconditions.checkArgument(world != null, "Cannot get players at island to null world"); - - return this.islandManager.getPlayersAtIsland(island.getIsland(), APIUtil.toImplementation(world)); - } /** * Gives the Island Upgrades to a player @@ -313,48 +224,4 @@ public class IslandManager { Preconditions.checkArgument(island != null, "Cannot reset island to null island"); this.islandManager.resetIsland(island.getIsland()); } - - /** - * @return The Island of a player - */ - public Island getIsland(OfflinePlayer player) { - Preconditions.checkArgument(player != null, "Cannot get island to null player"); - - com.songoda.skyblock.island.Island island = this.islandManager.getIsland(player); - - if (island != null) { - return island.getAPIWrapper(); - } - - return new Island(null, player); - } - - /** - * Gets an Island by its UUID - * Returns null if an Island with the given UUID does not exist - * - * @param islandUUID The UUID of the Island - * @return The Island with the given UUID, or null if one was not found - */ - public Island getIslandByUUID(UUID islandUUID) { - Preconditions.checkArgument(islandUUID != null, "Cannot get island with a null UUID"); - - com.songoda.skyblock.island.Island island = this.islandManager.getIslandByUUID(islandUUID); - - return island != null ? island.getAPIWrapper() : null; - } - - /** - * @return A List of loaded Islands - */ - public List getIslands() { - List islands = new ArrayList<>(); - - for (int i = 0; i < this.islandManager.getIslands().size(); i++) { - islands.add(this.islandManager.getIslands().get(this.islandManager.getIslands().keySet().toArray()[i]) - .getAPIWrapper()); - } - - return islands; - } } diff --git a/src/main/java/com/songoda/skyblock/api/island/IslandMember.java b/src/main/java/com/songoda/skyblock/api/island/IslandMember.java new file mode 100644 index 00000000..13358e49 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/island/IslandMember.java @@ -0,0 +1,37 @@ +package com.songoda.skyblock.api.island; + +import com.songoda.skyblock.playerdata.PlayerData; +import org.bukkit.entity.Player; + +import java.util.UUID; + +public interface IslandMember { + + /** + * @return The player if the player is online, otherwise null + */ + Player getPlayer(); + + /** + * @return The player's name + */ + String getName(); + + /** + * @return The player's UUID + */ + UUID getUniqueId(); + + /** + * @return The player's role on the island + */ + IslandRole getIslandRole(); + + void setRole(IslandRole role); + + /** + * @return The player's data + */ + PlayerData getPlayerData(); + +} diff --git a/src/main/java/com/songoda/skyblock/api/island/IslandStatus.java b/src/main/java/com/songoda/skyblock/api/island/IslandStatus.java index ebc78b32..0814c48a 100644 --- a/src/main/java/com/songoda/skyblock/api/island/IslandStatus.java +++ b/src/main/java/com/songoda/skyblock/api/island/IslandStatus.java @@ -1,7 +1,7 @@ package com.songoda.skyblock.api.island; public enum IslandStatus { - OPEN, - CLOSED, - WHITELISTED + + OPEN, CLOSED, WHITELISTED + } diff --git a/src/main/java/com/songoda/skyblock/api/island/IslandVisitManager.java b/src/main/java/com/songoda/skyblock/api/island/IslandVisitManager.java new file mode 100644 index 00000000..2ab28c6c --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/island/IslandVisitManager.java @@ -0,0 +1,74 @@ +package com.songoda.skyblock.api.island; + +import com.google.common.base.Preconditions; +import com.songoda.skyblock.api.island.Island; +import org.bukkit.entity.Player; + +import java.util.List; +import java.util.Set; +import java.util.UUID; + +public interface IslandVisitManager { + + /** + * @return The Safe Level for the Island + */ + public int getSafeLevel(); + + /** + * Set the Safe Level for the Island + */ + public void setSafeLevel(int safeLevel); + + /** + * @return true of conditions met, false otherwise + */ + public boolean isVisitor(UUID playerUUID); + + /** + * @return A Set of players that have visited the Island + */ + public Set getVisitors(); + + /** + * Add a player to the visited players for the Island + */ + public void addVisitor(UUID playerUUID); + + /** + * Remove a player from the visited players for the Island + */ + public void removeVisitor(UUID playerUUID); + + /** + * @return true of conditions met, false otherwise + */ + public boolean isVoter(UUID playerUUID); + + /** + * @return A Set of players that have voted for the Island + */ + public Set getVoters(); + + /** + * Add a player to the voted players for the Island + */ + public void addVoter(UUID playerUUID); + + /** + * Remove a player from the voted players for the Island + */ + public void removeVoter(UUID playerUUID); + + /** + * @return All players on the island from all worlds + */ + List getPlayers(); + + /** + * @param world The world to get the players from + * @return All players on the island + */ + List getPlayers(IslandWorld world); + +} diff --git a/src/main/java/com/songoda/skyblock/api/island/IslandWeather.java b/src/main/java/com/songoda/skyblock/api/island/IslandWeather.java new file mode 100644 index 00000000..3087ef0e --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/island/IslandWeather.java @@ -0,0 +1,19 @@ +package com.songoda.skyblock.api.island; + +import org.bukkit.WeatherType; + +public interface IslandWeather { + + boolean isSynchronised(); + + void setSynchronised(boolean synchronised); + + int getTime(); + + void setTime(int time); + + WeatherType getWeather(); + + void setWeather(WeatherType weather); + +} diff --git a/src/main/java/com/songoda/skyblock/api/levelling/LevellingManager.java b/src/main/java/com/songoda/skyblock/api/levelling/LevellingManager.java index 018d552f..966fad93 100644 --- a/src/main/java/com/songoda/skyblock/api/levelling/LevellingManager.java +++ b/src/main/java/com/songoda/skyblock/api/levelling/LevellingManager.java @@ -21,7 +21,7 @@ public class LevellingManager { */ public void calculatePoints(Island island) { Preconditions.checkArgument(island != null, "Cannot calculate points to null island"); - this.levellingManager.startScan(null, island.getIsland()); + this.levellingManager.startScan(null, island); } /** diff --git a/src/main/java/com/songoda/skyblock/api/upgrade/IslandUpgrade.java b/src/main/java/com/songoda/skyblock/api/upgrade/IslandUpgrade.java new file mode 100644 index 00000000..ccb73911 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/upgrade/IslandUpgrade.java @@ -0,0 +1,54 @@ +package com.songoda.skyblock.api.upgrade; + +public interface IslandUpgrade { + + /** + * Name of the upgrade. Used for registering and getting the upgrade. + * @return The upgrade's name + */ + String getKey(); + + /** + * The upgrade's display name. Used for displaying the upgrade's name. + * @return The upgrade's display name + */ + String getDisplayName(); + + /** + * The upgrade's description. Used for displaying the upgrade's description. + * @return The upgrade's description + */ + String getDescription(); + + /** + * Add a level to the upgrade if the upgrade is not maxed out + */ + void addLevel(); + + /** + * @return The level of the upgrade + */ + int getLevel(); + + /** + * Set the level of the upgrade. Can't be lower than 0 and higher than the max level. + */ + void setLevel(int level); + + /** + * @return Max level of the upgrade + */ + int getMaxLevel(); + + /** + * @return true if the upgrade is its max level, otherwise false + */ + boolean isMaxLevel(); + + /** + * The upgrade's cost. Used for displaying the upgrade's cost. + * @return The upgrade's cost + */ + UpgradeCost getCost(); + +} diff --git a/src/main/java/com/songoda/skyblock/api/upgrade/IslandUpgradeManager.java b/src/main/java/com/songoda/skyblock/api/upgrade/IslandUpgradeManager.java new file mode 100644 index 00000000..bfaae875 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/upgrade/IslandUpgradeManager.java @@ -0,0 +1,42 @@ +package com.songoda.skyblock.api.upgrade; + +import java.util.Set; + +public interface IslandUpgradeManager { + + /** + * @param key The key of the upgrade + * @return true if the island has the specified upgrade, otherwise false + */ + boolean hasUpgrade(String key); + + default void addUpgrade(String key) { + addUpgrade(getUpgrade(key)); + } + + void addUpgrade(IslandUpgrade upgrade); + + /** + * Remove an upgrade from the island if it has it + * @param key The upgrade's key to remove + */ + default void removeUpgrade(String key) { + removeUpgrade(getUpgrade(key)); + } + + /** + * @param upgrade The upgrade to remove + */ + void removeUpgrade(IslandUpgrade upgrade); + + /** + * @return The upgrade by its key if the island has the upgrade, otherwise null + */ + IslandUpgrade getUpgrade(String key); + + /** + * @return All upgrades the island has + */ + Set getUpgrades(); + +} diff --git a/src/main/java/com/songoda/skyblock/api/upgrade/UpgradeCost.java b/src/main/java/com/songoda/skyblock/api/upgrade/UpgradeCost.java new file mode 100644 index 00000000..0c29d6a6 --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/upgrade/UpgradeCost.java @@ -0,0 +1,21 @@ +package com.songoda.skyblock.api.upgrade; + +public class UpgradeCost { + + private final String type; + private final int cost; + + public UpgradeCost(String type, int cost) { + this.type = type; + this.cost = cost; + } + + public String getType() { + return type; + } + + public int getCost() { + return cost; + } + +} diff --git a/src/main/java/com/songoda/skyblock/api/upgrade/UpgradeManager.java b/src/main/java/com/songoda/skyblock/api/upgrade/UpgradeManager.java new file mode 100644 index 00000000..5a6351dc --- /dev/null +++ b/src/main/java/com/songoda/skyblock/api/upgrade/UpgradeManager.java @@ -0,0 +1,25 @@ +package com.songoda.skyblock.api.upgrade; + +import java.util.List; +import java.util.Set; + +public interface UpgradeManager { + + void registerUpgrade(IslandUpgrade upgrade); + + void unregisterUpgrade(IslandUpgrade upgrade); + + boolean isUpgradeRegistered(String key); + + /** + * @param key The key of the upgrade + * @return The upgrade if the upgrade is registered, otherwise null + */ + IslandUpgrade getUpgrade(String key); + + /** + * @return All registered upgrades + */ + List getUpgrades(); + +} diff --git a/src/main/java/com/songoda/skyblock/api/visit/Visit.java b/src/main/java/com/songoda/skyblock/api/visit/Visit.java deleted file mode 100644 index d1add8af..00000000 --- a/src/main/java/com/songoda/skyblock/api/visit/Visit.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.songoda.skyblock.api.visit; - -import com.google.common.base.Preconditions; -import com.songoda.skyblock.api.island.Island; - -import java.util.Set; -import java.util.UUID; - -public class Visit { - - private final Island handle; - - public Visit(Island handle) { - this.handle = handle; - } - - /** - * @return The Safe Level for the Island - */ - public int getSafeLevel() { - return this.handle.getIsland().getVisit().getSafeLevel(); - } - - /** - * Set the Safe Level for the Island - */ - public void setSafeLevel(int safeLevel) { - this.handle.getIsland().getVisit().setSafeLevel(safeLevel); - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean isVisitor(UUID uuid) { - Preconditions.checkArgument(uuid != null, "Cannot return condition to null uuid"); - return getVisitors().contains(uuid); - } - - /** - * @return A Set of players that have visited the Island - */ - public Set getVisitors() { - return this.handle.getIsland().getVisit().getVisitors(); - } - - /** - * Add a player to the visited players for the Island - */ - public void addVisitor(UUID uuid) { - Preconditions.checkArgument(uuid != null, "Cannot add visitor to null uuid"); - this.handle.getIsland().getVisit().addVisitor(uuid); - } - - /** - * Remove a player from the visited players for the Island - */ - public void removeVisitor(UUID uuid) { - Preconditions.checkArgument(uuid != null, "Cannot remove visitor to null uuid"); - this.handle.getIsland().getVisit().removeVisitor(uuid); - } - - /** - * @return true of conditions met, false otherwise - */ - public boolean isVoter(UUID uuid) { - Preconditions.checkArgument(uuid != null, "Cannot return condition to null uuid"); - return getVoters().contains(uuid); - } - - /** - * @return A Set of players that have voted for the Island - */ - public Set getVoters() { - return this.handle.getIsland().getVisit().getVoters(); - } - - /** - * Add a player to the voted players for the Island - */ - public void addVoter(UUID uuid) { - Preconditions.checkArgument(uuid != null, "Cannot add voter to null uuid"); - this.handle.getIsland().getVisit().addVoter(uuid); - } - - /** - * Remove a player from the voted players for the Island - */ - public void removeVoter(UUID uuid) { - Preconditions.checkArgument(uuid != null, "Cannot remove voter to null uuid"); - this.handle.getIsland().getVisit().removeVoter(uuid); - } - - /** - * @return Implementation for the Island - */ - public Island getIsland() { - return handle; - } -} diff --git a/src/main/java/com/songoda/skyblock/database/DataProvider.java b/src/main/java/com/songoda/skyblock/database/DataProvider.java index dfb91c1c..bb006e2a 100644 --- a/src/main/java/com/songoda/skyblock/database/DataProvider.java +++ b/src/main/java/com/songoda/skyblock/database/DataProvider.java @@ -194,6 +194,81 @@ public interface DataProvider { */ Set getLoadedPlayers(); + /** + * Check if a player is member of any island + * @param player The player to check + * @return true if member of any island false otherwise + */ + default boolean hasIsland(Player player) { + return hasIsland(player.getUniqueId()); + } + + /** + * Check if a player is member of any island + * @param player The player to check + * @return true if member of any island false otherwise + */ + default boolean hasIsland(OfflinePlayer player) { + return hasIsland(player.getUniqueId()); + } + + /** + * Check if a player is member of any island + * @param playerUUID The player's UUID to check + * @return true if member of any island false otherwise + */ + boolean hasIsland(UUID playerUUID); + + /** + * Get the island of a player + * @param player The player to get its island + * @return The island of the player if the island loaded in memory, null otherwise + */ + default Island getPlayerIsland(Player player) { + return getPlayerIsland(player.getUniqueId()); + } + + /** + * Get the island of a player + * @param player The player to get its island + * @return The island of the player if the island loaded in memory, null otherwise + */ + default Island getPlayerIsland(OfflinePlayer player) { + return getPlayerIsland(player.getUniqueId()); + } + + /** + * Get the island of a player + * @param playerUUID The player's UUID to get its island + * @return The island of the player if the island loaded in memory, null otherwise + */ + Island getPlayerIsland(UUID playerUUID); + + /** + * Check if a player's island is loaded in memory + * @param player The player to check + * @return true if the island is loaded false otherwise + */ + default boolean isPlayerIslandLoaded(Player player) { + return isPlayerIslandLoaded(player.getUniqueId()); + } + + /** + * Check if a player's island is loaded in memory + * @param player The player to check + * @return true if the island is loaded false otherwise + */ + default boolean isPlayerIslandLoaded(OfflinePlayer player) { + return isPlayerIslandLoaded(player.getUniqueId()); + } + + /** + * Check if a player's island is loaded in memory + * @param playerUUID The player's UUID to check + * @return true if the island is loaded false otherwise + */ + boolean isPlayerIslandLoaded(UUID playerUUID); + /** * Check if an island has data in the database * @param islandUUID The island's UUID to check diff --git a/src/main/java/com/songoda/skyblock/database/sources/FlatFileDataProvider.java b/src/main/java/com/songoda/skyblock/database/sources/FlatFileDataProvider.java index 01e0cb1c..c484eac6 100644 --- a/src/main/java/com/songoda/skyblock/database/sources/FlatFileDataProvider.java +++ b/src/main/java/com/songoda/skyblock/database/sources/FlatFileDataProvider.java @@ -58,6 +58,11 @@ public class FlatFileDataProvider implements DataProvider { return playerDataStorage.containsKey(playerUUID); } + @Override + public PlayerData getPlayerData(UUID playerUUID) { + return playerDataStorage.get(playerUUID); + } + @Override public void unloadPlayerData(UUID playerUUID) { playerDataStorage.remove(playerUUID); @@ -88,6 +93,21 @@ public class FlatFileDataProvider implements DataProvider { return new HashSet<>(playerDataStorage.values()); } + @Override + public boolean hasIsland(UUID playerUUID) { + return playerDataStorage.get(playerUUID).getIsland() != null; + } + + @Override + public Island getPlayerIsland(UUID playerUUID) { + return getIsland(playerDataStorage.get(playerUUID).getIsland()); + } + + @Override + public boolean isPlayerIslandLoaded(UUID playerUUID) { + return islandStorage.containsKey(playerDataStorage.get(playerUUID).getIsland()); + } + @Override public Island loadIsland(UUID islandUUID) { return null; @@ -98,6 +118,11 @@ public class FlatFileDataProvider implements DataProvider { return islandStorage.containsKey(islandUUID); } + @Override + public Island getIsland(UUID islandUUID) { + return islandStorage.get(islandUUID); + } + @Override public void unloadIslandData(UUID islandUUID) { islandStorage.remove(islandUUID); @@ -108,11 +133,6 @@ public class FlatFileDataProvider implements DataProvider { } - @Override - public void saveIsland(Island island) { - saveIsland(island.getIslandUUID()); - } - @Override public void saveIsland(UUID islandUUID) { diff --git a/src/main/java/com/songoda/skyblock/island/Island.java b/src/main/java/com/songoda/skyblock/island/Island.java index 9f069cbc..18397d4d 100644 --- a/src/main/java/com/songoda/skyblock/island/Island.java +++ b/src/main/java/com/songoda/skyblock/island/Island.java @@ -44,10 +44,14 @@ public class Island { private final SkyBlock plugin; private final com.songoda.skyblock.api.island.Island apiWrapper; - private final Map> islandPermissions = new HashMap<>(); - private final List islandLocations = new ArrayList<>(); - private final Map coopPlayers = new HashMap<>(); - private final Set whitelistedPlayers = new HashSet<>(); + private final Map> islandPermissions; + private final List islandLocations; + private final Map coopPlayers; + //TODO load island these in constructor + private final Set whitelistedPlayers; + private final Map bannedPlayers; + private final Map visits; + private final Map islandMembers; private UUID islandUUID; private UUID ownerUUID; @@ -58,7 +62,6 @@ public class Island { private int maxMembers; private boolean deleted = false; private Biome biome; - private boolean isWeatherSynced; private int islandTime; private FileConfiguration islandData; @@ -66,6 +69,13 @@ public class Island { public Island(UUID islandUUID) { this.plugin = SkyBlock.getInstance(); this.islandUUID = islandUUID; + this.islandPermissions = new HashMap<>(); + this.islandLocations = new ArrayList<>(); + this.coopPlayers = new HashMap<>(); + this.whitelistedPlayers = new HashSet<>(); + this.bannedPlayers = new HashMap<>(); + this.visits = new HashMap<>(); + this.islandMembers = new HashMap<>(); switch (plugin.getDataManager().getDatabaseType()) { case POSTGRESQL: @@ -98,21 +108,27 @@ public class Island { default: File dataFile = new File(new File(plugin.getDataFolder().toString() + "/island-data"), FastUUID.toString(islandUUID) + ".yml"); this.islandData = YamlConfiguration.loadConfiguration(dataFile); + this.ownerUUID = FastUUID.parseUUID(islandData.getString("Owner")); break; } - - this.ownerUUID = FastUUID.parseUUID(data.getString("owner")); - this.size = data.getInt("size"); if (size > 1000 || size < 0) { size = 51; + plugin.getLogger().severe("Island size is not valid, resetting to default size of 51 for island: " + islandUUID); } - this.level = new IslandLevel(ownerUUID, plugin); + this.level = new IslandLevel(islandUUID, plugin); this.apiWrapper = new com.songoda.skyblock.api.island.Island(this); } public Island(@Nonnull OfflinePlayer player) { this.plugin = SkyBlock.getInstance(); + this.islandPermissions = new HashMap<>(); + this.islandLocations = new ArrayList<>(); + this.coopPlayers = new HashMap<>(); + this.whitelistedPlayers = new HashSet<>(); + this.bannedPlayers = new HashMap<>(); + this.visits = new HashMap<>(); + this.islandMembers = new HashMap<>(); FileManager fileManager = plugin.getFileManager(); diff --git a/src/main/java/com/songoda/skyblock/island/IslandLevel.java b/src/main/java/com/songoda/skyblock/island/IslandLevel.java index 8f174d9a..90a6424e 100644 --- a/src/main/java/com/songoda/skyblock/island/IslandLevel.java +++ b/src/main/java/com/songoda/skyblock/island/IslandLevel.java @@ -21,7 +21,7 @@ public class IslandLevel { private final SkyBlock plugin; - private UUID ownerUUID; + private UUID islandUUID; private long lastCalculatedLevel = 0; private double lastCalculatedPoints = 0; @@ -31,11 +31,11 @@ public class IslandLevel { // Highest level achieved, to prevent reward farming (since is level can decrease) private long highestLevel; - public IslandLevel(UUID ownerUUID, SkyBlock plugin) { + public IslandLevel(UUID islandUUID, SkyBlock plugin) { this.plugin = plugin; - this.ownerUUID = ownerUUID; - - final Config config = plugin.getFileManager().getConfig(new File(new File(plugin.getDataFolder().toString() + "/level-data"), ownerUUID.toString() + ".yml")); + this.islandUUID = islandUUID; + //TODO load data by database type + final Config config = plugin.getFileManager().getConfig(new File(new File(plugin.getDataFolder().toString() + "/level-data"), islandUUID.toString() + ".yml")); final FileConfiguration configLoad = config.getFileConfiguration(); final ConfigurationSection section = configLoad.getConfigurationSection("Levelling.Materials"); @@ -60,10 +60,6 @@ public class IslandLevel { this.highestLevel = configLoad.contains("Levelling.Highest-Level") ? configLoad.getLong("Levelling.Highest-Level") : getLevel(); } - public void setOwnerUUID(UUID ownerUUID) { - this.ownerUUID = ownerUUID; - } - public double getPoints() { FileConfiguration configLoad = this.plugin.getLevelling();