Skip to content

Commit

Permalink
AbstractTextInput: Hard-code isAllowedCharacter
Browse files Browse the repository at this point in the history
It shouldn't ever change and this way the same Vigilance build continues to be
compatible on 1.20.5+ where the MC method was moved to another class.

GitHub: #85
  • Loading branch information
Johni0702 committed May 2, 2024
1 parent 10c424e commit be72662
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
kotlin = "1.5.10"
jetbrains-annotations = "23.0.0"
elementa = "507"
elementa = "638"
nightconfig = "3.6.0"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ internal abstract class AbstractTextInput(
val operationToRedo = redoStack.pop()
operationToRedo.redo()
undoStack.push(operationToRedo)
} else if (platform.isAllowedInChat(typedChar)) { // Most of the ASCII characters
} else if (isAllowedCharacter(typedChar)) { // Most of the ASCII characters
commitTextAddition(typedChar.toString())
} else if (keyCode == UKeyboard.KEY_LEFT) {
val holdingShift = UKeyboard.isShiftKeyDown()
Expand Down Expand Up @@ -1006,4 +1006,11 @@ internal abstract class AbstractTextInput(
removeTextOperation.undo()
}
}

private companion object {
// Mirroring ChatAllowedCharacters.isAllowedCharacter
private fun isAllowedCharacter(chr: Char): Boolean {
return chr.code != 167 && chr >= ' ' && chr.code != 127
}
}
}
2 changes: 0 additions & 2 deletions src/main/kotlin/gg/essential/vigilance/impl/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ interface Platform {

fun i18n(key: String): String

fun isAllowedInChat(char: Char): Boolean

@ApiStatus.Internal
companion object {
internal val platform: Platform =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gg.essential.vigilance.impl;

import net.minecraft.client.resources.I18n;
import net.minecraft.util.ChatAllowedCharacters;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

Expand All @@ -14,9 +13,4 @@ public class PlatformImpl implements Platform {
public String i18n(@NotNull String key) {
return I18n.format(key);
}

@Override
public boolean isAllowedInChat(char c) {
return ChatAllowedCharacters.isAllowedCharacter(c);
}
}

0 comments on commit be72662

Please sign in to comment.