Skip to content

Commit

Permalink
Add compatibility for plugin 'HuskTowns' (#36)
Browse files Browse the repository at this point in the history
* Add dependency to compatible with plugin 'HuskTowns'

* Add compatibility for plugin 'HuskTowns'

* Update README.md
  • Loading branch information
Uni0305 authored Jul 28, 2024
1 parent b297744 commit fa29b84
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ProtectionLib.canUse(player,location);
4) Add softdepend to plugin.yml

```yaml
softdepend: [ WorldGuard, Towny, Factions, Lands, PlotSquared, CrashClaim ]
softdepend: [ WorldGuard, Towny, Factions, Lands, PlotSquared, CrashClaim, HuskTowns ]
```
# Supported plugins
Expand All @@ -59,3 +59,4 @@ ProtectionLib.canUse(player,location);
- [Lands](https://www.spigotmc.org/resources/lands-land-claim-plugin-grief-prevention-protection-gui-management-nations-wars-1-17-support.53313/) (Paid)
- [PlotSquared](https://www.spigotmc.org/resources/plotsquared.1177/) (Free)
- [CrashClaim](https://www.spigotmc.org/resources/crashclaim-claiming-plugin.94037/) (Paid)
- [HuskTowns](https://www.spigotmc.org/resources/92672) (Paid)
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ dependencies {
//compileOnly("com.github.TechFortress:GriefPrevention:16.18")
implementation(files("libs/GriefPrevention-16.18.jar"))
compileOnly("net.william278.huskclaims:huskclaims-bukkit:1.1.2")
compileOnly("net.william278.husktowns:husktowns-bukkit:3.0.4")
}

java {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/th0rgal/protectionlib/ProtectionLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public static void init(JavaPlugin plugin) {
} catch (Exception | NoClassDefFoundError e) {
if (debug) e.printStackTrace();
}
try {
handleCompatibility("HuskTowns", plugin, (m, p) -> new HuskTownsCompat(m, p));
} catch (Exception | NoClassDefFoundError e) {
if (debug) e.printStackTrace();
}
}

public static void setDebug(boolean debug) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.th0rgal.protectionlib.compatibilities;

import io.th0rgal.protectionlib.ProtectionCompatibility;
import net.william278.husktowns.api.BukkitHuskTownsAPI;
import net.william278.husktowns.api.HuskTownsAPI;
import net.william278.husktowns.claim.Position;
import net.william278.husktowns.libraries.cloplib.operation.OperationType;
import net.william278.husktowns.user.OnlineUser;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;

public class HuskTownsCompat extends ProtectionCompatibility {
private final HuskTownsAPI commonAPI;
private final BukkitHuskTownsAPI bukkitAPI;

public HuskTownsCompat(JavaPlugin mainPlugin, Plugin plugin) {
super(mainPlugin, plugin);
commonAPI = HuskTownsAPI.getInstance();
bukkitAPI = BukkitHuskTownsAPI.getInstance();
}

@Override
public boolean canBuild(Player player, Location target) {
return isOperationAllowed(player, target, OperationType.BLOCK_PLACE);
}

@Override
public boolean canBreak(Player player, Location target) {
return isOperationAllowed(player, target, OperationType.BLOCK_BREAK);
}

@Override
public boolean canInteract(Player player, Location target) {
OperationType type = target.getBlock().getType().isBlock() ? OperationType.BLOCK_INTERACT : OperationType.ENTITY_INTERACT;
return isOperationAllowed(player, target, type);
}

@Override
public boolean canUse(Player player, Location target) {
return isOperationAllowed(player, target, OperationType.BLOCK_INTERACT);
}

private boolean isOperationAllowed(@NotNull Player player, @NotNull Location location, @NotNull OperationType type) {
OnlineUser user = bukkitAPI.getOnlineUser(player);
Position position = bukkitAPI.getPosition(location);
return commonAPI.isOperationAllowed(user, type, position);
}
}

0 comments on commit fa29b84

Please sign in to comment.