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();
}
}
}
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();
}
}
}
}
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);
}
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);
}
Aggregations