aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2021-04-09 14:48:24 +0200
committerCow <cow@volloeko.de>2021-04-09 14:48:24 +0200
commita3f2cd8c51179c54661751525ae02249d0341934 (patch)
treed6db22266f6cf94312ca24aba4fd69b685f1510b /src/main/java
parent911e7b32e781b327fb87f7229bfea34389636b5d (diff)
downloadCowlection-a3f2cd8c51179c54661751525ae02249d0341934.tar.gz
Cowlection-a3f2cd8c51179c54661751525ae02249d0341934.tar.bz2
Cowlection-a3f2cd8c51179c54661751525ae02249d0341934.zip
Added Dungeons Master mode support
- fixed unexpected API-related exceptions voiding chat output
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/cowtipper/cowlection/command/MooCommand.java52
-rw-r--r--src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java22
-rw-r--r--src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java17
3 files changed, 69 insertions, 22 deletions
diff --git a/src/main/java/de/cowtipper/cowlection/command/MooCommand.java b/src/main/java/de/cowtipper/cowlection/command/MooCommand.java
index 52dee14..f924774 100644
--- a/src/main/java/de/cowtipper/cowlection/command/MooCommand.java
+++ b/src/main/java/de/cowtipper/cowlection/command/MooCommand.java
@@ -532,15 +532,25 @@ public class MooCommand extends CommandBase {
for (Map.Entry<String, HySkyBlockStats.Profile.Dungeons.Type> dungeonTypeEntry : dungeonTypes.entrySet()) {
// dungeon type entry for chat
HySkyBlockStats.Profile.Dungeons.Type dungeonType = dungeonTypeEntry.getValue();
+ if (!dungeonType.hasPlayed()) {
+ // never played this dungeon type
+ continue;
+ }
String dungeonTypeName = Utils.fancyCase(dungeonTypeEntry.getKey());
- dungeonsComponent.appendFreshSibling(new MooChatComponent.KeyValueChatComponent(" " + dungeonTypeName, dungeonType.getSummary()))
+ boolean isMasterFloor = dungeonTypeName.startsWith("Master ");
+ dungeonsComponent.appendFreshSibling(new MooChatComponent.KeyValueChatComponent(" " + dungeonTypeName, dungeonType.getSummary(isMasterFloor)))
.setHover(dungeonHover);
// dungeon type entry for tooltip
- int dungeonTypeLevel = dungeonTypeEntry.getValue().getLevel();
- dungeonHover.appendFreshSibling(new MooChatComponent.KeyValueChatComponent(dungeonTypeName, "Level " + (MooConfig.useRomanNumerals() ? Utils.convertArabicToRoman(dungeonTypeLevel) : dungeonTypeLevel)));
+ if (isMasterFloor) {
+ dungeonHover.appendFreshSibling(new MooChatComponent(dungeonTypeName).gold());
+ } else {
+ // non-master dungeon
+ int dungeonTypeLevel = dungeonTypeEntry.getValue().getLevel();
+ dungeonHover.appendFreshSibling(new MooChatComponent.KeyValueChatComponent(dungeonTypeName, "Level " + (MooConfig.useRomanNumerals() ? Utils.convertArabicToRoman(dungeonTypeLevel) : dungeonTypeLevel)));
+ }
// for each floor
- Map<String, StringBuilder> floorStats = new LinkedHashMap<>();
+ SortedMap<String, StringBuilder> floorStats = new TreeMap<>();
// ... add completed floors:
if (dungeonType.getTierCompletions() != null) {
for (Map.Entry<String, Integer> floorCompletions : dungeonType.getTierCompletions().entrySet()) {
@@ -551,21 +561,31 @@ public class MooCommand extends CommandBase {
}
}
// ... add played floors
- for (Map.Entry<String, Integer> floorPlayed : dungeonType.getTimesPlayed().entrySet()) {
- StringBuilder floorSummary = floorStats.get(floorPlayed.getKey());
- if (floorSummary == null) {
- // hasn't beaten this floor, but already attempted it
- floorSummary = new StringBuilder("0");
- floorStats.put(floorPlayed.getKey(), floorSummary);
+ Map<String, Integer> dungeonTypeTimesPlayed = dungeonType.getTimesPlayed();
+ if (dungeonTypeTimesPlayed != null) {
+ for (Map.Entry<String, Integer> floorPlayed : dungeonTypeTimesPlayed.entrySet()) {
+ StringBuilder floorSummary = floorStats.get(floorPlayed.getKey());
+ if (floorSummary == null) {
+ // hasn't beaten this floor, but already attempted it
+ floorSummary = new StringBuilder("0");
+ floorStats.put(floorPlayed.getKey(), floorSummary);
+ }
+ // played floor count:
+ floorSummary.append(EnumChatFormatting.DARK_GRAY).append(" / ").append(EnumChatFormatting.YELLOW).append(floorPlayed.getValue());
+ }
+ } else {
+ // missing value for attempted floors, only show completed floors
+ for (StringBuilder floorSummary : floorStats.values()) {
+ floorSummary.append(EnumChatFormatting.DARK_GRAY).append(" / ").append(EnumChatFormatting.YELLOW).append(EnumChatFormatting.OBFUSCATED).append("#");
}
- // played floor count:
- floorSummary.append(EnumChatFormatting.DARK_GRAY).append(" / ").append(EnumChatFormatting.YELLOW).append(floorPlayed.getValue());
}
// ... add best scores
- for (Map.Entry<String, Integer> bestScores : dungeonType.getBestScore().entrySet()) {
- StringBuilder floorSummary = floorStats.getOrDefault(bestScores.getKey(), new StringBuilder());
- // best floor score:
- floorSummary.append(EnumChatFormatting.DARK_GRAY).append(" (").append(EnumChatFormatting.WHITE).append(bestScores.getValue()).append(EnumChatFormatting.DARK_GRAY).append(")");
+ if (dungeonType.getBestScore() != null) {
+ for (Map.Entry<String, Integer> bestScores : dungeonType.getBestScore().entrySet()) {
+ StringBuilder floorSummary = floorStats.getOrDefault(bestScores.getKey(), new StringBuilder());
+ // best floor score:
+ floorSummary.append(EnumChatFormatting.DARK_GRAY).append(" (").append(EnumChatFormatting.WHITE).append(bestScores.getValue()).append(EnumChatFormatting.DARK_GRAY).append(")");
+ }
}
// add floor stats to dungeon type:
diff --git a/src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java b/src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java
index 0efd9c5..9eae1c3 100644
--- a/src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java
+++ b/src/main/java/de/cowtipper/cowlection/command/exception/ThrowingConsumer.java
@@ -1,6 +1,7 @@
package de.cowtipper.cowlection.command.exception;
import de.cowtipper.cowlection.Cowlection;
+import de.cowtipper.cowlection.util.MooChatComponent;
import net.minecraft.command.CommandException;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.EnumChatFormatting;
@@ -15,11 +16,28 @@ public interface ThrowingConsumer<T> extends Consumer<T> {
try {
acceptThrows(t);
} catch (CommandException e) {
- IChatComponent errorMsg = new ChatComponentTranslation(e.getMessage(), e.getErrorObjects());
+ ChatComponentTranslation errorMsg = new ChatComponentTranslation(e.getMessage(), e.getErrorObjects());
errorMsg.getChatStyle().setColor(EnumChatFormatting.RED);
- Cowlection.getInstance().getChatHelper().sendMessage(errorMsg);
+ handleException(e, errorMsg);
+ } catch (Exception e) {
+ String stackTraceInfo = null;
+ for (StackTraceElement traceElement : e.getStackTrace()) {
+ if (traceElement.getClassName().startsWith("de.cowtipper")) {
+ stackTraceInfo = traceElement.getClassName()
+ + EnumChatFormatting.WHITE + "#" + EnumChatFormatting.GRAY + traceElement.getMethodName()
+ + EnumChatFormatting.WHITE + ":" + EnumChatFormatting.GRAY + traceElement.getLineNumber();
+ break;
+ }
+ }
+ handleException(e, new MooChatComponent(EnumChatFormatting.DARK_RED + "Something went wrong: " + EnumChatFormatting.RED + e.toString()
+ + (stackTraceInfo == null ? "" : EnumChatFormatting.GRAY + " (" + EnumChatFormatting.WHITE + "in " + EnumChatFormatting.GRAY + stackTraceInfo + EnumChatFormatting.GRAY + ")")));
}
}
+ default void handleException(Exception exception, IChatComponent errorMsg) {
+ Cowlection.getInstance().getChatHelper().sendMessage(errorMsg);
+ exception.printStackTrace();
+ }
+
void acceptThrows(T t) throws CommandException;
}
diff --git a/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java b/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java
index 98fab87..d2fff18 100644
--- a/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java
+++ b/src/main/java/de/cowtipper/cowlection/data/HySkyBlockStats.java
@@ -327,12 +327,17 @@ public class HySkyBlockStats {
StringBuilder output = new StringBuilder();
String spacer = indent ? "\n " : "\n";
- Map<String, Type> latestDungeonType = Utils.getLastNMapEntries(dungeon_types, 1);
+ // print detail of 4 latest dungeon types (cata + master cata + xx + master xx)
+ Map<String, Type> latestDungeonType = Utils.getLastNMapEntries(dungeon_types, 4);
for (Map.Entry<String, Type> dungeonTypeEntry : latestDungeonType.entrySet()) {
if (!indent) {
output.append(spacer);
}
if (dungeonTypeEntry != null) {
+ if (!dungeonTypeEntry.getValue().hasPlayed()) {
+ // never played this dungeon type
+ continue;
+ }
Map<String, Integer> highestFloorCompletions = Utils.getLastNMapEntries(dungeonTypeEntry.getValue().getTierCompletions(), nHighestFloors);
String latestDungeonTypeName = Utils.fancyCase(dungeonTypeEntry.getKey());
if (highestFloorCompletions != null) {
@@ -359,6 +364,10 @@ public class HySkyBlockStats {
StringBuilder dungeonTypesLevels = new StringBuilder();
if (dungeon_types != null && !dungeon_types.isEmpty()) {
for (Map.Entry<String, HySkyBlockStats.Profile.Dungeons.Type> dungeonType : dungeon_types.entrySet()) {
+ if (dungeonType.getKey().startsWith("master_")) {
+ // master floors don't have their own experience/levels, skip!
+ continue;
+ }
if (dungeonTypesLevels.length() == 0) {
dungeonTypesLevels.append(EnumChatFormatting.DARK_GRAY).append(" [").append(EnumChatFormatting.GRAY);
} else {
@@ -396,7 +405,7 @@ public class HySkyBlockStats {
}
public boolean hasPlayed() {
- return experience > 0;
+ return experience > 0 || best_score != null;
}
/**
@@ -404,7 +413,7 @@ public class HySkyBlockStats {
*
* @return summary text
*/
- public String getSummary() {
+ public String getSummary(boolean isMasterFloor) {
String floorCompletion;
if (tier_completions != null) {
int highestTierCompletions = tier_completions.get(String.valueOf(highest_tier_completed));
@@ -413,7 +422,7 @@ public class HySkyBlockStats {
// played dungeons but never completed a floor
floorCompletion = "not a single floor...";
}
- return "Level " + getLevel() + EnumChatFormatting.GRAY + " (beaten " + EnumChatFormatting.YELLOW + floorCompletion + EnumChatFormatting.GRAY + ")";
+ return (isMasterFloor ? "" : "Level " + getLevel()) + EnumChatFormatting.GRAY + " (beaten " + EnumChatFormatting.YELLOW + floorCompletion + EnumChatFormatting.GRAY + ")";
}
}