All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.hendrixshen.magiclib.carpet.api.Validator Maven / Gradle / Ivy

There is a newer version: 0.7.398+fe2125a-beta
Show newest version
package top.hendrixshen.magiclib.carpet.api;

import carpet.settings.ParsedRule;
import net.minecraft.class_124;
import net.minecraft.class_2168;
import net.minecraft.class_2561;
import top.hendrixshen.magiclib.carpet.impl.RuleHelper;
import top.hendrixshen.magiclib.carpet.impl.RuleOption;
import top.hendrixshen.magiclib.compat.minecraft.api.network.chat.ComponentCompatApi;
import top.hendrixshen.magiclib.impl.carpet.CarpetEntrypoint;
import top.hendrixshen.magiclib.util.MessageUtil;

//#if MC >= 11901
//$$ import carpet.api.settings.CarpetRule;
//#endif

//#if MC >= 11901
//$$ @SuppressWarnings("removal")
//$$ public abstract class Validator extends carpet.api.settings.Validator {
//#else
public abstract class Validator extends carpet.settings.Validator {
//#endif
    @Override
    //#if MC >= 11901
    //$$ public T validate(CommandSourceStack source, CarpetRule carpetRule, T newValue, String userInput) {
    //$$     return this.validateCompat(source, RuleHelper.getSettingManager((ParsedRule) carpetRule).getRuleOption((ParsedRule) carpetRule), newValue, userInput);
    //#else
    public T validate(class_2168 source, ParsedRule carpetRule, T newValue, String userInput) {
        return this.validateCompat(source, RuleHelper.getSettingManager((ParsedRule) carpetRule).getRuleOption(carpetRule), newValue, userInput);
    //#endif
    }

    //#if MC > 11502
    //$$ @Override
    //#if MC >= 11901
    //$$ public void notifyFailure(CommandSourceStack source, CarpetRule carpetRule, String providedValue) {
    //#else
    //$$ public void notifyFailure(CommandSourceStack source, ParsedRule carpetRule, String providedValue) {
    //#endif
    //$$ }
    //#endif

    public class_2561 getDescription() {
        return null;
    }

    public T validateCompat(class_2168 source, RuleOption ruleOption, T newValue, String userInput) {
        if (this.getValidValue(source, ruleOption, newValue, userInput) != null) {
            return this.getValidValue(source, ruleOption, newValue, userInput);
        }

        MessageUtil.sendMessage(source, ComponentCompatApi.literal(CarpetEntrypoint.getSettingManager().trUI("could_not_set",
                CarpetEntrypoint.getSettingManager().getTranslatedRuleName(ruleOption.getName()))).method_10859(style -> style.method_10977(class_124.field_1061)));

        if (this.getDescription() != null) {
            MessageUtil.sendMessage(source, this.getDescription());
        }

        return null;
    }

    public abstract T getValidValue(class_2168 source, RuleOption ruleOption, T newValue, String userInput);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy