Search in sources :

Example 1 with CustomQuest

use of com.magmaguy.elitemobs.quests.CustomQuest in project EliteMobs by MagmaGuy.

the class PlayerData method readExistingData.

private void readExistingData(Statement statement, UUID uuid, ResultSet resultSet) throws Exception {
    playerDataHashMap.put(uuid, this);
    currency = resultSet.getDouble("Currency");
    guildPrestigeLevel = resultSet.getInt("GuildPrestigeLevel");
    maxGuildLevel = resultSet.getInt("GuildMaxLevel");
    activeGuildLevel = resultSet.getInt("GuildActiveLevel");
    score = resultSet.getInt("Score");
    kills = resultSet.getInt("Kills");
    highestLevelKilled = resultSet.getInt("HighestLevelKilled");
    deaths = resultSet.getInt("Deaths");
    questsCompleted = resultSet.getInt("QuestsCompleted");
    backTeleportLocation = ConfigurationLocation.serialize(resultSet.getString("BackTeleportLocation"));
    if (resultSet.getBytes("QuestStatus") != null) {
        try {
            quests = (List<Quest>) ObjectSerializer.fromString(new String(resultSet.getBytes("QuestStatus"), "UTF-8"));
            // Serializes ItemStack which require specific handling, necessary recovering the rewards
            for (Quest quest : quests) if (quest instanceof CustomQuest)
                ((CustomQuest) quest).applyTemporaryPermissions(Bukkit.getPlayer(uuid));
        } catch (Exception ex) {
            new WarningMessage("Failed to serialize quest data for player " + Bukkit.getPlayer(uuid) + " ! This player's quest data will be wiped to prevent future errors.");
            try {
                resetQuests(uuid);
            } catch (Exception ex2) {
                new WarningMessage("Failed to reset quest data! Ironic.");
                ex2.printStackTrace();
            }
        }
    }
    if (resultSet.getBytes("PlayerQuestCooldowns") != null) {
        try {
            playerQuestCooldowns = (PlayerQuestCooldowns) ObjectSerializer.fromString(new String(resultSet.getBytes("PlayerQuestCooldowns"), "UTF-8"));
            playerQuestCooldowns.startCooldowns(uuid);
        } catch (Exception exception) {
            new WarningMessage("Failed to get player quest cooldowns!  ! This player's quest cooldowns will be wiped to prevent future errors.");
            try {
                resetPlayerQuestCooldowns(uuid);
            } catch (Exception ex2) {
                new WarningMessage("Failed to reset quest cooldowns! Ironic.");
                ex2.printStackTrace();
            }
        }
    }
    new InfoMessage("User " + uuid + " data successfully read!");
}
Also used : CustomQuest(com.magmaguy.elitemobs.quests.CustomQuest) WarningMessage(com.magmaguy.elitemobs.utils.WarningMessage) InfoMessage(com.magmaguy.elitemobs.utils.InfoMessage) CustomQuest(com.magmaguy.elitemobs.quests.CustomQuest) Quest(com.magmaguy.elitemobs.quests.Quest)

Example 2 with CustomQuest

use of com.magmaguy.elitemobs.quests.CustomQuest in project EliteMobs by MagmaGuy.

the class QuestBookMenu method generateQuestEntry.

// NPC entity is null when the entry is generated based on a command and not a npc interaction
public static TextComponent[] generateQuestEntry(Quest quest, Player player, NPCEntity npcEntity) {
    QuestMenu.QuestText questText = new QuestMenu.QuestText(quest, npcEntity, player);
    // Condense all page elements
    List<TextComponent> elements = new ArrayList<>();
    elements.add(questText.getHeader());
    if (quest instanceof CustomQuest && !quest.getQuestObjectives().isOver())
        elements.addAll(questText.getBody());
    elements.add(questText.getFixedSummary());
    elements.addAll(questText.getSummary());
    elements.add(questText.getFixedRewards());
    elements.addAll(questText.getRewards());
    elements.add(questText.getAccept());
    if (quest instanceof CustomQuest)
        elements.add(questText.getTrack());
    // Arrange them into pages, taking character count into account
    List<TextComponent> pagesList = new ArrayList<>();
    int pageIndex = 0;
    int characterCount = 0;
    int characterLimit = 185;
    for (TextComponent textComponent : elements) {
        characterCount += ChatColor.stripColor(textComponent.getText()).length();
        if (pagesList.isEmpty()) {
            textComponent.addExtra("\n");
            pagesList.add(textComponent);
        } else if (characterCount > characterLimit) {
            characterCount = 0;
            characterCount += ChatColor.stripColor(textComponent.getText()).length();
            pageIndex++;
            textComponent.addExtra("\n");
            pagesList.add(textComponent);
        } else {
            textComponent.addExtra("\n");
            pagesList.get(pageIndex).addExtra(textComponent);
        }
    }
    TextComponent[] pages = new TextComponent[pagesList.size()];
    int pageCounter = 0;
    for (TextComponent textComponent : pagesList) {
        pages[pageCounter] = textComponent;
        pageCounter++;
    }
    return pages;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) CustomQuest(com.magmaguy.elitemobs.quests.CustomQuest) ArrayList(java.util.ArrayList)

Example 3 with CustomQuest

use of com.magmaguy.elitemobs.quests.CustomQuest in project EliteMobs by MagmaGuy.

the class QuestInventoryMenu method generateInventoryQuestEntry.

public static void generateInventoryQuestEntry(Quest quest, Player player, NPCEntity npcEntity) {
    QuestMenu.QuestText questText = new QuestMenu.QuestText(quest, npcEntity, player);
    String title = "";
    if (questText.getHeader().getText() != null)
        title = questText.getHeader().getText();
    Inventory questInventory = Bukkit.createInventory(player, 27, title);
    int titleEntry = 4;
    List<Integer> loreEntries = new ArrayList<>(Arrays.asList(13, 14, 12, 15, 11, 16, 10, 17, 9));
    List<Integer> objectivesEntries = new ArrayList<>(Arrays.asList(21, 20, 19, 18));
    List<Integer> rewardEntries = new ArrayList<>(Arrays.asList(23, 24, 25));
    Material titleMaterial = Material.PAINTING;
    Material trackingMaterial = Material.TARGET;
    Material loreMaterial = Material.BOOK;
    Material objectivesMaterial = Material.ITEM_FRAME;
    Material rewardsMaterial = Material.GOLD_INGOT;
    Material acceptMaterial = Material.EMERALD;
    questInventory.setItem(titleEntry, generateItemStackEntry(questText.getHeader(), new TextComponent(), titleMaterial).get(0));
    if (quest instanceof CustomQuest && quest.isAccepted())
        questInventory.setItem(trackEntry, generateItemStackEntry(questText.getTrack(), new TextComponent(), trackingMaterial).get(0));
    questInventory.setItem(acceptEntry, generateItemStackEntry(questText.getAccept(), new TextComponent(), acceptMaterial).get(0));
    if (quest instanceof CustomQuest)
        fillItemSlotLists(questInventory, loreEntries, new TextComponent(" "), questText.getBody(), loreMaterial);
    fillItemSlotLists(questInventory, objectivesEntries, questText.getFixedSummary(), questText.getSummary(), objectivesMaterial);
    fillItemSlotLists(questInventory, rewardEntries, questText.getFixedRewards(), questText.getRewards(), rewardsMaterial);
    new QuestInventory(player, quest, questInventory, npcEntity);
    player.openInventory(questInventory);
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) CustomQuest(com.magmaguy.elitemobs.quests.CustomQuest) Material(org.bukkit.Material) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Inventory(org.bukkit.inventory.Inventory)

Aggregations

CustomQuest (com.magmaguy.elitemobs.quests.CustomQuest)3 TextComponent (net.md_5.bungee.api.chat.TextComponent)2 Quest (com.magmaguy.elitemobs.quests.Quest)1 InfoMessage (com.magmaguy.elitemobs.utils.InfoMessage)1 WarningMessage (com.magmaguy.elitemobs.utils.WarningMessage)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Material (org.bukkit.Material)1 Inventory (org.bukkit.inventory.Inventory)1