<commit_before>package tc.oc.pgm.tracker.trackers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import javax.inject.Inject;

import net.md_5.bungee.api.chat.TranslatableComponent;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.time.Duration;
import java.time.Instant;
import tc.oc.commons.bukkit.util.Materials;
import tc.oc.pgm.events.ListenerScope;
import tc.oc.pgm.events.PlayerParticipationStopEvent;
import tc.oc.pgm.match.Match;
import tc.oc.pgm.match.MatchPlayer;
import tc.oc.pgm.match.MatchScope;
import tc.oc.pgm.match.Matches;

/**
 * Predicts the death of players who disconnect while participating, and simulates the
 * damage and death events that would have been fired if they had stayed in the game.
 *
 * Also prevents team switching while in imminent danger..
 */
@ListenerScope(MatchScope.RUNNING)
public class CombatLogTracker implements Listener {
    // Logout within this time since last damage is considered combat log
    private static final Duration RECENT_DAMAGE_THRESHOLD = Duration.ofSeconds(3);

    // Maximum height player can fall without taking damage
    private static final double SAFE_FALL_DISTANCE = 2;

    // Minimum water required to stop the player's fall
    private static final int BREAK_FALL_WATER_DEPTH = 3;

    private final Match match;

    private static class Damage {
        public final Instant time;
        public final EntityDamageEvent event;

        private Damage(Instant time, EntityDamageEvent event) {
            this.time = time;
            this.event = event;
        }
    }

    private static class ImminentDeath {
        public final EntityDamageEvent.DamageCause cause; // what will cause the death
        public final Location deathLocation;
        public final Block blockDamager;
        public final boolean alreadyDamaged;              // if the player has already been damaged by this cause

        private ImminentDeath(EntityDamageEvent.DamageCause cause, Location deathLocation, @Nullable Block blockDamager, boolean damaged) {
            this.cause = cause;
            this.deathLocation = deathLocation;
            this.blockDamager = blockDamager;
            this.alreadyDamaged = damaged;
        }
    }

    private Map<Player, Damage> recentDamage = new HashMap<>();

    @Inject CombatLogTracker(Match match) {
        this.match = match;
    }

    private static boolean hasFireResistance(LivingEntity entity) {
        for(PotionEffect effect : entity.getActivePotionEffects()) {
            if(PotionEffectType.FIRE_RESISTANCE.equals(effect.getType())) return true;
        }
        return false;
    }

    private static double getResistanceFactor(LivingEntity entity) {
        int amplifier = 0;
        for(PotionEffect effect : entity.getActivePotionEffects()) {
            if(PotionEffectType.DAMAGE_RESISTANCE.equals(effect.getType()) && effect.getAmplifier() > amplifier) {
                amplifier = effect.getAmplifier();
            }
        }
        return 1d - (amplifier / 5d);
    }

    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void onPlayerDamage(EntityDamageEvent event) {
        if(event.getDamage() <= 0) return;
<commit_msg>Change combat log event priority<commit_after>package tc.oc.pgm.tracker.trackers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nullable;
import javax.inject.Inject;

import net.md_5.bungee.api.chat.TranslatableComponent;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByBlockEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.time.Duration;
import java.time.Instant;
import tc.oc.commons.bukkit.util.Materials;
import tc.oc.pgm.events.ListenerScope;
import tc.oc.pgm.events.PlayerParticipationStopEvent;
import tc.oc.pgm.match.Match;
import tc.oc.pgm.match.MatchPlayer;
import tc.oc.pgm.match.MatchScope;
import tc.oc.pgm.match.Matches;

/**
 * Predicts the death of players who disconnect while participating, and simulates the
 * damage and death events that would have been fired if they had stayed in the game.
 *
 * Also prevents team switching while in imminent danger..
 */
@ListenerScope(MatchScope.RUNNING)
public class CombatLogTracker implements Listener {
    // Logout within this time since last damage is considered combat log
    private static final Duration RECENT_DAMAGE_THRESHOLD = Duration.ofSeconds(3);

    // Maximum height player can fall without taking damage
    private static final double SAFE_FALL_DISTANCE = 2;

    // Minimum water required to stop the player's fall
    private static final int BREAK_FALL_WATER_DEPTH = 3;

    private final Match match;

    private static class Damage {
        public final Instant time;
        public final EntityDamageEvent event;

        private Damage(Instant time, EntityDamageEvent event) {
            this.time = time;
            this.event = event;
        }
    }

    private static class ImminentDeath {
        public final EntityDamageEvent.DamageCause cause; // what will cause the death
        public final Location deathLocation;
        public final Block blockDamager;
        public final boolean alreadyDamaged;              // if the player has already been damaged by this cause

        private ImminentDeath(EntityDamageEvent.DamageCause cause, Location deathLocation, @Nullable Block blockDamager, boolean damaged) {
            this.cause = cause;
            this.deathLocation = deathLocation;
            this.blockDamager = blockDamager;
            this.alreadyDamaged = damaged;
        }
    }

    private Map<Player, Damage> recentDamage = new HashMap<>();

    @Inject CombatLogTracker(Match match) {
        this.match = match;
    }

    private static boolean hasFireResistance(LivingEntity entity) {
        for(PotionEffect effect : entity.getActivePotionEffects()) {
            if(PotionEffectType.FIRE_RESISTANCE.equals(effect.getType())) return true;
        }
        return false;
    }

    private static double getResistanceFactor(LivingEntity entity) {
        int amplifier = 0;
        for(PotionEffect effect : entity.getActivePotionEffects()) {
            if(PotionEffectType.DAMAGE_RESISTANCE.equals(effect.getType()) && effect.getAmplifier() > amplifier) {
                amplifier = effect.getAmplifier();
            }
        }
        return 1d - (amplifier / 5d);
    }

    @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
    public void onPlayerDamage(EntityDamageEvent event) {
        if(event.getDamage() <= 0) return;

{'fraction_non_alphanumeric': 0.08208182288969446, 'fraction_numerical': 0.0020714655618850335, 'mean_word_length': 3.432013769363167, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6346044', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2167, 'n_words': 572}