Skip to content

Commit 275cb9c

Browse files
fix: new stat discovered message
1 parent 72e9495 commit 275cb9c

5 files changed

Lines changed: 99 additions & 1 deletion

File tree

commons/src/main/java/net/swofty/commons/statistics/ItemStatistic.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ public String getPrefix() {
130130
return isPercentage ? "" : "+";
131131
}
132132

133+
public String getFullDisplayName() {
134+
return displayColor + symbol + " " + displayName;
135+
}
136+
133137
public static ItemStatistics getOfAllBaseValues() {
134138
ItemStatistics.Builder builder = ItemStatistics.builder();
135139
for (ItemStatistic stat : ItemStatistic.values()) {

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/data/SkyBlockDataHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ public Map<String, Object> getCoopValues() {
207207

208208
// Same Data enum as before - unchanged
209209
public enum Data {
210+
EXPERIENCED_STATISTICS("experienced_statistics", false, false, false,
211+
DatapointStringList.class, new DatapointStringList("experienced_statistics")),
210212
PROFILE_NAME("profile_name", false, true, false,
211213
DatapointString.class, new DatapointString("profile_name", "null"),
212214
(player, datapoint) -> {},

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/event/actions/custom/collection/ActionCollectionDisplay.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void run(CollectionUpdateEvent event) {
7373
switch (unlock.type()) {
7474
case RECIPE -> {
7575
CollectionCategory.UnlockRecipe recipeUnlock = (CollectionCategory.UnlockRecipe) unlock;
76-
if (recipeUnlock.getRecipe() != null) {
76+
if (recipeUnlock.getRecipe() == null) {
7777
Logger.error("We have a null recipe in collection unlocks for " + event.getItemType().name() + " in " + event.getPlayer().getCollection().get(event.getItemType()));
7878
return;
7979
}

type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/user/statistics/PlayerStatistics.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import lombok.Setter;
66
import net.kyori.adventure.bossbar.BossBar;
77
import net.kyori.adventure.text.Component;
8+
import net.kyori.adventure.text.event.ClickEvent;
89
import net.minestom.server.MinecraftServer;
910
import net.minestom.server.entity.LivingEntity;
1011
import net.minestom.server.entity.Player;
@@ -13,14 +14,17 @@
1314
import net.minestom.server.timer.ExecutionType;
1415
import net.minestom.server.timer.Scheduler;
1516
import net.minestom.server.timer.TaskSchedule;
17+
import net.swofty.commons.StringUtility;
1618
import net.swofty.commons.item.ItemType;
1719
import net.swofty.commons.item.PotatoType;
1820
import net.swofty.commons.item.attribute.attributes.ItemAttributeHotPotatoBookData;
1921
import net.swofty.commons.item.attribute.attributes.ItemAttributeRuneInfusedWith;
2022
import net.swofty.commons.statistics.ItemStatistic;
2123
import net.swofty.commons.statistics.ItemStatistics;
24+
import net.swofty.type.generic.data.datapoints.DatapointStringList;
2225
import net.swofty.type.skyblockgeneric.SkyBlockGenericLoader;
2326
import net.swofty.type.skyblockgeneric.bestiary.BestiaryData;
27+
import net.swofty.type.skyblockgeneric.data.SkyBlockDataHandler;
2428
import net.swofty.type.skyblockgeneric.data.datapoints.DatapointSkills;
2529
import net.swofty.type.skyblockgeneric.data.datapoints.DatapointSkyBlockExperience;
2630
import net.swofty.type.skyblockgeneric.enchantment.EnchantmentType;
@@ -426,9 +430,51 @@ public static void run() {
426430
manaLoop();
427431
missionLoop();
428432
statisticsLoop();
433+
experiencedStatisticsLoop();
429434
speedLoop();
430435
}
431436

437+
public static void experiencedStatisticsLoop() {
438+
Scheduler scheduler = MinecraftServer.getSchedulerManager();
439+
scheduler.submitTask(() -> {
440+
SkyBlockGenericLoader.getLoadedPlayers().forEach(player -> {
441+
Thread.startVirtualThread(() -> {
442+
List<String> experiencedStatistics = player.getSkyblockDataHandler().get(
443+
SkyBlockDataHandler.Data.EXPERIENCED_STATISTICS, DatapointStringList.class
444+
).getValue();
445+
446+
ItemStatistics statistics = player.getStatistics().allStatistics();
447+
for (ItemStatistic statistic : ItemStatistic.values()) {
448+
if (experiencedStatistics.contains(statistic.name())) continue;
449+
450+
@Nullable StatisticDescription description = StatisticDescription.fromStatistic(statistic);
451+
if (description == null) continue;
452+
453+
double experiencedValue = statistics.getOverall(statistic);
454+
if (experiencedValue <= 0) continue;
455+
456+
experiencedStatistics.add(statistic.name());
457+
player.getSkyblockDataHandler().get(
458+
SkyBlockDataHandler.Data.EXPERIENCED_STATISTICS, DatapointStringList.class
459+
).setValue(experiencedStatistics);
460+
461+
player.sendMessage("§a§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬");
462+
player.sendMessage("§6§lNEW STAT DISCOVERED! §r" + statistic.getFullDisplayName());
463+
player.sendMessage(" ");
464+
player.sendMessage(description.getDescription());
465+
player.sendMessage(" ");
466+
player.sendMessage(Component.text("§e§lCLICK HERE §r§eto learn more on the Official SkyBlock Wiki!")
467+
.hoverEvent(Component.text("§eClick to view the " + statistic.getDisplayName() + " §eWiki page!"))
468+
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, "https://wiki.hypixel.net/" + description.getWikiName()))
469+
);
470+
player.sendMessage("§a§l▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬");
471+
}
472+
});
473+
});
474+
return TaskSchedule.seconds(10);
475+
});
476+
}
477+
432478
public static void barLoop() {
433479
Scheduler scheduler = MinecraftServer.getSchedulerManager();
434480
scheduler.submitTask(() -> {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package net.swofty.type.skyblockgeneric.user.statistics;
2+
3+
import lombok.Getter;
4+
import net.swofty.commons.statistics.ItemStatistic;
5+
6+
import javax.annotation.Nullable;
7+
8+
@Getter
9+
public enum StatisticDescription {
10+
FORAGING_FORTUNE(ItemStatistic.FORAGING_FORTUNE,
11+
ItemStatistic.FORAGING_FORTUNE.getFullDisplayName() + " §7increases how many drops you get from breaking wood. For every §61" + ItemStatistic.FORAGING_FORTUNE.getFullDisplayName() + "§7, you gain a §a1% §7chance for an additional drop."),
12+
FARMING_FORTUNE(ItemStatistic.FARMING_FORTUNE,
13+
ItemStatistic.FARMING_FORTUNE.getFullDisplayName() + " §7increases how many drops you get from breaking crops. For every §61" + ItemStatistic.FARMING_FORTUNE.getFullDisplayName() + "§7, you gain a §a1% §7chance for an additional drop."),
14+
;
15+
16+
private final ItemStatistic attachedStatistic;
17+
private final String description;
18+
19+
StatisticDescription(ItemStatistic attachedStatistic, String description) {
20+
this.attachedStatistic = attachedStatistic;
21+
this.description = description;
22+
}
23+
24+
public String getWikiName() {
25+
// Return name() but capitalise it properly, keeping underscores, e.g. FORAGING_FORTUNE -> Foraging_Fortune
26+
String[] parts = this.name().split("_");
27+
StringBuilder wikiName = new StringBuilder();
28+
for (int i = 0; i < parts.length; i++) {
29+
String part = parts[i];
30+
wikiName.append(part.substring(0, 1).toUpperCase()).append(part.substring(1).toLowerCase());
31+
if (i < parts.length - 1) {
32+
wikiName.append("_");
33+
}
34+
}
35+
return wikiName.toString();
36+
}
37+
38+
public static @Nullable StatisticDescription fromStatistic(ItemStatistic statistic) {
39+
for (StatisticDescription description : values()) {
40+
if (description.getAttachedStatistic() == statistic) {
41+
return description;
42+
}
43+
}
44+
return null;
45+
}
46+
}

0 commit comments

Comments
 (0)