-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMiniMessageUtil.java
More file actions
39 lines (32 loc) · 1.42 KB
/
MiniMessageUtil.java
File metadata and controls
39 lines (32 loc) · 1.42 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
package com.wizardlybump17.wlib.util.bukkit;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import org.jetbrains.annotations.NotNull;
import java.util.Map;
public final class MiniMessageUtil {
private MiniMessageUtil() {
}
public static @NotNull Component getMessage(@NotNull String message, @NotNull Map<String, Object> placeholders) {
MiniMessage miniMessage = MiniMessage.miniMessage();
if (placeholders.isEmpty())
return miniMessage.deserialize(message);
TagResolver[] resolvers = new TagResolver[placeholders.size()];
int resolverIndex = 0;
for (Map.Entry<String, Object> entry : placeholders.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
resolvers[resolverIndex++] = TagResolver.builder()
.tag(
key,
Tag.inserting(value instanceof Component component ? component : Component.text(String.valueOf(value)))
)
.build();
}
return miniMessage.deserialize(message, resolvers);
}
public static @NotNull Component getMessage(@NotNull String message) {
return getMessage(message, Map.of());
}
}