Skip to content

Commit

Permalink
Optimized detection if a location is inside the spawn island (#1317)
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Aug 18, 2022
1 parent bc074e9 commit 26e889f
Showing 1 changed file with 7 additions and 8 deletions.
Expand Up @@ -24,6 +24,7 @@
import com.bgsoftware.superiorskyblock.api.upgrades.Upgrade;
import com.bgsoftware.superiorskyblock.api.upgrades.UpgradeLevel;
import com.bgsoftware.superiorskyblock.api.wrappers.SuperiorPlayer;
import com.bgsoftware.superiorskyblock.core.IslandArea;
import com.bgsoftware.superiorskyblock.core.SequentialListBuilder;
import com.bgsoftware.superiorskyblock.core.database.bridge.EmptyDatabaseBridge;
import com.bgsoftware.superiorskyblock.core.errors.ManagerLoadException;
Expand Down Expand Up @@ -78,6 +79,7 @@ public class SpawnIsland implements Island {
private final int islandSize;
private final Location minLocation;
private final Location maxLocation;
private final IslandArea islandArea;

private Biome biome = Biome.PLAINS;

Expand All @@ -95,6 +97,8 @@ public SpawnIsland(SuperiorSkyblockPlugin plugin) {
islandSize = plugin.getSettings().getSpawn().getSize();
minLocation = center.clone().subtract(islandSize, islandSize, islandSize);
maxLocation = center.clone().add(islandSize, islandSize, islandSize);
this.islandArea = new IslandArea(minLocation.getBlockX(), minLocation.getBlockZ(),
maxLocation.getBlockX(), maxLocation.getBlockZ());

if (center.getWorld() == null)
plugin.getProviders().runWorldsListeners(spawnLocation.split(", ")[0]);
Expand Down Expand Up @@ -456,14 +460,9 @@ public void resetChunks(boolean onlyProtected, Runnable onFinish) {

@Override
public boolean isInside(Location location) {
if (!location.getWorld().equals(getCenter(plugin.getSettings().getWorlds().getDefaultWorld()).getWorld()))
return false;

Location min = getMinimum();
Location max = getMaximum();

return min.getBlockX() <= location.getBlockX() && min.getBlockZ() <= location.getBlockZ() &&
max.getBlockX() >= location.getBlockX() && max.getBlockZ() >= location.getBlockZ();
World spawnWorld = center.getWorld();
return location.getWorld().equals(spawnWorld) &&
this.islandArea.intercepts(location.getBlockX(), location.getBlockZ());
}

@Override
Expand Down

0 comments on commit 26e889f

Please sign in to comment.