3
0
Mirror von https://github.com/Moulberry/AxiomPaperPlugin.git synchronisiert 2024-11-17 05:40:06 +01:00

Add support for GriefDefender

- Added `/integration/griefdefender/GriefDefenderIntegration.java`
- Added `/integration/griefdefender/GriefDefenderIntegrationImpl.java`
- Modified logic in `/integration/Integration.java` and `/integration/SectionPermissionChecker.java`

This commit enables AxiomPaper to support GriefDefender claims. When a world has GriefDefender enabled, players will only be able to use Axiom within territories where they have building permissions. These changes expand AxiomPaper's ability to check for more region protection plugins.
Dieser Commit ist enthalten in:
TWME 2024-06-28 01:02:57 +08:00
Ursprung 90b73eb7fc
Commit 709e78c3bc
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
7 geänderte Dateien mit 137 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -24,6 +24,7 @@ repositories {
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://maven.enginehub.org/repo/")
maven("https://maven.playpro.com")
maven("https://repo.glaremasters.me/repository/bloodshot")
}
dependencies {
@ -47,6 +48,9 @@ dependencies {
// CoreProtect support
compileOnly(libs.coreprotect)
// GriefDefender support
compileOnly(libs.griefdefender)
}
tasks {

Datei anzeigen

@ -9,6 +9,7 @@ reflection-remapper = "0.1.2-20240315.033304-2"
viaversion-api = "5.0.1"
worldguard-bukkit = "7.1.0-20240503.180049-12"
zstd-jni = "1.5.5-4"
griefdefender = "2.1.0-20240112.231634-8"
# Plugins
paperweight-userdev = "1.7.1"
@ -25,6 +26,7 @@ reflection-remapper = { group = "xyz.jpenilla", name = "reflection-remapper", ve
viaversion-api = { group = "com.viaversion", name = "viaversion-api", version.ref = "viaversion-api" }
worldguard-bukkit = { group = "com.sk89q.worldguard", name = "worldguard-bukkit", version.ref = "worldguard-bukkit" }
zstd-jni = { group = "com.github.luben", name = "zstd-jni", version = "1.5.5-4" }
griefdefender = { group = "com.griefdefender", name = "api", version.ref = "griefdefender" }
[plugins]
paperweight-userdev = { id = "io.papermc.paperweight.userdev", version.ref = "paperweight-userdev" }

Datei anzeigen

@ -85,7 +85,8 @@ public class AxiomDebugCommand {
);
enum IntegrationType {
PLOT_SQUARED,
WORLD_GUARD
WORLD_GUARD,
GRIEF_DEFENDER
}
manager.command(
base(manager, "canBreakBlockAtCurrentPosition").optional("type", EnumParser.enumParser(IntegrationType.class)).handler(context -> {
@ -99,6 +100,8 @@ public class AxiomDebugCommand {
canBreakBlock = PlotSquaredIntegration.canBreakBlock(player, block);
} else if (integrationType == IntegrationType.WORLD_GUARD) {
canBreakBlock = WorldGuardIntegration.canBreakBlock(player, block.getLocation());
} else if (integrationType == IntegrationType.GRIEF_DEFENDER) {
canBreakBlock = Integration.canBreakBlock(player, block);
} else {
canBreakBlock = Integration.canBreakBlock(player, block);
}
@ -115,6 +118,8 @@ public class AxiomDebugCommand {
canPlaceBlock = PlotSquaredIntegration.canPlaceBlock(player, player.getLocation());
} else if (integrationType == IntegrationType.WORLD_GUARD) {
canPlaceBlock = WorldGuardIntegration.canPlaceBlock(player, player.getLocation());
} else if (integrationType == IntegrationType.GRIEF_DEFENDER) {
canPlaceBlock = Integration.canPlaceBlock(player, player.getLocation());
} else {
canPlaceBlock = Integration.canPlaceBlock(player, player.getLocation());
}

Datei anzeigen

@ -1,28 +1,33 @@
package com.moulberry.axiom.integration;
import com.moulberry.axiom.integration.griefdefender.GriefDefenderIntegration;
import com.moulberry.axiom.integration.plotsquared.PlotSquaredIntegration;
import com.moulberry.axiom.integration.worldguard.WorldGuardIntegration;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.util.List;
public class Integration {
// todo: test if all this is working for both plotsqured, worldguard, plotsquared+worldguard
public static boolean canBreakBlock(Player player, Block block) {
return PlotSquaredIntegration.canBreakBlock(player, block) && WorldGuardIntegration.canBreakBlock(player, block.getLocation());
return PlotSquaredIntegration.canBreakBlock(player, block) && WorldGuardIntegration.canBreakBlock(player, block.getLocation()) && GriefDefenderIntegration.canBreakBlock(player, block.getLocation());
}
public static boolean canPlaceBlock(Player player, org.bukkit.Location loc) {
return PlotSquaredIntegration.canPlaceBlock(player, loc) && WorldGuardIntegration.canPlaceBlock(player, loc);
return PlotSquaredIntegration.canPlaceBlock(player, loc) && WorldGuardIntegration.canPlaceBlock(player, loc) && GriefDefenderIntegration.canPlaceBlock(player, loc);
}
public static SectionPermissionChecker checkSection(Player player, World world, int cx, int cy, int cz) {
SectionPermissionChecker plotSquared = PlotSquaredIntegration.checkSection(player, world, cx, cy, cz);
SectionPermissionChecker worldGuard = WorldGuardIntegration.checkSection(player, world, cx, cy, cz);
SectionPermissionChecker griefDefender = GriefDefenderIntegration.checkSection(player, world, cx, cy, cz);
return SectionPermissionChecker.combine(plotSquared, worldGuard);
List<SectionPermissionChecker> checkers = List.of(plotSquared, worldGuard, griefDefender);
return SectionPermissionChecker.combine(checkers);
}
}

Datei anzeigen

@ -9,6 +9,16 @@ public interface SectionPermissionChecker {
boolean allowed(int x, int y, int z);
Box bounds();
static SectionPermissionChecker combine(List<SectionPermissionChecker> checkers) {
if (checkers.isEmpty()) return NONE_ALLOWED;
SectionPermissionChecker currentCombinedChecker = checkers.getFirst();
for (int i = 1; i < checkers.size(); i++) {
currentCombinedChecker = combine(currentCombinedChecker , checkers.get(i));
}
return currentCombinedChecker ;
}
static SectionPermissionChecker combine(SectionPermissionChecker first, SectionPermissionChecker second) {
if (first.noneAllowed() || second.noneAllowed()) {
return NONE_ALLOWED;

Datei anzeigen

@ -0,0 +1,27 @@
package com.moulberry.axiom.integration.griefdefender;
import com.moulberry.axiom.integration.SectionPermissionChecker;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
public class GriefDefenderIntegration {
public static boolean canBreakBlock(Player player, Location loc) {
if (!Bukkit.getPluginManager().isPluginEnabled("GriefDefender")) {
return true;
}
return GriefDefenderIntegrationImpl.isBuilder(player, loc);
}
public static boolean canPlaceBlock(Player player, Location loc) {
return canBreakBlock(player, loc);
}
public static SectionPermissionChecker checkSection(Player player, World world, int cx, int cy, int cz) {
if (!Bukkit.getPluginManager().isPluginEnabled("GriefDefender")) {
return SectionPermissionChecker.ALL_ALLOWED;
}
return GriefDefenderIntegrationImpl.checkSection(player, world, cx, cy, cz);
}
}

Datei anzeigen

@ -0,0 +1,80 @@
package com.moulberry.axiom.integration.griefdefender;
import com.griefdefender.api.GriefDefender;
import com.griefdefender.api.claim.Claim;
import com.griefdefender.api.claim.TrustTypes;
import com.griefdefender.lib.flowpowered.math.vector.Vector3i;
import com.moulberry.axiom.integration.SectionPermissionChecker;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class GriefDefenderIntegrationImpl {
public static boolean isBuilder(Player player, Location loc) {
if (!GriefDefender.getCore().isEnabled(loc.getWorld().getUID())) {
return true;
}
Claim claim = GriefDefender.getCore().getClaimAt(loc);
if (claim == null) {
return true;
}
return claim.isUserTrusted(player.getUniqueId(), TrustTypes.BUILDER);
}
public static SectionPermissionChecker checkSection(Player player, World world, int cx, int cy, int cz) {
if (!GriefDefender.getCore().isEnabled(world.getUID())) {
return SectionPermissionChecker.ALL_ALLOWED;
}
int minX = Math.min(cx * 16, cx * 16 + 15);
int minY = Math.min(cy * 16, cy * 16 + 15);
int minZ = Math.min(cz * 16, cz * 16 + 15);
int maxX = Math.max(cx * 16, cx * 16 + 15);
int maxY = Math.max(cy * 16, cy * 16 + 15);
int maxZ = Math.max(cz * 16, cz * 16 + 15);
Vector3i lesserBoundaryCorner = new Vector3i(minX, minY, minZ);
Vector3i greaterBoundaryCorner = new Vector3i(maxX, maxY, maxZ);
List<Claim> claims = new ArrayList<>(GriefDefender.getCore().getAllClaims());
if (!GriefDefender.getCore().isEnabled(world.getUID())) {
return SectionPermissionChecker.ALL_ALLOWED;
}
claims.removeIf(claim -> !claim.getWorldUniqueId().equals(world.getUID()));
claims.removeIf(claim -> !claim.isUserTrusted(player.getUniqueId(), TrustTypes.BUILDER));
List<Claim> claimList = getClaimInArea(claims, lesserBoundaryCorner, greaterBoundaryCorner);
if (claimList.isEmpty()) {
return SectionPermissionChecker.NONE_ALLOWED;
}
return SectionPermissionChecker.ALL_ALLOWED;
}
private static @NotNull List<Claim> getClaimInArea(List<Claim> claims, Vector3i lesserBoundaryCorner, Vector3i greaterBoundaryCorner) {
List<Claim> claimList = new ArrayList<>();
for (Claim claim : claims) {
Vector3i lesser = claim.getLesserBoundaryCorner();
Vector3i greater = claim.getGreaterBoundaryCorner();
if (lesser.getX() <= lesserBoundaryCorner.getX() && lesser.getZ() <= lesserBoundaryCorner.getZ() && greater.getX() >= greaterBoundaryCorner.getX() && greater.getZ() >= greaterBoundaryCorner.getZ()) {
claimList.add(claim);
}
}
return claimList;
}
}