package com.hypixel.hytale.builtin.portals.components.voidevent.config;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
import com.hypixel.hytale.server.core.asset.type.ambiencefx.config.AmbienceFX;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.annotation.Nullable;
publicclassVoidEventConfig {
publicstaticfinal BuilderCodec<VoidEventConfig> CODEC;
privateintdurationSeconds=180;
private InvasionPortalConfig portalConfig;
private VoidEventStage[] stages;
private List<VoidEventStage> stagesSortedByStartTime;
private String musicAmbienceFX;
publicVoidEventConfig() {
}
publicintgetDurationSeconds() {
returnthis.durationSeconds;
}
publicintgetShouldStartAfterSeconds(int portalTimeLimitSeconds) {
return Math.max(10, portalTimeLimitSeconds - this.durationSeconds);
}
public InvasionPortalConfig getInvasionPortalConfig() {
returnthis.portalConfig;
}
public VoidEventStage[] getStages() {
returnthis.stages;
}
public List<VoidEventStage> getStagesSortedByStartTime() {
returnthis.stagesSortedByStartTime;
}
@Nullablepublic String getMusicAmbienceFX() {
returnthis.musicAmbienceFX;
}
privatevoidprocessConfig() {
this.stagesSortedByStartTime = newObjectArrayList<VoidEventStage>();
if (this.stages != null) {
Collections.addAll(this.stagesSortedByStartTime, this.stages);
this.stagesSortedByStartTime.sort(Comparator.comparingInt(VoidEventStage::getSecondsInto));
}
}
static {
CODEC = ((BuilderCodec.Builder)((BuilderCodec.Builder)((BuilderCodec.Builder)((BuilderCodec.Builder)((BuilderCodec.Builder)BuilderCodec.builder(VoidEventConfig.class, VoidEventConfig::new).append(newKeyedCodec("DurationSeconds", Codec.INTEGER), (config, o) -> config.durationSeconds = o, (config) -> config.durationSeconds).documentation("How long the void event lasts in seconds. The void event starts at the end of the instance. If your fragment is 10 minutes and this is 180 seconds, it will start 7 minutes in.").add()).append(newKeyedCodec("InvasionPortals", InvasionPortalConfig.CODEC), (config, o) -> config.portalConfig = o, (config) -> config.portalConfig).documentation("Configuration regarding the enemy portals that spawn around the players during the event").add()).append(newKeyedCodec("Stages", newArrayCodec(VoidEventStage.CODEC, (x$0) -> newVoidEventStage[x$0])), (config, o) -> config.stages = o, (config) -> config.stages).documentation("Certain event characteristics happen over stages that can be defined here. Stages are spread in time. Only one stage is \"active\" at a time.").add()).append(newKeyedCodec("MusicAmbienceFX", Codec.STRING), (config, o) -> config.musicAmbienceFX = o, (config) -> config.musicAmbienceFX).documentation("The ID of an AmbienceFX which will be used for the music during the event").addValidator(AmbienceFX.VALIDATOR_CACHE.getValidator()).add()).afterDecode(VoidEventConfig::processConfig)).build();
}
}