-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathForgeReminder.java
More file actions
117 lines (96 loc) · 4 KB
/
ForgeReminder.java
File metadata and controls
117 lines (96 loc) · 4 KB
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
package mod.gate.features;
import mod.gate.core.config.Config;
import mod.gate.core.events.Event;
import mod.gate.utils.ChatUtils;
import mod.gate.utils.Tablist;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import java.util.ArrayList;
public class ForgeReminder {
//region CONFIG
@Config(description = "the configuration for the forge reminder")
public ForgeConfig forgeReminder = new ForgeConfig();
//endregion
@Event(event = Tablist.TablistUpdateEvent.class)
public void onTablistUpdate(Tablist.TablistUpdateEvent event) {
if (event.type != Tablist.TablistUpdateType.OTHER) return;
// Finding if the 5th slot is unlocked, it isn't shown on Tablist
if (event.line.equals("Forges (+1 more)") && !forgeReminder.slots.get(5).unlocked) {
forgeReminder.slots.get(5).unlocked = true;
}
for (ForgeSlot slot : forgeReminder.slots) {
if (slot.slotNumber != 5) {
processLine(slot, event.line);
};
if (!slot.unlocked && System.currentTimeMillis() < slot.time && slot.time == 0L && !slot.notify) continue;
slot.notify = false;
Style style = Style.EMPTY
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.of("Click to warp to the forge [if unlocked]")))
//TODO find a way to make this click event work
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/warpforge"));
ChatUtils.sendChatMessage(Text.of(ChatUtils.PREFIX + "§8 | [§bForgeReminder§8] §f> " + "Forge §3slot " + slot.slotNumber + " §fis available for pickup.").getWithStyle(style).get(0));
}
}
private void processLine(ForgeSlot slot, String line) {
if (!line.startsWith(slot.slotNumber + ")")) return;
if (line.endsWith("EMPTY")) {
if (slot.time != 0L) slot.time = 0L;
slot.unlocked = true;
slot.notify = true;
} else if (line.endsWith("Ready!")) {
slot.time = System.currentTimeMillis();
slot.unlocked = true;
} else {
String DateToParse = line.substring(3);
long total = 0L;
for (String time : DateToParse.split(" ")) {
if (time.contains("s")) {
time = time.replace("s", "");
int s = Integer.parseInt(time);
total+= s * 1000L;
} else if (time.contains("m")) {
time = time.replace("m", "");
int m = Integer.parseInt(time);
total += m * 60000L;
} else if (time.contains("h")) {
time = time.replace("h", "");
int h = Integer.parseInt(time);
total += h * 3600000L;
} else if (time.contains("d")) {
time = time.replace("d", "");
int d = Integer.parseInt(time);
total += d * 86400000L;
}
}
total += System.currentTimeMillis();
slot.time = total;
slot.unlocked = true;
slot.notify = true;
}
}
public static class ForgeConfig {
public boolean enabled = true;
public ArrayList<ForgeSlot> slots = new ArrayList<>();
public ForgeConfig() {
slots.add(new ForgeSlot(1));
slots.add(new ForgeSlot(2));
slots.add(new ForgeSlot(3));
slots.add(new ForgeSlot(4));
slots.add(new ForgeSlot(5));
}
}
public static class ForgeSlot {
public long time;
public boolean unlocked;
public int slotNumber;
public boolean notify;
public ForgeSlot(int slotNumber) {
this.slotNumber = slotNumber;
this.time = 0L;
this.unlocked = false;
this.notify = true;
}
}
}