Search in sources :

Example 1 with Configuration

use of com.iridium.iridiumskyblock.configs.Configuration in project IridiumSkyblock by Iridium-Development.

the class EntityDamageListener method handleDamageBetweenPlayers.

public void handleDamageBetweenPlayers(EntityDamageByEntityEvent event, Player attacker, Player victim, Island island) {
    Configuration configuration = IridiumSkyblock.getInstance().getConfiguration();
    if (!configuration.pvpSettings.pvpOnIslands) {
        if (!messageIsOnCooldown(attacker)) {
            attacker.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotHurtPlayer.replace("%prefix%", configuration.prefix)));
        }
        if (event.getCause().equals(EntityDamageEvent.DamageCause.PROJECTILE)) {
            event.getDamager().remove();
        }
        event.setCancelled(true);
        return;
    }
    User attackerUser = IridiumSkyblock.getInstance().getUserManager().getUser(attacker);
    User victimUser = IridiumSkyblock.getInstance().getUserManager().getUser(victim);
    Optional<IslandTrusted> attackerTrusted = IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island, attackerUser);
    Optional<IslandTrusted> victimTrusted = IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island, victimUser);
    boolean attackerIsMember = island.equals(attackerUser.getIsland().orElse(null)) || attackerTrusted.isPresent();
    boolean victimIsMember = island.equals(victimUser.getIsland().orElse(null)) || victimTrusted.isPresent();
    // If pvp between members is allowed or neither attacker or victim is a member, return
    if (configuration.pvpSettings.pvpBetweenMembers || !(attackerIsMember || victimIsMember))
        return;
    if (!messageIsOnCooldown(attacker)) {
        attacker.sendMessage(StringUtils.color(IridiumSkyblock.getInstance().getMessages().cannotHurtMember.replace("%prefix%", configuration.prefix)));
    }
    if (event.getCause().equals(EntityDamageEvent.DamageCause.PROJECTILE))
        event.getDamager().remove();
    event.setCancelled(true);
}
Also used : User(com.iridium.iridiumskyblock.database.User) IslandTrusted(com.iridium.iridiumskyblock.database.IslandTrusted) Configuration(com.iridium.iridiumskyblock.configs.Configuration)

Aggregations

Configuration (com.iridium.iridiumskyblock.configs.Configuration)1 IslandTrusted (com.iridium.iridiumskyblock.database.IslandTrusted)1 User (com.iridium.iridiumskyblock.database.User)1