Skip to content

Commit

Permalink
feat: implement HuskClaims support
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Jan 16, 2024
1 parent 75dfeea commit d72ff44
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 4 deletions.
9 changes: 6 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,27 @@ repositories {
maven("https://maven.enginehub.org/repo/")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://jitpack.io")
maven("https://repo.william278.net/releases")
}

dependencies {
compileOnly("org.spigotmc:spigot-api:1.20.1-R0.1-SNAPSHOT")
compileOnly("org.spigotmc:spigot-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("com.sk89q.worldguard:worldguard-bukkit:7.1.0-SNAPSHOT")
compileOnly("com.palmergames.bukkit.towny:towny:0.99.2.0")
compileOnly("com.palmergames.bukkit.towny:towny:0.100.1.0")
compileOnly("com.massivecraft:Factions:1.6.9.5-U0.6.11") {
exclude("org.kitteh:paste-gg-api")
exclude("com.darkblade12:particleeffect")
exclude("org.spongepowered:configurate-hocon")
exclude("com.mojang:brigadier")
}
compileOnly("com.github.angeschossen:LandsAPI:6.29.12")
compileOnly("com.github.angeschossen:LandsAPI:6.44.0")
compileOnly("com.github.WhipDevelopment:CrashClaim:75abe3b665")
implementation(platform("com.intellectualsites.bom:bom-1.18.x:1.20"))
compileOnly("com.plotsquared:PlotSquared-Core")
compileOnly("com.plotsquared:PlotSquared-Bukkit")
compileOnly("com.github.TechFortress:GriefPrevention:16.18")
compileOnly("net.william278.huskclaims:huskclaims-common:1.0.1")
compileOnly("net.william278.huskclaims:huskclaims-bukkit:1.0.1")
}

java {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pluginVersion=1.3.6
pluginVersion=1.4.0
1 change: 1 addition & 0 deletions src/main/java/io/th0rgal/protectionlib/ProtectionLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static void init(JavaPlugin plugin) {
handleCompatibility("PlotSquared", plugin, (m, p) -> new PlotSquaredCompat(m, p));
handleCompatibility("CrashClaim", plugin, (m, p) -> new CrashClaimCompat(m, p));
handleCompatibility("GriefPrevention", plugin, (m, p) -> new GriefPreventionCompat(m, p));
handleCompatibility("HuskClaims", plugin, (m, p) -> new HuskClaimCompat(m, p));
}

public static boolean canBuild(Player player, Location target) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.th0rgal.protectionlib.compatibilities;

import io.th0rgal.protectionlib.ProtectionCompatibility;
import net.william278.cloplib.operation.OperationType;
import net.william278.huskclaims.api.BukkitHuskClaimsAPI;
import net.william278.huskclaims.api.HuskClaimsAPI;
import net.william278.huskclaims.position.Position;
import net.william278.huskclaims.trust.TrustLevel;
import net.william278.huskclaims.user.OnlineUser;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Optional;

public class HuskClaimCompat extends ProtectionCompatibility {

private final HuskClaimsAPI huskClaimsCommon;
private final BukkitHuskClaimsAPI huskClaimsBukkit;

public HuskClaimCompat(JavaPlugin mainPlugin, Plugin plugin) {
super(mainPlugin, plugin);
huskClaimsCommon = HuskClaimsAPI.getInstance();
huskClaimsBukkit = BukkitHuskClaimsAPI.getInstance();
}

@Override
public boolean canBuild(Player player, Location target) {
OnlineUser onlineUser = huskClaimsCommon.getOnlineUser(player.getUniqueId());
Position position = huskClaimsBukkit.getPosition(target);

Optional<TrustLevel> trustLevel = huskClaimsBukkit.getTrustLevelAt(position, onlineUser);
return trustLevel.isPresent() && trustLevel.get().getFlags().contains(OperationType.BLOCK_PLACE);
}

@Override
public boolean canBreak(Player player, Location target) {
OnlineUser onlineUser = huskClaimsCommon.getOnlineUser(player.getUniqueId());
Position position = huskClaimsBukkit.getPosition(target);

Optional<TrustLevel> trustLevel = huskClaimsBukkit.getTrustLevelAt(position, onlineUser);
return trustLevel.isPresent() && trustLevel.get().getFlags().contains(OperationType.BLOCK_BREAK);
}

@Override
public boolean canInteract(Player player, Location target) {
OnlineUser onlineUser = huskClaimsCommon.getOnlineUser(player.getUniqueId());
Position position = huskClaimsBukkit.getPosition(target);

OperationType operationType = target.getBlock().getType().isBlock() ? OperationType.BLOCK_INTERACT : OperationType.ENTITY_INTERACT;
Optional<TrustLevel> trustLevel = huskClaimsBukkit.getTrustLevelAt(position, onlineUser);
return trustLevel.isPresent() && trustLevel.get().getFlags().contains(operationType);
}

@Override
public boolean canUse(Player player, Location target) {
OnlineUser onlineUser = huskClaimsCommon.getOnlineUser(player.getUniqueId());
Position position = huskClaimsBukkit.getPosition(target);

Optional<TrustLevel> trustLevel = huskClaimsBukkit.getTrustLevelAt(position, onlineUser);
return trustLevel.isPresent() && trustLevel.get().getFlags().contains(OperationType.BLOCK_INTERACT);
}
}

0 comments on commit d72ff44

Please sign in to comment.