aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/AvgBinTooltip.java
blob: e81879af520eb2f748909da63fde75dc8507d8c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package de.hysky.skyblocker.skyblock.item.tooltip.adders;

import de.hysky.skyblocker.config.configs.GeneralConfig;
import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip;
import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder;
import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.Nullable;

import java.util.List;

public class AvgBinTooltip extends SimpleTooltipAdder {
	public AvgBinTooltip(int priority) {
		super(priority);
	}

	@Override
	public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List<Text> lines) {
		String neuName = stack.getNeuName();
		String internalID = stack.getSkyblockId();
		if (neuName == null || internalID == null) return;

		if (TooltipInfoType.ONE_DAY_AVERAGE.getData() == null || TooltipInfoType.THREE_DAY_AVERAGE.getData() == null) {
			ItemTooltip.nullWarning();
		} else {
                /*
                  We are skipping check average prices for potions, runes
                  and enchanted books because there is no data for their in API.
                 */
			if (!neuName.isEmpty() && LBinTooltip.lbinExist) {
				GeneralConfig.Average type = ItemTooltip.config.avg;

				// "No data" line because of API not keeping old data, it causes NullPointerException
				if (type == GeneralConfig.Average.ONE_DAY || type == GeneralConfig.Average.BOTH) {
					lines.add(
							Text.literal(String.format("%-19s", "1 Day Avg. Price:"))
							    .formatted(Formatting.GOLD)
							    .append(TooltipInfoType.ONE_DAY_AVERAGE.getData().get(neuName) == null
									    ? Text.literal("No data").formatted(Formatting.RED)
									    : ItemTooltip.getCoinsMessage(TooltipInfoType.ONE_DAY_AVERAGE.getData().get(neuName).getAsDouble(), stack.getCount())
							    )
					);
				}
				if (type == GeneralConfig.Average.THREE_DAY || type == GeneralConfig.Average.BOTH) {
					lines.add(
							Text.literal(String.format("%-19s", "3 Day Avg. Price:"))
							    .formatted(Formatting.GOLD)
							    .append(TooltipInfoType.THREE_DAY_AVERAGE.getData().get(neuName) == null
									    ? Text.literal("No data").formatted(Formatting.RED)
									    : ItemTooltip.getCoinsMessage(TooltipInfoType.THREE_DAY_AVERAGE.getData().get(neuName).getAsDouble(), stack.getCount())
							    )
					);
				}
			}
		}
	}

	@Override
	public boolean isEnabled() {
		//Both 1 day and 3 day averages use the same config option, so we only need to check one
		return TooltipInfoType.THREE_DAY_AVERAGE.isTooltipEnabled();
	}
}