mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-24 09:01:54 +01:00
More scoping
This commit is contained in:
parent
b5728e2255
commit
e9a5389680
@ -312,19 +312,19 @@ public class ExtensionManager {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private List<DiscoveredExtension> generateLoadOrder(@NotNull List<DiscoveredExtension> discoveredExtensions) {
|
private List<DiscoveredExtension> generateLoadOrder(@NotNull List<DiscoveredExtension> discoveredExtensions) {
|
||||||
// Do some mapping so we can map strings to extensions.
|
// Extension --> Extensions it depends on.
|
||||||
Map<DiscoveredExtension, List<DiscoveredExtension>> dependencyMap = new HashMap<>();
|
Map<DiscoveredExtension, List<DiscoveredExtension>> dependencyMap = new HashMap<>();
|
||||||
|
|
||||||
// Put dependencies in dependency map
|
// Put dependencies in dependency map
|
||||||
{
|
{
|
||||||
Map<String, DiscoveredExtension> extensionMap = new HashMap<>();
|
Map<String, DiscoveredExtension> extensionMap = new HashMap<>();
|
||||||
|
|
||||||
|
// go through all the discovered extensions and assign their name in a map.
|
||||||
for (DiscoveredExtension discoveredExtension : discoveredExtensions) {
|
for (DiscoveredExtension discoveredExtension : discoveredExtensions) {
|
||||||
extensionMap.put(discoveredExtension.getName().toLowerCase(), discoveredExtension);
|
extensionMap.put(discoveredExtension.getName().toLowerCase(), discoveredExtension);
|
||||||
}
|
}
|
||||||
|
|
||||||
allExtensions:
|
allExtensions: // go through all the discovered extensions and get their dependencies as extensions
|
||||||
// label the loop
|
|
||||||
for (DiscoveredExtension discoveredExtension : discoveredExtensions) {
|
for (DiscoveredExtension discoveredExtension : discoveredExtensions) {
|
||||||
|
|
||||||
List<DiscoveredExtension> dependencies = new ArrayList<>(discoveredExtension.getDependencies().length);
|
List<DiscoveredExtension> dependencies = new ArrayList<>(discoveredExtension.getDependencies().length);
|
||||||
@ -366,29 +366,32 @@ public class ExtensionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// List containing the real load order.
|
// List containing the load order.
|
||||||
LinkedList<DiscoveredExtension> sortedList = new LinkedList<>();
|
LinkedList<DiscoveredExtension> sortedList = new LinkedList<>();
|
||||||
|
|
||||||
// entries with empty lists
|
// TODO actually have to read this
|
||||||
List<Map.Entry<DiscoveredExtension, List<DiscoveredExtension>>> loadableExtensions;
|
{
|
||||||
|
// entries with empty lists
|
||||||
|
List<Map.Entry<DiscoveredExtension, List<DiscoveredExtension>>> loadableExtensions;
|
||||||
|
|
||||||
// While there are entries with no more elements (no more dependencies)
|
// While there are entries with no more elements (no more dependencies)
|
||||||
while (!(
|
while (!(
|
||||||
loadableExtensions = dependencyMap.entrySet().stream().filter(entry -> areAllDependenciesLoaded(entry.getValue())).collect(Collectors.toList())
|
loadableExtensions = dependencyMap.entrySet().stream().filter(entry -> areAllDependenciesLoaded(entry.getValue())).collect(Collectors.toList())
|
||||||
).isEmpty()
|
).isEmpty()
|
||||||
) {
|
) {
|
||||||
// Get all "loadable" (not actually being loaded!) extensions and put them in the sorted list.
|
// Get all "loadable" (not actually being loaded!) extensions and put them in the sorted list.
|
||||||
for (Map.Entry<DiscoveredExtension, List<DiscoveredExtension>> entry : loadableExtensions) {
|
for (Map.Entry<DiscoveredExtension, List<DiscoveredExtension>> entry : loadableExtensions) {
|
||||||
|
|
||||||
// Add to sorted list.
|
// Add to sorted list.
|
||||||
sortedList.add(entry.getKey());
|
sortedList.add(entry.getKey());
|
||||||
|
|
||||||
// Remove to make the next iterations a little bit quicker (hopefully) and to find cyclic dependencies.
|
// Remove to make the next iterations a little bit quicker (hopefully) and to find cyclic dependencies.
|
||||||
dependencyMap.remove(entry.getKey());
|
dependencyMap.remove(entry.getKey());
|
||||||
|
|
||||||
// Remove this dependency from all the lists (if they include it) to make way for next level of extensions.
|
// Remove this dependency from all the lists (if they include it) to make way for next level of extensions.
|
||||||
for (var dependencies : dependencyMap.values()) {
|
for (var dependencies : dependencyMap.values()) {
|
||||||
dependencies.remove(entry.getKey());
|
dependencies.remove(entry.getKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user