Skip to content

Commit

Permalink
Added a check to make sure center locations are valid with builders
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Oct 1, 2022
1 parent ad5b1c8 commit d0e901d
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -114,7 +114,7 @@ public Island.Builder setUniqueId(UUID uuid) {
@Override
public Island.Builder setCenter(Location center) {
Preconditions.checkNotNull(center, "center parameter cannot be null.");
// TODO: Make sure center is a valid location
Preconditions.checkState(isValidCenter(center), "The provided center is not centered.");
this.center = center;
return this;
}
Expand Down Expand Up @@ -459,5 +459,10 @@ public Island build() {
return plugin.getFactory().createIsland(this);
}

private static boolean isValidCenter(Location center) {
int maxIslandSize = plugin.getSettings().getMaxIslandSize() * 3;
return center.getBlockX() % maxIslandSize == 0 && center.getBlockZ() % maxIslandSize == 0 &&
plugin.getGrid().getIslandAt(center) == null;
}

}

0 comments on commit d0e901d

Please sign in to comment.