Constants interface

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

Файл: com/hypixel/hytale/server/worldgen/loader/cave/CaveTypesJsonLoader.java

Поля (3)

МодификаторыТипИмя
String ERROR_NOT_AN_ARRAY
String KEY_NAME
String SEED_CAVE_TYPE_SUFFIX

Исходный код

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

class="kw">import com.google.gson.JsonArray;
class="kw">import com.google.gson.JsonElement;
class="kw">import com.google.gson.JsonObject;
class="kw">import com.hypixel.hytale.builtin.worldgen.modifier.event.ModifyEvent;
class="kw">import com.hypixel.hytale.builtin.worldgen.modifier.event.ModifyEvents;
class="kw">import com.hypixel.hytale.procedurallib.json.JsonLoader;
class="kw">import com.hypixel.hytale.procedurallib.json.SeedString;
class="kw">import com.hypixel.hytale.server.worldgen.SeedStringResource;
class="kw">import com.hypixel.hytale.server.worldgen.cave.CaveType;
class="kw">import com.hypixel.hytale.server.worldgen.loader.context.CaveFileContext;
class="kw">import com.hypixel.hytale.server.worldgen.loader.context.ZoneFileContext;
class="kw">import com.hypixel.hytale.server.worldgen.util.ListPool;
class="kw">import java.nio.file.Path;
class="kw">import javax.annotation.Nonnull;

class="kw">public class CaveTypesJsonLoader class="kw">extends JsonLoader<SeedStringResource, CaveType[]> {
   class="kw">protected class="kw">final Path caveFolder;
   class="kw">protected class="kw">final ZoneFileContext zoneContext;
   class="kw">protected class="kw">final CaveFileContext caveContext;

   class="kw">public CaveTypesJsonLoader(SeedString<SeedStringResource> var1, Path var2, JsonElement var3, Path var4, ZoneFileContext var5) {
      super(var1, var2, var3);
      this.caveFolder = var4;
      this.zoneContext = var5;
      this.caveContext = new CaveFileContext("Caves", var5);
   }

   @Nonnull
   class="kw">public CaveType[] load() {
      if (this.json != null && this.json.isJsonArray()) {
         JsonArray var1 = this.json.getAsJsonArray();

         try (ListPool.Resource var2 = CaveType.ENTRY_POOL.acquire(var1.size())) {
            for (int var3 = 0; var3 < var1.size(); var3++) {
               JsonElement var4 = this.getOrLoad(var1.get(var3));
               if (!var4.isJsonObject()) {
                  throw error("Expected CaveType entry to be a JsonObject at index: %d", var3);
               }

               var2.add(this.loadCaveType(var4.getAsJsonObject()));
            }

            ModifyEvent.dispatch(
               ModifyEvents.CaveTypes.class,
               new ModifyEvents.CaveTypes(this.seed, this.caveContext, var2, var1x -> this.loadCaveType(this.loadFile(var1x).getAsJsonObject()))
            );
            class="kw">return var2.toArray();
         }
      } else {
         throw new IllegalArgumentException("CaveTypes must be a JSON array.");
      }
   }

   @Nonnull
   class="kw">protected CaveType loadCaveType(JsonObject var1) {
      JsonElement var2 = var1.get("Name");
      if (var2 == null) {
         throw error("CaveType is missing the 'Name' property");
      } else if (var2.isJsonPrimitive() && var2.getAsJsonPrimitive().isString()) {
         class="kw">return new CaveTypeJsonLoader(
               this.seed.append(String.format("-%s", var2)), this.dataFolder, var1, this.caveFolder, var2.getAsString(), this.zoneContext
            )
            .load();
      } else {
         throw error("CaveType 'Name' property is not a string");
      }
   }

   class="kw">public class="kw">interface Constants {
      String KEY_NAME = "Name";
      String SEED_CAVE_TYPE_SUFFIX = "-%s";
      String ERROR_NOT_AN_ARRAY = "CaveTypes must be a JSON array.";
   }
}