PrefabReference class

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

Файл: com/hypixel/hytale/server/core/asset/type/buildertool/config/PrefabListAsset.java

Поля (17)

МодификаторыТипИмя
public static final BuilderCodec<PrefabListAsset.PrefabReference> CODEC
private static final String[] EXTENSIONS
private static final int MAX_RECURSION_DEPTH
public List<Path> prefabPaths
public boolean recursive
return
public PrefabListAsset.PrefabRootDirectory rootDirectory
public String unprocessedPrefabPath
Path var1
Path var10
Path var11
Path var12
Path var13
Path var14
Path var2
Path var4
int var5

Методы (8)

МодификаторыВозвратСигнатура
abstract throw new InvalidPathExceptionthrow new InvalidPathException(this.unprocessedPrefabPath, "Failed to resolve path under assets root")
if if(this.unprocessedPrefabPath != null)
if if(this.rootDirectory == PrefabListAsset.PrefabRootDirectory.Asset)
if if(var12 == null)
if if(var14 != null)
if if(var11 == null)
if if(var2 == null)
public void processPrefabPathpublic void processPrefabPath()

Исходный код

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

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.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.codecs.EnumCodec;
class="kw">import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
class="kw">import com.hypixel.hytale.codec.validation.ValidatorCache;
class="kw">import com.hypixel.hytale.common.util.PathUtil;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.server.core.asset.AssetModule;
class="kw">import com.hypixel.hytale.server.core.asset.util.AssetPackPathUtil;
class="kw">import com.hypixel.hytale.server.core.prefab.PrefabStore;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectArrayList;
class="kw">import java.io.IOException;
class="kw">import java.nio.file.Files;
class="kw">import java.nio.file.InvalidPathException;
class="kw">import java.nio.file.Path;
class="kw">import java.util.List;
class="kw">import java.util.concurrent.ThreadLocalRandom;
class="kw">import java.util.function.Supplier;
class="kw">import java.util.logging.Level;
class="kw">import java.util.stream.Stream;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class PrefabListAsset class="kw">implements JsonAssetWithMap<String, DefaultAssetMap<String, PrefabListAsset>> {
   class="kw">public class="kw">static class="kw">final AssetBuilderCodec<String, PrefabListAsset> CODEC = AssetBuilderCodec.builder(
         PrefabListAsset.class,
         PrefabListAsset::new,
         Codec.STRING,
         (var0, var1) -> var0.id = var1,
         var0 -> var0.id,
         (var0, var1) -> var0.data = var1,
         var0 -> var0.data
      )
      .append(
         new KeyedCodec<>("Prefabs", new ArrayCodec<>(PrefabListAsset.PrefabReference.CODEC, PrefabListAsset.PrefabReference[]::new), true),
         (var0, var1) -> var0.prefabReferences = var1,
         var0 -> var0.prefabReferences
      )
      .add()
      .afterDecode(PrefabListAsset::convertPrefabReferencesToPrefabPaths)
      .build();
   class="kw">private class="kw">static AssetStore<String, PrefabListAsset, DefaultAssetMap<String, PrefabListAsset>> ASSET_STORE;
   class="kw">public class="kw">static class="kw">final ValidatorCache<String> VALIDATOR_CACHE = new ValidatorCache<>(new AssetKeyValidator<>(PrefabListAsset::getAssetStore));
   class="kw">private String id;
   class="kw">private Path[] prefabPaths;
   class="kw">private PrefabListAsset.PrefabReference[] prefabReferences;
   class="kw">private AssetExtraInfo.Data data;

   class="kw">public PrefabListAsset() {
   }

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

      class="kw">return ASSET_STORE;
   }

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

   class="kw">private void convertPrefabReferencesToPrefabPaths() {
      if (this.prefabReferences != null) {
         ObjectArrayList var1 = new ObjectArrayList();

         for (PrefabListAsset.PrefabReference var5 : this.prefabReferences) {
            var1.addAll(var5.prefabPaths);
         }

         this.prefabPaths = (Path[])var1.toArray(Path[]::new);
      }
   }

   class="kw">public Path[] getPrefabPaths() {
      class="kw">return this.prefabPaths;
   }

   @Nonnull
   class="kw">public PrefabListAsset.PrefabReference[] getPrefabReferences() {
      class="kw">return this.prefabReferences != null ? this.prefabReferences : new PrefabListAsset.PrefabReference[0];
   }

   @Nullable
   class="kw">public Path getRandomPrefab() {
      class="kw">return this.prefabPaths.length == 0 ? null : this.prefabPaths[ThreadLocalRandom.current().nextInt(this.prefabPaths.length)];
   }

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

   class="kw">public class="kw">static class PrefabReference {
      class="kw">public class="kw">static class="kw">final BuilderCodec<PrefabListAsset.PrefabReference> CODEC = BuilderCodec.builder(
            PrefabListAsset.PrefabReference.class, PrefabListAsset.PrefabReference::new
         )
         .append(
            new KeyedCodec<>("RootDirectory", new EnumCodec<>(PrefabListAsset.PrefabRootDirectory.class), true),
            (var0, var1) -> var0.rootDirectory = var1,
            var0 -> var0.rootDirectory
         )
         .add()
         .append(new KeyedCodec<>("Path", Codec.STRING, true), (var0, var1) -> var0.unprocessedPrefabPath = var1, var0 -> var0.unprocessedPrefabPath)
         .add()
         .append(new KeyedCodec<>("Recursive", Codec.BOOLEAN, false), (var0, var1) -> var0.recursive = var1, var0 -> var0.recursive)
         .add()
         .afterDecode(PrefabListAsset.PrefabReference::processPrefabPath)
         .build();
      class="kw">private class="kw">static class="kw">final int MAX_RECURSION_DEPTH = 5;
      class="kw">private class="kw">static class="kw">final String[] EXTENSIONS = new String[]{".prefab.json"};
      class="kw">public PrefabListAsset.PrefabRootDirectory rootDirectory;
      class="kw">public String unprocessedPrefabPath;
      class="kw">public boolean recursive = false;
      @Nonnull
      class="kw">public List<Path> prefabPaths = new ObjectArrayList();

      class="kw">public PrefabReference() {
      }

      class="kw">public void processPrefabPath() {
         if (this.unprocessedPrefabPath != null) {
            this.unprocessedPrefabPath = this.unprocessedPrefabPath.replace('\\', '/');
            if (this.rootDirectory == PrefabListAsset.PrefabRootDirectory.Asset) {
               try {
                  Path var10 = this.rootDirectory.getPrefabPath();
                  Path var12 = PathUtil.resolvePathWithinDir(var10, this.unprocessedPrefabPath);
                  if (var12 == null) {
                     throw new InvalidPathException(this.unprocessedPrefabPath, "Failed to resolve path under assets root");
                  }

                  Path var13 = AssetModule.get().getBaseAssetPack().getRoot();
                  Path var4 = var13.relativize(var12);
                  if (this.unprocessedPrefabPath.endsWith("/")) {
                     int var5 = this.recursive ? 5 : 1;
                     AssetPackPathUtil.visitAssetPaths(var4, ".prefab.json", var5, this.prefabPaths, List::add);
                  } else {
                     Path var14 = AssetPackPathUtil.resolveAssetPath(var4, EXTENSIONS);
                     if (var14 != null) {
                        this.prefabPaths.add(var14);
                     }
                  }

                  class="kw">return;
               } catch (Throwable var9) {
                  this.prefabPaths.clear();
                  ((HytaleLogger.Api)((HytaleLogger.Api)PrefabListAsset.getAssetStore().getLogger().atWarning()).withCause(var9))
                     .log("Exception collecting prefab assets for path: %s", this.unprocessedPrefabPath);
               }
            }

            Path var1 = this.rootDirectory.getPrefabPath();
            if (!this.unprocessedPrefabPath.endsWith("/")) {
               if (!this.unprocessedPrefabPath.endsWith(".prefab.json")) {
                  this.unprocessedPrefabPath = this.unprocessedPrefabPath + ".prefab.json";
               }

               Path var11 = PathUtil.resolvePathWithinDir(var1, this.unprocessedPrefabPath);
               if (var11 == null) {
                  PrefabListAsset.getAssetStore().getLogger().at(Level.SEVERE).log("Invalid prefab path: %s", this.unprocessedPrefabPath);
               } else {
                  this.prefabPaths.add(var11);
               }
            } else {
               Path var2 = PathUtil.resolvePathWithinDir(var1, this.unprocessedPrefabPath);
               if (var2 == null) {
                  PrefabListAsset.getAssetStore().getLogger().at(Level.SEVERE).log("Invalid prefab path: %s", this.unprocessedPrefabPath);
               } else {
                  try (Stream var3 = Files.walk(var2, this.recursive ? 5 : 1)) {
                     var3.filter(var0 -> Files.isRegularFile(var0)).filter(var0 -> var0.toString().endsWith(".prefab.json")).forEach(this.prefabPaths::add);
                  } catch (IOException var8) {
                     ((HytaleLogger.Api)PrefabListAsset.getAssetStore().getLogger().at(Level.SEVERE).withCause(var8))
                        .log("Failed to process prefab path: %s", this.unprocessedPrefabPath);
                  }
               }
            }
         }
      }
   }

   class="kw">public enum PrefabRootDirectory {
      Server(() -> PrefabStore.get().getServerPrefabsPath(), "server.commands.editprefab.ui.rootDirectory.server"),
      Asset(() -> PrefabStore.get().getAssetPrefabsPath(), "server.commands.editprefab.ui.rootDirectory.asset"),
      Worldgen(() -> PrefabStore.get().getWorldGenPrefabsPath(), "server.commands.editprefab.ui.rootDirectory.worldGen");

      class="kw">private class="kw">final Supplier<Path> prefabPath;
      class="kw">private class="kw">final String localizationString;

      PrefabRootDirectory(Supplier<Path> nullxx, String nullxxx) {
         this.prefabPath = nullxx;
         this.localizationString = nullxxx;
      }

      class="kw">public Path getPrefabPath() {
         class="kw">return this.prefabPath.get();
      }

      class="kw">public String getLocalizationString() {
         class="kw">return this.localizationString;
      }
   }
}