diff --git a/Hooks/BentoBox/build.gradle b/Hooks/BentoBox/build.gradle new file mode 100644 index 0000000..7924c18 --- /dev/null +++ b/Hooks/BentoBox/build.gradle @@ -0,0 +1,25 @@ +group 'Hooks:BentoBox' + +java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(16)) + } +} + +repositories { + mavenCentral() + maven { url "https://repo.codemc.org/repository/maven-public/" } +} + +dependencies { + compileOnly "world.bentobox:bentobox:2.6.0-SNAPSHOT" + compileOnly "world.bentobox:bskyblock:1.18.1-SNAPSHOT" + compileOnly "org.spigotmc:v1_8_R3-Taco:latest" + compileOnly project(":API") + compileOnly rootProject +} + +if (project.hasProperty('hook.compile_bentobox') && + !Boolean.valueOf(project.findProperty("hook.compile_bentobox").toString())) { + project.tasks.all { task -> task.enabled = false } +} \ No newline at end of file diff --git a/Hooks/BentoBox/src/main/java/com/bgsoftware/wildloaders/hooks/ClaimsProvider_BentoBox.java b/Hooks/BentoBox/src/main/java/com/bgsoftware/wildloaders/hooks/ClaimsProvider_BentoBox.java new file mode 100644 index 0000000..091dfdd --- /dev/null +++ b/Hooks/BentoBox/src/main/java/com/bgsoftware/wildloaders/hooks/ClaimsProvider_BentoBox.java @@ -0,0 +1,76 @@ +package com.bgsoftware.wildloaders.hooks; + +import com.bgsoftware.wildloaders.api.hooks.ClaimsProvider; +import org.bukkit.Chunk; +import org.bukkit.Location; +import world.bentobox.bentobox.BentoBox; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.database.objects.Island; +import world.bentobox.bentobox.lists.Flags; +import world.bentobox.bentobox.managers.IslandsManager; + +import java.util.UUID; + +public final class ClaimsProvider_BentoBox implements ClaimsProvider { + + private final IslandsManager islandsManager; + + public ClaimsProvider_BentoBox() { + this.islandsManager = BentoBox.getInstance().getIslands(); + } + + @Override + public boolean hasClaimAccess(UUID player, Chunk chunk) { + User bentoPlayer = BentoBox.getInstance().getPlayersManager().getUser(player); + + // There is no API method to get island at a specific chunk. + // Therefore we need to check for islands in each corner of the chunk. + + Location cornerLocation = new Location(chunk.getWorld(), chunk.getX() << 4, 100, chunk.getZ() << 4); + + IslandAccess islandAccess = IslandAccess.WILDERNESS; + + // Min x, Min z + if ((islandAccess = islandAccess.and(checkIslandAccess(bentoPlayer, cornerLocation))) == IslandAccess.DENIED) + return false; + + // Max x, Min z + cornerLocation.add(15, 0, 0); + if ((islandAccess = islandAccess.and(checkIslandAccess(bentoPlayer, cornerLocation))) == IslandAccess.DENIED) + return false; + + // Max x, Max z + cornerLocation.add(0, 0, 15); + if ((islandAccess = islandAccess.and(checkIslandAccess(bentoPlayer, cornerLocation))) == IslandAccess.DENIED) + return false; + + // Min x, Max z + cornerLocation.add(-15, 0, 0); + if ((islandAccess = islandAccess.and(checkIslandAccess(bentoPlayer, cornerLocation))) == IslandAccess.DENIED) + return false; + + // We only return true if one of the corners were inside an actual island. + return islandAccess == IslandAccess.ALLOWED; + } + + private IslandAccess checkIslandAccess(User bentoPlayer, Location location) { + Island island = this.islandsManager.getIslandAt(location).orElse(null); + if (island == null) + return IslandAccess.WILDERNESS; + + return island.isAllowed(bentoPlayer, Flags.PLACE_BLOCKS) ? IslandAccess.ALLOWED : IslandAccess.DENIED; + } + + enum IslandAccess { + + WILDERNESS, + ALLOWED, + DENIED; + + public IslandAccess and(IslandAccess other) { + return other.ordinal() > this.ordinal() ? other : this; + } + + } + +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 9b031bd..e3350a0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,6 +11,7 @@ nms.compile_v1_20=true nms.compile_v1_21=true hook.compile_advancedslimepaper=true hook.compile_advancedslimeworldmanager=true +hook.compile_bentobox=true hook.compile_epicspawners6=true hook.compile_epicspawners7=true hook.compile_factionsuuid=true diff --git a/settings.gradle b/settings.gradle index abd984f..cacaf52 100644 --- a/settings.gradle +++ b/settings.gradle @@ -11,6 +11,7 @@ include 'API' include 'Hooks' include 'Hooks:AdvancedSlimePaper' include 'Hooks:AdvancedSlimeWorldManager' +include 'Hooks:BentoBox' include 'Hooks:EpicSpawners6' include 'Hooks:EpicSpawners7' include 'Hooks:EpicSpawners8' diff --git a/src/main/java/com/bgsoftware/wildloaders/handlers/ProvidersHandler.java b/src/main/java/com/bgsoftware/wildloaders/handlers/ProvidersHandler.java index a7d0b9b..cf24933 100644 --- a/src/main/java/com/bgsoftware/wildloaders/handlers/ProvidersHandler.java +++ b/src/main/java/com/bgsoftware/wildloaders/handlers/ProvidersHandler.java @@ -60,6 +60,10 @@ public final class ProvidersHandler implements ProvidersManager { Optional claimsProvider = createInstance("ClaimsProvider_Lands"); claimsProvider.ifPresent(this::addClaimsProvider); } + if (Bukkit.getPluginManager().isPluginEnabled("BentoBox")) { + Optional claimsProvider = createInstance("ClaimsProvider_BentoBox"); + claimsProvider.ifPresent(this::addClaimsProvider); + } } private void loadTickableProviders() {