Allow vanilla translation text
This commit is contained in:
@@ -7,6 +7,30 @@ import net.minecraft.text.TextContent;
|
||||
import net.minecraft.text.TranslatableTextContent;
|
||||
|
||||
public final class TextSanitizer {
|
||||
private static final String[] VANILLA_TRANSLATION_PREFIXES = {
|
||||
"advancement.",
|
||||
"attribute.",
|
||||
"block.minecraft.",
|
||||
"chat.",
|
||||
"commands.",
|
||||
"death.",
|
||||
"effect.minecraft.",
|
||||
"enchantment.minecraft.",
|
||||
"entity.minecraft.",
|
||||
"gui.",
|
||||
"item.minecraft.",
|
||||
"itemGroup.",
|
||||
"key.",
|
||||
"menu.",
|
||||
"options.",
|
||||
"pack.",
|
||||
"recipe.",
|
||||
"resourcePack.",
|
||||
"stat.minecraft.",
|
||||
"subtitles.",
|
||||
"tutorial."
|
||||
};
|
||||
|
||||
private TextSanitizer() {
|
||||
}
|
||||
|
||||
@@ -17,8 +41,12 @@ public final class TextSanitizer {
|
||||
|
||||
TextContent content = text.getContent();
|
||||
|
||||
if (content instanceof TranslatableTextContent || content instanceof KeybindTextContent) {
|
||||
return true;
|
||||
if (content instanceof TranslatableTextContent translatable) {
|
||||
return !isVanillaTranslationKey(translatable.getKey());
|
||||
}
|
||||
|
||||
if (content instanceof KeybindTextContent keybind) {
|
||||
return !isVanillaKeybindKey(keybind.getKey());
|
||||
}
|
||||
|
||||
for (Text sibling : text.getSiblings()) {
|
||||
@@ -62,4 +90,26 @@ public final class TextSanitizer {
|
||||
append(sibling, out);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isVanillaTranslationKey(String key) {
|
||||
if (key == null || key.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (String prefix : VANILLA_TRANSLATION_PREFIXES) {
|
||||
if (key.startsWith(prefix)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return key.contains(".minecraft.");
|
||||
}
|
||||
|
||||
private static boolean isVanillaKeybindKey(String key) {
|
||||
if (key == null || !key.startsWith("key.")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return key.indexOf('.', 4) < 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,19 +77,19 @@ public abstract class ClientConnectionMixin {
|
||||
}
|
||||
|
||||
ExploitState.CapturedSignData captured = ExploitState.SIGNS.get(pos);
|
||||
Text[] textLines;
|
||||
if (captured != null) {
|
||||
textLines = signPacket.isFront() ? captured.getFront() : captured.getBack();
|
||||
} else {
|
||||
String[] packetText = signPacket.getText();
|
||||
textLines = new Text[] {
|
||||
Text.literal(packetText[0]),
|
||||
Text.literal(packetText[1]),
|
||||
Text.literal(packetText[2]),
|
||||
Text.literal(packetText[3])
|
||||
};
|
||||
if (captured == null || !captured.isSuspicious()) {
|
||||
SignLeakShieldTraceLog.info(
|
||||
"Outgoing sign packet allowed: captured sign missing or vanilla-safe pos=%s front=%s capturedPresent=%s",
|
||||
pos,
|
||||
signPacket.isFront(),
|
||||
captured != null
|
||||
);
|
||||
return packet;
|
||||
}
|
||||
|
||||
Text[] textLines;
|
||||
textLines = signPacket.isFront() ? captured.getFront() : captured.getBack();
|
||||
|
||||
String line1 = TextSanitizer.sanitize(textLines[0]);
|
||||
String line2 = TextSanitizer.sanitize(textLines[1]);
|
||||
String line3 = TextSanitizer.sanitize(textLines[2]);
|
||||
|
||||
Reference in New Issue
Block a user