package land.chipmunk.chipmunkmod.mixin;

import land.chipmunk.chipmunkmod.modules.custom_chat.CustomChat;
import net.minecraft.util.StringUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(StringUtil.class)
public class StringUtilMixin {
    @Inject(method = "isAllowedChatCharacter", at = @At("RETURN"), cancellable = true)
    private static void isAllowedChatCharacter (final int ch, final CallbackInfoReturnable<Boolean> cir) {
        if (!CustomChat.SHOULD_IGNORE_INVALID_CHAR.get()) {
            CustomChat.SHOULD_IGNORE_INVALID_CHAR.set(true);
            return;
        }

        // very legal [NUL] [LF] § Allowance.
        cir.setReturnValue(true);
    }
}
