package com.hypixel.hytale.server.worldgen.loader.context;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.nio.file.Path;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class ZoneFileContext extends FileContext<FileLoadingContext> {
private final FileContext.Registry<BiomeFileContext> tileBiomes = new FileContext.Registry<BiomeFileContext>("TileBiome");
private final FileContext.Registry<BiomeFileContext> customBiomes = new FileContext.Registry<BiomeFileContext>("CustomBiome");
public ZoneFileContext(int id, String name, Path filepath, FileLoadingContext context) {
super(id, name, filepath, context);
}
@Nonnull
public FileContext.Registry<BiomeFileContext> getTileBiomes() {
return this.tileBiomes;
}
@Nonnull
public FileContext.Registry<BiomeFileContext> getCustomBiomes() {
return this.customBiomes;
}
@Nonnull
public FileContext.Registry<BiomeFileContext> getBiomes(@Nonnull BiomeFileContext.Type type) {
FileContext.Registry var10000;
switch (type) {
case Tile -> var10000 = this.getTileBiomes();
case Custom -> var10000 = this.getCustomBiomes();
default -> throw new MatchException((String)null, (Throwable)null);
}
return var10000;
}
@Nonnull
public ZoneFileContext matchContext(@Nullable JsonElement json, String key) {
if (json != null && json.isJsonObject()) {
JsonElement element = json.getAsJsonObject().get(key);
if (element != null && element.isJsonObject()) {
JsonObject object = element.getAsJsonObject();
if (!object.has("File")) {
return this;
} else {
String filePath = object.get("File").getAsString();
return this.matchContext(filePath);
}
} else {
return this;
}
} else {
return this;
}
}
@Nonnull
public ZoneFileContext matchContext(@Nonnull String filePath) {
if (!filePath.startsWith("Zones.")) {
return this;
} else {
int nameStart = "Zones.".length();
int nameEnd = filePath.indexOf(46, nameStart);
if (nameEnd < nameStart) {
return this;
} else if (filePath.regionMatches(nameStart, this.getName(), 0, nameEnd - nameStart)) {
return this;
} else {
String zoneName = filePath.substring(nameStart, nameEnd);
FileContext.Registry<ZoneFileContext> zoneRegistry = ((FileLoadingContext)this.getParentContext()).getZones();
return !zoneRegistry.contains(zoneName) ? this : (ZoneFileContext)zoneRegistry.get(zoneName);
}
}
}
@Nonnull
protected BiomeFileContext createBiome(String name, Path path, BiomeFileContext.Type type) {
return this.createBiome(((FileLoadingContext)this.getParentContext()).nextBiomeId(), name, path, type);
}
@Nonnull
protected BiomeFileContext createBiome(int id, String name, Path path, BiomeFileContext.Type type) {
return new BiomeFileContext(((FileLoadingContext)this.getParentContext()).updateBiomeId(id), name, path, type, this);
}
public interface Constants {
String ZONE_PREFIX = "Zones.";
}
}