blob: 0431685465b8aa89c832653871a4cbeb1c206a06 (
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
|
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);
}
}
}
|