Fixed structures like trees being able to grow outside border

This commit is contained in:
BuildTools 2019-09-22 19:15:22 -06:00
parent b7958e3af2
commit 3acef806e9
2 changed files with 547 additions and 485 deletions

View File

@ -17,489 +17,500 @@ import java.util.*;
public class Island { public class Island {
private com.songoda.skyblock.island.Island handle; private com.songoda.skyblock.island.Island handle;
private OfflinePlayer player; private OfflinePlayer player;
public Island(com.songoda.skyblock.island.Island handle, OfflinePlayer player) { public Island(com.songoda.skyblock.island.Island handle, OfflinePlayer player) {
this.handle = handle; this.handle = handle;
this.player = player; this.player = player;
} }
/** /**
* @return The Island UUID * @return The Island UUID
*/ */
public UUID getIslandUUID() { public UUID getIslandUUID() {
return this.handle.getIslandUUID(); return this.handle.getIslandUUID();
} }
/** /**
* @return The Island owner UUID * @return The Island owner UUID
*/ */
public UUID getOwnerUUID() { public UUID getOwnerUUID() {
return this.handle.getOwnerUUID(); return this.handle.getOwnerUUID();
} }
/** /**
* @return The original Island owner UUID * @return The original Island owner UUID
*/ */
public UUID getOriginalOwnerUUID() { public UUID getOriginalOwnerUUID() {
return this.handle.getOriginalOwnerUUID(); return this.handle.getOriginalOwnerUUID();
} }
/** /**
* @return The Island size * @return The Island size
*/ */
public int getSize() { public int getSize() {
return this.handle.getSize(); return this.handle.getSize();
} }
/** /**
* Set the size of the Island * Set the size of the Island
*/ */
public void setSize(int size) { public void setSize(int size) {
Preconditions.checkArgument(size <= 1000, "Cannot set size to greater than 1000"); Preconditions.checkArgument(size <= 1000, "Cannot set size to greater than 1000");
Preconditions.checkArgument(size >= 50, "Cannot set size to less than 50"); Preconditions.checkArgument(size >= 50, "Cannot set size to less than 50");
this.handle.setSize(size); this.handle.setSize(size);
} }
/** /**
* @return The Island radius * @return The Island radius
*/ */
public double getRadius() { public double getRadius() {
return this.handle.getRadius(); return this.handle.getRadius();
} }
/** /**
* @return true if not null, false otherwise * @return true if not null, false otherwise
*/ */
public boolean hasPassword() { public boolean hasPassword() {
return this.handle.hasPassword(); return this.handle.hasPassword();
} }
/** /**
* Set the password for ownership * Set the password for ownership
*/ */
public void setPassword(String password) { public void setPassword(String password) {
Preconditions.checkArgument(password != null, "Cannot set password to null password"); Preconditions.checkArgument(password != null, "Cannot set password to null password");
this.handle.setPassword(password); this.handle.setPassword(password);
} }
/** /**
* Get the Location from the World in island world from World in environment. * Get the Location from the World in island world from World in environment.
* *
* @return Location of Island * @return Location of Island
*/ */
public Location getLocation(IslandWorld world, IslandEnvironment environment) { public Location getLocation(IslandWorld world, IslandEnvironment environment) {
Preconditions.checkArgument(world != null, "World in island world null does not exist"); Preconditions.checkArgument(world != null, "World in island world null does not exist");
Preconditions.checkArgument(environment != null, "World in environment null does not exist"); Preconditions.checkArgument(environment != null, "World in environment null does not exist");
return handle.getLocation(APIUtil.toImplementation(world), APIUtil.toImplementation(environment)); return handle.getLocation(APIUtil.toImplementation(world), APIUtil.toImplementation(environment));
} }
/** /**
* Set the Location from the World in island world from world in environment * Set the Location from the World in island world from world in environment
* followed by position * followed by position
*/ */
public void setLocation(IslandWorld world, IslandEnvironment environment, int x, int y, int z) { 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(world != null, "World in island world null does not exist");
Preconditions.checkArgument(environment != null, "World in environment null does not exist"); Preconditions.checkArgument(environment != null, "World in environment null does not exist");
World bukkitWorld = getLocation(world, environment).getWorld(); World bukkitWorld = getLocation(world, environment).getWorld();
this.handle.setLocation(APIUtil.toImplementation(world), APIUtil.toImplementation(environment), this.handle.setLocation(APIUtil.toImplementation(world), APIUtil.toImplementation(environment),
new Location(bukkitWorld, x, y, z)); new Location(bukkitWorld, x, y, z));
} }
/** /**
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean isBorder() { public boolean isBorder() {
return this.handle.isBorder(); return this.handle.isBorder();
} }
/** /**
* Set the border visible to players for the Island * Set the border visible to players for the Island
*/ */
public void setBorder(boolean border) { public void setBorder(boolean border) {
this.handle.setBorder(border); this.handle.setBorder(border);
} }
/** /**
* @return The color of the Island border * @return The color of the Island border
*/ */
public IslandBorderColor getBorderColor() { public IslandBorderColor getBorderColor() {
return APIUtil.fromImplementation(this.handle.getBorderColor()); return APIUtil.fromImplementation(this.handle.getBorderColor());
} }
/** /**
* Set the border color for the Island * Set the border color for the Island
*/ */
public void setBorderColor(IslandBorderColor color) { public void setBorderColor(IslandBorderColor color) {
Preconditions.checkArgument(color != null, "IslandBorderColor null does not exist"); Preconditions.checkArgument(color != null, "IslandBorderColor null does not exist");
this.handle.setBorderColor(APIUtil.toImplementation(color)); this.handle.setBorderColor(APIUtil.toImplementation(color));
} }
/** /**
* @return The biome set for the Island * @return The biome set for the Island
*/ */
public Biome getBiome() { public Biome getBiome() {
return this.handle.getBiome(); return this.handle.getBiome();
} }
/** /**
* Set the biome for the Island * Set the biome for the Island
*/ */
public void setBiome(Biome biome) { public void setBiome(Biome biome) {
Preconditions.checkArgument(biome != null, "Cannot set biome to null biome"); Preconditions.checkArgument(biome != null, "Cannot set biome to null biome");
this.handle.setBiome(biome); this.handle.setBiome(biome);
} }
/** /**
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean isDayCycleSynchronizedSynchronized() { public boolean isDayCycleSynchronizedSynchronized() {
return this.handle.isWeatherSynchronized(); return this.handle.isWeatherSynchronized();
} }
/** /**
* Set the Day Cycle of the Island to be Synchronized with the World cycle * Set the Day Cycle of the Island to be Synchronized with the World cycle
*/ */
public void setDayCycleSynchronzied(boolean sync) { public void setDayCycleSynchronzied(boolean sync) {
this.handle.setWeatherSynchronized(sync); this.handle.setWeatherSynchronized(sync);
} }
/** /**
* @return The WeatherType set for the Island * @return The WeatherType set for the Island
*/ */
public WeatherType getWeather() { public WeatherType getWeather() {
return this.handle.getWeather(); return this.handle.getWeather();
} }
/** /**
* Set the weather for the Island * Set the weather for the Island
*/ */
public void setWeather(WeatherType weatherType) { public void setWeather(WeatherType weatherType) {
Preconditions.checkArgument(weatherType != null, "Cannot set weather to null weather"); Preconditions.checkArgument(weatherType != null, "Cannot set weather to null weather");
this.handle.setWeather(weatherType); this.handle.setWeather(weatherType);
} }
/** /**
* @return The time set for the Island * @return The time set for the Island
*/ */
public int getTime() { public int getTime() {
return this.handle.getTime(); return this.handle.getTime();
} }
/** /**
* Set the time for the Island * Set the time for the Island
*/ */
public void setTime(int time) { public void setTime(int time) {
this.handle.setTime(time); this.handle.setTime(time);
} }
/** /**
* @return A Set of cooped players * @return A Set of cooped players
*/ */
public Map<UUID, IslandCoop> getCoopPlayers() { public Map<UUID, IslandCoop> getCoopPlayers() {
return this.handle.getCoopPlayers(); return this.handle.getCoopPlayers();
} }
/** /**
* Add a player to the coop players for the Island * Add a player to the coop players for the Island
*/ */
public void addCoopPlayer(UUID uuid, IslandCoop islandCoop) { public void addCoopPlayer(UUID uuid, IslandCoop islandCoop) {
Preconditions.checkArgument(uuid != null, "Cannot add coop player to null uuid"); Preconditions.checkArgument(uuid != null, "Cannot add coop player to null uuid");
this.handle.addCoopPlayer(uuid, islandCoop); this.handle.addCoopPlayer(uuid, islandCoop);
} }
/** /**
* Add a player to the coop players for the Island * Add a player to the coop players for the Island
*/ */
public void addCoopPlayer(OfflinePlayer player, IslandCoop islandCoop) { public void addCoopPlayer(OfflinePlayer player, IslandCoop islandCoop) {
Preconditions.checkArgument(player != null, "Cannot add coop player to null player"); Preconditions.checkArgument(player != null, "Cannot add coop player to null player");
this.handle.addCoopPlayer(player.getUniqueId(), islandCoop); this.handle.addCoopPlayer(player.getUniqueId(), islandCoop);
} }
/** /**
* Remove a player from the coop players for the Island * Remove a player from the coop players for the Island
*/ */
public void removeCoopPlayer(UUID uuid) { public void removeCoopPlayer(UUID uuid) {
Preconditions.checkArgument(uuid != null, "Cannot remove coop player to null uuid"); Preconditions.checkArgument(uuid != null, "Cannot remove coop player to null uuid");
this.handle.removeCoopPlayer(uuid); this.handle.removeCoopPlayer(uuid);
} }
/** /**
* Remove a player from the coop players for the Island * Remove a player from the coop players for the Island
*/ */
public void removeCoopPlayer(OfflinePlayer player) { public void removeCoopPlayer(OfflinePlayer player) {
Preconditions.checkArgument(player != null, "Cannot remove coop player to null player"); Preconditions.checkArgument(player != null, "Cannot remove coop player to null player");
this.handle.removeCoopPlayer(player.getUniqueId()); this.handle.removeCoopPlayer(player.getUniqueId());
} }
/** /**
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean isCoopPlayer(UUID uuid) { public boolean isCoopPlayer(UUID uuid) {
Preconditions.checkArgument(uuid != null, "Cannot return condition to null uuid"); Preconditions.checkArgument(uuid != null, "Cannot return condition to null uuid");
return this.handle.isCoopPlayer(uuid); return this.handle.isCoopPlayer(uuid);
} }
/** /**
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean isCoopPlayer(OfflinePlayer player) { public boolean isCoopPlayer(OfflinePlayer player) {
Preconditions.checkArgument(player != null, "Cannot return condition to null player"); Preconditions.checkArgument(player != null, "Cannot return condition to null player");
return this.handle.isCoopPlayer(player.getUniqueId()); return this.handle.isCoopPlayer(player.getUniqueId());
} }
/** /**
* @return The IslandRole of a player * @return The IslandRole of a player
*/ */
public IslandRole getRole(OfflinePlayer player) { public IslandRole getRole(OfflinePlayer player) {
Preconditions.checkArgument(player != null, "Cannot get role for null player"); Preconditions.checkArgument(player != null, "Cannot get role for null player");
for (com.songoda.skyblock.island.IslandRole role : com.songoda.skyblock.island.IslandRole.values()) { for (com.songoda.skyblock.island.IslandRole role : com.songoda.skyblock.island.IslandRole.values()) {
if (this.handle.hasRole(role, player.getUniqueId())) { if (this.handle.hasRole(role, player.getUniqueId())) {
return APIUtil.fromImplementation(role); return APIUtil.fromImplementation(role);
} }
} }
return null; return null;
} }
/** /**
* @return A Set of players with IslandRole * @return A Set of players with IslandRole
*/ */
public Set<UUID> getPlayersWithRole(IslandRole role) { public Set<UUID> getPlayersWithRole(IslandRole role) {
Preconditions.checkArgument(role != null, "Cannot get players will null role"); Preconditions.checkArgument(role != null, "Cannot get players will null role");
return this.handle.getRole(APIUtil.toImplementation(role)); return this.handle.getRole(APIUtil.toImplementation(role));
} }
/** /**
* Set the IslandRole of a player for the Island * Set the IslandRole of a player for the Island
* *
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean setRole(OfflinePlayer player, IslandRole role) { public boolean setRole(OfflinePlayer player, IslandRole role) {
Preconditions.checkArgument(player != null, "Cannot set role of null player"); Preconditions.checkArgument(player != null, "Cannot set role of null player");
return setRole(player.getUniqueId(), role); return setRole(player.getUniqueId(), role);
} }
/** /**
* Set the IslandRole of a player for the Island * Set the IslandRole of a player for the Island
* *
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean setRole(UUID uuid, IslandRole role) { public boolean setRole(UUID uuid, IslandRole role) {
Preconditions.checkArgument(uuid != null, "Cannot set role of null player"); Preconditions.checkArgument(uuid != null, "Cannot set role of null player");
Preconditions.checkArgument(role != null, "Cannot set role to null role"); Preconditions.checkArgument(role != null, "Cannot set role to null role");
return this.handle.setRole(APIUtil.toImplementation(role), uuid); return this.handle.setRole(APIUtil.toImplementation(role), uuid);
} }
/** /**
* Remove the IslandRole of a player for the Island * Remove the IslandRole of a player for the Island
* *
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean removeRole(OfflinePlayer player, IslandRole role) { public boolean removeRole(OfflinePlayer player, IslandRole role) {
Preconditions.checkArgument(player != null, "Cannot remove role of null player"); Preconditions.checkArgument(player != null, "Cannot remove role of null player");
return removeRole(player.getUniqueId(), role); return removeRole(player.getUniqueId(), role);
} }
/** /**
* Remove the IslandRole of a player for the Island * Remove the IslandRole of a player for the Island
* *
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean removeRole(UUID uuid, IslandRole role) { public boolean removeRole(UUID uuid, IslandRole role) {
Preconditions.checkArgument(uuid != null, "Cannot remove role of null player"); Preconditions.checkArgument(uuid != null, "Cannot remove role of null player");
Preconditions.checkArgument(role != null, "Cannot remove role to null role"); Preconditions.checkArgument(role != null, "Cannot remove role to null role");
return this.handle.removeRole(APIUtil.toImplementation(role), uuid); return this.handle.removeRole(APIUtil.toImplementation(role), uuid);
} }
/** /**
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean hasRole(OfflinePlayer player, IslandRole role) { public boolean hasRole(OfflinePlayer player, IslandRole role) {
Preconditions.checkArgument(player != null, "Cannot check role of null player"); Preconditions.checkArgument(player != null, "Cannot check role of null player");
return handle.hasRole(APIUtil.toImplementation(role), player.getUniqueId()); return handle.hasRole(APIUtil.toImplementation(role), player.getUniqueId());
} }
/** /**
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean hasRole(UUID uuid, IslandRole role) { public boolean hasRole(UUID uuid, IslandRole role) {
Preconditions.checkArgument(uuid != null, "Cannot check role of null player"); Preconditions.checkArgument(uuid != null, "Cannot check role of null player");
Preconditions.checkArgument(role != null, "Cannot check role to null role"); Preconditions.checkArgument(role != null, "Cannot check role to null role");
return handle.hasRole(APIUtil.toImplementation(role), uuid); return handle.hasRole(APIUtil.toImplementation(role), uuid);
} }
/** /**
* Set the condition of an IslandUpgrade for the Island * Set the condition of an IslandUpgrade for the Island
*/ */
public void setUpgrade(Player player, IslandUpgrade upgrade, boolean status) { public void setUpgrade(Player player, IslandUpgrade upgrade, boolean status) {
Preconditions.checkArgument(upgrade != null, "Cannot set upgrade to null upgrade"); Preconditions.checkArgument(upgrade != null, "Cannot set upgrade to null upgrade");
this.handle.setUpgrade(player, APIUtil.toImplementation(upgrade), status); this.handle.setUpgrade(player, APIUtil.toImplementation(upgrade), status);
} }
/** /**
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean hasUpgrade(IslandUpgrade upgrade) { public boolean hasUpgrade(IslandUpgrade upgrade) {
Preconditions.checkArgument(upgrade != null, "Cannot check upgrade to null upgrade"); Preconditions.checkArgument(upgrade != null, "Cannot check upgrade to null upgrade");
return this.handle.hasUpgrade(APIUtil.toImplementation(upgrade)); return this.handle.hasUpgrade(APIUtil.toImplementation(upgrade));
} }
/** /**
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean isUpgrade(IslandUpgrade upgrade) { public boolean isUpgrade(IslandUpgrade upgrade) {
Preconditions.checkArgument(upgrade != null, "Cannot check upgrade to null upgrade"); Preconditions.checkArgument(upgrade != null, "Cannot check upgrade to null upgrade");
return this.handle.isUpgrade(APIUtil.toImplementation(upgrade)); return this.handle.isUpgrade(APIUtil.toImplementation(upgrade));
} }
/** /**
* @return Setting of an IslandRole for the Island * @return Setting of an IslandRole for the Island
*/ */
public IslandSetting getSetting(IslandRole role, String setting) { public IslandSetting getSetting(IslandRole role, String setting) {
Preconditions.checkArgument(role != null, "Cannot get setting to null role"); Preconditions.checkArgument(role != null, "Cannot get setting to null role");
Preconditions.checkArgument(setting != null, "Cannot get setting for null setting"); Preconditions.checkArgument(setting != null, "Cannot get setting for null setting");
return new IslandSetting(this.handle.getSetting(APIUtil.toImplementation(role), setting)); return new IslandSetting(this.handle.getSetting(APIUtil.toImplementation(role), setting));
} }
/** /**
* @return A List of Settings of an IslandRole for the Island * @return A List of Settings of an IslandRole for the Island
*/ */
public List<IslandSetting> getSettings(IslandRole role) { public List<IslandSetting> getSettings(IslandRole role) {
Preconditions.checkArgument(role != null, "Cannot get settings to null role"); Preconditions.checkArgument(role != null, "Cannot get settings to null role");
List<IslandSetting> settings = new ArrayList<>(); List<IslandSetting> settings = new ArrayList<>();
for (com.songoda.skyblock.island.IslandSetting settingList : this.handle for (com.songoda.skyblock.island.IslandSetting settingList : this.handle
.getSettings(APIUtil.toImplementation(role))) { .getSettings(APIUtil.toImplementation(role))) {
settings.add(new IslandSetting(settingList)); settings.add(new IslandSetting(settingList));
} }
return settings; return settings;
} }
/** /**
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean isOpen() { public boolean isOpen() {
return handle.isOpen(); return handle.isOpen();
} }
public void setOpen(boolean open) { public void setOpen(boolean open) {
this.handle.setOpen(open); this.handle.setOpen(open);
} }
/** /**
* @return A List from IslandMessage for the Island * @return A List from IslandMessage for the Island
*/ */
public List<String> getMessage(IslandMessage message) { public List<String> getMessage(IslandMessage message) {
Preconditions.checkArgument(message != null, "Cannot get message for null message"); Preconditions.checkArgument(message != null, "Cannot get message for null message");
return this.handle.getMessage(APIUtil.toImplementation(message)); return this.handle.getMessage(APIUtil.toImplementation(message));
} }
/** /**
* @return The author of an IslandMessage for the Island * @return The author of an IslandMessage for the Island
*/ */
public String getMessageAuthor(IslandMessage message) { public String getMessageAuthor(IslandMessage message) {
Preconditions.checkArgument(message != null, "Cannot get message author for null message"); Preconditions.checkArgument(message != null, "Cannot get message author for null message");
return this.handle.getMessageAuthor(APIUtil.toImplementation(message)); return this.handle.getMessageAuthor(APIUtil.toImplementation(message));
} }
/** /**
* Set the IslandMessage for the Island * Set the IslandMessage for the Island
*/ */
public void setMessage(IslandMessage message, String author, List<String> messageLines) { public void setMessage(IslandMessage message, String author, List<String> messageLines) {
Preconditions.checkArgument(message != null, "Cannot set message for null message"); Preconditions.checkArgument(message != null, "Cannot set message for null message");
this.handle.setMessage(APIUtil.toImplementation(message), author, messageLines); this.handle.setMessage(APIUtil.toImplementation(message), author, messageLines);
} }
/** /**
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean hasStructure() { public boolean hasStructure() {
return this.handle.hasStructure(); return this.handle.hasStructure();
} }
/** /**
* @return The Structure name for the Island * @return The Structure name for the Island
*/ */
public String getStructure() { public String getStructure() {
return this.handle.getStructure(); return this.handle.getStructure();
} }
/** /**
* Set the Structure for the Island * Set the Structure for the Island
*/ */
public void setStructure(String structure) { public void setStructure(String structure) {
Preconditions.checkArgument(structure != null, "Cannot set structure to null structure"); Preconditions.checkArgument(structure != null, "Cannot set structure to null structure");
this.handle.setStructure(structure); this.handle.setStructure(structure);
} }
/** /**
* @return The Visit implementation for the Island * @return The Visit implementation for the Island
*/ */
public Visit getVisit() { public Visit getVisit() {
return new Visit(this); return new Visit(this);
} }
/** /**
* @return The Ban implementation for the Island * @return The Ban implementation for the Island
*/ */
public Ban getBan() { public Ban getBan() {
return new Ban(this); return new Ban(this);
} }
/** /**
* @return The Level implementation for the Island * @return The Level implementation for the Island
*/ */
public IslandLevel getLevel() { public IslandLevel getLevel() {
return new IslandLevel(this); return new IslandLevel(this);
} }
/** /**
* @return true of conditions met, false otherwise * @return true of conditions met, false otherwise
*/ */
public boolean isLoaded() { public boolean isLoaded() {
return this.handle != null; return this.handle != null;
} }
/** /**
* Loads the Island if unloaded * Loads the Island if unloaded
*/ */
public void load() { public void load() {
if (this.handle == null) { if (this.handle == null) {
this.handle = SkyBlockAPI.getImplementation().getIslandManager().loadIsland(player); this.handle = SkyBlockAPI.getImplementation().getIslandManager().loadIsland(player);
} }
} }
/** /**
* Unloads the Island if loaded * Unloads the Island if loaded
*/ */
public void unload() { public void unload() {
if (this.handle != null) { if (this.handle != null) {
SkyBlockAPI.getImplementation().getIslandManager().unloadIsland(getIsland(), null); SkyBlockAPI.getImplementation().getIslandManager().unloadIsland(getIsland(), null);
this.handle = null; this.handle = null;
} }
} }
/** /**
* Sets the player of the Island * Sets the player of the Island
*/ */
public void setPlayer(OfflinePlayer player) { public void setPlayer(OfflinePlayer player) {
this.player = player; this.player = player;
} }
/** /**
* @return Implementation for the Island * @return Implementation for the Island
*/ */
public com.songoda.skyblock.island.Island getIsland() { public com.songoda.skyblock.island.Island getIsland() {
return handle; return handle;
} }
@Override
public boolean equals(Object object) {
if (!(object instanceof Island))
return false;
Island other = (Island) object;
if (!other.getIslandUUID().equals(getIslandUUID()))
return false;
return true;
}
} }

View File

@ -0,0 +1,51 @@
package com.songoda.skyblock.listeners;
import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.StructureGrowEvent;
import com.songoda.skyblock.SkyBlock;
import com.songoda.skyblock.island.Island;
import com.songoda.skyblock.island.IslandManager;
import com.songoda.skyblock.world.WorldManager;
public class Grow implements Listener {
private final SkyBlock skyblock;
public Grow(SkyBlock skyblock) {
this.skyblock = skyblock;
}
/**
* Checks that a structure like a tree is not growing outside or into another island.
* @author LimeGlass
*/
@EventHandler
public void onStructureGrow(StructureGrowEvent event) {
WorldManager worldManager = skyblock.getWorldManager();
if (!worldManager.isIslandWorld(event.getWorld()))
return;
IslandManager islandManager = skyblock.getIslandManager();
Island origin = islandManager.getIslandAtLocation(event.getLocation());
for (BlockState state : event.getBlocks()) {
Island growingTo = islandManager.getIslandAtLocation(state.getLocation());
// This block is ok to continue as it's not related to Skyblock islands.
if (origin == null && growingTo == null)
continue;
// A block from the structure is outside/inside that it's not suppose to.
if (origin == null || growingTo == null) {
event.getBlocks().remove(state);
continue;
}
// The structure is growing from one island to another.
if (!origin.getIslandUUID().equals(growingTo.getIslandUUID())) {
event.getBlocks().remove(state);
continue;
}
}
}
}