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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
package me.Danker.features.loot;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import me.Danker.events.ModInitEvent;
import me.Danker.utils.Utils;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class TrophyFishTracker {
public static JsonObject fish = new JsonObject();
public static JsonObject fishSession = new JsonObject();
public static Pattern fishPattern = Pattern.compile("TROPHY FISH! You caught a (?<fish>.*) (?<tier>.*).");
public static String configFile;
public static JsonObject createEmpty() {
JsonObject fish = new JsonObject();
JsonObject tiers = new JsonObject();
tiers.addProperty("BRONZE", 0);
tiers.addProperty("SILVER", 0);
tiers.addProperty("GOLD", 0);
tiers.addProperty("DIAMOND", 0);
fish.add("Sulpher Skitter", Utils.deepCopy(tiers));
fish.add("Obfuscated 1", Utils.deepCopy(tiers));
fish.add("Steaming-Hot Flounder", Utils.deepCopy(tiers));
fish.add("Obfuscated 2", Utils.deepCopy(tiers));
fish.add("Gusher", Utils.deepCopy(tiers));
fish.add("Blobfish", Utils.deepCopy(tiers));
fish.add("Slugfish", Utils.deepCopy(tiers));
fish.add("Obfuscated 3", Utils.deepCopy(tiers));
fish.add("Flyfish", Utils.deepCopy(tiers));
fish.add("Lavahorse", Utils.deepCopy(tiers));
fish.add("Mana Ray", Utils.deepCopy(tiers));
fish.add("Volcanic Stonefish", Utils.deepCopy(tiers));
fish.add("Vanille", Utils.deepCopy(tiers));
fish.add("Skeleton Fish", Utils.deepCopy(tiers));
fish.add("Moldfin", Utils.deepCopy(tiers));
fish.add("Soul Fish", Utils.deepCopy(tiers));
fish.add("Karate Fish", Utils.deepCopy(tiers));
fish.add("Golden Fish", Utils.deepCopy(tiers));
return fish;
}
@SubscribeEvent
public void init(ModInitEvent event) {
configFile = event.configDirectory + "/dsmtrophyfish.json";
if (fish.entrySet().isEmpty()) fish = createEmpty();
fishSession = createEmpty();
}
@SubscribeEvent(receiveCanceled = true)
public void onChat(ClientChatReceivedEvent event) {
String message = StringUtils.stripControlCodes(event.message.getUnformattedText());
if (!Utils.inSkyblock) return;
if (!Utils.tabLocation.equals("Crimson Isle")) return;
if (event.type == 2) return;
if (message.contains(":")) return;
Matcher matcher = fishPattern.matcher(message);
if (matcher.matches()) {
String fishName = matcher.group("fish");
String tier = matcher.group("tier");
JsonObject fishObj = fish.get(fishName).getAsJsonObject();
int amount = fishObj.get(tier).getAsInt();
fishObj.addProperty(tier, amount + 1);
JsonObject fishSessionObj = fishSession.get(fishName).getAsJsonObject();
int amountSession = fishSessionObj.get(tier).getAsInt();
fishSessionObj.addProperty(tier, amountSession + 1);
save();
}
}
public static void save() {
try (FileWriter writer = new FileWriter(configFile)) {
new GsonBuilder().create().toJson(fish, writer);
writer.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
public static String getTierCount(JsonObject obj, String name) {
JsonObject type = obj.get(name).getAsJsonObject();
int bronze = type.get("BRONZE").getAsInt();
int silver = type.get("SILVER").getAsInt();
int gold = type.get("GOLD").getAsInt();
int diamond = type.get("DIAMOND").getAsInt();
return EnumChatFormatting.DARK_GRAY + "" + bronze + EnumChatFormatting.WHITE + "-" +
EnumChatFormatting.GRAY + silver + EnumChatFormatting.WHITE + "-" +
EnumChatFormatting.GOLD + gold + EnumChatFormatting.WHITE + "-" +
EnumChatFormatting.AQUA + diamond;
}
public static int getSum(JsonObject obj, String name) {
JsonObject type = obj.get(name).getAsJsonObject();
return type.get("BRONZE").getAsInt() +
type.get("SILVER").getAsInt() +
type.get("GOLD").getAsInt() +
type.get("DIAMOND").getAsInt();
}
}
|