diff --git a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java index 5f48c1133..2419619bd 100755 --- a/src/main/java/us/tastybento/bskyblock/BSkyBlock.java +++ b/src/main/java/us/tastybento/bskyblock/BSkyBlock.java @@ -82,7 +82,7 @@ public class BSkyBlock extends JavaPlugin{ // Save data playersManager.shutdown(); islandsManager.shutdown(); - offlineHistoryMessages.shutdown(); + //offlineHistoryMessages.shutdown(); plugin = null; } diff --git a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java index c8cca3672..fec0418b8 100755 --- a/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java +++ b/src/main/java/us/tastybento/bskyblock/commands/IslandCommand.java @@ -1012,7 +1012,7 @@ public class IslandCommand extends BSBCommand{ Player player = (Player) sender; Island island = plugin.getIslands().getIsland(player.getUniqueId()); - if(!island.isLocked()){ + if(!island.getLocked()){ // TODO: Expel all visitors // TODO: send offline messages island.setLocked(false); diff --git a/src/main/java/us/tastybento/bskyblock/database/OfflineHistoryMessages.java b/src/main/java/us/tastybento/bskyblock/database/OfflineHistoryMessages.java index b2516fac0..aa2691a8f 100755 --- a/src/main/java/us/tastybento/bskyblock/database/OfflineHistoryMessages.java +++ b/src/main/java/us/tastybento/bskyblock/database/OfflineHistoryMessages.java @@ -21,12 +21,11 @@ public class OfflineHistoryMessages { private BSBDatabase database; // Offline Messages - private HashMap> messages; + private HashMap> messages = new HashMap>(); public OfflineHistoryMessages(BSkyBlock plugin){ this.plugin = plugin; database = BSBDatabase.getDatabase(); - messages = new HashMap>(); } public void load(){ diff --git a/src/main/java/us/tastybento/bskyblock/database/RunTest.java b/src/main/java/us/tastybento/bskyblock/database/RunTest.java index d24abd50f..d0bed3b35 100644 --- a/src/main/java/us/tastybento/bskyblock/database/RunTest.java +++ b/src/main/java/us/tastybento/bskyblock/database/RunTest.java @@ -3,6 +3,7 @@ package us.tastybento.bskyblock.database; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.UUID; import org.bukkit.Location; import org.bukkit.Material; @@ -12,6 +13,7 @@ import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.database.flatfile.FlatFileDatabaseConnecter; import us.tastybento.bskyblock.database.flatfile.FlatFileDatabaseInserter; import us.tastybento.bskyblock.database.flatfile.FlatFileDatabaseSelecter; +import us.tastybento.bskyblock.database.objects.Island; public class RunTest { @@ -24,9 +26,14 @@ public class RunTest { new DatabaseConnectionSettingsImpl( "127.0.0.1", 3306, "exampleDatabase","user", "pass")); */ - Test test = new Test(); - test.setId(34); + Island test = new Island(); test.setName("testname"); + test.setOwner(UUID.randomUUID()); + test.addMember(UUID.randomUUID()); + test.addToBanList(UUID.randomUUID()); + test.setCenter(new Location(plugin.getServer().getWorld("world"), 1, 2, 3, 1, 1)); + test.setLocked(true); + /* HashMap homes = new HashMap(); homes.put(1, new Location(plugin.getServer().getWorld("world"), 1, 2, 3, 1, 1)); homes.put(2, new Location(plugin.getServer().getWorld("world"), 3, 3, 3, 3, 3)); @@ -35,22 +42,25 @@ public class RunTest { items.add(new ItemStack(Material.ACTIVATOR_RAIL, 2)); items.add(new ItemStack(Material.FEATHER,5)); test.setInventory(items); - - FlatFileDatabaseInserter inserter = new FlatFileDatabaseInserter(plugin, Test.class, connecter); + */ + FlatFileDatabaseInserter inserter = new FlatFileDatabaseInserter(plugin, Island.class, connecter); inserter.insertObject(test); + + plugin.getLogger().info("DEBUG: ALL WRITTEN! Now reading..."); - FlatFileDatabaseSelecter selecter = new FlatFileDatabaseSelecter(plugin, Test.class, connecter); + FlatFileDatabaseSelecter selecter = new FlatFileDatabaseSelecter(plugin, Island.class, connecter); test = selecter.selectObject(); plugin.getLogger().info("DEBUG: name = " + test.getName()); - plugin.getLogger().info("DEBUG: id = " + test.getId()); + plugin.getLogger().info("DEBUG: owner = " + test.getOwner()); + /* homes = test.getHomeLocations(); plugin.getLogger().info("DEBUG: homes = " + homes); items = test.getInventory(); plugin.getLogger().info("DEBUG: items = " + items); - +*/ } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseInserter.java b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseInserter.java index 75eb69199..799dea79d 100644 --- a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseInserter.java +++ b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseInserter.java @@ -5,11 +5,15 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; @@ -56,9 +60,29 @@ public class FlatFileDatabaseInserter extends AbstractDatabaseHandler { Method method = propertyDescriptor.getReadMethod(); Object value = method.invoke(instance); - + plugin.getLogger().info("DEBUG: writing " + field.getName()); + plugin.getLogger().info("DEBUG: property desc = " + propertyDescriptor.getPropertyType().getTypeName()); // TODO: depending on the type, it'll need serializing - config.set(field.getName(), value); + if (propertyDescriptor.getPropertyType().equals(UUID.class)) { + plugin.getLogger().info("DEBUG: writing UUID for " + field.getName()); + if (value != null) { + config.set(field.getName(), ((UUID)value).toString()); + } else { + config.set(field.getName(), "null"); + } + } else if (propertyDescriptor.getPropertyType().equals(Set.class)) { + plugin.getLogger().info("DEBUG: Hashset for " + field.getName()); + + List list = new ArrayList(); + for (Object object : (Set)value) { + if (object instanceof UUID) { + list.add(((UUID)object).toString()); + } + } + config.set(field.getName(), list); + } else { + config.set(field.getName(), value); + } } diff --git a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseSelecter.java b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseSelecter.java index a4eefdb39..1c43d7557 100644 --- a/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseSelecter.java +++ b/src/main/java/us/tastybento/bskyblock/database/flatfile/FlatFileDatabaseSelecter.java @@ -6,6 +6,10 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.UUID; import org.bukkit.configuration.file.YamlConfiguration; @@ -81,15 +85,31 @@ public class FlatFileDatabaseSelecter extends AbstractDatabaseHandler { field.getName(), type); Method method = propertyDescriptor.getWriteMethod(); - plugin.getLogger().info("DEBUG: " + propertyDescriptor.getPropertyType().getTypeName()); + plugin.getLogger().info("DEBUG: " + field.getName() + ": " + propertyDescriptor.getPropertyType().getTypeName()); if (propertyDescriptor.getPropertyType().equals(HashMap.class)) { plugin.getLogger().info("DEBUG: is HashMap"); - // TODO: this may not work with all keys. Further serialization may be required. + // TODO: this may not work with all keys. Further serialization may be required. HashMap value = new HashMap(); for (String key : config.getConfigurationSection(field.getName()).getKeys(false)) { value.put(key, config.get(field.getName() + "." + key)); } method.invoke(instance, value); + } else if (propertyDescriptor.getPropertyType().equals(Set.class)) { + plugin.getLogger().info("DEBUG: is Set " + propertyDescriptor.getReadMethod().getGenericReturnType().getTypeName()); + + // TODO: this may not work with all keys. Further serialization may be required. + Set value = new HashSet((List) config.getList(field.getName())); + + method.invoke(instance, value); + } else if (propertyDescriptor.getPropertyType().equals(UUID.class)) { + plugin.getLogger().info("DEBUG: is UUID"); + String uuid = (String)config.get(field.getName()); + if (uuid.equals("null")) { + method.invoke(instance, (Object)null); + } else { + Object value = UUID.fromString(uuid); + method.invoke(instance, value); + } } else { Object value = config.get(field.getName()); method.invoke(instance, value); diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/Island.java b/src/main/java/us/tastybento/bskyblock/database/objects/Island.java index e9a796093..9bfffca1e 100755 --- a/src/main/java/us/tastybento/bskyblock/database/objects/Island.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/Island.java @@ -5,10 +5,10 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; -import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.events.island.IslandLockEvent; import us.tastybento.bskyblock.api.events.island.IslandUnlockEvent; import us.tastybento.bskyblock.config.Settings; @@ -22,273 +22,6 @@ import us.tastybento.bskyblock.config.Settings; * @author Poslovitch */ public class Island { - private BSkyBlock plugin; - - //// Island //// - // The center of the island itself - private Location center; - // Island range - private int range; - - // Coordinates of the island area - private int minX; - private int minZ; - // Coordinates of minimum protected area - private int minProtectedX; - private int minProtectedZ; - // Protection size - private int protectionRange; - // World the island is in - private World world; - - // Display name - private String name; - - // Time parameters - private long createdDate; - private long updatedDate; - - //// Team //// - // Owner (Team Leader) - private UUID owner; - // Members (use set because each value must be unique) - private Set members; - // Trustees - private Set trustees; - // Coops - private Set coops; - // Banned players - private Set banned; - - //// State //// - private boolean locked = false; - private boolean isSpawn = false; - private boolean purgeProtected = false; - - //// Protection //// - private HashMap flags = new HashMap(); - - public Island(Location location, UUID owner, int protectionRange) { - this.members = new HashSet(); - this.members.add(owner); - this.owner = owner; - this.coops = new HashSet(); - this.trustees = new HashSet(); - this.banned = new HashSet(); - this.createdDate = System.currentTimeMillis(); - this.updatedDate = System.currentTimeMillis(); - this.name = ""; - this.world = location.getWorld(); - this.center = location; - this.minX = center.getBlockX() - Settings.islandDistance; - this.minZ = center.getBlockZ() - Settings.islandDistance; - this.protectionRange = protectionRange; - this.minProtectedX = center.getBlockX() - protectionRange; - this.minProtectedZ = center.getBlockZ() - protectionRange; - } - - /** - * @return the center Location - */ - public Location getCenter(){ - return center; - } - - /** - * @return the x coordinate of the island center - */ - public int getX(){ - return center.getBlockX(); - } - - /** - * @return the y coordinate of the island center - */ - public int getY(){ - return center.getBlockY(); - } - - /** - * @return the z coordinate of the island center - */ - public int getZ(){ - return center.getBlockZ(); - } - - /** - * @return the island range - */ - public int getRange(){ - return range; - } - - /** - * @param range - the range to set - */ - public void setRange(int range){ - this.range = range; - } - - /** - * @return the island display name or the owner's name if none is set - */ - public String getName(){ - return (name != null) ? name : plugin.getServer().getOfflinePlayer(owner).getName(); - } - - /** - * @param name - the display name to set - * Set to null to remove the display name - */ - public void setName(String name){ - this.name = name; - } - - /** - * @return the date when the island was created - */ - public long getCreatedDate(){ - return createdDate; - } - - /** - * @param createdDate - the createdDate to sets - */ - public void setCreatedDate(long createdDate){ - this.createdDate = createdDate; - } - - /** - * @return the date when the island was updated (team member connection, etc...) - */ - public long getUpdatedDate(){ - return updatedDate; - } - - /** - * @param updatedDate - the updatedDate to sets - */ - public void setUpdatedDate(long updatedDate){ - this.updatedDate = updatedDate; - } - - /** - * @return the owner (team leader) - */ - public UUID getOwner(){ - return owner; - } - - /** - * Sets the owner of the island. If the owner was previous banned, they are unbanned - * @param owner - the owner/team leader to set - */ - public void setOwner(UUID owner){ - this.owner = owner; - this.banned.remove(owner); - } - - /** - * @return the members of the island (owner included) - */ - public Set getMembers(){ - return members; - } - - /** - * @param members - the members to set - */ - public void setMembers(Set members){ - this.members = members; - } - - /** - * @return the trustees players of the island - */ - public Set getTrustees(){ - return trustees; - } - - /** - * @param trustees - the trustees to set - */ - public void setTrustees(Set trustees){ - this.trustees = trustees; - } - - /** - * @return the coop players of the island - */ - public Set getCoops(){ - return coops; - } - - /** - * @param coops - the coops to set - */ - public void setCoops(Set coops){ - this.coops = coops; - } - - /** - * @return true if the island is locked, otherwise false - */ - public boolean isLocked(){ - return locked; - } - - /** - * Locks/Unlocks the island. May be cancelled by - * {@link IslandLockEvent} or {@link IslandUnlockEvent}. - * @param locked - the lock state to set - */ - public void setLocked(boolean locked){ - if(locked){ - // Lock the island - IslandLockEvent event = new IslandLockEvent(this); - plugin.getServer().getPluginManager().callEvent(event); - - if(!event.isCancelled()){ - this.locked = locked; - } - } else { - // Unlock the island - IslandUnlockEvent event = new IslandUnlockEvent(this); - plugin.getServer().getPluginManager().callEvent(event); - - if(!event.isCancelled()){ - this.locked = locked; - } - } - } - - /** - * @return true if the island is the spawn otherwise false - */ - public boolean isSpawn(){ - return isSpawn; - } - - /** - * @param isSpawn - if the island is the spawn - */ - public void setSpawn(boolean isSpawn){ - this.isSpawn = isSpawn; - } - - /** - * @return true if the island is protected from the Purge, otherwise false - */ - public boolean isPurgeProtected(){ - return purgeProtected; - } - - /** - * @param purgeProtected - if the island is protected from the Purge - */ - public void setPurgeProtected(boolean purgeProtected){ - this.purgeProtected = purgeProtected; - } /** * Island Guard Settings flags @@ -544,49 +277,72 @@ public class Island { WITHER_BLOW_UP_SHULKER_BOX } - /** - * Resets the flags to their default as set in config.yml for this island - */ - public void setFlagsDefaults(){ - /*for(SettingsFlag flag : SettingsFlag.values()){ - this.flags.put(flag, Settings.defaultIslandSettings.get(flag)); - }*/ //TODO default flags - } + //// Island //// + // The center of the island itself + private Location center; - /** - * Resets the flags to their default as set in config.yml for the spawn - */ - public void setSpawnFlagsDefaults(){ - /*for(SettingsFlag flag : SettingsFlag.values()){ - this.flags.put(flag, Settings.defaultSpawnSettings.get(flag)); - }*/ //TODO default flags - } + // Island range + private int range; - /** - * Get the Island Guard flag status - * @param flag - * @return true or false, or false if flag is not in the list - */ - public boolean getFlag(SettingsFlag flag){ - if(flags.containsKey(flag)) return flags.get(flag); - else return false; - } + // Coordinates of the island area + private int minX; - /** - * Set the Island Guard flag status - * @param flag - * @param value - */ - public void setFlag(SettingsFlag flag, boolean value){ - flags.put(flag, value); - } + private int minZ; - /** - * Toggles the Island Guard flag status if it is in the list - * @param flag - */ - public void toggleFlag(SettingsFlag flag){ - if(flags.containsKey(flag)) flags.put(flag, (flags.get(flag)) ? false : true); + // Coordinates of minimum protected area + private int minProtectedX; + + private int minProtectedZ; + + // Protection size + private int protectionRange; + + // World the island is in + private World world; + + // Display name + private String name; + + // Time parameters + private long createdDate; + + private long updatedDate; + + //// Team //// + // Owner (Team Leader) + private UUID owner; + + // Members (use set because each value must be unique) + private Set members = new HashSet(); + + // Trustees + private Set trustees = new HashSet(); + // Coops + private Set coops = new HashSet(); + + // Banned players + private Set banned = new HashSet(); + //// State //// + private boolean locked = false; + private boolean spawn = false; + private boolean purgeProtected = false; + //// Protection //// + private HashMap flags = new HashMap(); + + public Island() {}; + + public Island(Location location, UUID owner, int protectionRange) { + this.members.add(owner); + this.owner = owner; + this.createdDate = System.currentTimeMillis(); + this.updatedDate = System.currentTimeMillis(); + this.world = location.getWorld(); + this.center = location; + this.minX = center.getBlockX() - Settings.islandDistance; + this.minZ = center.getBlockZ() - Settings.islandDistance; + this.protectionRange = protectionRange; + this.minProtectedX = center.getBlockX() - protectionRange; + this.minProtectedZ = center.getBlockZ() - protectionRange; } /** @@ -598,32 +354,6 @@ public class Island { banned.remove(playerUUID); } - - /** - * Checks if a location is within this island's protected area - * - * @param target - * @return true if it is, false if not - */ - public boolean onIsland(Location target) { - if (center.getWorld() != null) { - if (target.getBlockX() >= minProtectedX && target.getBlockX() < (minProtectedX + protectionRange) - && target.getBlockZ() >= minProtectedZ && target.getBlockZ() < (minProtectedZ + protectionRange)) { - return true; - } - } - - return false; - } - - public boolean inIslandSpace(int x, int z) { - if (x >= center.getBlockX() - Settings.islandDistance / 2 && x < center.getBlockX() + Settings.islandDistance / 2 && z >= center.getBlockZ() - Settings.islandDistance / 2 - && z < center.getBlockZ() + Settings.islandDistance / 2) { - return true; - } - return false; - } - /** * Adds target to a list of banned players for this island. May be blocked by the event being cancelled. * If the player is a member, coop or trustee, they will be removed from those lists. @@ -646,14 +376,158 @@ public class Island { } /** - * Removes target from the banned list. May be cancelled by unban event. - * @param targetUUID - * @return true if successful, otherwise false. + * @return the banned */ - public boolean removeFromBanList(UUID targetUUID) { - // TODO fire unban event - banned.remove(targetUUID); - return true; + public Set getBanned() { + return banned; + } + /** + * @return the center Location + */ + public Location getCenter(){ + return center; + } + /** + * @return the coop players of the island + */ + public Set getCoops(){ + return coops; + } + /** + * @return the date when the island was created + */ + public long getCreatedDate(){ + return createdDate; + } + /** + * Get the Island Guard flag status + * @param flag + * @return true or false, or false if flag is not in the list + */ + public boolean getFlag(SettingsFlag flag){ + if(flags.containsKey(flag)) { + return flags.get(flag); + } else { + return false; + } + } + + /** + * @return the flags + */ + public HashMap getFlags() { + return flags; + } + /** + * @return the members of the island (owner included) + */ + public Set getMembers(){ + return members; + } + /** + * @return the minProtectedX + */ + public int getMinProtectedX() { + return minProtectedX; + } + + /** + * @return the minProtectedZ + */ + public int getMinProtectedZ() { + return minProtectedZ; + } + + /** + * @return the minX + */ + public int getMinX() { + return minX; + } + + /** + * @return the minZ + */ + public int getMinZ() { + return minZ; + } + + /** + * @return the island display name or the owner's name if none is set + */ + public String getName(){ + return (name != null) ? name : Bukkit.getServer().getOfflinePlayer(owner).getName(); + } + + /** + * @return the owner (team leader) + */ + public UUID getOwner(){ + return owner; + } + + /** + * @return the protectionRange + */ + public int getProtectionRange() { + return protectionRange; + } + + /** + * @return the island range + */ + public int getRange(){ + return range; + } + + /** + * @return the trustees players of the island + */ + public Set getTrustees(){ + return trustees; + } + + /** + * @return the date when the island was updated (team member connection, etc...) + */ + public long getUpdatedDate(){ + return updatedDate; + } + + /** + * @return the world + */ + public World getWorld() { + return world; + } + + /** + * @return the x coordinate of the island center + */ + public int getX(){ + return center.getBlockX(); + } + + /** + * @return the y coordinate of the island center + */ + public int getY(){ + return center.getBlockY(); + } + + /** + * @return the z coordinate of the island center + */ + public int getZ(){ + return center.getBlockZ(); + } + + public boolean inIslandSpace(int x, int z) { + if (x >= center.getBlockX() - Settings.islandDistance / 2 && x < center.getBlockX() + Settings.islandDistance / 2 && z >= center.getBlockZ() - Settings.islandDistance / 2 + && z < center.getBlockZ() + Settings.islandDistance / 2) { + return true; + } + return false; } /** @@ -666,10 +540,182 @@ public class Island { } /** - * @return the protectionRange + * @return true if the island is locked, otherwise false */ - public int getProtectionRange() { - return protectionRange; + public boolean getLocked(){ + return locked; + } + + /** + * @return true if the island is protected from the Purge, otherwise false + */ + public boolean getPurgeProtected(){ + return purgeProtected; + } + + /** + * @return true if the island is the spawn otherwise false + */ + public boolean getSpawn(){ + return spawn; + } + + /** + * Checks if a location is within this island's protected area + * + * @param target + * @return true if it is, false if not + */ + public boolean onIsland(Location target) { + if (center.getWorld() != null) { + if (target.getBlockX() >= minProtectedX && target.getBlockX() < (minProtectedX + protectionRange) + && target.getBlockZ() >= minProtectedZ && target.getBlockZ() < (minProtectedZ + protectionRange)) { + return true; + } + } + + return false; + } + + /** + * Removes target from the banned list. May be cancelled by unban event. + * @param targetUUID + * @return true if successful, otherwise false. + */ + public boolean removeFromBanList(UUID targetUUID) { + // TODO fire unban event + banned.remove(targetUUID); + return true; + } + + /** + * @param banned the banned to set + */ + public void setBanned(Set banned) { + this.banned = banned; + } + + /** + * @param center the center to set + */ + public void setCenter(Location center) { + this.center = center; + } + + /** + * @param coops - the coops to set + */ + public void setCoops(Set coops){ + this.coops = coops; + } + + /** + * @param createdDate - the createdDate to sets + */ + public void setCreatedDate(long createdDate){ + this.createdDate = createdDate; + } + + /** + * Set the Island Guard flag status + * @param flag + * @param value + */ + public void setFlag(SettingsFlag flag, boolean value){ + flags.put(flag, value); + } + + /** + * @param flags the flags to set + */ + public void setFlags(HashMap flags) { + this.flags = flags; + } + + /** + * Resets the flags to their default as set in config.yml for this island + */ + public void setFlagsDefaults(){ + /*for(SettingsFlag flag : SettingsFlag.values()){ + this.flags.put(flag, Settings.defaultIslandSettings.get(flag)); + }*/ //TODO default flags + } + + /** + * Locks/Unlocks the island. May be cancelled by + * {@link IslandLockEvent} or {@link IslandUnlockEvent}. + * @param locked - the lock state to set + */ + public void setLocked(boolean locked){ + if(locked){ + // Lock the island + IslandLockEvent event = new IslandLockEvent(this); + Bukkit.getServer().getPluginManager().callEvent(event); + + if(!event.isCancelled()){ + this.locked = locked; + } + } else { + // Unlock the island + IslandUnlockEvent event = new IslandUnlockEvent(this); + Bukkit.getServer().getPluginManager().callEvent(event); + + if(!event.isCancelled()){ + this.locked = locked; + } + } + } + + /** + * @param members - the members to set + */ + public void setMembers(Set members){ + this.members = members; + } + + /** + * @param minProtectedX the minProtectedX to set + */ + public void setMinProtectedX(int minProtectedX) { + this.minProtectedX = minProtectedX; + } + + /** + * @param minProtectedZ the minProtectedZ to set + */ + public void setMinProtectedZ(int minProtectedZ) { + this.minProtectedZ = minProtectedZ; + } + + /** + * @param minX the minX to set + */ + public void setMinX(int minX) { + this.minX = minX; + } + + /** + * @param minZ the minZ to set + */ + public void setMinZ(int minZ) { + this.minZ = minZ; + } + + /** + * @param name - the display name to set + * Set to null to remove the display name + */ + public void setName(String name){ + this.name = name; + } + + /** + * Sets the owner of the island. If the owner was previous banned, they are unbanned + * @param owner - the owner/team leader to set + */ + public void setOwner(UUID owner){ + this.owner = owner; + this.banned.remove(owner); } /** @@ -680,9 +726,63 @@ public class Island { } /** - * @return the banned + * @param purgeProtected - if the island is protected from the Purge */ - public Set getBanned() { - return banned; + public void setPurgeProtected(boolean purgeProtected){ + this.purgeProtected = purgeProtected; } -} + + /** + * @param range - the range to set + */ + public void setRange(int range){ + this.range = range; + } + + /** + * @param isSpawn - if the island is the spawn + */ + public void setSpawn(boolean isSpawn){ + this.spawn = isSpawn; + } + + /** + * Resets the flags to their default as set in config.yml for the spawn + */ + public void setSpawnFlagsDefaults(){ + /*for(SettingsFlag flag : SettingsFlag.values()){ + this.flags.put(flag, Settings.defaultSpawnSettings.get(flag)); + }*/ //TODO default flags + } + + /** + * @param trustees - the trustees to set + */ + public void setTrustees(Set trustees){ + this.trustees = trustees; + } + + /** + * @param updatedDate - the updatedDate to sets + */ + public void setUpdatedDate(long updatedDate){ + this.updatedDate = updatedDate; + } + + /** + * @param world the world to set + */ + public void setWorld(World world) { + this.world = world; + } + + /** + * Toggles the Island Guard flag status if it is in the list + * @param flag + */ + public void toggleFlag(SettingsFlag flag){ + if(flags.containsKey(flag)) { + flags.put(flag, (flags.get(flag)) ? false : true); + } + } +} \ No newline at end of file