Skip to content

Commit

Permalink
Checks 4 corners of island to avoid overlapping issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Jun 29, 2019
1 parent feef61c commit 4efdada
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import java.io.IOException;
import java.util.EnumMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand Down Expand Up @@ -257,7 +259,9 @@ private Location getNextIsland() {
}
// Find a free spot
Map<Result, Integer> result = new EnumMap<>(Result.class);
// Check center
Result r = isIsland(last);

while (!r.equals(Result.FREE) && result.getOrDefault(Result.BLOCK_AT_CENTER, 0) < MAX_UNOWNED_ISLANDS) {
last = nextGridLocation(last);
result.merge(r, 1, (k,v) -> v++);
Expand All @@ -282,8 +286,20 @@ private Location getNextIsland() {
*/
private Result isIsland(Location location){
location = Util.getClosestIsland(location);
if (plugin.getIslands().getIslandAt(location).isPresent() || plugin.getIslandDeletionManager().inDeletion(location)) {
return Result.ISLAND_FOUND;

// Check 4 corners
int dist = plugin.getIWM().getIslandDistance(location.getWorld());
Set<Location> locs = new HashSet<>();
locs.add(location);
locs.add(new Location(location.getWorld(), location.getBlockX() - dist, 0, location.getBlockZ() - dist));
locs.add(new Location(location.getWorld(), location.getBlockX() - dist, 0, location.getBlockZ() + dist - 1));
locs.add(new Location(location.getWorld(), location.getBlockX() + dist - 1, 0, location.getBlockZ() - dist));
locs.add(new Location(location.getWorld(), location.getBlockX() + dist - 1, 0, location.getBlockZ() + dist - 1));

for (Location l : locs) {
if (plugin.getIslands().getIslandAt(l).isPresent() || plugin.getIslandDeletionManager().inDeletion(l)) {
return Result.ISLAND_FOUND;
}
}

if (!plugin.getIWM().isUseOwnGenerator(location.getWorld())) {
Expand Down

0 comments on commit 4efdada

Please sign in to comment.