package de.hessj.dailyquests;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.AbstractMap.SimpleEntry;
import java.util.Map.Entry;
import org.bukkit.Material;
import org.bukkit.block.data.type.Beehive;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.entity.EntityBreedEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTameEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.FurnaceBurnEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerEditBookEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.scoreboard.Scoreboard;

import de.hessj.helper.Helper.Type;
import net.kyori.adventure.text.Component;
import net.md_5.bungee.api.ChatColor;

public class DailyQuestsListeners implements Listener {
        public static ArrayList<String> todaysQuest = new ArrayList<String>();
        public static String questDesc;
        public static String questAction;
        public static String questTarget;
        public static String questTool;
        public static String questCount;
        public static Integer questId;
        public Boolean given = false;
        public Boolean freeSpace = false;
        public de.hessj.helper.Helper helper = new de.hessj.helper.Helper();

        @EventHandler
        public void craftBlocker(PrepareItemCraftEvent e) {
                if (e.getInventory().containsAtLeast(App.main.diamondDust, 1) && e.getInventory().getResult() != null
                                && !e.getInventory().getResult().getType().equals(Material.DIAMOND)) {
                        e.getInventory().setResult(null);
                }
        }

        @EventHandler
        public void ovenBlocker(FurnaceBurnEvent e) {

                if (e.getFuel() != null && e.getFuel().equals(App.main.diamondDust)) {
                        e.setCancelled(true);
                }
        }

        public void giveSmallReward(Object obj, Player p) {
                List<ItemStack> giveList = Arrays.asList(new ItemStack(Material.EMERALD), App.main.diamondDust);
                Random rand = new Random();
                ItemStack randomElement = giveList.get(rand.nextInt(giveList.size()));
                String itemName = "";
                if (randomElement.equals(new ItemStack(Material.EMERALD))) {
                        itemName = "Smaragd";
                } else if (randomElement.equals(App.main.diamondDust)) {
                        itemName = "Diamant-Staub";
                }

                for (ItemStack i : p.getInventory().getStorageContents()) {
                        if (randomElement.equals(App.main.diamondDust)) {
                                if (i != null && i.getType() == randomElement.getType() && i.hasItemMeta()
                                                && i.getItemMeta() != null
                                                && i.getItemMeta().getPersistentDataContainer() != null
                                                && i.getItemMeta().getPersistentDataContainer().has(
                                                                App.main.nskdiamondDust, PersistentDataType.STRING)) {
                                        if (i.getAmount() < 64) {
                                                i.setAmount(i.getAmount() + 1);
                                                given = true;
                                                break;
                                        }
                                } else {
                                        if (i == null) {
                                                freeSpace = true;
                                        }
                                }
                        } else {
                                if (i != null && i.getType() == randomElement.getType()) {
                                        if (i.getAmount() < 64) {
                                                i.setAmount(i.getAmount() + 1);
                                                given = true;
                                                break;
                                        }
                                } else {
                                        if (i == null) {
                                                freeSpace = true;
                                        }
                                }
                        }
                }
                if (!freeSpace && !given) {// ansonsten checken für free space
                       
                        p.sendMessage(helper.R3SMessage(Type.ERROR, "[DailyQuests] Dein Inventar ist voll, deine Questbelohnung wurde gedropped!"));
                        p.getWorld().dropItem(
                                        p.getLocation(), randomElement);
                                        App.main.getConfig()
                                        .set("players."
                                                        + p.getUniqueId()
                                                        + ".currentQuests." + obj.toString() + ".state", "finished");
                        App.main.saveConfig();
                } else {
                        if (!given && freeSpace) {
                                p.getInventory()
                                                .addItem(randomElement);
                        }
                        p.sendMessage(helper.R3SMessage(Type.SUCCESS, "[DailyQuests] Du hast 1x " + itemName + " als Questbelohnung erhalten!"));
                        App.main.getConfig()
                                        .set("players."
                                                        + p.getUniqueId()
                                                        + ".currentQuests." + obj.toString() + ".state", "finished");
                        App.main.saveConfig();
                }

        }

        public static void getTodaysQuest() {
                App.main.getConfig().addDefault("quests.19.description", "Sammle [x]x Honig");
                App.main.getConfig().addDefault("quests.19.action", "honey");
                App.main.getConfig().addDefault("quests.19.target", "none");
                App.main.getConfig().addDefault("quests.19.tool", "Material.GLASS_BOTTLE");
                App.main.getConfig().addDefault("quests.19.count", "[mid]");
                App.main.getConfig().addDefault("quests.18.description", "Gehe eine Runde angeln");
                App.main.getConfig().addDefault("quests.18.action", "fish");
                App.main.getConfig().addDefault("quests.18.target", "none");
                App.main.getConfig().addDefault("quests.18.tool", "Material.FISHING_ROD");
                App.main.getConfig().addDefault("quests.18.count", "[once]");
                App.main.getConfig().addDefault("quests.17.description", "Melke eine Kuh");
                App.main.getConfig().addDefault("quests.17.action", "milk");
                App.main.getConfig().addDefault("quests.17.target", "EntityType.COW");
                App.main.getConfig().addDefault("quests.17.tool", "Material.BUCKET");
                App.main.getConfig().addDefault("quests.17.count", "[once]");
                App.main.getConfig().addDefault("quests.16.description", "Heile einen Eisengolem");
                App.main.getConfig().addDefault("quests.16.action", "heal");
                App.main.getConfig().addDefault("quests.16.target", "EntityType.IRON_GOLEM");
                App.main.getConfig().addDefault("quests.16.tool", "Material.IRON_INGOT");
                App.main.getConfig().addDefault("quests.16.count", "[once]");
                App.main.getConfig().addDefault("quests.15.description", "Backe einen Kuchen");
                App.main.getConfig().addDefault("quests.15.action", "bake");
                App.main.getConfig().addDefault("quests.15.target", "Material.CAKE");
                App.main.getConfig().addDefault("quests.15.tool", "none");
                App.main.getConfig().addDefault("quests.15.count", "[once]");
                App.main.getConfig().addDefault("quests.14.description", "Schreibe ein Buch");
                App.main.getConfig().addDefault("quests.14.action", "write");
                App.main.getConfig().addDefault("quests.14.target", "Material.WRITABLE_BOOK");
                App.main.getConfig().addDefault("quests.14.tool", "none");
                App.main.getConfig().addDefault("quests.14.count", "[once]");
                App.main.getConfig().addDefault("quests.13.description", "Schere ein Schaf");
                App.main.getConfig().addDefault("quests.13.action", "shear");
                App.main.getConfig().addDefault("quests.13.target", "EntityType.SHEEP");
                App.main.getConfig().addDefault("quests.13.tool", "none");
                App.main.getConfig().addDefault("quests.13.count", "[once]");
                App.main.getConfig().addDefault("quests.12.description", "Begehe Bedrock mit Lederstiefel");
                App.main.getConfig().addDefault("quests.12.action", "touch");
                App.main.getConfig().addDefault("quests.12.target", "Material.BEDROCK");
                App.main.getConfig().addDefault("quests.12.tool", "Material.LEATHER_BOOTS");
                App.main.getConfig().addDefault("quests.12.count", "[once]");
                App.main.getConfig().addDefault("quests.11.description", "Züchte [x]x Kuh");
                App.main.getConfig().addDefault("quests.11.action", "breed");
                App.main.getConfig().addDefault("quests.11.target", "CraftCow");
                App.main.getConfig().addDefault("quests.11.tool", "none");
                App.main.getConfig().addDefault("quests.11.count", "[low]");
                App.main.getConfig().addDefault("quests.10.description", "Schneeballschlacht mit Schneemann");
                App.main.getConfig().addDefault("quests.10.action", "snowfight");
                App.main.getConfig().addDefault("quests.10.target", "EntityType.SNOWMAN");
                App.main.getConfig().addDefault("quests.10.tool", "Material.SNOWBALL");
                App.main.getConfig().addDefault("quests.10.count", "[once]");
                App.main.getConfig().addDefault("quests.9.description", "Reise zum End");
                App.main.getConfig().addDefault("quests.9.action", "travel");
                App.main.getConfig().addDefault("quests.9.target",
                                App.main.getServer().getWorlds().get(0).getName() + "_end");
                App.main.getConfig().addDefault("quests.9.tool", "none");
                App.main.getConfig().addDefault("quests.9.count", "[once]");
                App.main.getConfig().addDefault("quests.8.description", "Reise zum Nether");
                App.main.getConfig().addDefault("quests.8.action", "travel");
                App.main.getConfig().addDefault("quests.8.target",
                                App.main.getServer().getWorlds().get(0).getName() + "_nether");
                App.main.getConfig().addDefault("quests.8.tool", "none");
                App.main.getConfig().addDefault("quests.8.count", "[once]");
                App.main.getConfig().addDefault("quests.7.description", "Töte [x]x Skelett mit Bogen");
                App.main.getConfig().addDefault("quests.7.action", "kill");
                App.main.getConfig().addDefault("quests.7.target", "EntityType.SKELETON");
                App.main.getConfig().addDefault("quests.7.tool", "Material.BOW");
                App.main.getConfig().addDefault("quests.7.count", "[high]");
                App.main.getConfig().addDefault("quests.6.description", "Zähme einen Ozelot");
                App.main.getConfig().addDefault("quests.6.action", "tame");
                App.main.getConfig().addDefault("quests.6.target", "EntityType.OCELOT");
                App.main.getConfig().addDefault("quests.6.tool", "none");
                App.main.getConfig().addDefault("quests.6.count", "[once]");
                App.main.getConfig().addDefault("quests.5.description", "Zähme einen Wolf");
                App.main.getConfig().addDefault("quests.5.action", "tame");
                App.main.getConfig().addDefault("quests.5.target", "EntityType.WOLF");
                App.main.getConfig().addDefault("quests.5.tool", "none");
                App.main.getConfig().addDefault("quests.5.count", "[once]");
                App.main.getConfig().addDefault("quests.4.description", "Töte [x]x Spinne");
                App.main.getConfig().addDefault("quests.4.action", "kill");
                App.main.getConfig().addDefault("quests.4.target", "EntityType.SPIDER");
                App.main.getConfig().addDefault("quests.4.tool", "none");
                App.main.getConfig().addDefault("quests.4.count", "[mid]");
                App.main.getConfig().addDefault("quests.3.description", "Baue [x]x Kohle mit Holzaxt ab");
                App.main.getConfig().addDefault("quests.3.action", "break");
                App.main.getConfig().addDefault("quests.3.target", "Material.COAL_ORE");
                App.main.getConfig().addDefault("quests.3.tool", "Material.WOODEN_AXE");
                App.main.getConfig().addDefault("quests.3.count", "[high]");
                App.main.getConfig().addDefault("quests.2.description", "Baue [x]x Kohle ab");
                App.main.getConfig().addDefault("quests.2.action", "break");
                App.main.getConfig().addDefault("quests.2.target", "Material.COAL_ORE");
                App.main.getConfig().addDefault("quests.2.tool", "none");
                App.main.getConfig().addDefault("quests.2.count", "[high]");
                App.main.getConfig().addDefault("quests.1.description", "Töte [x]x Zombie mit Holzschwert");
                App.main.getConfig().addDefault("quests.1.action", "kill");
                App.main.getConfig().addDefault("quests.1.target", "EntityType.ZOMBIE");
                App.main.getConfig().addDefault("quests.1.tool", "Material.WOODEN_SWORD");
                App.main.getConfig().addDefault("quests.1.count", "[high]");
                App.main.getConfig().options().copyDefaults(true);
                App.main.saveConfig();

        }

        public static ArrayList<String> questList = new ArrayList<String>();

        public static void getDailyQuests(Player p) {
                if (!App.main.getConfig().contains(("players." + p.getUniqueId()).toString())) {
                        int questsAvailable = 0;
                        for (Object obj : App.main.getConfig().getConfigurationSection("quests").getKeys(false)
                                        .toArray()) {
                                questsAvailable++;
                                obj.toString();// damit Warning weg ist
                        }
                        int randoQuestOne = 9999;
                        int randoQuestTwo = 9999;
                        int randoQuestThree = 9999;
                        for (int i = 1; i <= 3; i++) {
                                int randomQuestID = new Random().nextInt(questsAvailable) + 1;
                                while (randomQuestID == randoQuestOne || randomQuestID == randoQuestTwo
                                                || randomQuestID == randoQuestThree) {
                                        randomQuestID = new Random().nextInt(questsAvailable) + 1;
                                }
                                questDesc = App.main.getConfig().getString("quests." + randomQuestID + ".description");
                                questAction = App.main.getConfig().getString("quests." + randomQuestID + ".action");
                                questTarget = App.main.getConfig().getString("quests." + randomQuestID + ".target");
                                questTool = App.main.getConfig().getString("quests." + randomQuestID + ".tool");
                                questCount = App.main.getConfig().getString("quests." + randomQuestID + ".count");
                                questId = randomQuestID;
                                if (i == 1) {
                                        randoQuestOne = randomQuestID;
                                } else if (i == 2) {
                                        randoQuestTwo = randomQuestID;
                                } else if (i == 3) {
                                        randoQuestThree = randomQuestID;
                                }
                                App.main.getConfig().set(
                                                "players." + p.getUniqueId() + ".currentQuests." + questId + ".state",
                                                "ongoing");
                                App.main.getConfig()
                                                .set("players." + p.getUniqueId() + ".currentQuests." + questId
                                                                + ".currentcount",
                                                                0);
                                int qCount = 9999;
                                if (questCount.equals("[once]")) {
                                        qCount = 1;
                                } else if (questCount.equals("[low]")) {
                                        qCount = random_int(1, 3);

                                } else if (questCount.equals("[mid]")) {
                                        qCount = random_int(2, 4);
                                } else if (questCount.equals("[high]")) {
                                        qCount = random_int(3, 5);
                                }
                                App.main.getConfig().set("players." + p.getUniqueId() + ".currentQuests." + questId
                                                + ".countneeded", qCount);
                                App.main.getConfig().set("players." + p.getUniqueId() + ".rewards", "pending");
                        }
                        App.main.saveConfig();
                }
        }

        public static int random_int(int Min, int Max) {
                return (int) (Math.random() * (Max - Min)) + Min;
        }

        @EventHandler
        public void onLogoff(PlayerQuitEvent e) {
                Entry<Scoreboard, Boolean> actionMapEntry = DailyQuestsCommands.boards.get(e.getPlayer().getName());
                if (actionMapEntry != null) {
                        Scoreboard board = actionMapEntry.getKey();
                        DailyQuestsCommands.boards.put(e.getPlayer().getName(),
                                        new SimpleEntry<Scoreboard, Boolean>(board, false));
                }
        }

        @EventHandler
        public void onLogin(PlayerJoinEvent e) {
              
              
              
                e.getPlayer().discoverRecipe(App.main.nskDD);









                e.getPlayer().sendMessage(helper.R3SMessage(Type.INFO, "[DailyQuests] Hallo, " + e.getPlayer().getName()
                                + ". Du kannst die Questanzeige mit \"/quest\" ein- oder ausblenden."));
                getDailyQuests(e.getPlayer());
        }

        @EventHandler
        public void onItemUse(PlayerInteractEvent e) {
                if ((e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK)
                                && e.getPlayer().getInventory().getItemInMainHand().getType() == Material.PLAYER_HEAD
                                && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().displayName() != null && e.getPlayer().getInventory().getItemInMainHand().getItemMeta().displayName()
                                                .equals(Component.translatable(ChatColor.WHITE + "Überraschungsbox"))) {
                        e.setCancelled(true);
                        freeSpace = false;
                        ItemStack randoItem = App.main.rewardList
                                        .get(((new Random())).nextInt(App.main.rewardList.size()));
                        for (ItemStack i : e.getPlayer().getInventory().getStorageContents()) {
                                if (i == null || i == randoItem) {
                                        freeSpace = true;
                                }
                        }
                        if (freeSpace) {
                                e.getPlayer().getInventory().addItem(randoItem);
                                e.getPlayer().getInventory().getItemInMainHand()
                                                .setAmount(e.getPlayer().getInventory().getItemInMainHand().getAmount()
                                                                - 1);
                        } else {
                                e.getPlayer().sendMessage(helper.R3SMessage(Type.ERROR, "[DailyQuests] Dein Inventar ist voll!"));
                        }
                }
        }

        @EventHandler
        public void onEntityHurt(EntityDamageByEntityEvent e) {
                if (e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() instanceof Player
                                && e.getEntity().getType().equals(EntityType.SNOW_GOLEM)) {
                        for (Object obj : App.main.getConfig()
                                        .getConfigurationSection("players."
                                                        + ((Player) ((Projectile) e.getDamager()).getShooter())
                                                                        .getUniqueId()
                                                        + ".currentQuests")
                                        .getKeys(false).toArray()) {
                                // obj = questnr
                                if (!obj.toString().equals("null")) {
                                        if ((App.main.getConfig().get("quests." + obj.toString() + ".action"))
                                                        .toString()
                                                        .equals("snowfight")) {

                                                if (("EntityType." + e.getEntityType().toString())
                                                                .equals((App.main.getConfig().get(
                                                                                "quests." + obj.toString() + ".target"))
                                                                                                .toString())
                                                                && App.main.getConfig()
                                                                                .get("players."
                                                                                                + ((Player) ((Projectile) e
                                                                                                                .getDamager()).getShooter())
                                                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".state")
                                                                                .equals("ongoing")) {
                                                        if (!App.main.getConfig()
                                                                        .get("quests." + obj.toString() + ".tool")
                                                                        .equals("none")) {
                                                                if (("Material." + ((Player) ((Projectile) e
                                                                                .getDamager()).getShooter())
                                                                                                .getInventory()
                                                                                                .getItemInMainHand()
                                                                                                .getType().toString())
                                                                                                                .equals(
                                                                                                                                App.main.getConfig()
                                                                                                                                                .get("quests." + obj
                                                                                                                                                                .toString()
                                                                                                                                                                + ".tool"))) {
                                                                        App.main.getConfig().set(
                                                                                        "players."
                                                                                                        + ((Player) ((Projectile) e
                                                                                                                        .getDamager()).getShooter())
                                                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".currentcount",
                                                                                        App.main.getConfig()
                                                                                                        .getInt("players."
                                                                                                                        + ((Player) ((Projectile) e
                                                                                                                                        .getDamager()).getShooter())
                                                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                                }
                                                        } else {
                                                                App.main.getConfig().set(
                                                                                "players." + ((Player) ((Projectile) e
                                                                                                .getDamager()).getShooter())
                                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                App.main.getConfig()
                                                                                                .getInt("players."
                                                                                                                + ((Player) ((Projectile) e
                                                                                                                                .getDamager()).getShooter())
                                                                                                                                                .getUniqueId()
                                                                                                                + ".currentQuests."
                                                                                                                + obj.toString()
                                                                                                                + ".currentcount")
                                                                                                + 1);
                                                        }
                                                        App.main.saveConfig();
                                                }
                                                if (App.main.getConfig()
                                                                .getInt("players." + ((Player) ((Projectile) e
                                                                                .getDamager()).getShooter())
                                                                                                .getUniqueId()
                                                                                + ".currentQuests." + obj.toString()
                                                                                + ".currentcount") == App.main
                                                                                                .getConfig()
                                                                                                .getInt("players."
                                                                                                                + ((Player) ((Projectile) e
                                                                                                                                .getDamager()).getShooter())
                                                                                                                                                .getUniqueId()
                                                                                                                + ".currentQuests."
                                                                                                                + obj.toString()
                                                                                                                + ".countneeded")
                                                                && App.main.getConfig()
                                                                                .get("players."
                                                                                                + ((Player) ((Projectile) e
                                                                                                                .getDamager()).getShooter())
                                                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".state")
                                                                                .equals("ongoing")) {

                                                        freeSpace = false;
                                                        given = false;

                                                        giveSmallReward(obj, ((Player) ((Projectile) e.getDamager())
                                                                        .getShooter()));

                                                }
                                                DailyQuestsCommands.updateSB(
                                                                ((Player) ((Projectile) e.getDamager()).getShooter()));
                                        }
                                }
                        }
                }
        }

        @EventHandler
        public void onEntityKill(EntityDeathEvent e) {
                if (e.getEntity().getKiller() instanceof Player) {
                        for (Object obj : App.main.getConfig()
                                        .getConfigurationSection("players." + e.getEntity().getKiller().getUniqueId()
                                                        + ".currentQuests")
                                        .getKeys(false).toArray()) {
                                // obj = questnr
                                if (!obj.toString().equals("null")) {
                                        if ((App.main.getConfig().get("quests." + obj.toString() + ".action"))
                                                        .toString().equals("kill")) {

                                                if (("EntityType." + e.getEntityType().toString())
                                                                .equals((App.main.getConfig().get(
                                                                                "quests." + obj.toString() + ".target"))
                                                                                                .toString())
                                                                && App.main.getConfig().get("players."
                                                                                + e.getEntity().getKiller()
                                                                                                .getUniqueId()
                                                                                + ".currentQuests." + obj.toString()
                                                                                + ".state").equals("ongoing")) {
                                                        if (!App.main.getConfig()
                                                                        .get("quests." + obj.toString() + ".tool")
                                                                        .equals("none")) {
                                                                if (("Material." + e.getEntity().getKiller()
                                                                                .getInventory().getItemInMainHand()
                                                                                .getType().toString()).equals(
                                                                                                App.main.getConfig()
                                                                                                                .get("quests." + obj
                                                                                                                                .toString()
                                                                                                                                + ".tool"))) {
                                                                        App.main.getConfig().set(
                                                                                        "players." + e.getEntity()
                                                                                                        .getKiller()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".currentcount",
                                                                                        App.main.getConfig()
                                                                                                        .getInt("players."
                                                                                                                        + e.getEntity().getKiller()
                                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                                }
                                                        } else {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getEntity()
                                                                                                .getKiller()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getEntity().getKiller()
                                                                                                                                                .getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                        App.main.saveConfig();
                                                }
                                                if (App.main.getConfig()
                                                                .getInt("players."
                                                                                + e.getEntity().getKiller()
                                                                                                .getUniqueId()
                                                                                + ".currentQuests."
                                                                                + obj.toString()
                                                                                + ".currentcount") == App.main
                                                                                                .getConfig()
                                                                                                .getInt("players." + e
                                                                                                                .getEntity()
                                                                                                                .getKiller()
                                                                                                                .getUniqueId()
                                                                                                                + ".currentQuests."
                                                                                                                + obj.toString()
                                                                                                                + ".countneeded")
                                                                && App.main.getConfig().get("players."
                                                                                + e.getEntity().getKiller()
                                                                                                .getUniqueId()
                                                                                + ".currentQuests." + obj.toString()
                                                                                + ".state").equals("ongoing")) {
                                                        freeSpace = false;
                                                        given = false;
                                                        giveSmallReward(obj, e.getEntity().getKiller());

                                                }
                                                DailyQuestsCommands.updateSB(e.getEntity().getKiller());
                                        }
                                }
                        }
                }
        }

        @EventHandler
        public void onCraft(CraftItemEvent e) {
                for (Object obj : App.main.getConfig()
                                .getConfigurationSection("players." + ((Player) e.getWhoClicked()).getUniqueId()
                                                + ".currentQuests")
                                .getKeys(false).toArray()) {
                        // obj = questnr
                        if (!obj.toString().equals("null")) {
                                if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString()
                                                .equals("bake")) {
                                        if (("Material." + e.getRecipe().getResult().getType().toString())
                                                        .equals((App.main.getConfig()
                                                                        .get("quests." + obj.toString() + ".target"))
                                                                                        .toString())
                                                        && App.main.getConfig().get("players."
                                                                        + ((Player) e.getWhoClicked()).getUniqueId()
                                                                        + ".currentQuests." + obj.toString() + ".state")
                                                                        .equals("ongoing")) {
                                                if (!App.main.getConfig().get("quests." + obj.toString() + ".tool")
                                                                .equals("none")) {
                                                        if (("Material." + ((Player) e.getWhoClicked()).getInventory()
                                                                        .getItemInMainHand().getType()
                                                                        .toString())
                                                                                        .equals(App.main.getConfig()
                                                                                                        .get("quests." + obj
                                                                                                                        .toString()
                                                                                                                        + ".tool"))) {
                                                                App.main.getConfig()
                                                                                .set("players." + ((Player) e
                                                                                                .getWhoClicked())
                                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + ((Player) e.getWhoClicked())
                                                                                                                                                .getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                } else {
                                                        App.main.getConfig()
                                                                        .set("players." + ((Player) e.getWhoClicked())
                                                                                        .getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString()
                                                                                        + ".currentcount",
                                                                                        App.main.getConfig()
                                                                                                        .getInt("players."
                                                                                                                        + ((Player) e.getWhoClicked())
                                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                }
                                                App.main.saveConfig();
                                        }
                                        if (App.main.getConfig()
                                                        .getInt("players." + ((Player) e.getWhoClicked()).getUniqueId()
                                                                        + ".currentQuests."
                                                                        + obj.toString() + ".currentcount") == App.main
                                                                                        .getConfig()
                                                                                        .getInt("players." + ((Player) e
                                                                                                        .getWhoClicked())
                                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".countneeded")
                                                        && App.main.getConfig().get("players."
                                                                        + ((Player) e.getWhoClicked()).getUniqueId()
                                                                        + ".currentQuests." + obj.toString() + ".state")
                                                                        .equals("ongoing")) {

                                                freeSpace = false;
                                                given = false;
                                                giveSmallReward(obj, ((Player) e.getWhoClicked()));

                                        }
                                        DailyQuestsCommands.updateSB(((Player) e.getWhoClicked()));
                                }
                        }
                }
        }

        @EventHandler
        public void onBlockBreak(BlockBreakEvent e) {
                for (Object obj : App.main.getConfig()
                                .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests")
                                .getKeys(false)
                                .toArray()) {
                        // obj = questnr
                        if (!obj.toString().equals("null")) {
                                if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString()
                                                .equals("break")) {

                                        if (("Material." + e.getBlock().getType().toString())
                                                        .equals((App.main.getConfig()
                                                                        .get("quests." + obj.toString() + ".target"))
                                                                                        .toString())
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {
                                                if (!App.main.getConfig().get("quests." + obj.toString() + ".tool")
                                                                .equals("none")) {
                                                        if (("Material." + e.getPlayer().getInventory()
                                                                        .getItemInMainHand().getType().toString())
                                                                                        .equals(App.main.getConfig()
                                                                                                        .get("quests." + obj
                                                                                                                        .toString()
                                                                                                                        + ".tool"))) {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getPlayer()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getPlayer().getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                } else {
                                                        App.main.getConfig()
                                                                        .set("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString()
                                                                                        + ".currentcount",
                                                                                        App.main.getConfig().getInt(
                                                                                                        "players." + e.getPlayer()
                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                }
                                                App.main.saveConfig();
                                        }
                                        if (App.main.getConfig()
                                                        .getInt("players." + e.getPlayer().getUniqueId()
                                                                        + ".currentQuests." + obj.toString()
                                                                        + ".currentcount") == App.main
                                                                                        .getConfig()
                                                                                        .getInt("players." + e
                                                                                                        .getPlayer()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".countneeded")
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {

                                                freeSpace = false;
                                                given = false;
                                                giveSmallReward(obj, e.getPlayer());
                                        }
                                        DailyQuestsCommands.updateSB(e.getPlayer());
                                }
                        }
                }
        }

        @EventHandler
        public void onGolemHeal(PlayerInteractEntityEvent e) {
                for (Object obj : App.main.getConfig()
                                .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests")
                                .getKeys(false)
                                .toArray()) {
                        // obj = questnr
                        if (!obj.toString().equals("null")) {
                                if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString()
                                                .equals("heal")) {

                                        if (("EntityType." + e.getRightClicked().getType().toString())////////////
                                                        .equals((App.main.getConfig()
                                                                        .get("quests." + obj.toString() + ".target"))
                                                                                        .toString())
                                                        && ((LivingEntity) e.getRightClicked()).getHealth() < 100
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {
                                                if (!App.main.getConfig().get("quests." + obj.toString() + ".tool")
                                                                .equals("none")) {
                                                        if (("Material." + e.getPlayer().getInventory()
                                                                        .getItemInMainHand().getType().toString())
                                                                                        .equals(App.main.getConfig()
                                                                                                        .get("quests." + obj
                                                                                                                        .toString()
                                                                                                                        + ".tool"))) {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getPlayer()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getPlayer().getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                } else {
                                                        App.main.getConfig()
                                                                        .set("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString()
                                                                                        + ".currentcount",
                                                                                        App.main.getConfig().getInt(
                                                                                                        "players." + e.getPlayer()
                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                }
                                                App.main.saveConfig();
                                        }
                                        if (App.main.getConfig()
                                                        .getInt("players." + e.getPlayer().getUniqueId()
                                                                        + ".currentQuests." + obj.toString()
                                                                        + ".currentcount") == App.main
                                                                                        .getConfig()
                                                                                        .getInt("players." + e
                                                                                                        .getPlayer()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".countneeded")
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {

                                                freeSpace = false;
                                                given = false;
                                                giveSmallReward(obj, e.getPlayer());
                                        }
                                        DailyQuestsCommands.updateSB(e.getPlayer());
                                }
                        }
                }
        }

        @EventHandler
        public void onCowMilking(PlayerInteractEntityEvent e) {
                for (Object obj : App.main.getConfig()
                                .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests")
                                .getKeys(false)
                                .toArray()) {
                        // obj = questnr
                        if (!obj.toString().equals("null")) {
                                if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString()
                                                .equals("milk")) {

                                        if (("EntityType." + e.getRightClicked().getType().toString())////////////
                                                        .equals((App.main.getConfig()
                                                                        .get("quests." + obj.toString() + ".target"))
                                                                                        .toString())
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {
                                                if (!App.main.getConfig().get("quests." + obj.toString() + ".tool")
                                                                .equals("none")) {
                                                        if (("Material." + e.getPlayer().getInventory()
                                                                        .getItemInMainHand().getType().toString())
                                                                                        .equals(App.main.getConfig()
                                                                                                        .get("quests." + obj
                                                                                                                        .toString()
                                                                                                                        + ".tool"))) {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getPlayer()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getPlayer().getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                } else {
                                                        App.main.getConfig()
                                                                        .set("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString()
                                                                                        + ".currentcount",
                                                                                        App.main.getConfig().getInt(
                                                                                                        "players." + e.getPlayer()
                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                }
                                                App.main.saveConfig();
                                        }
                                        if (App.main.getConfig()
                                                        .getInt("players." + e.getPlayer().getUniqueId()
                                                                        + ".currentQuests." + obj.toString()
                                                                        + ".currentcount") == App.main
                                                                                        .getConfig()
                                                                                        .getInt("players." + e
                                                                                                        .getPlayer()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".countneeded")
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {

                                                freeSpace = false;
                                                given = false;
                                                giveSmallReward(obj, e.getPlayer());

                                        }
                                        DailyQuestsCommands.updateSB(e.getPlayer());
                                }
                        }
                }
        }

        @EventHandler
        public void onFish(PlayerFishEvent e) {

                for (Object obj : App.main.getConfig()
                                .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests")
                                .getKeys(false)
                                .toArray()) {
                        // obj = questnr
                        if (!obj.toString().equals("null")) {
                                if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString()
                                                .equals("fish")) {

                                        if (App.main.getConfig()
                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                        + ".currentQuests."
                                                                        + obj.toString() + ".state")
                                                        .equals("ongoing")) {
                                                if (!App.main.getConfig().get("quests." + obj.toString() + ".tool")
                                                                .equals("none")) {
                                                        if (("Material." + e.getPlayer().getInventory()
                                                                        .getItemInMainHand().getType().toString())
                                                                                        .equals(App.main.getConfig()
                                                                                                        .get("quests." + obj
                                                                                                                        .toString()
                                                                                                                        + ".tool"))
                                                                        && e.getCaught() != null) {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getPlayer()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getPlayer().getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                } else {
                                                        App.main.getConfig()
                                                                        .set("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString()
                                                                                        + ".currentcount",
                                                                                        App.main.getConfig().getInt(
                                                                                                        "players." + e.getPlayer()
                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                }
                                                App.main.saveConfig();
                                        }
                                        if (App.main.getConfig()
                                                        .getInt("players." + e.getPlayer().getUniqueId()
                                                                        + ".currentQuests." + obj.toString()
                                                                        + ".currentcount") == App.main
                                                                                        .getConfig()
                                                                                        .getInt("players." + e
                                                                                                        .getPlayer()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".countneeded")
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {

                                                freeSpace = false;
                                                given = false;
                                                giveSmallReward(obj, e.getPlayer());
                                        }
                                        DailyQuestsCommands.updateSB(e.getPlayer());
                                }
                        }
                }
        }

        @EventHandler
        public void onTame(EntityTameEvent e) {
                for (Object obj : App.main.getConfig()
                                .getConfigurationSection("players." + e.getOwner().getUniqueId() + ".currentQuests")
                                .getKeys(false)
                                .toArray()) {
                        // obj = questnr
                        if (!obj.toString().equals("null")) {
                                if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString()
                                                .equals("tame")) {

                                        if (("EntityType." + e.getEntityType())
                                                        .equals((App.main.getConfig()
                                                                        .get("quests." + obj.toString() + ".target"))
                                                                                        .toString())
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getOwner().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {
                                                if (!App.main.getConfig().get("quests." + obj.toString() + ".tool")
                                                                .equals("none")) {
                                                        if (("Material."
                                                                        + ((Player) e.getOwner()).getInventory()
                                                                                        .getItemInMainHand().getType()
                                                                                        .toString())
                                                                                                        .equals(App.main.getConfig()
                                                                                                                        .get("quests." + obj
                                                                                                                                        .toString()
                                                                                                                                        + ".tool"))) {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getOwner()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getOwner().getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                } else {
                                                        App.main.getConfig()
                                                                        .set("players." + e.getOwner().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString()
                                                                                        + ".currentcount",
                                                                                        App.main.getConfig().getInt(
                                                                                                        "players." + e.getOwner()
                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                }
                                                App.main.saveConfig();
                                        }
                                        if (App.main.getConfig()
                                                        .getInt("players." + e.getOwner().getUniqueId()
                                                                        + ".currentQuests." + obj.toString()
                                                                        + ".currentcount") == App.main
                                                                                        .getConfig()
                                                                                        .getInt("players." + e
                                                                                                        .getOwner()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".countneeded")
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getOwner().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {

                                                freeSpace = false;
                                                given = false;
                                                giveSmallReward(obj, (Player) e.getOwner());

                                        }
                                        DailyQuestsCommands.updateSB(((Player) e.getOwner()));
                                }
                        }
                }
        }

        @EventHandler
        public void onNetherEnter(PlayerChangedWorldEvent e) {
                for (Object obj : App.main.getConfig()
                                .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests")
                                .getKeys(false)
                                .toArray()) {
                        // obj = questnr
                        if (!obj.toString().equals("null")) {
                                if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString()
                                                .equals("travel")) {

                                        if (e.getPlayer().getWorld().getName()
                                                        .equals((App.main.getConfig()
                                                                        .get("quests." + obj.toString() + ".target"))
                                                                                        .toString())
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {
                                                if (!App.main.getConfig().get("quests." + obj.toString() + ".tool")
                                                                .equals("none")) {
                                                        if (("Material."
                                                                        + ((Player) e.getPlayer()).getInventory()
                                                                                        .getItemInMainHand().getType()
                                                                                        .toString())
                                                                                                        .equals(App.main.getConfig()
                                                                                                                        .get("quests." + obj
                                                                                                                                        .toString()
                                                                                                                                        + ".tool"))) {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getPlayer()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getPlayer().getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                } else {
                                                        App.main.getConfig()
                                                                        .set("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString()
                                                                                        + ".currentcount",
                                                                                        App.main.getConfig().getInt(
                                                                                                        "players." + e.getPlayer()
                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                }
                                                App.main.saveConfig();
                                        }
                                        if (App.main.getConfig()
                                                        .getInt("players." + e.getPlayer().getUniqueId()
                                                                        + ".currentQuests." + obj.toString()
                                                                        + ".currentcount") == App.main
                                                                                        .getConfig()
                                                                                        .getInt("players." + e
                                                                                                        .getPlayer()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".countneeded")
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {

                                                freeSpace = false;
                                                given = false;
                                                giveSmallReward(obj, e.getPlayer());

                                        }
                                        DailyQuestsCommands.updateSB(((Player) e.getPlayer()));
                                }
                        }
                }
        }

        @EventHandler
        public void onBreed(EntityBreedEvent e) {
                if (e.getBreeder() != null) {
                        for (Object obj : App.main.getConfig()
                                        .getConfigurationSection(
                                                        "players." + e.getBreeder().getUniqueId() + ".currentQuests")
                                        .getKeys(false).toArray()) {
                                // obj = questnr
                                if (!obj.toString().equals("null")) {
                                        if ((App.main.getConfig().get("quests." + obj.toString() + ".action"))
                                                        .toString().equals("breed")) {

                                                if (e.getEntity().toString()
                                                                .equals((App.main.getConfig().get(
                                                                                "quests." + obj.toString() + ".target"))
                                                                                                .toString())

                                                                && App.main.getConfig().get("players."
                                                                                + e.getBreeder().getUniqueId()
                                                                                + ".currentQuests." + obj.toString()
                                                                                + ".state").equals("ongoing")) {
                                                        if (!App.main.getConfig()
                                                                        .get("quests." + obj.toString() + ".tool")
                                                                        .equals("none")) {
                                                                if (("Material." + ((Player) e.getBreeder())
                                                                                .getInventory().getItemInMainHand()
                                                                                .getType().toString()).equals(
                                                                                                App.main.getConfig()
                                                                                                                .get("quests." + obj
                                                                                                                                .toString()
                                                                                                                                + ".tool"))) {
                                                                        App.main.getConfig().set(
                                                                                        "players." + e.getBreeder()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".currentcount",
                                                                                        App.main.getConfig()
                                                                                                        .getInt("players."
                                                                                                                        + e.getBreeder().getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                                }
                                                        } else {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getBreeder()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getBreeder().getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                        App.main.saveConfig();
                                                }
                                                if (App.main.getConfig()
                                                                .getInt("players." + e.getBreeder().getUniqueId()
                                                                                + ".currentQuests." + obj.toString()
                                                                                + ".currentcount") == App.main
                                                                                                .getConfig()
                                                                                                .getInt("players." + e
                                                                                                                .getBreeder()
                                                                                                                .getUniqueId()
                                                                                                                + ".currentQuests."
                                                                                                                + obj.toString()
                                                                                                                + ".countneeded")
                                                                && App.main.getConfig().get("players."
                                                                                + e.getBreeder().getUniqueId()
                                                                                + ".currentQuests." + obj.toString()
                                                                                + ".state").equals("ongoing")) {

                                                        freeSpace = false;
                                                        given = false;
                                                        giveSmallReward(obj, (Player) e.getBreeder());

                                                }
                                                DailyQuestsCommands.updateSB(((Player) e.getBreeder()));
                                        }
                                }
                        }
                }
        }

        @EventHandler
        public void onBlockTouch(PlayerMoveEvent e) {
                for (Object obj : App.main.getConfig()
                                .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests")
                                .getKeys(false)
                                .toArray()) {
                        // obj = questnr
                        if (!obj.toString().equals("null")) {
                                if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString()
                                                .equals("touch")) {

                                        if (("Material." + e.getPlayer().getLocation().subtract(0, 1, 0).getBlock()
                                                        .getType().toString())
                                                                        .equals((App.main.getConfig().get("quests."
                                                                                        + obj.toString() + ".target"))
                                                                                                        .toString())

                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {
                                                // WENN SPIELER LEDER BOOTS AN HAT
                                                if (!App.main.getConfig().get("quests." + obj.toString() + ".tool")
                                                                .equals("none")) {
                                                        if (e.getPlayer().getInventory().getBoots() != null
                                                                        && ("Material." + e.getPlayer().getInventory()
                                                                                        .getBoots().getType()
                                                                                        .toString())
                                                                                                        .equals(App.main.getConfig()
                                                                                                                        .get("quests." + obj
                                                                                                                                        .toString()
                                                                                                                                        + ".tool"))) {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getPlayer()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getPlayer().getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                } else {
                                                        App.main.getConfig()
                                                                        .set("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString()
                                                                                        + ".currentcount",
                                                                                        App.main.getConfig().getInt(
                                                                                                        "players." + e.getPlayer()
                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                }
                                                App.main.saveConfig();
                                        }
                                        if (App.main.getConfig()
                                                        .getInt("players." + e.getPlayer().getUniqueId()
                                                                        + ".currentQuests." + obj.toString()
                                                                        + ".currentcount") == App.main
                                                                                        .getConfig()
                                                                                        .getInt("players." + e
                                                                                                        .getPlayer()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".countneeded")
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {

                                                freeSpace = false;
                                                given = false;
                                                giveSmallReward(obj, e.getPlayer());
                                        }
                                        DailyQuestsCommands.updateSB(e.getPlayer());
                                }
                        }
                }

        }

        @EventHandler
        public void onSheepShear(PlayerShearEntityEvent e) {
                if (("EntityType." + e.getEntity().getType().toString()).equals("EntityType.SHEEP")) {
                        for (Object obj : App.main.getConfig()
                                        .getConfigurationSection(
                                                        "players." + e.getPlayer().getUniqueId() + ".currentQuests")
                                        .getKeys(false)
                                        .toArray()) {
                                // obj = questnr
                                if (!obj.toString().equals("null")) {
                                        if ((App.main.getConfig().get("quests." + obj.toString() + ".action"))
                                                        .toString().equals("shear")) {

                                                if (("EntityType." + e.getEntity().getType().toString())
                                                                .equals((App.main.getConfig().get(
                                                                                "quests." + obj.toString() + ".target"))
                                                                                                .toString())

                                                                && App.main.getConfig().get("players."
                                                                                + e.getPlayer().getUniqueId()
                                                                                + ".currentQuests."
                                                                                + obj.toString() + ".state")
                                                                                .equals("ongoing")) {
                                                        // WENN SPIELER LEDER BOOTS AN HAT
                                                        if (!App.main.getConfig()
                                                                        .get("quests." + obj.toString() + ".tool")
                                                                        .equals("none")) {
                                                                if (e.getPlayer().getInventory().getItemInMainHand()
                                                                                .getType().toString()
                                                                                .equals(App.main.getConfig().get(
                                                                                                "quests." + obj.toString()
                                                                                                                + ".tool"))) {
                                                                        App.main.getConfig().set(
                                                                                        "players." + e.getPlayer()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".currentcount",
                                                                                        App.main.getConfig().getInt(
                                                                                                        "players." + e.getPlayer()
                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                                }
                                                        } else {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getPlayer()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getPlayer().getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                        App.main.saveConfig();
                                                }
                                                if (App.main.getConfig()
                                                                .getInt("players." + e.getPlayer().getUniqueId()
                                                                                + ".currentQuests." + obj.toString()
                                                                                + ".currentcount") == App.main
                                                                                                .getConfig()
                                                                                                .getInt("players." + e
                                                                                                                .getPlayer()
                                                                                                                .getUniqueId()
                                                                                                                + ".currentQuests."
                                                                                                                + obj.toString()
                                                                                                                + ".countneeded")
                                                                && App.main.getConfig().get("players."
                                                                                + e.getPlayer().getUniqueId()
                                                                                + ".currentQuests."
                                                                                + obj.toString() + ".state")
                                                                                .equals("ongoing")) {

                                                        freeSpace = false;
                                                        given = false;
                                                        giveSmallReward(obj, e.getPlayer());
                                                }
                                                DailyQuestsCommands.updateSB(e.getPlayer());
                                        }
                                }
                        }

                }

        }

        @EventHandler
        public void onHoneyCollect(PlayerInteractEvent e) {

                if (e.getClickedBlock() != null
                                && (e.getClickedBlock().getType() == Material.BEEHIVE
                                                || e.getClickedBlock().getType() == Material.BEE_NEST)
                                && e.getAction() == Action.RIGHT_CLICK_BLOCK) {

                        Beehive b = (Beehive) e.getClickedBlock().getState().getBlockData();

                        for (Object obj : App.main.getConfig()
                                        .getConfigurationSection(
                                                        "players." + e.getPlayer().getUniqueId() + ".currentQuests")
                                        .getKeys(false)
                                        .toArray()) {
                                // obj = questnr
                                if (!obj.toString().equals("null")) {
                                        if ((App.main.getConfig().get("quests." + obj.toString() + ".action"))
                                                        .toString().equals("honey")) {

                                                if (App.main.getConfig()
                                                                .get("players." + e.getPlayer().getUniqueId()
                                                                                + ".currentQuests."
                                                                                + obj.toString() + ".state")
                                                                .equals("ongoing") && b.getHoneyLevel() == 5) {
                                                        // WENN SPIELER LEDER BOOTS AN HAT
                                                        if (!App.main.getConfig()
                                                                        .get("quests." + obj.toString() + ".tool")
                                                                        .equals("none")) {
                                                                if (("Material."
                                                                                + e.getPlayer().getInventory()
                                                                                                .getItemInMainHand()
                                                                                                .getType().toString())
                                                                                                                .equals(App.main.getConfig()
                                                                                                                                .get("quests." + obj
                                                                                                                                                .toString()
                                                                                                                                                + ".tool"))) {
                                                                        App.main.getConfig().set(
                                                                                        "players." + e.getPlayer()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".currentcount",
                                                                                        App.main.getConfig().getInt(
                                                                                                        "players." + e.getPlayer()
                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                                }
                                                        } else {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getPlayer()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getPlayer().getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                        App.main.saveConfig();
                                                }
                                                if (App.main.getConfig()
                                                                .getInt("players." + e.getPlayer().getUniqueId()
                                                                                + ".currentQuests." + obj.toString()
                                                                                + ".currentcount") == App.main
                                                                                                .getConfig()
                                                                                                .getInt("players." + e
                                                                                                                .getPlayer()
                                                                                                                .getUniqueId()
                                                                                                                + ".currentQuests."
                                                                                                                + obj.toString()
                                                                                                                + ".countneeded")
                                                                && App.main.getConfig().get("players."
                                                                                + e.getPlayer().getUniqueId()
                                                                                + ".currentQuests."
                                                                                + obj.toString() + ".state")
                                                                                .equals("ongoing")) {

                                                        freeSpace = false;
                                                        given = false;
                                                        giveSmallReward(obj, e.getPlayer());
                                                }
                                                DailyQuestsCommands.updateSB(e.getPlayer());
                                        }
                                }
                        }

                }

        }

        @EventHandler
        public void onBookWrite(PlayerEditBookEvent e) {

                for (Object obj : App.main.getConfig()
                                .getConfigurationSection("players." + e.getPlayer().getUniqueId() + ".currentQuests")
                                .getKeys(false)
                                .toArray()) {
                        // obj = questnr
                        if (!obj.toString().equals("null")) {
                                if ((App.main.getConfig().get("quests." + obj.toString() + ".action")).toString()
                                                .equals("write")) {

                                        if (e.isSigning() && App.main.getConfig().get(
                                                        "players." + e.getPlayer().getUniqueId() + ".currentQuests."
                                                                        + obj.toString() + ".state")
                                                        .equals("ongoing")) {
                                                if (!App.main.getConfig().get("quests." + obj.toString() + ".tool")
                                                                .equals("none")) {
                                                        if (("Material." + e.getPlayer().getInventory()
                                                                        .getItemInMainHand().getType().toString())
                                                                                        .equals(App.main.getConfig()
                                                                                                        .get("quests." + obj
                                                                                                                        .toString()
                                                                                                                        + ".tool"))) {
                                                                App.main.getConfig()
                                                                                .set("players." + e.getPlayer()
                                                                                                .getUniqueId()
                                                                                                + ".currentQuests."
                                                                                                + obj.toString()
                                                                                                + ".currentcount",
                                                                                                App.main.getConfig()
                                                                                                                .getInt("players."
                                                                                                                                + e.getPlayer().getUniqueId()
                                                                                                                                + ".currentQuests."
                                                                                                                                + obj.toString()
                                                                                                                                + ".currentcount")
                                                                                                                + 1);
                                                        }
                                                } else {
                                                        App.main.getConfig()
                                                                        .set("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString()
                                                                                        + ".currentcount",
                                                                                        App.main.getConfig().getInt(
                                                                                                        "players." + e.getPlayer()
                                                                                                                        .getUniqueId()
                                                                                                                        + ".currentQuests."
                                                                                                                        + obj.toString()
                                                                                                                        + ".currentcount")
                                                                                                        + 1);
                                                }
                                                App.main.saveConfig();
                                        }
                                        if (App.main.getConfig()
                                                        .getInt("players." + e.getPlayer().getUniqueId()
                                                                        + ".currentQuests." + obj.toString()
                                                                        + ".currentcount") == App.main
                                                                                        .getConfig()
                                                                                        .getInt("players." + e
                                                                                                        .getPlayer()
                                                                                                        .getUniqueId()
                                                                                                        + ".currentQuests."
                                                                                                        + obj.toString()
                                                                                                        + ".countneeded")
                                                        && App.main.getConfig()
                                                                        .get("players." + e.getPlayer().getUniqueId()
                                                                                        + ".currentQuests."
                                                                                        + obj.toString() + ".state")
                                                                        .equals("ongoing")) {

                                                freeSpace = false;
                                                given = false;
                                                giveSmallReward(obj, e.getPlayer());
                                        }
                                        DailyQuestsCommands.updateSB(e.getPlayer());
                                }
                        }
                }
        }
}