Search in sources :

Example 1 with DiscoveryInfo

use of com.wynntils.modules.questbook.instances.DiscoveryInfo in project Wynntils by Wynntils.

the class QuestManager method parseDiscoveries.

private static void parseDiscoveries(List<ItemStack> discoveries) {
    for (ItemStack stack : discoveries) {
        try {
            DiscoveryInfo discovery = new DiscoveryInfo(stack, true);
            if (!discovery.isValid())
                continue;
            currentDiscoveries.put(discovery.getName(), discovery);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : DiscoveryInfo(com.wynntils.modules.questbook.instances.DiscoveryInfo) ItemStack(net.minecraft.item.ItemStack)

Example 2 with DiscoveryInfo

use of com.wynntils.modules.questbook.instances.DiscoveryInfo in project Wynntils by Wynntils.

the class CommandExportDiscoveries method onQuestBookUpdate.

private void onQuestBookUpdate() {
    FrameworkManager.getEventBus().unregister(this);
    File exportFolder = new File(Reference.MOD_STORAGE_ROOT, "export");
    exportFolder.mkdirs();
    String date = dateFormat.format(new Date());
    File exportFile = new File(exportFolder, date + "-discoveries.csv");
    try {
        exportFile.createNewFile();
    } catch (IOException ex) {
        ex.printStackTrace();
        return;
    }
    List<DiscoveryInfo> discoveries = new ArrayList<>(QuestManager.getCurrentDiscoveries());
    discoveries.sort((d1, d2) -> {
        if (d1.getMinLevel() != d2.getMinLevel()) {
            return d1.getMinLevel() - d2.getMinLevel();
        } else if (d1.getType() != d2.getType()) {
            return d1.getType().getOrder() - d2.getType().getOrder();
        } else {
            return d1.getName().compareTo(d2.getName());
        }
    });
    OutputStreamWriter output = null;
    try {
        output = new OutputStreamWriter(new FileOutputStream(exportFile));
        output.write("level,type,name\n");
        Iterator<DiscoveryInfo> discoveriesIterator = discoveries.iterator();
        while (discoveriesIterator.hasNext()) {
            DiscoveryInfo discovery = discoveriesIterator.next();
            output.write(discovery.getMinLevel() + ",");
            output.write(StringUtils.firstCharToUpper(new String[] { discovery.getType().toString().toLowerCase() }) + ",");
            output.write("\"" + TextFormatting.getTextWithoutFormattingCodes(discovery.getName()) + "\"");
            if (discoveriesIterator.hasNext()) {
                output.write("\n");
            }
        }
        ITextComponent text = new TextComponentString("Exported discoveries to ");
        ITextComponent fileText = new TextComponentString(exportFile.getName());
        fileText.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, exportFile.getCanonicalPath()));
        fileText.getStyle().setUnderlined(true);
        text.appendSibling(fileText);
        McIf.mc().addScheduledTask(() -> McIf.player().sendMessage(text));
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (output != null) {
            try {
                output.close();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}
Also used : ClickEvent(net.minecraft.util.text.event.ClickEvent) ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) IOException(java.io.IOException) TextComponentString(net.minecraft.util.text.TextComponentString) DiscoveryInfo(com.wynntils.modules.questbook.instances.DiscoveryInfo) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File)

Example 3 with DiscoveryInfo

use of com.wynntils.modules.questbook.instances.DiscoveryInfo in project Wynntils by Wynntils.

the class ChatManager method processRealMessage.

public static Pair<ITextComponent, Pair<Supplier<Boolean>, Function<ITextComponent, ITextComponent>>> processRealMessage(ITextComponent in) {
    if (in == null)
        return new Pair<>(in, null);
    ITextComponent original = in.createCopy();
    // Reorganizing
    if (!in.getUnformattedComponentText().isEmpty()) {
        ITextComponent newMessage = new TextComponentString("");
        for (ITextComponent component : in) {
            component = component.createCopy();
            component.getSiblings().clear();
            newMessage.appendSibling(component);
        }
        in = newMessage;
    }
    // language translation
    if (TranslationConfig.INSTANCE.enableTextTranslation) {
        boolean wasTranslated = translateMessage(in);
        if (wasTranslated && !TranslationConfig.INSTANCE.keepOriginal)
            return new Pair<>(null, null);
    }
    // timestamps
    if (ChatConfig.INSTANCE.addTimestampsToChat) {
        in = addTimestamp(in);
    }
    // popup sound
    if (McIf.getFormattedText(in).contains("§4 requires your ") && McIf.getUnformattedText(in).contains(" skill to be at least "))
        McIf.player().playSound(popOffSound, 1f, 1f);
    // wynnic and gavellian translator
    if (StringUtils.hasWynnic(McIf.getUnformattedText(in)) || StringUtils.hasGavellian(McIf.getUnformattedText(in))) {
        Pair<ArrayList<ITextComponent>, ArrayList<ITextComponent>> result = translateWynnicMessage(in.createCopy(), original);
        ArrayList<ITextComponent> untranslatedComponents = result.a;
        ArrayList<ITextComponent> translatedComponents = result.b;
        in = new TextComponentString("");
        boolean translateWynnic = false;
        boolean translateGavellian = false;
        switch(ChatConfig.INSTANCE.translateCondition) {
            case always:
                translateWynnic = true;
                translateGavellian = true;
                break;
            case discovery:
                if (!PlayerInfo.get(CharacterData.class).isLoaded()) {
                    translateWynnic = true;
                    translateGavellian = true;
                    break;
                }
                if (QuestManager.getCurrentDiscoveries().isEmpty() && !discoveriesLoaded) {
                    QuestManager.updateAnalysis(EnumSet.of(AnalysePosition.DISCOVERIES, AnalysePosition.SECRET_DISCOVERIES), true, true);
                    return new Pair<ITextComponent, Pair<Supplier<Boolean>, Function<ITextComponent, ITextComponent>>>(original, new Pair<>(ChatManager::getDiscoveriesLoaded, s -> ChatManager.processRealMessage(s).a));
                }
                translateWynnic = QuestManager.getCurrentDiscoveries().stream().map(DiscoveryInfo::getName).map(TextFormatting::getTextWithoutFormattingCodes).collect(Collectors.toList()).contains("Wynn Plains Monument");
                translateGavellian = QuestManager.getCurrentDiscoveries().stream().map(DiscoveryInfo::getName).map(TextFormatting::getTextWithoutFormattingCodes).collect(Collectors.toList()).contains("Ne du Valeos du Ellach");
                break;
            case book:
                if (!PlayerInfo.get(CharacterData.class).isLoaded()) {
                    translateWynnic = true;
                    translateGavellian = true;
                    break;
                }
                for (Slot slot : McIf.player().inventoryContainer.inventorySlots) {
                    if (slot.getStack().getItem() == Items.ENCHANTED_BOOK) {
                        if (!translateWynnic) {
                            translateWynnic = TextFormatting.getTextWithoutFormattingCodes(slot.getStack().getDisplayName()).equals("Ancient Wynnic Transcriber");
                        }
                        if (!translateGavellian) {
                            translateGavellian = TextFormatting.getTextWithoutFormattingCodes(slot.getStack().getDisplayName()).equals("High Gavellian Transcriber");
                        }
                    }
                    if (translateWynnic && translateGavellian) {
                        break;
                    }
                }
                break;
            case never:
                translateWynnic = false;
                translateGavellian = false;
                break;
        }
        WynncraftLanguage language;
        for (int i = 0; i < untranslatedComponents.size(); i++) {
            ITextComponent untranslated = untranslatedComponents.get(i);
            ITextComponent translated = translatedComponents.get(i);
            if (translateWynnic && StringUtils.hasWynnic(McIf.getUnformattedText(untranslated))) {
                language = WynncraftLanguage.WYNNIC;
            } else if (translateGavellian && StringUtils.hasGavellian(McIf.getUnformattedText(untranslated))) {
                language = WynncraftLanguage.GAVELLIAN;
            } else {
                language = WynncraftLanguage.NORMAL;
            }
            if (language != WynncraftLanguage.NORMAL) {
                if (ChatConfig.INSTANCE.translateIntoChat) {
                    translated.getSiblings().clear();
                    in.appendSibling(translated);
                } else {
                    untranslated.getSiblings().clear();
                    // join the next component
                    while (language != WynncraftLanguage.NORMAL && i + 1 < untranslatedComponents.size()) {
                        ITextComponent toAdd = untranslatedComponents.get(i + 1);
                        ITextComponent toHover = translatedComponents.get(i + 1);
                        if ((translateWynnic && StringUtils.hasWynnic(McIf.getUnformattedText(toAdd))) || (translateGavellian && StringUtils.hasGavellian(McIf.getUnformattedText(toAdd)))) {
                            toAdd.getSiblings().clear();
                            toHover.getSiblings().clear();
                            untranslated.appendSibling(toAdd);
                            translated.appendSibling(toHover);
                            i++;
                        } else {
                            language = WynncraftLanguage.NORMAL;
                        }
                    }
                    if (!McIf.getUnformattedText(translated).equals(McIf.getUnformattedText(untranslated))) {
                        untranslated.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, translated));
                    }
                    in.appendSibling(untranslated);
                }
            } else {
                untranslated.getSiblings().clear();
                if (!McIf.getUnformattedText(translated).equals(McIf.getUnformattedText(untranslated))) {
                    untranslated.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(TextFormatting.GRAY + "You don't know this language!")));
                }
                in.appendSibling(untranslated);
            }
        }
    }
    // clickable duel messages
    Matcher duelMatcher = duelReg.matcher(McIf.getUnformattedText(in));
    if (ChatConfig.INSTANCE.clickableDuelMessage && duelMatcher.find()) {
        String command = duelMatcher.group(1);
        for (ITextComponent textComponent : in.getSiblings()) {
            if (McIf.getUnformattedText(textComponent).contains("/duel")) {
                textComponent.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)).setUnderlined(true).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Duel!")));
            }
        }
    }
    // clickable coordinates
    if (ChatConfig.INSTANCE.clickableCoordinates && coordinateReg.matcher(McIf.getUnformattedText(in)).find()) {
        ITextComponent temp = new TextComponentString("");
        for (ITextComponent texts : in) {
            Matcher m = coordinateReg.matcher(texts.getUnformattedComponentText());
            if (!m.find()) {
                ITextComponent newComponent = new TextComponentString(texts.getUnformattedComponentText());
                newComponent.setStyle(texts.getStyle().createShallowCopy());
                temp.appendSibling(newComponent);
                continue;
            }
            // As far as i could find all other messages from the Wynnter Fair use text components properly.
            if (m.start() > 0 && McIf.getUnformattedText(texts).charAt(m.start() - 1) == '§')
                continue;
            String crdText = McIf.getUnformattedText(texts);
            Style style = texts.getStyle();
            String command = "/compass ";
            List<ITextComponent> crdMsg = new ArrayList<>();
            // Pre-text
            ITextComponent preText = new TextComponentString(crdText.substring(0, m.start()));
            preText.setStyle(style.createShallowCopy());
            crdMsg.add(preText);
            // Coordinates:
            command += crdText.substring(m.start(1), m.end(1)).replaceAll("[ ,]", "") + " ";
            command += crdText.substring(m.start(3), m.end(3)).replaceAll("[ ,]", "");
            ITextComponent clickableText = new TextComponentString(crdText.substring(m.start(), m.end()));
            clickableText.setStyle(style.createShallowCopy());
            clickableText.getStyle().setColor(TextFormatting.DARK_AQUA).setUnderlined(true).setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command)).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(command)));
            crdMsg.add(clickableText);
            // Post-text
            ITextComponent postText = new TextComponentString(crdText.substring(m.end()));
            postText.setStyle(style.createShallowCopy());
            crdMsg.add(postText);
            temp.getSiblings().addAll(crdMsg);
        }
        in = temp;
    }
    // chat item tooltips
    if (ChatItemManager.ENCODED_PATTERN.matcher(McIf.getUnformattedText(in)).find()) {
        ITextComponent temp = new TextComponentString("");
        for (ITextComponent comp : in) {
            Matcher m = ChatItemManager.ENCODED_PATTERN.matcher(comp.getUnformattedComponentText());
            if (!m.find()) {
                ITextComponent newComponent = new TextComponentString(comp.getUnformattedComponentText());
                newComponent.setStyle(comp.getStyle().createShallowCopy());
                temp.appendSibling(newComponent);
                continue;
            }
            do {
                String text = McIf.getUnformattedText(comp);
                Style style = comp.getStyle();
                ITextComponent item = ChatItemManager.decodeItem(m.group());
                if (item == null) {
                    // couldn't decode, skip
                    comp = new TextComponentString(comp.getUnformattedComponentText());
                    comp.setStyle(style.createShallowCopy());
                    continue;
                }
                ITextComponent preText = new TextComponentString(text.substring(0, m.start()));
                preText.setStyle(style.createShallowCopy());
                temp.appendSibling(preText);
                temp.appendSibling(item);
                comp = new TextComponentString(text.substring(m.end()));
                comp.setStyle(style.createShallowCopy());
                // recreate matcher for new substring
                m = ChatItemManager.ENCODED_PATTERN.matcher(comp.getUnformattedText());
            } while (// search for multiple items in the same message
            m.find());
            // leftover text after item(s)
            temp.appendSibling(comp);
        }
        in = temp;
    }
    return new Pair<>(in, null);
}
Also used : CharacterData(com.wynntils.core.framework.instances.data.CharacterData) net.minecraft.util.text(net.minecraft.util.text) ChatItemManager(com.wynntils.modules.utilities.managers.ChatItemManager) ForgeEventFactory(net.minecraftforge.event.ForgeEventFactory) Date(java.util.Date) McIf(com.wynntils.McIf) ChatOverlay(com.wynntils.modules.chat.overlays.ChatOverlay) ClickEvent(net.minecraft.util.text.event.ClickEvent) PositionedSoundRecord(net.minecraft.client.audio.PositionedSoundRecord) SimpleDateFormat(java.text.SimpleDateFormat) Pair(com.wynntils.core.utils.objects.Pair) Function(java.util.function.Function) Supplier(java.util.function.Supplier) TranslationManager(com.wynntils.webapi.services.TranslationManager) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Matcher(java.util.regex.Matcher) TranslationConfig(com.wynntils.modules.utilities.configs.TranslationConfig) WynncraftLanguage(com.wynntils.modules.chat.language.WynncraftLanguage) DiscoveryInfo(com.wynntils.modules.questbook.instances.DiscoveryInfo) DateFormat(java.text.DateFormat) EnumSet(java.util.EnumSet) SoundEvents(net.minecraft.init.SoundEvents) PlayerInfo(com.wynntils.core.framework.instances.PlayerInfo) Items(net.minecraft.init.Items) Collectors(java.util.stream.Collectors) ChatConfig(com.wynntils.modules.chat.configs.ChatConfig) StringUtils(com.wynntils.core.utils.StringUtils) List(java.util.List) CPacketEntityAction(net.minecraft.network.play.client.CPacketEntityAction) HoverEvent(net.minecraft.util.text.event.HoverEvent) Slot(net.minecraft.inventory.Slot) ResourceLocation(net.minecraft.util.ResourceLocation) AnalysePosition(com.wynntils.modules.questbook.enums.AnalysePosition) QuestManager(com.wynntils.modules.questbook.managers.QuestManager) PacketQueue(com.wynntils.modules.core.managers.PacketQueue) Pattern(java.util.regex.Pattern) SPacketCustomSound(net.minecraft.network.play.server.SPacketCustomSound) SoundEvent(net.minecraft.util.SoundEvent) HoverEvent(net.minecraft.util.text.event.HoverEvent) Matcher(java.util.regex.Matcher) ClickEvent(net.minecraft.util.text.event.ClickEvent) ArrayList(java.util.ArrayList) DiscoveryInfo(com.wynntils.modules.questbook.instances.DiscoveryInfo) Function(java.util.function.Function) WynncraftLanguage(com.wynntils.modules.chat.language.WynncraftLanguage) Slot(net.minecraft.inventory.Slot) Supplier(java.util.function.Supplier) Pair(com.wynntils.core.utils.objects.Pair)

Example 4 with DiscoveryInfo

use of com.wynntils.modules.questbook.instances.DiscoveryInfo in project Wynntils by Wynntils.

the class DiscoveriesPage method getSearchResults.

@Override
protected List<List<DiscoveryInfo>> getSearchResults(String text) {
    List<DiscoveryInfo> discoveries = new ArrayList<>(QuestManager.getCurrentDiscoveries());
    boolean isSearching = text != null && !text.isEmpty();
    // Apply Filters
    discoveries.removeIf(c -> {
        if (c.getType() == null)
            return true;
        switch(c.getType()) {
            case TERRITORY:
                return !territory;
            case WORLD:
                return !world;
            case SECRET:
                return !secret;
            default:
                return true;
        }
    });
    // Apply search terms
    if (isSearching) {
        discoveries.removeIf(c -> !doesSearchMatch(c.getName().toLowerCase(), text.toLowerCase()));
    }
    // Undiscovered data collection
    if (undiscoveredSecret || undiscoveredTerritory || undiscoveredWorld) {
        List<DiscoveryProfile> allDiscoveriesSearch = new ArrayList<>(WebManager.getDiscoveries());
        discoveries.addAll(allDiscoveriesSearch.stream().filter(c -> {
            // Shows/Hides discoveries if requirements met/not met
            if (!QuestBookConfig.INSTANCE.showAllDiscoveries) {
                if (c.getLevel() > PlayerInfo.get(CharacterData.class).getLevel()) {
                    return false;
                }
                boolean requirementsMet = true;
                for (String requirement : c.getRequirements()) {
                    requirementsMet &= QuestManager.getCurrentDiscoveries().stream().anyMatch(foundDiscovery -> TextFormatting.getTextWithoutFormattingCodes(foundDiscovery.getName()).equals(requirement));
                }
                if (!requirementsMet) {
                    return false;
                }
            }
            // Apply search term
            if (isSearching) {
                if (!doesSearchMatch(c.getName().toLowerCase(), text.toLowerCase())) {
                    return false;
                }
            }
            // Checks if already in list
            if (QuestManager.getCurrentDiscoveries().stream().anyMatch(foundDiscovery -> {
                boolean nameMatch = TextFormatting.getTextWithoutFormattingCodes(foundDiscovery.getName()).equals(c.getName());
                boolean levelMatch = foundDiscovery.getMinLevel() == c.getLevel();
                boolean typeMatch = foundDiscovery.getType().name().toLowerCase(Locale.ROOT).equals(c.getType());
                return nameMatch && levelMatch && typeMatch;
            })) {
                return false;
            }
            // Removes based on filters
            if (c.getType() == null)
                return false;
            switch(c.getType()) {
                case "territory":
                    return undiscoveredTerritory;
                case "world":
                    return undiscoveredWorld;
                case "secret":
                    return undiscoveredSecret;
                default:
                    return false;
            }
        }).map(discoveryProfile -> {
            DiscoveryType discoveryType = DiscoveryType.valueOf(discoveryProfile.getType().toUpperCase(Locale.ROOT));
            return new DiscoveryInfo(discoveryProfile.getName(), discoveryType, discoveryProfile.getLevel(), false);
        }).collect(Collectors.toList()));
    }
    discoveries.sort(Comparator.comparingInt(DiscoveryInfo::getMinLevel));
    return getListSplitIntoParts(discoveries, 13);
}
Also used : DiscoveryInfo(com.wynntils.modules.questbook.instances.DiscoveryInfo) CharacterData(com.wynntils.core.framework.instances.data.CharacterData) java.util(java.util) TerritoryProfile(com.wynntils.webapi.profiles.TerritoryProfile) McIf(com.wynntils.McIf) ScreenRenderer(com.wynntils.core.framework.rendering.ScreenRenderer) PositionedSoundRecord(net.minecraft.client.audio.PositionedSoundRecord) DiscoveryType(com.wynntils.modules.questbook.enums.DiscoveryType) WebManager(com.wynntils.webapi.WebManager) DiscoveryProfile(com.wynntils.webapi.profiles.DiscoveryProfile) DiscoveryInfo(com.wynntils.modules.questbook.instances.DiscoveryInfo) Utils(com.wynntils.core.utils.Utils) SoundEvents(net.minecraft.init.SoundEvents) PlayerInfo(com.wynntils.core.framework.instances.PlayerInfo) CompassManager(com.wynntils.modules.core.managers.CompassManager) ScaledResolution(net.minecraft.client.gui.ScaledResolution) IconContainer(com.wynntils.modules.questbook.instances.IconContainer) TextFormatting(net.minecraft.util.text.TextFormatting) GlStateManager(net.minecraft.client.renderer.GlStateManager) Request(com.wynntils.webapi.request.Request) IOException(java.io.IOException) CommonColors(com.wynntils.core.framework.rendering.colors.CommonColors) QuestBookConfig(com.wynntils.modules.questbook.configs.QuestBookConfig) Collectors(java.util.stream.Collectors) QuestBookListPage(com.wynntils.modules.questbook.instances.QuestBookListPage) Textures(com.wynntils.core.framework.rendering.textures.Textures) TextComponentString(net.minecraft.util.text.TextComponentString) RequestHandler(com.wynntils.webapi.request.RequestHandler) Location(com.wynntils.core.utils.objects.Location) MainWorldMapUI(com.wynntils.modules.map.overlays.ui.MainWorldMapUI) AnalysePosition(com.wynntils.modules.questbook.enums.AnalysePosition) QuestManager(com.wynntils.modules.questbook.managers.QuestManager) SmartFontRenderer(com.wynntils.core.framework.rendering.SmartFontRenderer) CharacterData(com.wynntils.core.framework.instances.data.CharacterData) DiscoveryType(com.wynntils.modules.questbook.enums.DiscoveryType) TextComponentString(net.minecraft.util.text.TextComponentString) DiscoveryProfile(com.wynntils.webapi.profiles.DiscoveryProfile)

Aggregations

DiscoveryInfo (com.wynntils.modules.questbook.instances.DiscoveryInfo)4 McIf (com.wynntils.McIf)2 PlayerInfo (com.wynntils.core.framework.instances.PlayerInfo)2 CharacterData (com.wynntils.core.framework.instances.data.CharacterData)2 AnalysePosition (com.wynntils.modules.questbook.enums.AnalysePosition)2 QuestManager (com.wynntils.modules.questbook.managers.QuestManager)2 IOException (java.io.IOException)2 Collectors (java.util.stream.Collectors)2 PositionedSoundRecord (net.minecraft.client.audio.PositionedSoundRecord)2 SoundEvents (net.minecraft.init.SoundEvents)2 ScreenRenderer (com.wynntils.core.framework.rendering.ScreenRenderer)1 SmartFontRenderer (com.wynntils.core.framework.rendering.SmartFontRenderer)1 CommonColors (com.wynntils.core.framework.rendering.colors.CommonColors)1 Textures (com.wynntils.core.framework.rendering.textures.Textures)1 StringUtils (com.wynntils.core.utils.StringUtils)1 Utils (com.wynntils.core.utils.Utils)1 Location (com.wynntils.core.utils.objects.Location)1 Pair (com.wynntils.core.utils.objects.Pair)1 ChatConfig (com.wynntils.modules.chat.configs.ChatConfig)1 WynncraftLanguage (com.wynntils.modules.chat.language.WynncraftLanguage)1