[DEV] Backport fixes from DEV branch.

This commit is contained in:
2024-07-21 13:15:02 +02:00
parent 134dd86e99
commit 62e532fcc3
70 changed files with 510 additions and 88 deletions

View File

@@ -22,12 +22,12 @@ public class CraterPlayerEvent extends CraterEvent {
public PlayerLoggedIn(BridgedPlayer player, boolean isFromVanish) {
super(player);
this.isFromVanish = false;
this.isFromVanish = isFromVanish;
}
}
@Getter @Setter
@Getter
public static class PlayerLoggedOut extends CraterPlayerEvent {
private final boolean isFromVanish;
@@ -37,7 +37,7 @@ public class CraterPlayerEvent extends CraterEvent {
public PlayerLoggedOut(BridgedPlayer player, boolean isFromVanish) {
super(player);
this.isFromVanish = false;
this.isFromVanish = isFromVanish;
}
}

View File

@@ -0,0 +1,8 @@
package com.hypherionmc.craterlib.core.platform;
public enum LoaderType {
FABRIC,
FORGE,
NEOFORGE,
PAPER
}

View File

@@ -12,8 +12,11 @@ public interface ModloaderEnvironment {
public final ModloaderEnvironment INSTANCE = InternalServiceUtil.load(ModloaderEnvironment.class);
@Deprecated(forRemoval = true, since = "2.0.2")
boolean isFabric();
LoaderType getLoaderType();
String getGameVersion();
File getGameFolder();

View File

@@ -14,12 +14,9 @@ import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.RegistryAccess;
import net.minecraft.data.registries.VanillaRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style;
import java.util.function.Consumer;
public class ChatUtils {
private static final GsonComponentSerializer adventureSerializer = GsonComponentSerializer.builder().options(
@@ -70,7 +67,7 @@ public class ChatUtils {
public static String resolve(net.kyori.adventure.text.Component component, boolean formatted) {
Component c = adventureToMojang(component);
String returnVal = ChatFormatting.stripFormatting(c.getString());
String returnVal = ChatFormatting.stripFormatting(DiscordMarkdownStripper.stripMarkdown(c.getString()));
if (formatted) {
returnVal = DiscordSerializer.INSTANCE.serialize(safeCopy(c).copy());

View File

@@ -0,0 +1,35 @@
package com.hypherionmc.craterlib.utils;
import org.jetbrains.annotations.NotNull;
import java.util.regex.Pattern;
public class DiscordMarkdownStripper {
// Patterns for different markdown syntaxes
private static final Pattern BOLD = Pattern.compile("\\*\\*(.*?)\\*\\*");
private static final Pattern ITALIC_UNDERSCORE = Pattern.compile("_(.*?)_");
private static final Pattern ITALIC_ASTERISK = Pattern.compile("\\*(.*?)\\*");
private static final Pattern UNDERLINE = Pattern.compile("__(.*?)__");
private static final Pattern STRIKETHROUGH = Pattern.compile("~~(.*?)~~");
private static final Pattern CODE_BLOCK = Pattern.compile("```(.+?)```", Pattern.DOTALL);
private static final Pattern INLINE_CODE = Pattern.compile("`([^`]*)`");
private static final Pattern BLOCKQUOTE = Pattern.compile("^> (.*?$)", Pattern.MULTILINE);
private static final Pattern MARKDOWN_LINK = Pattern.compile("\\[(.*?)\\]\\((.*?)\\)");
private static final Pattern PLAIN_URL = Pattern.compile("\\b(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
public static String stripMarkdown(@NotNull String text) {
text = BOLD.matcher(text).replaceAll("$1");
text = ITALIC_UNDERSCORE.matcher(text).replaceAll("$1");
text = ITALIC_ASTERISK.matcher(text).replaceAll("$1");
text = UNDERLINE.matcher(text).replaceAll("$1");
text = STRIKETHROUGH.matcher(text).replaceAll("$1");
text = CODE_BLOCK.matcher(text).replaceAll("$1");
text = INLINE_CODE.matcher(text).replaceAll("$1");
text = BLOCKQUOTE.matcher(text).replaceAll("$1");
text = MARKDOWN_LINK.matcher(text).replaceAll("$1");
text = PLAIN_URL.matcher(text).replaceAll("<$0>");
return text;
}
}