WorldGenBuilderCodec class

Пакет: com.hypixel.hytale.server.worldgen

Файл: com/hypixel/hytale/server/worldgen/HytaleWorldGenProvider.java

extends: BuilderCodec<HytaleWorldGenProvider>

Поля (3)

МодификаторыТипИмя
private final Object lock
HytaleWorldGenProvider var2
private final Map<String, Semver> versions

Методы (5)

МодификаторыВозвратСигнатура
public HytaleWorldGenProvider getDefaultValuepublic HytaleWorldGenProvider getDefaultValue(ExtraInfo var1)
public void setVersionspublic void setVersions(@Nonnull Map<String, Semver> var1)
abstract super super(var1)
synchronized synchronized(this.lock)
synchronized synchronized(this.lock)

Исходный код

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

class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.ExtraInfo;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.common.semver.Semver;
class="kw">import com.hypixel.hytale.common.util.PathUtil;
class="kw">import com.hypixel.hytale.procedurallib.json.SeedString;
class="kw">import com.hypixel.hytale.server.core.universe.Universe;
class="kw">import com.hypixel.hytale.server.core.universe.world.worldgen.IWorldGen;
class="kw">import com.hypixel.hytale.server.core.universe.world.worldgen.WorldGenLoadException;
class="kw">import com.hypixel.hytale.server.core.universe.world.worldgen.provider.IWorldGenProvider;
class="kw">import com.hypixel.hytale.server.worldgen.loader.ChunkGeneratorJsonLoader;
class="kw">import com.hypixel.hytale.server.worldgen.prefab.PrefabStoreRoot;
class="kw">import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
class="kw">import java.nio.file.Files;
class="kw">import java.nio.file.Path;
class="kw">import java.util.Map;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class HytaleWorldGenProvider class="kw">implements IWorldGenProvider {
   class="kw">public class="kw">static class="kw">final String ID = "Hytale";
   class="kw">public class="kw">static class="kw">final String DEFAULT_NAME = "Default";
   class="kw">public class="kw">static class="kw">final Semver MIN_VERSION = new Semver(0L, 0L, 0L);
   class="kw">public class="kw">static class="kw">final HytaleWorldGenProvider.WorldGenBuilderCodec CODEC = new HytaleWorldGenProvider.WorldGenBuilderCodec(
      BuilderCodec.builder(HytaleWorldGenProvider.class, HytaleWorldGenProvider::new)
         .documentation("The standard generator for Hytale.")
         .<String>append(new KeyedCodec<>("Name", Codec.STRING), (var0, var1) -> var0.name = var1, var0 -> var0.name)
         .documentation("The name of the generator to use. \"*Default*\" if not provided.")
         .add()
         .<Semver>append(new KeyedCodec<>("Version", Semver.CODEC), (var0, var1) -> var0.version = var1, var0 -> var0.version)
         .documentation("The version of the generator to use. \"0.0.0\" if not provided.")
         .add()
         .<String>append(new KeyedCodec<>("Path", Codec.STRING), (var0, var1) -> var0.path = var1, var0 -> var0.path)
         .documentation("The path to the world generation configuration. \n\nDefaults to the server provided world generation folder if not set.")
         .add()
   );
   @Nonnull
   class="kw">private String name = "Default";
   @Nonnull
   class="kw">private Semver version = MIN_VERSION;
   @Nullable
   class="kw">private String path;

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

   @Nonnull
   class="kw">public Semver getVersion() {
      class="kw">return this.version;
   }

   @Nonnull
   @Override
   class="kw">public IWorldGen getGenerator() class="kw">throws WorldGenLoadException {
      Path var1;
      if (this.path != null) {
         var1 = Path.of(this.path);
         if (!PathUtil.isInTrustedRoot(var1)) {
            throw new WorldGenLoadException("World gen path must be within a trusted directory: " + this.path);
         }
      } else {
         var1 = Universe.getWorldGenPath();
      }

      if (!"Default".equals(this.name) || !Files.exists(var1.resolve("World.json"))) {
         Path var2 = PathUtil.resolvePathWithinDir(var1, this.name);
         if (var2 == null) {
            throw new WorldGenLoadException("Invalid world gen name: " + this.name);
         }

         var1 = var2;
      }

      try {
         WorldGenConfig var4 = new WorldGenConfig(var1, this.name, this.version);
         class="kw">return new ChunkGeneratorJsonLoader(new SeedString<>("ChunkGenerator", new SeedStringResource(PrefabStoreRoot.DEFAULT, var4)), var4).load();
      } catch (Error var3) {
         throw new WorldGenLoadException("Failed to load world gen!", var3);
      }
   }

   @Override
   class="kw">public String toString() {
      class="kw">return "HytaleWorldGenProvider{name='" + this.name + "', version=" + this.version + ", path='" + this.path + "'}";
   }

   class="kw">public class="kw">static class WorldGenBuilderCodec class="kw">extends BuilderCodec<HytaleWorldGenProvider> {
      class="kw">private class="kw">final Object lock = new Object();
      class="kw">private class="kw">final Map<String, Semver> versions = new Object2ObjectOpenHashMap();

      class="kw">protected WorldGenBuilderCodec(@Nonnull BuilderCodec.BuilderBase<HytaleWorldGenProvider, ?> var1) {
         super(var1);
      }

      class="kw">public HytaleWorldGenProvider getDefaultValue(ExtraInfo var1) {
         HytaleWorldGenProvider var2 = new HytaleWorldGenProvider();
         class="kw">synchronized (this.lock) {
            var2.version = this.versions.getOrDefault("Default", HytaleWorldGenProvider.MIN_VERSION);
         }

         this.afterDecode(var2, var1);
         class="kw">return var2;
      }

      class="kw">public void setVersions(@Nonnull Map<String, Semver> var1) {
         class="kw">synchronized (this.lock) {
            this.versions.clear();
            this.versions.putAll(var1);
         }
      }
   }
}