Search in sources :

Example 1 with DataStore

use of me.ryanhamshire.GriefPrevention.DataStore 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)1 DataStore (me.ryanhamshire.GriefPrevention.DataStore)1 PlayerData (me.ryanhamshire.GriefPrevention.PlayerData)1