Internal upload, API rework start

This commit is contained in:
ceze88 2022-10-30 13:51:40 +01:00
parent f1cafbbb6d
commit 2763ce9ccd
26 changed files with 1278 additions and 879 deletions

View File

@ -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();
}
}

View File

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

View File

@ -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();
}

View File

@ -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<IslandBan> 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);
}

View File

@ -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<IslandBankTransaction> getTransactions();
/**
* @param type The TransactionType to filter by
* @return All transactions that matches the TransactionType
*/
Set<IslandBankTransaction> 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<IslandBankTransaction> 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<IslandBankTransaction> getTransactions(TransactionType type, int limit, int offset);
/**
* @param limit Max amount of transactions to return
* @return All transactions up to the limit
*/
Set<IslandBankTransaction> 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<IslandBankTransaction> 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<IslandBankTransaction> 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<IslandBankTransaction> 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<IslandBankTransaction> 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<IslandBankTransaction> 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<IslandBankTransaction> 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<IslandBankTransaction> 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<IslandBankTransaction> 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<IslandBankTransaction> 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<IslandBankTransaction> 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();
}

View File

@ -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();
}

View File

@ -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<Transaction> getLogForPlayer(UUID uuid) {
Player player = Bukkit.getPlayer(uuid);
if (player == null) return null;
return getImplementation().getTransactionList(player);
}
}

View File

@ -0,0 +1,7 @@
package com.songoda.skyblock.api.bank;
public enum TransactionType {
Deposit, Withdraw
}

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -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<UUID> 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<UUID> 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<Player> 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<Player> 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<Island> getIslands() {
List<Island> 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;
}
}

View File

@ -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();
}

View File

@ -1,7 +1,7 @@
package com.songoda.skyblock.api.island;
public enum IslandStatus {
OPEN,
CLOSED,
WHITELISTED
OPEN, CLOSED, WHITELISTED
}

View File

@ -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<UUID> 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<UUID> 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<Player> getPlayers();
/**
* @param world The world to get the players from
* @return All players on the island
*/
List<Player> getPlayers(IslandWorld world);
}

View File

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

View File

@ -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);
}
/**

View File

@ -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();
}

View File

@ -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<IslandUpgrade> getUpgrades();
}

View File

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

View File

@ -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<IslandUpgrade> getUpgrades();
}

View File

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

View File

@ -194,6 +194,81 @@ public interface DataProvider {
*/
Set<PlayerData> 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

View File

@ -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) {

View File

@ -44,10 +44,14 @@ public class Island {
private final SkyBlock plugin;
private final com.songoda.skyblock.api.island.Island apiWrapper;
private final Map<IslandRole, List<IslandPermission>> islandPermissions = new HashMap<>();
private final List<IslandLocation> islandLocations = new ArrayList<>();
private final Map<UUID, IslandCoop> coopPlayers = new HashMap<>();
private final Set<UUID> whitelistedPlayers = new HashSet<>();
private final Map<IslandRole, List<IslandPermission>> islandPermissions;
private final List<IslandLocation> islandLocations;
private final Map<UUID, IslandCoop> coopPlayers;
//TODO load island these in constructor
private final Set<UUID> whitelistedPlayers;
private final Map<UUID, Ban> bannedPlayers;
private final Map<UUID, Visit> visits;
private final Map<UUID, PlayerData> 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();

View File

@ -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();