mirror of
https://github.com/YouHaveTrouble/PreventStabby.git
synced 2026-05-12 13:26:56 +00:00
possibly fix false negative check when worldguard is involved
This commit is contained in:
@@ -176,7 +176,14 @@ public class PlayerManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (!attackerPlayerData.isPvpEnabled() || (PreventStabby.worldGuardHookEnabled() && !WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(attackerId)))) {
|
||||
Boolean attackerForcedPvpState = null;
|
||||
Boolean victimForcedPvpState = null;
|
||||
if (PreventStabby.worldGuardHookEnabled()) {
|
||||
attackerForcedPvpState = WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(attackerId));
|
||||
victimForcedPvpState = WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(victimId));
|
||||
}
|
||||
|
||||
if (!attackerPlayerData.isPvpEnabled() || Boolean.FALSE.equals(attackerForcedPvpState)) {
|
||||
String message = switch (victimClassifier) {
|
||||
case PLAYER -> plugin.getConfigCache().cannot_attack_attacker;
|
||||
case PET -> plugin.getConfigCache().cannot_attack_pets_victim;
|
||||
@@ -186,7 +193,7 @@ public class PlayerManager {
|
||||
return new DamageCheckResult(false, attackerId, victimId, message, victimClassifier.equals(Target.EntityClassifier.PLAYER));
|
||||
}
|
||||
|
||||
if (!victimPlayerData.isPvpEnabled() || (PreventStabby.worldGuardHookEnabled() && !WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(victimId)))) {
|
||||
if (!victimPlayerData.isPvpEnabled() || Boolean.FALSE.equals(victimForcedPvpState)) {
|
||||
String message = switch (victimClassifier) {
|
||||
case PLAYER -> plugin.getConfigCache().cannot_attack_victim;
|
||||
case PET -> plugin.getConfigCache().cannot_attack_pets_attacker;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class WorldGuardHook {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPlayerForcedToPvp(Player player) {
|
||||
public static Boolean isPlayerForcedToPvp(Player player) {
|
||||
if (player == null) return false;
|
||||
if (!PreventStabby.worldGuardHookEnabled()) return false;
|
||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||
@@ -60,7 +60,11 @@ public class WorldGuardHook {
|
||||
if (loc.getWorld() == null) return false;
|
||||
LocalPlayer localPlayer = WorldGuardPlugin.inst().wrapPlayer(player);
|
||||
ApplicableRegionSet set = query.getApplicableRegions(new Location(BukkitAdapter.adapt(loc.getWorld()), loc.getX(), loc.getY(), loc.getZ()));
|
||||
return set.testState(localPlayer, FORCE_PVP_FLAG);
|
||||
return switch (set.queryState(localPlayer, FORCE_PVP_FLAG)) {
|
||||
case ALLOW -> true;
|
||||
case DENY -> false;
|
||||
case null-> null;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user