Search in sources :

Example 1 with TaskProgress

use of com.leonardobishop.quests.common.player.questprogressfile.TaskProgress in project Quests by LMBishop.

the class FarmingCertainTaskType method onBlockBreak.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (!(event.getBlock().getState().getBlockData() instanceof Ageable)) {
        return;
    }
    QPlayer qPlayer = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
    if (qPlayer == null) {
        return;
    }
    Ageable crop = (Ageable) event.getBlock().getState().getBlockData();
    if (crop.getAge() != crop.getMaximumAge()) {
        return;
    }
    for (Quest quest : super.getRegisteredQuests()) {
        if (qPlayer.hasStartedQuest(quest)) {
            QuestProgress questProgress = qPlayer.getQuestProgressFile().getQuestProgress(quest);
            for (Task task : quest.getTasksOfType(super.getType())) {
                if (!TaskUtils.validateWorld(event.getPlayer(), task))
                    continue;
                TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
                if (taskProgress.isCompleted()) {
                    continue;
                }
                if (matchBlock(task, event.getBlock())) {
                    int brokenBlocksNeeded = (int) task.getConfigValue("amount");
                    int progressBlocksBroken;
                    if (taskProgress.getProgress() == null) {
                        progressBlocksBroken = 0;
                    } else {
                        progressBlocksBroken = (int) taskProgress.getProgress();
                    }
                    taskProgress.setProgress(progressBlocksBroken + 1);
                    if (((int) taskProgress.getProgress()) >= brokenBlocksNeeded) {
                        taskProgress.setCompleted(true);
                    }
                }
            }
        }
    }
}
Also used : QuestProgress(com.leonardobishop.quests.common.player.questprogressfile.QuestProgress) Task(com.leonardobishop.quests.common.quest.Task) TaskProgress(com.leonardobishop.quests.common.player.questprogressfile.TaskProgress) Ageable(org.bukkit.block.data.Ageable) QPlayer(com.leonardobishop.quests.common.player.QPlayer) Quest(com.leonardobishop.quests.common.quest.Quest) EventHandler(org.bukkit.event.EventHandler)

Example 2 with TaskProgress

use of com.leonardobishop.quests.common.player.questprogressfile.TaskProgress in project Quests by LMBishop.

the class FarmingTaskType method onBlockBreak.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (!(event.getBlock().getState().getBlockData() instanceof Ageable)) {
        return;
    }
    QPlayer qPlayer = plugin.getPlayerManager().getPlayer(event.getPlayer().getUniqueId());
    if (qPlayer == null) {
        return;
    }
    Ageable crop = (Ageable) event.getBlock().getState().getBlockData();
    if (crop.getAge() != crop.getMaximumAge()) {
        return;
    }
    for (Quest quest : super.getRegisteredQuests()) {
        if (qPlayer.hasStartedQuest(quest)) {
            QuestProgress questProgress = qPlayer.getQuestProgressFile().getQuestProgress(quest);
            for (Task task : quest.getTasksOfType(super.getType())) {
                if (!TaskUtils.validateWorld(event.getPlayer(), task))
                    continue;
                TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
                if (taskProgress.isCompleted()) {
                    continue;
                }
                int brokenBlocksNeeded = (int) task.getConfigValue("amount");
                int progressBlocksBroken;
                if (taskProgress.getProgress() == null) {
                    progressBlocksBroken = 0;
                } else {
                    progressBlocksBroken = (int) taskProgress.getProgress();
                }
                taskProgress.setProgress(progressBlocksBroken + 1);
                if (((int) taskProgress.getProgress()) >= brokenBlocksNeeded) {
                    taskProgress.setCompleted(true);
                }
            }
        }
    }
}
Also used : QuestProgress(com.leonardobishop.quests.common.player.questprogressfile.QuestProgress) Task(com.leonardobishop.quests.common.quest.Task) TaskProgress(com.leonardobishop.quests.common.player.questprogressfile.TaskProgress) Ageable(org.bukkit.block.data.Ageable) QPlayer(com.leonardobishop.quests.common.player.QPlayer) Quest(com.leonardobishop.quests.common.quest.Quest) EventHandler(org.bukkit.event.EventHandler)

Example 3 with TaskProgress

use of com.leonardobishop.quests.common.player.questprogressfile.TaskProgress in project Quests by LMBishop.

the class MythicMobsKillingType method onMobKill.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMobKill(MythicMobDeathEvent event) {
    Entity killer = event.getKiller();
    Entity mob = event.getEntity();
    if (mob == null || mob instanceof Player) {
        return;
    }
    if (killer == null) {
        return;
    }
    String mobName = event.getMobType().getInternalName();
    double level = event.getMobLevel();
    QPlayer qPlayer = plugin.getPlayerManager().getPlayer(killer.getUniqueId());
    if (qPlayer == null) {
        return;
    }
    for (Quest quest : super.getRegisteredQuests()) {
        if (qPlayer.hasStartedQuest(quest)) {
            QuestProgress questProgress = qPlayer.getQuestProgressFile().getQuestProgress(quest);
            for (Task task : quest.getTasksOfType(super.getType())) {
                if (!TaskUtils.validateWorld(killer.getWorld().getName(), task))
                    continue;
                TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
                if (taskProgress.isCompleted()) {
                    continue;
                }
                String configName = (String) task.getConfigValue("name");
                int minMobLevel = (int) task.getConfigValue("min-level", -1);
                int requiredLevel = (int) task.getConfigValue("level", -1);
                if (!mobName.equals(configName) || level < minMobLevel) {
                    return;
                }
                if (requiredLevel != -1 && level != requiredLevel) {
                    return;
                }
                int mobKillsNeeded = (int) task.getConfigValue("amount");
                int progressKills;
                if (taskProgress.getProgress() == null) {
                    progressKills = 0;
                } else {
                    progressKills = (int) taskProgress.getProgress();
                }
                taskProgress.setProgress(progressKills + 1);
                if (((int) taskProgress.getProgress()) >= mobKillsNeeded) {
                    taskProgress.setCompleted(true);
                }
            }
        }
    }
}
Also used : QuestProgress(com.leonardobishop.quests.common.player.questprogressfile.QuestProgress) Entity(org.bukkit.entity.Entity) QPlayer(com.leonardobishop.quests.common.player.QPlayer) Player(org.bukkit.entity.Player) Task(com.leonardobishop.quests.common.quest.Task) TaskProgress(com.leonardobishop.quests.common.player.questprogressfile.TaskProgress) QPlayer(com.leonardobishop.quests.common.player.QPlayer) Quest(com.leonardobishop.quests.common.quest.Quest) EventHandler(org.bukkit.event.EventHandler)

Example 4 with TaskProgress

use of com.leonardobishop.quests.common.player.questprogressfile.TaskProgress in project Quests by LMBishop.

the class FabledSkyblockLevelTaskType method onIslandLevel.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onIslandLevel(IslandLevelChangeEvent event) {
    List<UUID> members = new ArrayList<>();
    members.add(event.getIsland().getOwnerUUID());
    members.addAll(event.getIsland().getCoopPlayers().keySet());
    for (UUID member : members) {
        QPlayer qPlayer = plugin.getPlayerManager().getPlayer(member);
        if (qPlayer == null) {
            continue;
        }
        for (Quest quest : super.getRegisteredQuests()) {
            if (qPlayer.hasStartedQuest(quest)) {
                QuestProgress questProgress = qPlayer.getQuestProgressFile().getQuestProgress(quest);
                for (Task task : quest.getTasksOfType(super.getType())) {
                    TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
                    if (taskProgress.isCompleted()) {
                        continue;
                    }
                    int islandValueNeeded = (int) task.getConfigValue("level");
                    taskProgress.setProgress(event.getLevel().getLevel());
                    if (((double) taskProgress.getProgress()) >= islandValueNeeded) {
                        taskProgress.setCompleted(true);
                    }
                }
            }
        }
    }
}
Also used : QuestProgress(com.leonardobishop.quests.common.player.questprogressfile.QuestProgress) Task(com.leonardobishop.quests.common.quest.Task) ArrayList(java.util.ArrayList) TaskProgress(com.leonardobishop.quests.common.player.questprogressfile.TaskProgress) UUID(java.util.UUID) QPlayer(com.leonardobishop.quests.common.player.QPlayer) Quest(com.leonardobishop.quests.common.quest.Quest) EventHandler(org.bukkit.event.EventHandler)

Example 5 with TaskProgress

use of com.leonardobishop.quests.common.player.questprogressfile.TaskProgress in project Quests by LMBishop.

the class MythicMobsKillingType method handle.

private void handle(LivingEntity killer, Entity mob, String mobName, double level) {
    if (killer == null) {
        return;
    }
    if (mob == null || mob instanceof Player) {
        return;
    }
    QPlayer qPlayer = plugin.getPlayerManager().getPlayer(killer.getUniqueId());
    if (qPlayer == null) {
        return;
    }
    for (Quest quest : super.getRegisteredQuests()) {
        if (qPlayer.hasStartedQuest(quest)) {
            QuestProgress questProgress = qPlayer.getQuestProgressFile().getQuestProgress(quest);
            for (Task task : quest.getTasksOfType(super.getType())) {
                if (!TaskUtils.validateWorld(killer.getWorld().getName(), task))
                    continue;
                TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
                if (taskProgress.isCompleted()) {
                    continue;
                }
                String configName = (String) task.getConfigValue("name");
                int minMobLevel = (int) task.getConfigValue("min-level", -1);
                int requiredLevel = (int) task.getConfigValue("level", -1);
                if (!mobName.equals(configName) || level < minMobLevel) {
                    return;
                }
                if (requiredLevel != -1 && level != requiredLevel) {
                    return;
                }
                int mobKillsNeeded = (int) task.getConfigValue("amount");
                int progressKills;
                if (taskProgress.getProgress() == null) {
                    progressKills = 0;
                } else {
                    progressKills = (int) taskProgress.getProgress();
                }
                taskProgress.setProgress(progressKills + 1);
                if (((int) taskProgress.getProgress()) >= mobKillsNeeded) {
                    taskProgress.setCompleted(true);
                }
            }
        }
    }
}
Also used : QuestProgress(com.leonardobishop.quests.common.player.questprogressfile.QuestProgress) QPlayer(com.leonardobishop.quests.common.player.QPlayer) Player(org.bukkit.entity.Player) Task(com.leonardobishop.quests.common.quest.Task) TaskProgress(com.leonardobishop.quests.common.player.questprogressfile.TaskProgress) QPlayer(com.leonardobishop.quests.common.player.QPlayer) Quest(com.leonardobishop.quests.common.quest.Quest)

Aggregations

TaskProgress (com.leonardobishop.quests.common.player.questprogressfile.TaskProgress)60 QuestProgress (com.leonardobishop.quests.common.player.questprogressfile.QuestProgress)59 QPlayer (com.leonardobishop.quests.common.player.QPlayer)55 Quest (com.leonardobishop.quests.common.quest.Quest)54 Task (com.leonardobishop.quests.common.quest.Task)53 EventHandler (org.bukkit.event.EventHandler)43 Player (org.bukkit.entity.Player)34 ItemStack (org.bukkit.inventory.ItemStack)8 QuestProgressFile (com.leonardobishop.quests.common.player.questprogressfile.QuestProgressFile)7 Material (org.bukkit.Material)7 ParsedQuestItem (com.leonardobishop.quests.bukkit.item.ParsedQuestItem)5 QuestItem (com.leonardobishop.quests.bukkit.item.QuestItem)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)5 Entity (org.bukkit.entity.Entity)5 BigDecimal (java.math.BigDecimal)4 UUID (java.util.UUID)4 World (org.bukkit.World)4 Ageable (org.bukkit.block.data.Ageable)4 ArrayList (java.util.ArrayList)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3