Search in sources :

Example 1 with PlayerData

use of me.ryanhamshire.GriefPrevention.PlayerData in project MyPet by xXKeyleXx.

the class GriefPreventionHook method canHurt.

@Override
public boolean canHurt(Player attacker, Entity defender) {
    try {
        if (!griefPrevention.claimsEnabledForWorld(defender.getWorld())) {
            return true;
        }
        if (!(defender instanceof Monster) && griefPrevention.config_claims_protectCreatures) {
            if (defender instanceof Tameable) {
                final Tameable tameable = (Tameable) defender;
                if (tameable.isTamed() && tameable.getOwner() != null) {
                    UUID ownerID = tameable.getOwner().getUniqueId();
                    if (attacker.getUniqueId().equals(ownerID)) {
                        return false;
                    }
                    PlayerData attackerData = griefPrevention.dataStore.getPlayerData(attacker.getUniqueId());
                    if (attackerData.ignoreClaims) {
                        return true;
                    }
                    if (!GriefPrevention.instance.pvpRulesApply(defender.getLocation().getWorld()) || (GriefPrevention.instance.config_pvp_protectPets && defender.getType() != EntityType.WOLF)) {
                        return false;
                    } else if (attackerData.pvpImmune) {
                        return false;
                    }
                }
            }
            PlayerData playerData = griefPrevention.dataStore.getPlayerData(attacker.getUniqueId());
            Claim claim = griefPrevention.dataStore.getClaimAt(defender.getLocation(), false, playerData.lastClaim);
            if (claim != null) {
                if (!(defender.getWorld().getPVP() && defender.getType() == EntityType.WOLF)) {
                    if (claim.allowContainers(attacker) != null) {
                        return false;
                    }
                }
            }
        }
    } catch (Throwable ignored) {
    }
    return true;
}
Also used : UUID(java.util.UUID) PlayerData(me.ryanhamshire.GriefPrevention.PlayerData) Claim(me.ryanhamshire.GriefPrevention.Claim)

Example 2 with PlayerData

use of me.ryanhamshire.GriefPrevention.PlayerData in project MyPet by xXKeyleXx.

the class GriefPreventionHook method canHurt.

@Override
public boolean canHurt(Player attacker, Player defender) {
    try {
        if (griefPrevention.pvpRulesApply(attacker.getWorld())) {
            if (attacker != defender) {
                DataStore dataStore = griefPrevention.dataStore;
                PlayerData defenderData = dataStore.getPlayerData(defender.getUniqueId());
                PlayerData attackerData = dataStore.getPlayerData(attacker.getUniqueId());
                if (griefPrevention.config_pvp_protectFreshSpawns) {
                    if (defenderData.pvpImmune || attackerData.pvpImmune) {
                        return false;
                    }
                }
                if ((griefPrevention.config_pvp_noCombatInPlayerLandClaims) || (griefPrevention.config_pvp_noCombatInAdminLandClaims)) {
                    Claim attackerClaim = dataStore.getClaimAt(attacker.getLocation(), false, attackerData.lastClaim);
                    if (!attackerData.ignoreClaims) {
                        if ((attackerClaim != null) && (!attackerData.inPvpCombat())) {
                            if (attackerClaim.isAdminClaim() && attackerClaim.parent == null && griefPrevention.config_pvp_noCombatInAdminLandClaims) {
                                return false;
                            }
                            if (attackerClaim.isAdminClaim() && attackerClaim.parent != null && griefPrevention.config_pvp_noCombatInAdminSubdivisions) {
                                return false;
                            }
                            if (!attackerClaim.isAdminClaim() && griefPrevention.config_pvp_noCombatInPlayerLandClaims) {
                                return false;
                            }
                        }
                        Claim defenderClaim = dataStore.getClaimAt(defender.getLocation(), false, defenderData.lastClaim);
                        if (defenderClaim != null && !defenderData.inPvpCombat()) {
                            if (defenderClaim.isAdminClaim() && defenderClaim.parent == null && griefPrevention.config_pvp_noCombatInAdminLandClaims) {
                                return false;
                            }
                            if (defenderClaim.isAdminClaim() && defenderClaim.parent != null && griefPrevention.config_pvp_noCombatInAdminSubdivisions) {
                                return false;
                            }
                            if (!defenderClaim.isAdminClaim() && griefPrevention.config_pvp_noCombatInPlayerLandClaims) {
                                return false;
                            }
                        }
                    }
                }
            }
        }
    } catch (Throwable ignored) {
    }
    return true;
}
Also used : DataStore(me.ryanhamshire.GriefPrevention.DataStore) PlayerData(me.ryanhamshire.GriefPrevention.PlayerData) Claim(me.ryanhamshire.GriefPrevention.Claim)

Aggregations

Claim (me.ryanhamshire.GriefPrevention.Claim)2 PlayerData (me.ryanhamshire.GriefPrevention.PlayerData)2 UUID (java.util.UUID)1 DataStore (me.ryanhamshire.GriefPrevention.DataStore)1