<commit_before>package com.skelril.aurora.city.engine;

import com.sk89q.commandbook.CommandBook;
import com.sk89q.worldedit.blocks.ItemID;
import com.skelril.aurora.admin.AdminComponent;
import com.skelril.aurora.admin.AdminState;
import com.skelril.aurora.events.ApocalypseBedSpawnEvent;
import com.skelril.aurora.events.ApocalypseLocalSpawnEvent;
import com.skelril.aurora.events.PlayerAdminModeChangeEvent;
import com.skelril.aurora.homes.EnderPearlHomesComponent;
import com.skelril.aurora.jail.JailComponent;
import com.skelril.aurora.util.*;
import com.zachsthings.libcomponents.ComponentInformation;
import com.zachsthings.libcomponents.Depend;
import com.zachsthings.libcomponents.InjectComponent;
import com.zachsthings.libcomponents.bukkit.BukkitComponent;
import com.zachsthings.libcomponents.config.ConfigurationBase;
import com.zachsthings.libcomponents.config.Setting;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
 * @author Turtle9598
 */
@ComponentInformation(friendlyName = "Apocalypse", desc = "Sends an invasion force after the residents of the server.")
@Depend(components = {JailComponent.class, AdminComponent.class, EnderPearlHomesComponent.class})
public class ApocalypseComponent extends BukkitComponent implements Listener {

    private final CommandBook inst = CommandBook.inst();
    private final Logger log = inst.getLogger();
    private final Server server = CommandBook.server();

    @InjectComponent
    private JailComponent jailComponent;
    @InjectComponent
    private AdminComponent adminComponent;
    @InjectComponent
    private EnderPearlHomesComponent homesComponent;

    private LocalConfiguration config;

    @Override
    public void enable() {

        config = configure(new LocalConfiguration());
        //noinspection AccessStaticViaInstance
        inst.registerEvents(this);
    }

    @Override
    public void reload() {

        super.reload();
        configure(config);
    }

    private static class LocalConfiguration extends ConfigurationBase {

        @Setting("multiplier")
        public int multiplier = 6;
        @Setting("local-de-multiplier")
        public int deMultiplier = 4;
        @Setting("max-mobs")
        public int maxMobs = 1000;
        @Setting("armour-chance")
        public int armourChance = 100;
        @Setting("weapon-chance")
        public int weaponChance = 100;
        @Setting("mob")
        public String cityAttackMobString = "zombie";
        @Setting("enable-safe-respawn-location")
        public boolean enableSafeRespawn = true;
        @Setting("safe-respawn-radius")
        public int safeRespawnRadius = 10;
        @Setting("enable-ultimate-chaos")
        public boolean enableUltimateChaos = true;

        public EntityType attackMob = getAttackMob();

        private EntityType getAttackMob() {

            try {
                return EntityType.fromName(cityAttackMobString.toUpperCase());
            } catch (Exception e) {
                return null;
            }
        }
    }

    /*
    @EventHandler(priority = EventPriority.MONITOR)
    public void onEntitySpawn(CreatureSpawnEvent event) {

        if (config.enableUltimateChaos
                && event.getLocation().getWorld().isThundering()
                && event.getEntity().getType().equals(config.attackMob)
                && !event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL)
                && event.isCancelled())
            event.setCancelled(false);
    }
    */

    @EventHandler(ignoreCancelled = true)
    public void onEntityTarget(EntityTargetLivingEntityEvent event) {

        Entity target = event.getTarget();
        Entity targeter = event.getEntity();

        if (!(target instanceof Player) || !targeter.isValid() || !targeter.getType().equals(config.attackMob)) return;

        Player player = (Player) target;
        if (checkEntity((LivingEntity) targeter) && ItemUtil.hasAncientArmour(player) && ChanceUtil.getChance(8)) {

            targeter.setFireTicks(ChanceUtil.getRandom(20 * 60));
        }
    }

    @EventHandler(ignoreCancelled = true)
    public void onEntityDamageEntity(EntityDamageByEntityEvent event) {

        Entity target = event.getEntity();
        Entity attacker = event.getDamager();

        if (target == null || !(target instanceof LivingEntity) || !target.isValid()) return;
        if (attacker == null || !(attacker instanceof LivingEntity) || !attacker.isValid()) return;
        if (target.getType() == null || attacker.getType() == null || !checkEntity((LivingEntity) attacker)) return;

        Player player;
        switch (target.getType()) {
            case PLAYER:
                player = (Player) target;
                if (ItemUtil.hasAncientArmour(player)) {<commit_msg>Fixed a potential problem with the Master Sword during a thunderstorm<commit_after>package com.skelril.aurora.city.engine;

import com.sk89q.commandbook.CommandBook;
import com.sk89q.worldedit.blocks.ItemID;
import com.skelril.aurora.admin.AdminComponent;
import com.skelril.aurora.admin.AdminState;
import com.skelril.aurora.events.ApocalypseBedSpawnEvent;
import com.skelril.aurora.events.ApocalypseLocalSpawnEvent;
import com.skelril.aurora.events.PlayerAdminModeChangeEvent;
import com.skelril.aurora.homes.EnderPearlHomesComponent;
import com.skelril.aurora.jail.JailComponent;
import com.skelril.aurora.util.*;
import com.zachsthings.libcomponents.ComponentInformation;
import com.zachsthings.libcomponents.Depend;
import com.zachsthings.libcomponents.InjectComponent;
import com.zachsthings.libcomponents.bukkit.BukkitComponent;
import com.zachsthings.libcomponents.config.ConfigurationBase;
import com.zachsthings.libcomponents.config.Setting;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.*;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.inventory.EntityEquipment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

/**
 * @author Turtle9598
 */
@ComponentInformation(friendlyName = "Apocalypse", desc = "Sends an invasion force after the residents of the server.")
@Depend(components = {JailComponent.class, AdminComponent.class, EnderPearlHomesComponent.class})
public class ApocalypseComponent extends BukkitComponent implements Listener {

    private final CommandBook inst = CommandBook.inst();
    private final Logger log = inst.getLogger();
    private final Server server = CommandBook.server();

    @InjectComponent
    private JailComponent jailComponent;
    @InjectComponent
    private AdminComponent adminComponent;
    @InjectComponent
    private EnderPearlHomesComponent homesComponent;

    private LocalConfiguration config;

    @Override
    public void enable() {

        config = configure(new LocalConfiguration());
        //noinspection AccessStaticViaInstance
        inst.registerEvents(this);
    }

    @Override
    public void reload() {

        super.reload();
        configure(config);
    }

    private static class LocalConfiguration extends ConfigurationBase {

        @Setting("multiplier")
        public int multiplier = 6;
        @Setting("local-de-multiplier")
        public int deMultiplier = 4;
        @Setting("max-mobs")
        public int maxMobs = 1000;
        @Setting("armour-chance")
        public int armourChance = 100;
        @Setting("weapon-chance")
        public int weaponChance = 100;
        @Setting("mob")
        public String cityAttackMobString = "zombie";
        @Setting("enable-safe-respawn-location")
        public boolean enableSafeRespawn = true;
        @Setting("safe-respawn-radius")
        public int safeRespawnRadius = 10;
        @Setting("enable-ultimate-chaos")
        public boolean enableUltimateChaos = true;

        public EntityType attackMob = getAttackMob();

        private EntityType getAttackMob() {

            try {
                return EntityType.fromName(cityAttackMobString.toUpperCase());
            } catch (Exception e) {
                return null;
            }
        }
    }

    /*
    @EventHandler(priority = EventPriority.MONITOR)
    public void onEntitySpawn(CreatureSpawnEvent event) {

        if (config.enableUltimateChaos
                && event.getLocation().getWorld().isThundering()
                && event.getEntity().getType().equals(config.attackMob)
                && !event.getSpawnReason().equals(CreatureSpawnEvent.SpawnReason.NATURAL)
                && event.isCancelled())
            event.setCancelled(false);
    }
    */

    @EventHandler(ignoreCancelled = true)
    public void onEntityTarget(EntityTargetLivingEntityEvent event) {

        Entity target = event.getTarget();
        Entity targeter = event.getEntity();

        if (!(target instanceof Player) || !targeter.isValid() || !targeter.getType().equals(config.attackMob)) return;

        Player player = (Player) target;
        if (checkEntity((LivingEntity) targeter) && ItemUtil.hasAncientArmour(player) && ChanceUtil.getChance(8)) {

            targeter.setFireTicks(ChanceUtil.getRandom(20 * 60));
        }
    }

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onEntityDamageEntity(EntityDamageByEntityEvent event) {

        Entity target = event.getEntity();
        Entity attacker = event.getDamager();

        if (target == null || !(target instanceof LivingEntity) || !target.isValid()) return;
        if (attacker == null || !(attacker instanceof LivingEntity) || !attacker.isValid()) return;
        if (target.getType() == null || attacker.getType() == null || !checkEntity((LivingEntity) attacker)) return;

        Player player;
        switch (target.getType()) {
            case PLAYER:
                player = (Player) target;
                if (ItemUtil.hasAncientArmour(player)) {
{'fraction_non_alphanumeric': 0.10243243243243243, 'fraction_numerical': 0.004864864864864865, 'mean_word_length': 3.5217922606924645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2144469', 'n_tokens_mistral': 3299, 'n_tokens_neox': 3139, 'n_words': 616}