this string has no description
0
Achievement.java
91 lines 3.5 kB view raw
1package me.maemoon.plugin; 2 3import com.hypixel.hytale.assetstore.AssetExtraInfo; 4import com.hypixel.hytale.assetstore.AssetKeyValidator; 5import com.hypixel.hytale.assetstore.AssetRegistry; 6import com.hypixel.hytale.assetstore.AssetStore; 7import com.hypixel.hytale.assetstore.codec.AssetBuilderCodec; 8import com.hypixel.hytale.assetstore.map.DefaultAssetMap; 9import com.hypixel.hytale.assetstore.map.JsonAssetWithMap; 10import com.hypixel.hytale.codec.Codec; 11import com.hypixel.hytale.codec.KeyedCodec; 12import com.hypixel.hytale.codec.validation.ValidatorCache; 13import com.hypixel.hytale.codec.validation.Validators; 14 15import javax.annotation.Nonnull; 16 17public class Achievement implements JsonAssetWithMap<String, DefaultAssetMap<String, Achievement>> { 18 public static final AssetBuilderCodec<String, Achievement> CODEC; 19 public static final ValidatorCache<String> VALIDATOR_CACHE; 20 private static AssetStore<String, Achievement, DefaultAssetMap<String, Achievement>> ASSET_STORE; 21 22 protected String id; 23 protected String name; 24 protected String icon; 25 protected String description; 26 protected AssetExtraInfo.Data data; 27 @Override 28 public String getId() { 29 return this.id; 30 } 31 32 public static AssetStore<String, Achievement, DefaultAssetMap<String, Achievement>> getAssetStore() { 33 if (ASSET_STORE == null) { 34 ASSET_STORE = AssetRegistry.getAssetStore(Achievement.class); 35 } 36 return ASSET_STORE; 37 } 38 39 public static DefaultAssetMap<String, Achievement> getAssetMap() { 40 return getAssetStore().getAssetMap(); 41 } 42 43 public Achievement(String id, String name, String icon, String description) { 44 this.id = id; 45 this.name = name; 46 this.icon = icon; 47 this.description = description; 48 } 49 50 protected Achievement() { 51 } 52 53 static { 54 AssetBuilderCodec.Builder<String, Achievement> builder = AssetBuilderCodec.builder( 55 Achievement.class, 56 Achievement::new, 57 Codec.STRING, 58 (achievement, s) -> achievement.id = s, 59 (achievement) -> achievement.id, 60 (asset, data) -> asset.data = data, 61 (asset) -> asset.data 62 ); 63 64 var nameField = builder.appendInherited( 65 new KeyedCodec<>("Name", Codec.STRING), 66 (achievement, s) -> achievement.name = s, 67 (achievement) -> achievement.name, 68 (achievement, parent) -> achievement.name = parent.name 69 ); 70 nameField.addValidator(Validators.nonNull()).add(); 71 72 var iconField = builder.appendInherited( 73 new KeyedCodec<>("Icon", Codec.STRING), 74 (achievement, s) -> achievement.icon = s, 75 (achievement) -> achievement.icon, 76 (achievement, parent) -> achievement.icon = parent.icon 77 ); 78 iconField.addValidator(Validators.nonNull()).add(); 79 80 var descriptionField = builder.appendInherited( 81 new KeyedCodec<>("Description", Codec.STRING), 82 (achievement, s) -> achievement.description = s, 83 (achievement) -> achievement.description, 84 (achievement, parent) -> achievement.description = parent.description 85 ); 86 descriptionField.addValidator(Validators.nonNull()).add(); 87 88 CODEC = builder.build(); 89 VALIDATOR_CACHE = new ValidatorCache<>(new AssetKeyValidator<>(Achievement::getAssetStore)); 90 } 91}