Skip to content

Commit 494df6d

Browse files
authored
Merge pull request #196 from Kawi16/main
feat: huskclaims hook & residence fix
2 parents 3fb744f + 401ad47 commit 494df6d

10 files changed

Lines changed: 62 additions & 8 deletions

File tree

build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ allprojects {
6666
name = "minecodes-repository-releases"
6767
url = uri("https://maven.minecodes.pl/releases")
6868
}
69+
maven {
70+
name = "william278Releases"
71+
url = uri("https://repo.william278.net/releases")
72+
}
6973
}
7074
}
7175

core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dependencies {
5555

5656
implementation(platform("com.intellectualsites.bom:bom-newest:1.56"))
5757
compileOnly("com.intellectualsites.plotsquared:plotsquared-core")
58+
compileOnly("net.william278.huskclaims:huskclaims-bukkit:1.5.10")
5859

5960
compileOnly("org.projectlombok:lombok:1.18.44")
6061
annotationProcessor("org.projectlombok:lombok:1.18.44")

core/src/main/java/github/nighter/smartspawner/hooks/IntegrationManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class IntegrationManager {
3636
private boolean hasIridiumSkyblock = false;
3737
private boolean hasPlotSquared = false;
3838
private boolean hasResidence = false;
39+
private boolean hasHuskClaims = false;
3940

4041
// Integration plugin flags
4142
private boolean hasAuraSkills = false;
@@ -151,6 +152,11 @@ private void checkProtectionPlugins() {
151152
Plugin residence = Bukkit.getPluginManager().getPlugin("Residence");
152153
return residence != null && residence.isEnabled();
153154
}, true);
155+
156+
hasHuskClaims = checkPlugin("HuskClaims", () -> {
157+
Plugin hc = Bukkit.getPluginManager().getPlugin("HuskClaims");
158+
return hc != null && hc.isEnabled();
159+
}, true);
154160
}
155161

156162
private void checkIntegrationPlugins() {

core/src/main/java/github/nighter/smartspawner/hooks/protections/CheckBreakBlock.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public static boolean CanPlayerBreakBlock(@NotNull final Player player, @NotNull
2222
if (integrationManager.isHasPlotSquared() && !PlotSquared.canInteract(player, location)) return false;
2323
if (integrationManager.isHasResidence() && !Residence.canPlayerBreakBlock(player, location)) return false;
2424
if (integrationManager.isHasMinePlots() && !MinePlots.canPlayerBreakBlock(player, location)) return false;
25+
if (integrationManager.isHasHuskClaims() && !HuskClaims.canPlayerBreakBlock(player, location)) return false;
2526
return true;
2627
}
2728
}

core/src/main/java/github/nighter/smartspawner/hooks/protections/CheckOpenMenu.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static boolean CanPlayerOpenMenu(@NotNull final Player player, @NotNull L
2626
if (integrationManager.isHasIridiumSkyblock() && !IridiumSkyblock.canPlayerOpenMenu(player, location)) return false;
2727
if (integrationManager.isHasPlotSquared() && !PlotSquared.canInteract(player, location)) return false;
2828
if (integrationManager.isHasResidence() && !Residence.canInteract(player, location)) return false;
29+
if (integrationManager.isHasHuskClaims() && !HuskClaims.canPlayerOpenMenu(player, location)) return false;
2930
return !integrationManager.isHasRedProtect() || RedProtectAPI.canPlayerOpenMenuOnClaim(player, location);
3031
}
3132
}

core/src/main/java/github/nighter/smartspawner/hooks/protections/CheckStackBlock.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static boolean CanPlayerPlaceBlock(@NotNull final Player player, @NotNull
2626
if (integrationManager.isHasIridiumSkyblock() && !IridiumSkyblock.canPlayerStackBlock(player, location)) return false;
2727
if (integrationManager.isHasPlotSquared() && !PlotSquared.canInteract(player, location)) return false;
2828
if (integrationManager.isHasResidence() && !Residence.canStack(player, location)) return false;
29+
if (integrationManager.isHasHuskClaims() && !HuskClaims.canPlayerStackBlock(player, location)) return false;
2930
return !integrationManager.isHasRedProtect() || RedProtectAPI.canPlayerStackClaimBlock(player, location);
3031
}
3132
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package github.nighter.smartspawner.hooks.protections.api;
2+
3+
import net.william278.huskclaims.api.BukkitHuskClaimsAPI;
4+
import net.william278.huskclaims.claim.Claim;
5+
import net.william278.huskclaims.libraries.cloplib.operation.Operation;
6+
import net.william278.huskclaims.libraries.cloplib.operation.OperationType;
7+
import net.william278.huskclaims.position.Position;
8+
import net.william278.huskclaims.user.OnlineUser;
9+
import org.bukkit.Location;
10+
import org.bukkit.entity.Player;
11+
import org.jetbrains.annotations.NotNull;
12+
13+
public class HuskClaims {
14+
public static boolean canPlayerBreakBlock(@NotNull Player player, @NotNull Location location) {
15+
return check(player, location, OperationType.BLOCK_BREAK);
16+
}
17+
18+
public static boolean canPlayerStackBlock(@NotNull Player player, @NotNull Location location) {
19+
return check(player, location, OperationType.BLOCK_INTERACT);
20+
}
21+
22+
public static boolean canPlayerOpenMenu(@NotNull Player player, @NotNull Location location) {
23+
return check(player, location, OperationType.BLOCK_INTERACT);
24+
}
25+
26+
private static boolean check(Player player, Location location, OperationType operationType) {
27+
OnlineUser user = BukkitHuskClaimsAPI.getInstance().getOnlineUser(player);
28+
if (user == null) return true;
29+
Position position = BukkitHuskClaimsAPI.getInstance().getPosition(location);
30+
Claim claim = BukkitHuskClaimsAPI.getInstance().getClaimAt(position).orElse(null);
31+
if (claim == null) return true;
32+
return BukkitHuskClaimsAPI.getInstance().isOperationAllowed(Operation.of(user, operationType, position, true));
33+
}
34+
}

core/src/main/java/github/nighter/smartspawner/hooks/protections/api/Residence.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package github.nighter.smartspawner.hooks.protections.api;
22

33
import com.bekvon.bukkit.residence.api.ResidenceApi;
4+
import com.bekvon.bukkit.residence.containers.Flags;
45
import com.bekvon.bukkit.residence.protection.ClaimedResidence;
6+
import com.bekvon.bukkit.residence.protection.FlagPermissions;
57
import org.bukkit.Location;
68
import org.bukkit.entity.Player;
79
import org.jetbrains.annotations.NotNull;
810

9-
import java.util.Map;
10-
1111
public class Residence {
1212
public static boolean canPlayerBreakBlock(@NotNull Player player, @NotNull Location location) {
1313
return check(player, location, "build");
@@ -24,12 +24,13 @@ public static boolean canStack(@NotNull Player player, @NotNull Location locatio
2424
private static boolean check(Player player, Location location, String flagName) {
2525
ClaimedResidence claimedResidence = ResidenceApi.getResidenceManager().getByLoc(location);
2626
if (claimedResidence == null) return true;
27-
Map<String, Boolean> flags = claimedResidence.getPermissions().getPlayerFlags(player.getUniqueId());
28-
if (flags == null) return true;
29-
for (String flag : flags.keySet()) {
30-
if (flag.equalsIgnoreCase(flagName) && flags.get(flag))
31-
return true;
27+
FlagPermissions perms = claimedResidence.getPermissions();
28+
if (perms == null) return true;
29+
try {
30+
boolean globalDefault = perms.has(Flags.valueOf(flagName), true);
31+
return perms.playerHas(player, Flags.valueOf(flagName), globalDefault);
32+
} catch (IllegalArgumentException ex) {
33+
return true;
3234
}
33-
return false;
3435
}
3536
}

core/src/main/resources/paper-plugin.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ dependencies:
9090
load: BEFORE
9191
required: false
9292
join-classpath: true
93+
HuskClaims:
94+
load: BEFORE
95+
required: false
96+
join-classpath: true
9397

9498
# World Management Plugins
9599
Multiverse-Core:

core/src/main/resources/plugin.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ softdepend:
3030
- minePlots
3131
- PlotSquared
3232
- Residence
33+
- HuskClaims
3334

3435
# World Management Plugins
3536
- Multiverse-Core

0 commit comments

Comments
 (0)