mirror of
https://github.com/BG-Software-LLC/WildLoaders.git
synced 2024-11-22 11:56:17 +01:00
Adds support to BentoBox (#110)
This commit is contained in:
parent
96281d7531
commit
307c181552
25
Hooks/BentoBox/build.gradle
Normal file
25
Hooks/BentoBox/build.gradle
Normal file
@ -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 }
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -60,6 +60,10 @@ public final class ProvidersHandler implements ProvidersManager {
|
||||
Optional<ClaimsProvider> claimsProvider = createInstance("ClaimsProvider_Lands");
|
||||
claimsProvider.ifPresent(this::addClaimsProvider);
|
||||
}
|
||||
if (Bukkit.getPluginManager().isPluginEnabled("BentoBox")) {
|
||||
Optional<ClaimsProvider> claimsProvider = createInstance("ClaimsProvider_BentoBox");
|
||||
claimsProvider.ifPresent(this::addClaimsProvider);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadTickableProviders() {
|
||||
|
Loading…
Reference in New Issue
Block a user