Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix Lands Integration #3

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
dependencies {
compileOnly 'com.github.InsightsPlugin:Insights:feature~addons-SNAPSHOT'
compileOnly 'com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT'
compileOnly 'com.github.angeschossen:LandsAPI:5.1.13'
compileOnly 'com.github.angeschossen:LandsAPI:7.1.12'
}

blossom {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import dev.frankheijden.insights.api.addons.Region;
import dev.frankheijden.insights.api.objects.chunk.ChunkLocation;
import dev.frankheijden.insights.api.objects.chunk.ChunkPart;
import me.angeschossen.lands.api.LandsIntegration;
import me.angeschossen.lands.api.events.ChunkDeleteEvent;
import me.angeschossen.lands.api.events.ChunkPostClaimEvent;
import me.angeschossen.lands.api.integration.LandsIntegration;
import me.angeschossen.lands.api.land.ChunkCoordinate;
import me.angeschossen.lands.api.land.Container;
import me.angeschossen.lands.api.land.Land;
import org.bukkit.Location;
import org.bukkit.World;
Expand All @@ -26,19 +27,23 @@ public class LandsAddon implements InsightsAddon, Listener {
private final LandsIntegration integration;

public LandsAddon() {
this.integration = new LandsIntegration(InsightsPlugin.getInstance());
this.integration = LandsIntegration.of(InsightsPlugin.getInstance());
}

public String getKey(Land land, World world) {
return land.getId() + "-" + world.getName();
return land.getULID().toString() + "-" + world.getName();
}

public Optional<Region> adapt(Land land, World world) {
if (land == null) return Optional.empty();

Collection<ChunkCoordinate> coordinates = land.getChunks(world);
if (coordinates == null || coordinates.isEmpty()) return Optional.empty();
return Optional.of(new LandsRegion(coordinates, getKey(land, world)));
Container container = land.getContainer(world);
if(container == null) return Optional.empty();

Collection<? extends ChunkCoordinate> coordinates = container.getChunks();
if (coordinates.isEmpty()) return Optional.empty();

return Optional.of(new LandsRegion(world, coordinates, getKey(land, world)));
}

@Override
Expand All @@ -58,7 +63,7 @@ public String getVersion() {

@Override
public Optional<Region> getRegion(Location location) {
return adapt(integration.getLand(
return adapt(integration.getLandByChunk(
location.getWorld(),
location.getBlockX() >> 4,
location.getBlockZ() >> 4
Expand All @@ -81,10 +86,12 @@ private void clearLandCache(Land land, World world) {

public class LandsRegion implements Region {

private final Collection<ChunkCoordinate> coordinates;
private final World world;
private final Collection<? extends ChunkCoordinate> coordinates;
private final String key;

public LandsRegion(Collection<ChunkCoordinate> coordinates, String key) {
public LandsRegion(World world, Collection<? extends ChunkCoordinate> coordinates, String key) {
this.world = world;
this.coordinates = coordinates;
this.key = key;
}
Expand All @@ -103,7 +110,7 @@ public String getKey() {
public List<ChunkPart> toChunkParts() {
List<ChunkPart> parts = new ArrayList<>(coordinates.size());
for (ChunkCoordinate coordinate : coordinates) {
parts.add(new ChunkPart(new ChunkLocation(coordinate.getWorld(), coordinate.getX(), coordinate.getZ())));
parts.add(new ChunkPart(new ChunkLocation(world, coordinate.getX(), coordinate.getZ())));
}
return parts;
}
Expand Down