diff --git a/dough-api/pom.xml b/dough-api/pom.xml index b1f10846..d9a6c890 100644 --- a/dough-api/pom.xml +++ b/dough-api/pom.xml @@ -432,6 +432,14 @@ 1.13-SNAPSHOT provided + + + + org.popcraft + bolt-bukkit + 1.0.580 + provided + diff --git a/dough-protection/pom.xml b/dough-protection/pom.xml index 81b750fc..100c547d 100644 --- a/dough-protection/pom.xml +++ b/dough-protection/pom.xml @@ -254,6 +254,13 @@ provided + + + org.popcraft + bolt-bukkit + 1.0.580 + provided + diff --git a/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java index 10ec5b2f..bebd5b33 100644 --- a/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java +++ b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/ProtectionManager.java @@ -20,6 +20,7 @@ import io.github.bakedlibs.dough.protection.loggers.LogBlockLogger; import io.github.bakedlibs.dough.protection.modules.BentoBoxProtectionModule; import io.github.bakedlibs.dough.protection.modules.BlockLockerProtectionModule; +import io.github.bakedlibs.dough.protection.modules.BoltProtectionModule; import io.github.bakedlibs.dough.protection.modules.ChestProtectProtectionModule; import io.github.bakedlibs.dough.protection.modules.FactionsUUIDProtectionModule; import io.github.bakedlibs.dough.protection.modules.FunnyGuildsProtectionModule; @@ -95,6 +96,7 @@ private void loadModuleImplementations(Plugin plugin) { registerModule(pm, "HuskTowns", huskTowns -> new HuskTownsProtectionModule(huskTowns)); registerModule(pm, "ShopChest", shopChest -> new ShopChestProtectionModule(shopChest)); registerModule(pm, "HuskClaims", huskClaims -> new HuskClaimsProtectionModule(huskClaims)); + registerModule(pm, "Bolt", bolt -> new BoltProtectionModule(bolt)); /* * The following Plugins work by utilising one of the above listed diff --git a/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/modules/BoltProtectionModule.java b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/modules/BoltProtectionModule.java new file mode 100644 index 00000000..1c88e3f3 --- /dev/null +++ b/dough-protection/src/main/java/io/github/bakedlibs/dough/protection/modules/BoltProtectionModule.java @@ -0,0 +1,61 @@ +package io.github.bakedlibs.dough.protection.modules; + +import io.github.bakedlibs.dough.protection.ActionType; +import io.github.bakedlibs.dough.protection.Interaction; +import io.github.bakedlibs.dough.protection.ProtectionModule; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.plugin.Plugin; +import org.popcraft.bolt.BoltAPI; +import org.popcraft.bolt.protection.Protection; +import org.popcraft.bolt.util.Permission; + +import javax.annotation.Nonnull; + +public class BoltProtectionModule implements ProtectionModule { + + private BoltAPI bolt; + private final Plugin plugin; + + public BoltProtectionModule(@Nonnull Plugin plugin) { + this.plugin = plugin; + } + + @Override + public Plugin getPlugin() { + return this.plugin; + } + + @Override + public void load() { + bolt = this.plugin.getServer().getServicesManager().load(BoltAPI.class); + } + + @Override + public boolean hasPermission(OfflinePlayer p, Location l, Interaction action) { + if (action.getType() != ActionType.BLOCK) { + return true; + } + + String permission = boltPermission(action); + if (permission == null) { + return true; + } + Protection protection = this.bolt.findProtection(l.getBlock()); + return this.bolt.canAccess(protection, p.getUniqueId(), permission); + } + + private String boltPermission(Interaction interaction) { + switch (interaction) { + case BREAK_BLOCK: + case ATTACK_PLAYER: + case ATTACK_ENTITY: + return Permission.DESTROY; + case PLACE_BLOCK: + case INTERACT_BLOCK: + case INTERACT_ENTITY: + return Permission.INTERACT; + } + return null; + } +}