Skip to content

Commit

Permalink
Merge pull request #265 from rymiel/bolt
Browse files Browse the repository at this point in the history
Add Bolt protection module
  • Loading branch information
Sfiguz7 authored Mar 18, 2024
2 parents f0c2a47 + 4e31489 commit a23d95e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
8 changes: 8 additions & 0 deletions dough-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,14 @@
<version>1.13-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<!-- Bolt -->
<dependency>
<groupId>org.popcraft</groupId>
<artifactId>bolt-bukkit</artifactId>
<version>1.0.580</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
7 changes: 7 additions & 0 deletions dough-protection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@
<scope>provided</scope>
</dependency>

<!-- Bolt -->
<dependency>
<groupId>org.popcraft</groupId>
<artifactId>bolt-bukkit</artifactId>
<version>1.0.580</version>
<scope>provided</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit a23d95e

Please sign in to comment.