aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/eu/olli/cowmoonication/util/Utils.java
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-03-28 04:11:23 +0100
committerCow <cow@volloeko.de>2020-03-28 04:11:23 +0100
commit25714bc7ec6295630506b4ce0e6d4c4d8341ab34 (patch)
treeffa6ae145b4c1e26398bf446fa33e098cfacaa10 /src/main/java/eu/olli/cowmoonication/util/Utils.java
parent0a105c807a3f8040ada76c4e4edac4a79fe32fe6 (diff)
downloadCowlection-25714bc7ec6295630506b4ce0e6d4c4d8341ab34.tar.gz
Cowlection-25714bc7ec6295630506b4ce0e6d4c4d8341ab34.tar.bz2
Cowlection-25714bc7ec6295630506b4ce0e6d4c4d8341ab34.zip
Reworked best friends list
- Saving best friends' UUIDs now (instead of just the name), also checking for name changes periodically to keep best friends list up to date - Moved best friends add/remove functionality from config GUI back to commands (`/moo <add|remove> <name>`)
Diffstat (limited to 'src/main/java/eu/olli/cowmoonication/util/Utils.java')
-rw-r--r--src/main/java/eu/olli/cowmoonication/util/Utils.java59
1 files changed, 4 insertions, 55 deletions
diff --git a/src/main/java/eu/olli/cowmoonication/util/Utils.java b/src/main/java/eu/olli/cowmoonication/util/Utils.java
index 60e2ea3..0b890f0 100644
--- a/src/main/java/eu/olli/cowmoonication/util/Utils.java
+++ b/src/main/java/eu/olli/cowmoonication/util/Utils.java
@@ -1,65 +1,14 @@
package eu.olli.cowmoonication.util;
-import eu.olli.cowmoonication.Cowmoonication;
-import net.minecraft.client.Minecraft;
-import net.minecraft.util.ChatComponentText;
-import net.minecraft.util.IChatComponent;
-import net.minecraftforge.client.event.ClientChatReceivedEvent;
-import net.minecraftforge.common.MinecraftForge;
-
-import java.io.File;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
-public class Utils {
- public static final Pattern VALID_USERNAME = Pattern.compile("^[\\w]{1,16}$");
- private static final Pattern USELESS_JSON_CONTENT_PATTERN = Pattern.compile("\"[A-Za-z]+\":false,?");
- private final Cowmoonication main;
- private final File modsDir;
- private String[] aboveChatMessage;
- private long aboveChatMessageExpiration;
-
- public Utils(Cowmoonication main, File sourceFile) {
- this.main = main;
- modsDir = sourceFile.getParentFile();
- }
-
- public void sendMessage(String text) {
- sendMessage(new ChatComponentText(text));
- }
-
- public void sendMessage(IChatComponent chatComponent) {
- ClientChatReceivedEvent event = new ClientChatReceivedEvent((byte) 1, chatComponent);
- MinecraftForge.EVENT_BUS.post(event);
- if (!event.isCanceled()) {
- Minecraft.getMinecraft().thePlayer.addChatMessage(event.message);
- }
- }
+public final class Utils {
+ private static final Pattern VALID_USERNAME = Pattern.compile("^[\\w]{1,16}$");
- public void sendAboveChatMessage(String... text) {
- aboveChatMessage = text;
- aboveChatMessageExpiration = Minecraft.getSystemTime() + 5000;
+ private Utils() {
}
- public String[] getAboveChatMessage() {
- if (aboveChatMessageExpiration < Minecraft.getSystemTime()) {
- // message expired
- aboveChatMessage = null;
- }
- return aboveChatMessage;
- }
-
- public boolean isValidMcName(String username) {
+ public static boolean isValidMcName(String username) {
return VALID_USERNAME.matcher(username).matches();
}
-
- public String cleanChatComponent(IChatComponent chatComponent) {
- String component = IChatComponent.Serializer.componentToJson(chatComponent);
- Matcher jsonMatcher = USELESS_JSON_CONTENT_PATTERN.matcher(component);
- return jsonMatcher.replaceAll("");
- }
-
- public File getModsFolder() {
- return modsDir;
- }
}