Search in sources :

Example 1 with PlayerData

use of net.kaikk.mc.gpp.PlayerData in project MyPet by xXKeyleXx.

the class GriefPreventionPlusHook method canHurt.

@Override
public boolean canHurt(Player attacker, Player defender) {
    try {
        if (attacker.hasPermission("griefprevention.nopvpimmunity")) {
            return true;
        }
        if (attacker != defender) {
            DataStore dataStore = griefPrevention.getDataStore();
            final PlayerData defenderData = dataStore.getPlayerData(defender.getUniqueId());
            final 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) {
                final Claim attackerClaim = dataStore.getClaimAt(attacker.getLocation(), false, attackerData.lastClaim);
                if (attackerClaim != null) {
                    if (attackerClaim.isAdminClaim() && (attackerClaim.getParent() == null) && griefPrevention.config.pvp_noCombatInAdminLandClaims) {
                        return false;
                    }
                    if (attackerClaim.isAdminClaim() && (attackerClaim.getParent() != null) && griefPrevention.config.pvp_noCombatInAdminSubdivisions) {
                        return false;
                    }
                    if (!attackerClaim.isAdminClaim() && griefPrevention.config.pvp_noCombatInPlayerLandClaims) {
                        return false;
                    }
                }
                final Claim defenderClaim = dataStore.getClaimAt(defender.getLocation(), false, defenderData.lastClaim);
                if (defenderClaim != null) {
                    if (defenderClaim.isAdminClaim() && (defenderClaim.getParent() == null) && griefPrevention.config.pvp_noCombatInAdminLandClaims) {
                        return false;
                    }
                    if (defenderClaim.isAdminClaim() && (defenderClaim.getParent() != null) && griefPrevention.config.pvp_noCombatInAdminSubdivisions) {
                        return false;
                    }
                    if (!defenderClaim.isAdminClaim() && griefPrevention.config.pvp_noCombatInPlayerLandClaims) {
                        return false;
                    }
                }
            }
        }
    } catch (Throwable ignored) {
    }
    return true;
}
Also used : DataStore(net.kaikk.mc.gpp.DataStore) PlayerData(net.kaikk.mc.gpp.PlayerData) Claim(net.kaikk.mc.gpp.Claim)

Example 2 with PlayerData

use of net.kaikk.mc.gpp.PlayerData in project MyPet by xXKeyleXx.

the class GriefPreventionPlusHook method canHurt.

@Override
public boolean canHurt(Player attacker, Entity defender) {
    try {
        if (!griefPrevention.claimsEnabledForWorld(defender.getWorld())) {
            return true;
        }
        DataStore dataStore = griefPrevention.getDataStore();
        if (!(defender instanceof Monster) && griefPrevention.config.claims_protectCreatures) {
            if (defender instanceof Tameable && !griefPrevention.config.pvp_enabledWorlds.contains(defender.getWorld().getUID())) {
                final Tameable tameable = (Tameable) defender;
                if (tameable.isTamed() && (tameable.getOwner() != null)) {
                    final UUID ownerID = tameable.getOwner().getUniqueId();
                    if (attacker.getUniqueId().equals(ownerID)) {
                        return false;
                    }
                    final PlayerData attackerData = dataStore.getPlayerData(attacker.getUniqueId());
                    if (attackerData.ignoreClaims) {
                        return true;
                    }
                }
            }
            PlayerData playerData = dataStore.getPlayerData(attacker.getUniqueId());
            Claim claim = dataStore.getClaimAt(defender.getLocation(), false, playerData.lastClaim);
            if (claim != null) {
                if (claim.canOpenContainers(attacker) != null) {
                    return false;
                }
            }
        }
    } catch (Throwable ignored) {
    }
    return true;
}
Also used : Tameable(org.bukkit.entity.Tameable) DataStore(net.kaikk.mc.gpp.DataStore) Monster(org.bukkit.entity.Monster) UUID(java.util.UUID) PlayerData(net.kaikk.mc.gpp.PlayerData) Claim(net.kaikk.mc.gpp.Claim)

Aggregations

Claim (net.kaikk.mc.gpp.Claim)2 DataStore (net.kaikk.mc.gpp.DataStore)2 PlayerData (net.kaikk.mc.gpp.PlayerData)2 UUID (java.util.UUID)1 Monster (org.bukkit.entity.Monster)1 Tameable (org.bukkit.entity.Tameable)1