check for worldguard force pvp region within pvp check

This commit is contained in:
2025-02-28 12:08:06 +01:00
parent df20c95e38
commit d013eabd02
3 changed files with 6 additions and 3 deletions
@@ -3,6 +3,7 @@ package me.youhavetrouble.preventstabby.data;
import me.youhavetrouble.preventstabby.PreventStabby;
import me.youhavetrouble.preventstabby.api.event.PlayerEnterCombatEvent;
import me.youhavetrouble.preventstabby.api.event.PlayerLeaveCombatEvent;
import me.youhavetrouble.preventstabby.hooks.WorldGuardHook;
import me.youhavetrouble.preventstabby.util.PluginMessages;
import me.youhavetrouble.preventstabby.util.PvpState;
import org.bukkit.Bukkit;
@@ -174,7 +175,7 @@ public class PlayerManager {
}
}
if (!attackerPlayerData.isPvpEnabled()) {
if (!attackerPlayerData.isPvpEnabled() && !WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(attackerId))) {
String message = switch (victimClassifier) {
case PLAYER -> plugin.getConfigCache().cannot_attack_attacker;
case PET -> plugin.getConfigCache().cannot_attack_pets_victim;
@@ -184,7 +185,7 @@ public class PlayerManager {
return new DamageCheckResult(false, attackerId, victimId, message, victimClassifier.equals(Target.EntityClassifier.PLAYER));
}
if (!victimPlayerData.isPvpEnabled()) {
if (!victimPlayerData.isPvpEnabled() && !WorldGuardHook.isPlayerForcedToPvp(Bukkit.getPlayer(victimId))) {
String message = switch (victimClassifier) {
case PLAYER -> plugin.getConfigCache().cannot_attack_victim;
case PET -> plugin.getConfigCache().cannot_attack_pets_attacker;
@@ -52,6 +52,8 @@ public class WorldGuardHook {
}
public static boolean isPlayerForcedToPvp(Player player) {
if (player == null) return false;
if (!PreventStabby.worldGuardHookEnabled()) return false;
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
RegionQuery query = container.createQuery();
org.bukkit.Location loc = player.getLocation();