package com.hypixel.hytale.component.system; import com.hypixel.hytale.component.ComponentRegistry; import com.hypixel.hytale.component.SystemGroup; import com.hypixel.hytale.component.dependency.Dependency; import com.hypixel.hytale.component.dependency.DependencyGraph; import java.util.Arrays; import java.util.Collections; import java.util.Set; import javax.annotation.Nonnull; import javax.annotation.Nullable; public interface ISystem { ISystem[] EMPTY_ARRAY = new ISystem[0]; default void onSystemRegistered() { } default void onSystemUnregistered() { } @Nullable default SystemGroup getGroup() { return null; } @Nonnull default Set> getDependencies() { return Collections.emptySet(); } static void calculateOrder(@Nonnull ComponentRegistry registry, @Nonnull ISystem[] sortedSystems, int systemSize) { DependencyGraph graph = new DependencyGraph<>(Arrays.copyOf(sortedSystems, systemSize)); graph.resolveEdges(registry); graph.sort(sortedSystems); } }