Search in sources :

Example 1 with Pair

use of com.wynntils.core.utils.objects.Pair in project Wynntils by Wynntils.

the class LootRunPath method generatePoints.

private Pair<List<LootRunPath.LootRunPathLocation>, List<Vector3d>> generatePoints(int sampleRate) {
    Pair<List<Location>, List<Vector3d>> sample = spline.sample(sampleRate);
    List<Location> rawLocations = sample.a;
    List<LootRunPath.LootRunPathLocation> locations = new ArrayList<>();
    Iterator<CustomColor> colorIterator = COLORS.iterator();
    CustomColor currentColor = null;
    CustomColor nextColor = colorIterator.next();
    float changeRed = 0;
    float changeGreen = 0;
    float changeBlue = 0;
    for (int i = 0; i < rawLocations.size(); i++) {
        if (i % (sampleRate * MapConfig.LootRun.INSTANCE.cycleDistance) == 0) {
            currentColor = new CustomColor(nextColor);
            if (!colorIterator.hasNext()) {
                colorIterator = COLORS.iterator();
            }
            nextColor = colorIterator.next();
            changeRed = (nextColor.r - currentColor.r) / (sampleRate * MapConfig.LootRun.INSTANCE.cycleDistance);
            changeGreen = (nextColor.g - currentColor.g) / (sampleRate * MapConfig.LootRun.INSTANCE.cycleDistance);
            changeBlue = (nextColor.b - currentColor.b) / (sampleRate * MapConfig.LootRun.INSTANCE.cycleDistance);
        } else {
            currentColor = new CustomColor(currentColor);
            currentColor.r += changeRed;
            currentColor.g += changeGreen;
            currentColor.b += changeBlue;
        }
        LootRunPathLocation location = new LootRunPathLocation(rawLocations.get(i), currentColor);
        locations.add(location);
    }
    List<LootRunPath.LootRunPathLocation> locationsSample = locations;
    List<Vector3d> derivative = sample.b;
    return new Pair<>(locationsSample, derivative);
}
Also used : Vector3d(javax.vecmath.Vector3d) CustomColor(com.wynntils.core.framework.rendering.colors.CustomColor) Location(com.wynntils.core.utils.objects.Location) Pair(com.wynntils.core.utils.objects.Pair)

Example 2 with Pair

use of com.wynntils.core.utils.objects.Pair in project Wynntils by Wynntils.

the class LootRunPath method generatePointsByChunk.

private Pair<Long2ObjectMap<List<List<LootRunPath.LootRunPathLocation>>>, Long2ObjectMap<List<List<Vector3d>>>> generatePointsByChunk(List<LootRunPathLocation> locationsList, List<Vector3d> derivativesList) {
    ChunkPos lastChunkPos = null;
    List<LootRunPath.LootRunPathLocation> lastLocationList = null;
    List<Vector3d> lastDirectionList = null;
    Long2ObjectMap<List<List<LootRunPath.LootRunPathLocation>>> sampleByChunk = new Long2ObjectOpenHashMap<>();
    Long2ObjectMap<List<List<Vector3d>>> derivativeByChunk = new Long2ObjectOpenHashMap<>();
    for (int i = 0; i < locationsList.size(); i++) {
        LootRunPathLocation location = locationsList.get(i);
        Vector3d direction = derivativesList.get(i);
        ChunkPos currentChunkPos = new ChunkPos(MathHelper.fastFloor(location.getLocation().x) >> 4, MathHelper.fastFloor(location.getLocation().z) >> 4);
        if (!currentChunkPos.equals(lastChunkPos)) {
            if (lastChunkPos != null && location.getLocation().distance(locationsList.get(i - 1).getLocation()) < 32) {
                lastLocationList.add(location);
                lastDirectionList.add(direction);
            }
            lastChunkPos = currentChunkPos;
            sampleByChunk.putIfAbsent(ChunkPos.asLong(currentChunkPos.x, currentChunkPos.z), new ArrayList<>());
            derivativeByChunk.putIfAbsent(ChunkPos.asLong(currentChunkPos.x, currentChunkPos.z), new ArrayList<>());
            lastLocationList = new ArrayList<>();
            lastDirectionList = new ArrayList<>();
            sampleByChunk.get(ChunkPos.asLong(currentChunkPos.x, currentChunkPos.z)).add(lastLocationList);
            derivativeByChunk.get(ChunkPos.asLong(currentChunkPos.x, currentChunkPos.z)).add(lastDirectionList);
        }
        lastLocationList.add(location);
        lastDirectionList.add(derivativesList.get(i));
    }
    return new Pair<>(sampleByChunk, derivativeByChunk);
}
Also used : Vector3d(javax.vecmath.Vector3d) ChunkPos(net.minecraft.util.math.ChunkPos) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Pair(com.wynntils.core.utils.objects.Pair)

Example 3 with Pair

use of com.wynntils.core.utils.objects.Pair in project Wynntils by Wynntils.

the class ChatManager method translateWynnicMessage.

// returns a list of untranslated components and translated components
private static Pair<ArrayList<ITextComponent>, ArrayList<ITextComponent>> translateWynnicMessage(ITextComponent in, ITextComponent original) {
    boolean capital = false;
    boolean isGuildOrParty = Pattern.compile(TabManager.DEFAULT_GUILD_REGEX.replace("&", "§")).matcher(McIf.getFormattedText(original)).find() || Pattern.compile(TabManager.DEFAULT_PARTY_REGEX.replace("&", "§")).matcher(McIf.getFormattedText(original)).find();
    boolean foundStart = false;
    boolean foundEndTimestamp = !ChatConfig.INSTANCE.addTimestampsToChat;
    boolean previousTranslated = false;
    ArrayList<ITextComponent> untranslatedComponents = new ArrayList<>();
    ArrayList<ITextComponent> translatedComponents = new ArrayList<>();
    WynncraftLanguage language = WynncraftLanguage.NORMAL;
    if (foundEndTimestamp && !McIf.getUnformattedText(in.getSiblings().get(ChatConfig.INSTANCE.addTimestampsToChat ? 3 : 0)).contains("/") && !isGuildOrParty) {
        foundStart = true;
    }
    for (ITextComponent component : in) {
        component = component.createCopy();
        component.getSiblings().clear();
        String currentNonTranslated = "";
        // oldText is the untranslated component that is being built
        // newText is the translated component that is being built
        StringBuilder oldText = new StringBuilder();
        StringBuilder newText = new StringBuilder();
        StringBuilder number = new StringBuilder();
        for (char character : McIf.getUnformattedText(component).toCharArray()) {
            if (StringUtils.isWynnicNumber(character)) {
                if (previousTranslated) {
                    oldText.append(currentNonTranslated);
                    newText.append(currentNonTranslated);
                    currentNonTranslated = "";
                }
                if (!previousTranslated || language != WynncraftLanguage.WYNNIC) {
                    previousTranslated = true;
                    ITextComponent oldComponent = new TextComponentString(oldText.toString());
                    oldComponent.setStyle(component.getStyle().createDeepCopy());
                    untranslatedComponents.add(oldComponent);
                    ITextComponent newComponent = new TextComponentString(newText.toString());
                    newComponent.setStyle(component.getStyle().createDeepCopy());
                    if (language.getFormat() != null)
                        newComponent.getStyle().setColor(language.getFormat());
                    translatedComponents.add(newComponent);
                    language = WynncraftLanguage.WYNNIC;
                    oldText = new StringBuilder();
                    newText = new StringBuilder();
                }
                number.append(character);
            } else {
                if (!number.toString().isEmpty()) {
                    oldText.append(number.toString());
                    newText.append(StringUtils.translateNumberFromWynnic(number.toString()));
                    number = new StringBuilder();
                }
                if (StringUtils.isWynnic(character)) {
                    if (previousTranslated) {
                        newText.append(currentNonTranslated);
                        oldText.append(currentNonTranslated);
                        currentNonTranslated = "";
                    }
                    if (!previousTranslated || language != WynncraftLanguage.WYNNIC) {
                        previousTranslated = true;
                        ITextComponent oldComponent = new TextComponentString(oldText.toString());
                        oldComponent.setStyle(component.getStyle().createDeepCopy());
                        untranslatedComponents.add(oldComponent);
                        ITextComponent newComponent = new TextComponentString(newText.toString());
                        newComponent.setStyle(component.getStyle().createDeepCopy());
                        if (language.getFormat() != null)
                            newComponent.getStyle().setColor(language.getFormat());
                        translatedComponents.add(newComponent);
                        language = WynncraftLanguage.WYNNIC;
                        oldText = new StringBuilder();
                        newText = new StringBuilder();
                    }
                    String englishVersion = StringUtils.translateCharacterFromWynnic(character);
                    if (capital && englishVersion.matches("[a-z]")) {
                        englishVersion = Character.toString(Character.toUpperCase(englishVersion.charAt(0)));
                    }
                    capital = ".?!".contains(englishVersion);
                    oldText.append(character);
                    newText.append(englishVersion);
                } else if (StringUtils.isGavellian(character)) {
                    if (previousTranslated) {
                        newText.append(currentNonTranslated);
                        oldText.append(currentNonTranslated);
                        currentNonTranslated = "";
                    }
                    if (!previousTranslated || language != WynncraftLanguage.GAVELLIAN) {
                        previousTranslated = true;
                        ITextComponent oldComponent = new TextComponentString(oldText.toString());
                        oldComponent.setStyle(component.getStyle().createDeepCopy());
                        untranslatedComponents.add(oldComponent);
                        ITextComponent newComponent = new TextComponentString(newText.toString());
                        newComponent.setStyle(component.getStyle().createDeepCopy());
                        if (language.getFormat() != null)
                            newComponent.getStyle().setColor(language.getFormat());
                        translatedComponents.add(newComponent);
                        language = WynncraftLanguage.GAVELLIAN;
                        oldText = new StringBuilder();
                        newText = new StringBuilder();
                    }
                    String englishVersion = StringUtils.translateCharacterFromGavellian(character);
                    if (capital && englishVersion.matches("[a-z]")) {
                        englishVersion = Character.toString(Character.toUpperCase(englishVersion.charAt(0)));
                        capital = false;
                    }
                    newText.append(englishVersion);
                    oldText.append(character);
                } else if (Character.toString(character).matches(nonTranslatable) || Character.toString(character).matches(optionalTranslatable)) {
                    if (previousTranslated) {
                        currentNonTranslated += character;
                    } else {
                        oldText.append(character);
                        newText.append(character);
                    }
                    capital = ".?!".contains(Character.toString(character));
                } else {
                    if (previousTranslated) {
                        previousTranslated = false;
                        ITextComponent oldComponent = new TextComponentString(oldText.toString());
                        oldComponent.setStyle(component.getStyle().createDeepCopy());
                        untranslatedComponents.add(oldComponent);
                        ITextComponent newComponent = new TextComponentString(newText.toString());
                        newComponent.setStyle(component.getStyle().createDeepCopy());
                        if (language.getFormat() != null)
                            newComponent.getStyle().setColor(language.getFormat());
                        translatedComponents.add(newComponent);
                        oldText = new StringBuilder(currentNonTranslated);
                        newText = new StringBuilder(currentNonTranslated);
                        currentNonTranslated = "";
                    }
                    oldText.append(character);
                    newText.append(character);
                    language = WynncraftLanguage.NORMAL;
                    if (character != ' ') {
                        capital = false;
                    }
                }
            }
        }
        if (!number.toString().isEmpty() && previousTranslated) {
            oldText.append(number);
            newText.append(StringUtils.translateNumberFromWynnic(number.toString()));
            language = WynncraftLanguage.WYNNIC;
        }
        if (!currentNonTranslated.isEmpty()) {
            oldText.append(currentNonTranslated);
            if (previousTranslated) {
                newText.append(currentNonTranslated);
            }
        }
        ITextComponent oldComponent = new TextComponentString(oldText.toString());
        oldComponent.setStyle(component.getStyle().createDeepCopy());
        untranslatedComponents.add(oldComponent);
        ITextComponent newComponent = new TextComponentString(newText.toString());
        newComponent.setStyle(component.getStyle().createDeepCopy());
        if (language.getFormat() != null)
            newComponent.getStyle().setColor(language.getFormat());
        translatedComponents.add(newComponent);
        // if found, capitalize
        if (!foundStart) {
            if (foundEndTimestamp) {
                if (McIf.getUnformattedText(in.getSiblings().get(ChatConfig.INSTANCE.addTimestampsToChat ? 3 : 0)).contains("/")) {
                    foundStart = McIf.getUnformattedText(component).contains(":");
                } else if (isGuildOrParty) {
                    foundStart = McIf.getUnformattedText(component).contains("]");
                }
            } else if (component.getUnformattedComponentText().contains("] ")) {
                foundEndTimestamp = true;
                if (!McIf.getUnformattedText(in.getSiblings().get(ChatConfig.INSTANCE.addTimestampsToChat ? 3 : 0)).contains("/") && !isGuildOrParty) {
                    foundStart = true;
                }
            }
            if (foundStart) {
                capital = true;
            }
        }
    }
    return new Pair<>(untranslatedComponents, translatedComponents);
}
Also used : WynncraftLanguage(com.wynntils.modules.chat.language.WynncraftLanguage) ArrayList(java.util.ArrayList) Pair(com.wynntils.core.utils.objects.Pair)

Example 4 with Pair

use of com.wynntils.core.utils.objects.Pair in project Wynntils by Wynntils.

the class ChatOverlay method addLine.

private void addLine(ChatTab tab, ITextComponent chatComponent, int updateCounter, boolean displayOnly, int chatLineId, boolean noProcessing) {
    ITextComponent originalMessage = chatComponent.createCopy();
    // message processor
    ITextComponent displayedMessage;
    Pair<Supplier<Boolean>, Function<ITextComponent, ITextComponent>> queueInfo = null;
    if (noProcessing) {
        displayedMessage = originalMessage;
    } else {
        Pair<ITextComponent, Pair<Supplier<Boolean>, Function<ITextComponent, ITextComponent>>> result = ChatManager.processRealMessage(originalMessage.createCopy());
        displayedMessage = result.a;
        queueInfo = result.b;
    }
    if (displayedMessage == null)
        return;
    // spam filter
    if (!noProcessing && tab.getLastMessage() != null) {
        if (ChatConfig.INSTANCE.blockChatSpamFilter && McIf.getFormattedText(tab.getLastMessage()).equals(McIf.getFormattedText(originalMessage)) && chatLineId == 0) {
            try {
                List<ChatLine> lines = tab.getCurrentMessages();
                if (lines != null && lines.size() > 0) {
                    // Delete all the lines with the previous group id found
                    int thisGroupId = tab.getCurrentGroupId() - 1;
                    for (int i = 0; i < lines.size(); ++i) {
                        if (lines.get(i) instanceof GroupedChatLine && ((GroupedChatLine) lines.get(i)).getGroupId() == thisGroupId) {
                            lines.remove(i);
                            --i;
                        }
                    }
                    // Add a new set of lines (reusing the same id, since it is no longer used)
                    ITextComponent chatWithCounter = displayedMessage.createCopy();
                    ITextComponent counter = new TextComponentString(" [" + (tab.getLastAmount()) + "x]");
                    counter.getStyle().setColor(TextFormatting.GRAY);
                    chatWithCounter.appendSibling(counter);
                    int chatWidth = MathHelper.floor((float) getChatWidth() / getChatScale());
                    List<ITextComponent> chatLines = GuiUtilRenderComponents.splitText(chatWithCounter, chatWidth, McIf.mc().fontRenderer, false, false);
                    Collections.reverse(chatLines);
                    lines.addAll(0, chatLines.stream().map(c -> new GroupedChatLine(updateCounter, c, chatLineId, thisGroupId)).collect(Collectors.toList()));
                    while (tab.getCurrentMessages().size() > ChatConfig.INSTANCE.chatHistorySize) {
                        tab.getCurrentMessages().remove(tab.getCurrentMessages().size() - 1);
                    }
                    tab.updateLastMessageAndAmount(originalMessage, tab.getLastAmount() + 1);
                    refreshChat();
                    if (queueInfo != null)
                        tab.getQueue().put(thisGroupId, new Pair<>(queueInfo.a, queueInfo.b));
                    return;
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        } else {
            tab.updateLastMessageAndAmount(originalMessage, 2);
        }
    } else if (!noProcessing) {
        tab.updateLastMessageAndAmount(originalMessage, 2);
    }
    // push mention
    if (!noProcessing && ChatManager.processUserMention(displayedMessage, originalMessage))
        tab.pushMention();
    // continue mc code
    int thisGroupId = noProcessing ? 0 : tab.increaseCurrentGroupId();
    int chatWidth = MathHelper.floor((float) getChatWidth() / getChatScale());
    List<ITextComponent> list = GuiUtilRenderComponents.splitText(displayedMessage, chatWidth, McIf.mc().fontRenderer, false, false);
    boolean flag = tab == getCurrentTab() && getChatOpen();
    for (ITextComponent itextcomponent : list) {
        if (flag && scrollPos > 0) {
            isScrolled = true;
            scroll(1);
        }
        tab.addMessage(noProcessing ? new ChatLine(updateCounter, itextcomponent, chatLineId) : new GroupedChatLine(updateCounter, itextcomponent, chatLineId, thisGroupId));
    }
    if (queueInfo != null)
        tab.getQueue().put(thisGroupId, new Pair<>(queueInfo.a, queueInfo.b));
    while (tab.getCurrentMessages().size() > ChatConfig.INSTANCE.chatHistorySize) {
        tab.getCurrentMessages().remove(tab.getCurrentMessages().size() - 1);
    }
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) TextComponentString(net.minecraft.util.text.TextComponentString) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Pair(com.wynntils.core.utils.objects.Pair)

Example 5 with Pair

use of com.wynntils.core.utils.objects.Pair 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)

Aggregations

Pair (com.wynntils.core.utils.objects.Pair)10 ArrayList (java.util.ArrayList)4 WynncraftLanguage (com.wynntils.modules.chat.language.WynncraftLanguage)3 ItemStack (net.minecraft.item.ItemStack)3 McIf (com.wynntils.McIf)2 PlayerInfo (com.wynntils.core.framework.instances.PlayerInfo)2 CustomColor (com.wynntils.core.framework.rendering.colors.CustomColor)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Vector3d (javax.vecmath.Vector3d)2 Pointer (com.sun.jna.Pointer)1 Reference (com.wynntils.Reference)1 WynnWorldEvent (com.wynntils.core.events.custom.WynnWorldEvent)1 FrameworkManager (com.wynntils.core.framework.FrameworkManager)1 FilterType (com.wynntils.core.framework.enums.FilterType)1 CharacterData (com.wynntils.core.framework.instances.data.CharacterData)1 SocialData (com.wynntils.core.framework.instances.data.SocialData)1 ServerUtils (com.wynntils.core.utils.ServerUtils)1 StringUtils (com.wynntils.core.utils.StringUtils)1