diff --git a/modern/build.gradle.kts b/modern/build.gradle.kts index c2e2a2a..3b8a0b6 100644 --- a/modern/build.gradle.kts +++ b/modern/build.gradle.kts @@ -16,6 +16,7 @@ dependencies { } compileOnly(":Residence4.9.2.2") // residence compileOnly(":GriefPrevention") // griefprevention + compileOnly("com.github.angeschossen:LandsAPI:6.0.2") // lands if (ultraRegionsSupport) compileOnly(":UltraRegions") // ultraregions compileOnly(project(":api", "shadow")) diff --git a/modern/src/main/java/net/islandearth/rpgregions/api/integrations/lands/LandsIntegration.java b/modern/src/main/java/net/islandearth/rpgregions/api/integrations/lands/LandsIntegration.java new file mode 100644 index 0000000..2c5a66d --- /dev/null +++ b/modern/src/main/java/net/islandearth/rpgregions/api/integrations/lands/LandsIntegration.java @@ -0,0 +1,78 @@ +package net.islandearth.rpgregions.api.integrations.lands; + +import me.angeschossen.lands.api.land.Land; +import net.islandearth.rpgregions.api.IRPGRegionsAPI; +import net.islandearth.rpgregions.api.events.RegionsEnterEvent; +import net.islandearth.rpgregions.api.integrations.IntegrationManager; +import net.islandearth.rpgregions.managers.data.region.ConfiguredRegion; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.plugin.Plugin; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +public class LandsIntegration implements IntegrationManager { + + private final IRPGRegionsAPI plugin; + private final me.angeschossen.lands.api.integration.LandsIntegration lands; + + public LandsIntegration(IRPGRegionsAPI plugin) { + this.plugin = plugin; + this.lands = new me.angeschossen.lands.api.integration.LandsIntegration((Plugin) plugin); + } + + @Override + public boolean isInRegion(Location location) { + return lands.isClaimed(location); + } + + @Override + public void handleMove(PlayerMoveEvent pme) { + Player player = pme.getPlayer(); + if (pme.getTo() == null) return; + Land oldLand = lands.getLand(pme.getFrom()); + Land land = lands.getLand(pme.getTo()); + if (oldLand == null || land == null || !land.exists()) return; + if (!checkRequirements(pme, land.getName())) return; + + Bukkit.getPluginManager().callEvent(new RegionsEnterEvent(player, land.getName(), !oldLand.equals(land))); + } + + @Override + public Optional getPrioritisedRegion(Location location) { + Land land = lands.getLand(location); + return land == null || !land.exists() + ? Optional.empty() + : plugin.getManagers().getRegionsCache().getConfiguredRegion(land.getName()); + } + + @Override + public boolean exists(World location, String region) { + Land land = lands.getLand(region); + return land != null && land.exists(); + } + + @Override + public Set getAllRegionNames(World world) { + Set landNames = new HashSet<>(); + for (Land land : lands.getLands()) { + final String name = land.getName(); + landNames.add(name); + } + return landNames; + } + + @Override + public @NonNull List getBoundingBoxPoints(Location regionLocation, @Nullable String regionId) { + return new ArrayList<>(); + } +} diff --git a/rpgregions/src/main/resources/plugin.yml b/rpgregions/src/main/resources/plugin.yml index 7ee6ca3..f2f3156 100644 --- a/rpgregions/src/main/resources/plugin.yml +++ b/rpgregions/src/main/resources/plugin.yml @@ -4,7 +4,7 @@ main: net.islandearth.rpgregions.RPGRegions api-version: '1.16' libraries: - "com.zaxxer:HikariCP:4.0.3" # database -softdepend: [Hyperverse, Multiverse, UltraRegions, WorldGuard, PlaceholderAPI, HeadDatabase, Residence, Plan, GriefPrevention, Vault, MythicMobs, AlonsoLevels, Dynmap, ProtocolLib, Quests, BetonQuest] +softdepend: [Hyperverse, Multiverse, UltraRegions, WorldGuard, PlaceholderAPI, HeadDatabase, Residence, Plan, GriefPrevention, Vault, MythicMobs, AlonsoLevels, Dynmap, ProtocolLib, Quests, BetonQuest, Lands] authors: [SamB440] description: Discoverable regions website: https://fortitude.islandearth.net \ No newline at end of file