WordList class

Пакет: com.hypixel.hytale.server.core.asset.type.wordlist

Файл: com/hypixel/hytale/server/core/asset/type/wordlist/WordList.java

implements: JsonAssetWithMap<String, DefaultAssetMap<String, WordList>>

Поля (10)

МодификаторыТипИмя
ASSET_STORE
final String WORDLISTS_TRANSLATION_FILE
WordList var1
String var1
String[] var2
List var2
String var3
List var3
List var4
String var8

Методы (11)

МодификаторыВозвратСигнатура
for for(int var3 = 0; var3 < this.translationKeys.length; var3++)
for for(Object var6 : var0)
for for(String var7 : var0)
static DefaultAssetMap<String, WordList> getAssetMapDefaultAssetMap<String, WordList> getAssetMap()
public String getIdString getId()
static WordList getWordListWordList getWordList(@Nullable String var0)
if if(ASSET_STORE == null)
if if(this.translationKeys != null)
if if(var0 != null && var0.length != 0)
if if(var0 != null && var0.length != 0)
protected void processConfigvoid processConfig()

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.asset.type.wordlist;

class="kw">import com.hypixel.hytale.assetstore.AssetExtraInfo;
class="kw">import com.hypixel.hytale.assetstore.AssetKeyValidator;
class="kw">import com.hypixel.hytale.assetstore.AssetRegistry;
class="kw">import com.hypixel.hytale.assetstore.AssetStore;
class="kw">import com.hypixel.hytale.assetstore.codec.AssetBuilderCodec;
class="kw">import com.hypixel.hytale.assetstore.map.DefaultAssetMap;
class="kw">import com.hypixel.hytale.assetstore.map.JsonAssetWithMap;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.validation.ValidatorCache;
class="kw">import com.hypixel.hytale.server.core.modules.i18n.I18nModule;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectArrayList;
class="kw">import java.util.Arrays;
class="kw">import java.util.Collections;
class="kw">import java.util.List;
class="kw">import java.util.Locale;
class="kw">import java.util.Random;
class="kw">import java.util.Set;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class WordList class="kw">implements JsonAssetWithMap<String, DefaultAssetMap<String, WordList>> {
   class="kw">private class="kw">static class="kw">final String WORDLISTS_TRANSLATION_FILE = "wordlists";
   class="kw">public class="kw">static class="kw">final AssetBuilderCodec<String, WordList> CODEC = AssetBuilderCodec.builder(
         WordList.class, WordList::new, Codec.STRING, (var0, var1) -> var0.id = var1, var0 -> var0.id, (var0, var1) -> var0.data = var1, var0 -> var0.data
      )
      .appendInherited(
         new KeyedCodec<>("TranslationKeys", Codec.STRING_ARRAY),
         (var0, var1) -> var0.translationKeys = var1,
         var0 -> var0.translationKeys,
         (var0, var1) -> var0.translationKeys = var1.translationKeys
      )
      .documentation(
         "The list of word message keys. Need to be added in Assets/Server/Languages/wordlists.lang. For example if the WordList asset file is 'animals' and you write 'cow' here, it will refer to 'animals.cow' (full path is 'wordlists.animals.cow')"
      )
      .add()
      .afterDecode(WordList::processConfig)
      .build();
   class="kw">private class="kw">static AssetStore<String, WordList, DefaultAssetMap<String, WordList>> ASSET_STORE;
   @Nonnull
   class="kw">public class="kw">static class="kw">final ValidatorCache<String> VALIDATOR_CACHE = new ValidatorCache<>(new AssetKeyValidator<>(WordList::getAssetStore));
   class="kw">private class="kw">static class="kw">final WordList EMPTY = new WordList();
   class="kw">protected AssetExtraInfo.Data data;
   class="kw">protected String id;
   class="kw">protected String[] translationKeys;

   @Nonnull
   class="kw">public class="kw">static AssetStore<String, WordList, DefaultAssetMap<String, WordList>> getAssetStore() {
      if (ASSET_STORE == null) {
         ASSET_STORE = AssetRegistry.getAssetStore(WordList.class);
      }

      class="kw">return ASSET_STORE;
   }

   class="kw">public class="kw">static DefaultAssetMap<String, WordList> getAssetMap() {
      class="kw">return (DefaultAssetMap<String, WordList>)getAssetStore().getAssetMap();
   }

   class="kw">public class="kw">static WordList getWordList(@Nullable String var0) {
      if (var0 != null && !var0.isEmpty()) {
         WordList var1 = getAssetMap().getAsset(var0);
         class="kw">return var1 == null ? EMPTY : var1;
      } else {
         class="kw">return EMPTY;
      }
   }

   class="kw">protected WordList() {
   }

   class="kw">public String getId() {
      class="kw">return this.id;
   }

   class="kw">protected void processConfig() {
      if (this.translationKeys != null) {
         String var1 = this.id.toLowerCase(Locale.ROOT);
         String[] var2 = new String[this.translationKeys.length];

         for (int var3 = 0; var3 < this.translationKeys.length; var3++) {
            var2[var3] = "wordlists." + var1 + "." + this.translationKeys[var3];
         }

         this.translationKeys = var2;
      }
   }

   @Nullable
   class="kw">public String pickDefaultLanguage(@Nonnull Random var1, @Nonnull Set<String> var2) {
      String var3 = this.pickTranslationKey(var1, var2, "en-US");
      class="kw">return var3 == null ? null : I18nModule.get().getMessage("en-US", var3);
   }

   @Nullable
   class="kw">public String pickTranslationKey(@Nonnull Random var1, @Nonnull Set<String> var2, String var3) {
      List var4 = toKeysListMinusTranslated(this.translationKeys, var2, var3);
      class="kw">return var4.isEmpty() ? null : var4.get(var1.nextInt(var4.size()));
   }

   @Nonnull
   class="kw">private class="kw">static <T> List<T> toListMinusSet(@Nullable T[] var0, @Nonnull Set<T> var1) {
      if (var0 != null && var0.length != 0) {
         List var2 = new ObjectArrayList(var0.length);

         for (Object var6 : var0) {
            if (!var1.contains(var6)) {
               var2.add(var6);
            }
         }

         class="kw">return var2;
      } else {
         class="kw">return Collections.emptyList();
      }
   }

   @Nonnull
   class="kw">private class="kw">static List<String> toKeysListMinusTranslated(@Nullable String[] var0, @Nonnull Set<String> var1, String var2) {
      if (var0 != null && var0.length != 0) {
         List var3 = new ObjectArrayList(var0.length);

         for (String var7 : var0) {
            String var8 = I18nModule.get().getMessage(var2, var7);
            if (var8 != null && !var1.contains(var8.toLowerCase(Locale.ROOT))) {
               var3.add(var7);
            }
         }

         class="kw">return var3;
      } else {
         class="kw">return Collections.emptyList();
      }
   }

   @Nonnull
   @Override
   class="kw">public String toString() {
      class="kw">return "WordList{id='" + this.id + "', translationKeys=" + Arrays.toString(this.translationKeys) + "}";
   }
}