blob: ad0e1c656273fc6bd0b4c116d112ab43cc0cf1ff (
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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/*
* Copyright (C) 2023 NotEnoughUpdates contributors
*
* This file is part of NotEnoughUpdates.
*
* NotEnoughUpdates is free software: you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* NotEnoughUpdates is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with NotEnoughUpdates. If not, see <https://www.gnu.org/licenses/>.
*/
package io.github.moulberry.notenoughupdates.miscgui.customtodos
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe
import io.github.moulberry.notenoughupdates.core.util.StringUtils
import io.github.moulberry.notenoughupdates.events.SidebarChangeEvent
import io.github.moulberry.notenoughupdates.events.TabListChangeEvent
import io.github.moulberry.notenoughupdates.miscgui.GuiInvButtonEditor
import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.init.Items
import net.minecraft.item.ItemStack
import net.minecraft.util.EnumChatFormatting
import net.minecraftforge.client.event.ClientChatReceivedEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.*
@NEUAutoSubscribe
object CustomTodoHud {
private fun matchString(todo: CustomTodo, text: String): Boolean {
return when (todo.triggerMatcher) {
CustomTodo.TriggerMatcher.REGEX -> text.matches(todo.trigger.toRegex())
CustomTodo.TriggerMatcher.STARTS_WITH -> text.startsWith(todo.trigger)
CustomTodo.TriggerMatcher.CONTAINS -> text.contains(todo.trigger)
CustomTodo.TriggerMatcher.EQUALS -> text == todo.trigger
}
}
@SubscribeEvent
fun onTabList(event: TabListChangeEvent) {
NotEnoughUpdates.INSTANCE.config.hidden.customTodos
.forEach { todo ->
if (todo.triggerTarget != CustomTodo.TriggerTarget.TAB_LIST) return@forEach
event.newLines.forEach { text ->
val doesMatch = matchString(todo, text)
if (doesMatch) {
todo.setDoneNow()
}
}
}
}
@SubscribeEvent
fun onSidebar(event: SidebarChangeEvent) {
NotEnoughUpdates.INSTANCE.config.hidden.customTodos
.forEach { todo ->
if (todo.triggerTarget != CustomTodo.TriggerTarget.SIDEBAR) return@forEach
event.lines.forEach { text ->
val doesMatch = matchString(todo, text)
if (doesMatch) {
todo.setDoneNow()
}
}
}
}
@SubscribeEvent
fun onChat(event: ClientChatReceivedEvent) {
val text = StringUtils.cleanColour(event.message.unformattedText)
NotEnoughUpdates.INSTANCE.config.hidden.customTodos
.forEach {
val isCorrectTrigger = when (it.triggerTarget) {
CustomTodo.TriggerTarget.CHAT -> event.type != 2.toByte()
CustomTodo.TriggerTarget.ACTIONBAR -> event.type == 2.toByte()
CustomTodo.TriggerTarget.TAB_LIST -> false
CustomTodo.TriggerTarget.SIDEBAR -> false
}
val doesMatch = matchString(it, text)
if (isCorrectTrigger && doesMatch)
it.setDoneNow()
}
}
fun encodeCustomItem(icon: String) = "CUSTOM" + Base64.getEncoder().encodeToString(icon.encodeToByteArray())
fun decodeCustomItem(customString: String): String {
require(customString.startsWith("CUSTOM"))
return Base64.getDecoder().decode(customString.substring(6)).decodeToString()
}
@JvmStatic
fun processInto(strings: MutableList<String>) {
NotEnoughUpdates.INSTANCE.config.hidden.customTodos
.filter { it.isEnabledOnCurrentProfile }
.forEach {
val readyAt = it.readyAtOnCurrentProfile ?: (System.currentTimeMillis() - 1000L)
val until = readyAt - System.currentTimeMillis()
if ((!it.showOnlyWhenReady && it.showWhen > 0) && until - (it.showWhen * 1000) > 0) return@forEach
if (it.showOnlyWhenReady && until >= 0) return@forEach
strings.add(
encodeCustomItem(it.icon) + ":§3" + it.label + ": " +
if (until <= 0)
EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.readyColour].toString() + "Ready!"
else if (until < 60 * 30 * 1000L)
EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.verySoonColour].toString()
+ Utils.prettyTime(until)
else if (until < 60 * 60 * 1000L)
EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.soonColour].toString()
+ Utils.prettyTime(until)
else if (until < 3 * 60 * 60 * 1000L)
EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.kindaSoonColour].toString()
+ Utils.prettyTime(until)
else
EnumChatFormatting.values()[NotEnoughUpdates.INSTANCE.config.miscOverlays.defaultColour].toString()
+ Utils.prettyTime(until)
)
}
}
fun parseItem(icon: String): ItemStack {
val stack = GuiInvButtonEditor.getStack(icon.uppercase())
if (stack.metadata == 255 || (stack.item == Items.painting && stack.metadata != 0)) return ItemStack(Items.paper)
return stack
}
}
|