-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathText.java
More file actions
56 lines (45 loc) · 1.72 KB
/
Copy pathText.java
File metadata and controls
56 lines (45 loc) · 1.72 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
package dev.vupe.core.util;
import dev.vupe.core.VupeCore;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.command.CommandSender;
import java.text.DecimalFormat;
import java.util.Map;
public final class Text {
private static final MiniMessage MM = MiniMessage.miniMessage();
private static final DecimalFormat NUMBER = new DecimalFormat("#,##0.##");
private Text() {}
public static Component component(String input) {
return MM.deserialize(input == null ? "" : input);
}
public static void send(CommandSender sender, String miniMessage) {
sender.sendMessage(component(prefix() + miniMessage));
}
public static void raw(CommandSender sender, String miniMessage) {
sender.sendMessage(component(miniMessage));
}
public static String prefix() {
return VupeCore.get().configs().get("branding").getString(
"brand.prefix",
"<dark_gray>[<#8B5CF6><bold>VUPE</bold><dark_gray>] <gray>"
);
}
public static String format(double value) {
if (Math.abs(value) < 1000) return NUMBER.format(value);
String[] suffix = {"", "K", "M", "B", "T", "Q", "Qi", "Sx", "Sp"};
double n = value;
int i = 0;
while (Math.abs(n) >= 1000 && i < suffix.length - 1) {
n /= 1000.0;
i++;
}
return NUMBER.format(n) + suffix[i];
}
public static String replace(String template, Map<String, String> values) {
String out = template;
for (Map.Entry<String, String> entry : values.entrySet()) {
out = out.replace("%" + entry.getKey() + "%", entry.getValue());
}
return out;
}
}