Code enum
Пакет: com.hypixel.hytale.builtin.adventure.worldevents.event
Файл: com/hypixel/hytale/builtin/adventure/worldevents/event/Validator.java
Поля (1)
| Модификаторы | Тип | Имя |
|---|---|---|
|
PASS, |
FAIL |
Исходный код
Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.adventure.worldevents.event;
class="kw">import com.google.errorprone.annotations.FormatMethod;
class="kw">import com.hypixel.hytale.builtin.adventure.worldevents.action.EventAction;
class="kw">import com.hypixel.hytale.builtin.adventure.worldevents.condition.EventCondition;
class="kw">import com.hypixel.hytale.builtin.adventure.worldevents.context.ContextKey;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectArrayList;
class="kw">import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet;
class="kw">import java.util.List;
class="kw">import java.util.Set;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">public class Validator {
class="kw">protected class="kw">final Set<StageAsset> visitedStages = new ReferenceOpenHashSet();
class="kw">protected class="kw">final Set<ContextKey> definedKeys = new ReferenceOpenHashSet();
class="kw">protected class="kw">final Set<ContextKey> referencedKeys = new ReferenceOpenHashSet();
class="kw">protected class="kw">final List<StageAsset> stages = new ObjectArrayList();
@Nullable
class="kw">protected String genericErrorMessage = null;
class="kw">public Validator() {
}
class="kw">public void reset() {
this.visitedStages.clear();
this.definedKeys.clear();
this.referencedKeys.clear();
this.stages.clear();
this.genericErrorMessage = null;
}
class="kw">public void addDefinedKey(@Nonnull String var1, @Nonnull String var2, @Nullable ContextKey var3) {
if (var3 == null) {
this.genericErrorMessage = String.format("Invalid config. Type: %s, Error: %s not defined", var1, var2);
} else {
this.definedKeys.add(var3);
}
}
class="kw">public void addReferencedKey(@Nonnull String var1, @Nonnull String var2, @Nullable ContextKey var3) {
if (var3 == null) {
this.genericErrorMessage = String.format("Invalid config. Type: %s, Error: %s not defined", var1, var2);
} else {
this.referencedKeys.add(var3);
}
}
@FormatMethod
class="kw">public void addErrorMessage(@Nonnull String var1, @Nonnull Object... var2) {
this.genericErrorMessage = String.format(var1, var2);
}
@Nonnull
class="kw">public Validator.Result validate(@Nonnull WorldEventAsset var1) {
this.reset();
StageAsset var2 = StageAsset.ASSET_MAP.getAsset(var1.root);
if (var2 == null) {
class="kw">return Validator.Result.fail("Missing root stage: %s", var1.root);
}
this.stages.add(var2);
this.visitedStages.add(var2);
for (int var3 = 0; var3 < this.stages.size(); var3++) {
StageAsset var4 = this.stages.get(var3);
for (Fork.Config var8 : var4.forks) {
for (EventCondition.Config var12 : var8.conditions) {
var12.validate(this);
if (this.genericErrorMessage != null) {
class="kw">return Validator.Result.fail("Invalid condition: %s", this.genericErrorMessage);
}
}
for (EventAction var19 : var8.actions) {
var19.validate(this);
if (this.genericErrorMessage != null) {
class="kw">return Validator.Result.fail("Invalid action: %s", this.genericErrorMessage);
}
}
if (var8.next != null) {
StageAsset var16 = StageAsset.ASSET_MAP.getAsset(var8.next);
if (var16 == null) {
class="kw">return Validator.Result.fail("Missing stage: %s", var8.next);
}
if (this.visitedStages.add(var16)) {
this.stages.add(var16);
}
}
}
}
for (ContextKey var14 : this.referencedKeys) {
if (!this.definedKeys.contains(var14)) {
class="kw">return Validator.Result.fail("Referenced name '%s' has not been defined", var14.getName());
}
}
class="kw">return this.hasCycle(var2, new ReferenceOpenHashSet(), new ReferenceOpenHashSet())
? Validator.Result.fail("Cyclic stage graph reachable from root stage: %s", var1.root)
: Validator.Result.pass();
}
class="kw">private boolean hasCycle(@Nonnull StageAsset var1, @Nonnull Set<StageAsset> var2, @Nonnull Set<StageAsset> var3) {
if (var3.contains(var1)) {
class="kw">return false;
}
if (!var2.add(var1)) {
class="kw">return true;
}
for (Fork.Config var7 : var1.forks) {
if (var7.next != null) {
StageAsset var8 = StageAsset.ASSET_MAP.getAsset(var7.next);
if (var8 != null && this.hasCycle(var8, var2, var3)) {
class="kw">return true;
}
}
}
var2.remove(var1);
var3.add(var1);
class="kw">return false;
}
class="kw">public enum Code {
PASS,
FAIL;
Code() {
}
}
class="kw">public record Result(Validator.Code code, @Nullable String message) {
class="kw">private class="kw">static class="kw">final Validator.Result PASS = new Validator.Result(Validator.Code.PASS, null);
class="kw">public Result {
}
class="kw">public class="kw">static Validator.Result pass() {
class="kw">return PASS;
}
@Nonnull
@FormatMethod
class="kw">public class="kw">static Validator.Result fail(@Nonnull String var0, Object... var1) {
class="kw">return new Validator.Result(Validator.Code.FAIL, String.format(var0, var1));
}
}
}