Constants interface

Пакет: com.hypixel.hytale.procedurallib.json

Файл: com/hypixel/hytale/procedurallib/json/DoubleThresholdJsonLoader.java

Поля (2)

МодификаторыТипИмя
String ERROR_NO_ENTRY
String ERROR_THRESHOLD_SIZE

Исходный код

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

class="kw">import com.google.gson.JsonArray;
class="kw">import com.google.gson.JsonElement;
class="kw">import com.hypixel.hytale.procedurallib.condition.DefaultDoubleThresholdCondition;
class="kw">import com.hypixel.hytale.procedurallib.condition.DoubleThreshold;
class="kw">import com.hypixel.hytale.procedurallib.condition.IDoubleThreshold;
class="kw">import java.nio.file.Path;
class="kw">import javax.annotation.Nonnull;

class="kw">public class DoubleThresholdJsonLoader<K class="kw">extends SeedResource> class="kw">extends JsonLoader<K, IDoubleThreshold> {
   class="kw">protected class="kw">final boolean defaultValue;

   class="kw">public DoubleThresholdJsonLoader(@Nonnull SeedString<K> var1, Path var2, JsonElement var3) {
      this(var1, var2, var3, true);
   }

   class="kw">public DoubleThresholdJsonLoader(@Nonnull SeedString<K> var1, Path var2, JsonElement var3, boolean var4) {
      super(var1.append(".DoubleThreshold"), var2, var3);
      this.defaultValue = var4;
   }

   @Nonnull
   class="kw">public IDoubleThreshold load() {
      if (this.json == null || this.json.isJsonNull()) {
         class="kw">return this.defaultValue ? DefaultDoubleThresholdCondition.DEFAULT_TRUE : DefaultDoubleThresholdCondition.DEFAULT_FALSE;
      }

      if (this.json.isJsonPrimitive()) {
         double var5 = this.json.getAsDouble();
         class="kw">return new DoubleThreshold.Single(0.0, var5);
      }

      JsonArray var1 = this.json.getAsJsonArray();
      if (var1.size() <= 0) {
         throw new IllegalArgumentException("Threshold array must contain at least one entry!");
      }

      if (var1.get(0).isJsonArray()) {
         DoubleThreshold.Single[] var2 = new DoubleThreshold.Single[var1.size()];

         for (int var3 = 0; var3 < var2.length; var3++) {
            JsonArray var4 = var1.get(var3).getAsJsonArray();
            if (var4.size() != 2) {
               throw new IllegalArgumentException("Threshold array entries must have 2 numbers for lower/upper limit!");
            }

            var2[var3] = new DoubleThreshold.Single(var4.get(0).getAsDouble(), var4.get(1).getAsDouble());
         }

         class="kw">return new DoubleThreshold.Multiple(var2);
      } else if (var1.size() != 2) {
         throw new IllegalArgumentException("Threshold array entries must have 2 numbers for lower/upper limit!");
      } else {
         class="kw">return new DoubleThreshold.Single(var1.get(0).getAsDouble(), var1.get(1).getAsDouble());
      }
   }

   class="kw">public class="kw">interface Constants {
      String ERROR_NO_ENTRY = "Threshold array must contain at least one entry!";
      String ERROR_THRESHOLD_SIZE = "Threshold array entries must have 2 numbers for lower/upper limit!";
   }
}