package me.maemoon.plugin; import com.hypixel.hytale.assetstore.AssetExtraInfo; import com.hypixel.hytale.assetstore.AssetKeyValidator; import com.hypixel.hytale.assetstore.AssetRegistry; import com.hypixel.hytale.assetstore.AssetStore; import com.hypixel.hytale.assetstore.codec.AssetBuilderCodec; import com.hypixel.hytale.assetstore.map.DefaultAssetMap; import com.hypixel.hytale.assetstore.map.JsonAssetWithMap; import com.hypixel.hytale.codec.Codec; import com.hypixel.hytale.codec.KeyedCodec; import com.hypixel.hytale.codec.validation.ValidatorCache; import com.hypixel.hytale.codec.validation.Validators; import javax.annotation.Nonnull; public class Achievement implements JsonAssetWithMap> { public static final AssetBuilderCodec CODEC; public static final ValidatorCache VALIDATOR_CACHE; private static AssetStore> ASSET_STORE; protected String id; protected String name; protected String icon; protected String description; protected AssetExtraInfo.Data data; @Override public String getId() { return this.id; } public static AssetStore> getAssetStore() { if (ASSET_STORE == null) { ASSET_STORE = AssetRegistry.getAssetStore(Achievement.class); } return ASSET_STORE; } public static DefaultAssetMap getAssetMap() { return getAssetStore().getAssetMap(); } public Achievement(String id, String name, String icon, String description) { this.id = id; this.name = name; this.icon = icon; this.description = description; } protected Achievement() { } static { AssetBuilderCodec.Builder builder = AssetBuilderCodec.builder( Achievement.class, Achievement::new, Codec.STRING, (achievement, s) -> achievement.id = s, (achievement) -> achievement.id, (asset, data) -> asset.data = data, (asset) -> asset.data ); var nameField = builder.appendInherited( new KeyedCodec<>("Name", Codec.STRING), (achievement, s) -> achievement.name = s, (achievement) -> achievement.name, (achievement, parent) -> achievement.name = parent.name ); nameField.addValidator(Validators.nonNull()).add(); var iconField = builder.appendInherited( new KeyedCodec<>("Icon", Codec.STRING), (achievement, s) -> achievement.icon = s, (achievement) -> achievement.icon, (achievement, parent) -> achievement.icon = parent.icon ); iconField.addValidator(Validators.nonNull()).add(); var descriptionField = builder.appendInherited( new KeyedCodec<>("Description", Codec.STRING), (achievement, s) -> achievement.description = s, (achievement) -> achievement.description, (achievement, parent) -> achievement.description = parent.description ); descriptionField.addValidator(Validators.nonNull()).add(); CODEC = builder.build(); VALIDATOR_CACHE = new ValidatorCache<>(new AssetKeyValidator<>(Achievement::getAssetStore)); } }