Search in sources :

Example 6 with IslandTrusted

use of com.iridium.iridiumskyblock.database.IslandTrusted in project IridiumSkyblock by Iridium-Development.

the class EntityDamageListener method handlePlayerDamage.

private void handlePlayerDamage(EntityDamageEvent event, Island island) {
    Configuration.IslandDamageSettings pvpSettings = IridiumSkyblock.getInstance().getConfiguration().pvpSettings;
    Player player = (Player) event.getEntity();
    User user = IridiumSkyblock.getInstance().getUserManager().getUser(player);
    Optional<IslandTrusted> trusted = IridiumSkyblock.getInstance().getIslandManager().getIslandTrusted(island, user);
    boolean isMember = island.equals(user.getIsland().orElse(null)) || trusted.isPresent();
    List<EntityDamageEvent.DamageCause> preventCauses = isMember ? pvpSettings.membersPreventedDamages : pvpSettings.visitorsPreventedDamages;
    if (preventCauses.contains(event.getCause())) {
        event.setCancelled(true);
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.iridium.iridiumskyblock.database.User) IslandTrusted(com.iridium.iridiumskyblock.database.IslandTrusted) Configuration(com.iridium.iridiumskyblock.configs.Configuration)

Aggregations

IslandTrusted (com.iridium.iridiumskyblock.database.IslandTrusted)6 User (com.iridium.iridiumskyblock.database.User)5 Player (org.bukkit.entity.Player)4 Island (com.iridium.iridiumskyblock.database.Island)3 Configuration (com.iridium.iridiumskyblock.configs.Configuration)2 IslandLog (com.iridium.iridiumskyblock.database.IslandLog)2 Placeholder (com.iridium.iridiumcore.utils.Placeholder)1 IridiumSkyblock (com.iridium.iridiumskyblock.IridiumSkyblock)1 PlaceholderBuilder (com.iridium.iridiumskyblock.PlaceholderBuilder)1 IslandTrustedGUI (com.iridium.iridiumskyblock.gui.IslandTrustedGUI)1 CooldownProvider (com.iridium.iridiumskyblock.managers.CooldownProvider)1 Duration (java.time.Duration)1 List (java.util.List)1 Optional (java.util.Optional)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Collectors (java.util.stream.Collectors)1 Entity (org.bukkit.entity.Entity)1 EventHandler (org.bukkit.event.EventHandler)1 Listener (org.bukkit.event.Listener)1