aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/eu/olli/cowlection/handler/DungeonCache.java
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-07-23 16:51:53 +0200
committerCow <cow@volloeko.de>2020-07-23 16:51:53 +0200
commit745a7c428971ed08eb91057a7c8a4ba18825a54f (patch)
tree0397d34e2426a3100129df65cb5b7520a37a7d68 /src/main/java/eu/olli/cowlection/handler/DungeonCache.java
parent70dba3149a04105488c33fdc6ea99be93eb616aa (diff)
downloadCowlection-745a7c428971ed08eb91057a7c8a4ba18825a54f.tar.gz
Cowlection-745a7c428971ed08eb91057a7c8a4ba18825a54f.tar.bz2
Cowlection-745a7c428971ed08eb91057a7c8a4ba18825a54f.zip
Added SkyBlock Dungeon deaths counter
Diffstat (limited to 'src/main/java/eu/olli/cowlection/handler/DungeonCache.java')
-rw-r--r--src/main/java/eu/olli/cowlection/handler/DungeonCache.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main/java/eu/olli/cowlection/handler/DungeonCache.java b/src/main/java/eu/olli/cowlection/handler/DungeonCache.java
new file mode 100644
index 0000000..0431685
--- /dev/null
+++ b/src/main/java/eu/olli/cowlection/handler/DungeonCache.java
@@ -0,0 +1,52 @@
+package eu.olli.cowlection.handler;
+
+import eu.olli.cowlection.Cowlection;
+import eu.olli.cowlection.util.TickDelay;
+import net.minecraft.util.EnumChatFormatting;
+
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class DungeonCache {
+ private boolean isInDungeon;
+ private final Map<String, Integer> deathCounter;
+ private final Cowlection main;
+
+ public DungeonCache(Cowlection main) {
+ this.main = main;
+ deathCounter = new HashMap<>();
+ }
+
+ public void onDungeonEntered() {
+ isInDungeon = true;
+ deathCounter.clear();
+ }
+
+ public void onDungeonLeft() {
+ isInDungeon = false;
+ deathCounter.clear();
+ }
+
+ public void addDeath(String playerName) {
+ int previousPlayerDeaths = deathCounter.getOrDefault(playerName, 0);
+ deathCounter.put(playerName, previousPlayerDeaths + 1);
+
+ new TickDelay(this::sendDeathCounts, 1);
+ }
+
+ public boolean isInDungeon() {
+ return isInDungeon;
+ }
+
+ public void sendDeathCounts() {
+ if (deathCounter.isEmpty()) {
+ main.getChatHelper().sendMessage(EnumChatFormatting.GOLD, "☠ Deaths: " + EnumChatFormatting.WHITE + "none \\o/");
+ } else {
+ String deaths = deathCounter.entrySet().stream().sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())).map(deathEntry -> " " + EnumChatFormatting.WHITE + deathEntry.getKey() + ": " + EnumChatFormatting.LIGHT_PURPLE + deathEntry.getValue())
+ .collect(Collectors.joining("\n"));
+ main.getChatHelper().sendMessage(EnumChatFormatting.RED, "☠ " + EnumChatFormatting.BOLD + "Deaths:\n" + deaths);
+ }
+ }
+}