From 5c4671a9bff23ba53311679315dcbaf567276470 Mon Sep 17 00:00:00 2001
From: Owen <23108066+Owen1212055@users.noreply.github.com>
Date: Sat, 22 Apr 2023 21:55:10 -0400
Subject: [PATCH] Fix LegacyPluginLoader dependency registration (#9165)

---
 patches/server/0013-Paper-Plugins.patch | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/patches/server/0013-Paper-Plugins.patch b/patches/server/0013-Paper-Plugins.patch
index be3340453e..3fb6bf384d 100644
--- a/patches/server/0013-Paper-Plugins.patch
+++ b/patches/server/0013-Paper-Plugins.patch
@@ -1762,10 +1762,10 @@ index 0000000000000000000000000000000000000000..a2fa8406bc3f0dcab6805633ae984d03
 +}
 diff --git a/src/main/java/io/papermc/paper/plugin/entrypoint/dependency/MetaDependencyTree.java b/src/main/java/io/papermc/paper/plugin/entrypoint/dependency/MetaDependencyTree.java
 new file mode 100644
-index 0000000000000000000000000000000000000000..1523cbb1801b937c3d40080df7d52e6cff8fc49c
+index 0000000000000000000000000000000000000000..e72bec3b0cbc41580f1b4beecae316d1c083d3e3
 --- /dev/null
 +++ b/src/main/java/io/papermc/paper/plugin/entrypoint/dependency/MetaDependencyTree.java
-@@ -0,0 +1,112 @@
+@@ -0,0 +1,117 @@
 +package io.papermc.paper.plugin.entrypoint.dependency;
 +
 +import com.google.common.graph.GraphBuilder;
@@ -1867,6 +1867,11 @@ index 0000000000000000000000000000000000000000..1523cbb1801b937c3d40080df7d52e6c
 +        return this.dependencies.contains(pluginIdentifier);
 +    }
 +
++    // Used by the legacy loader -- this isn't recommended
++    public void addDirectDependency(String dependency) {
++        this.dependencies.add(dependency);
++    }
++
 +    @Override
 +    public String toString() {
 +        return "ProviderDependencyTree{" +
@@ -2240,10 +2245,10 @@ index 0000000000000000000000000000000000000000..a9bca905eba67972e4d1b07b1d243272
 +}
 diff --git a/src/main/java/io/papermc/paper/plugin/entrypoint/strategy/LegacyPluginLoadingStrategy.java b/src/main/java/io/papermc/paper/plugin/entrypoint/strategy/LegacyPluginLoadingStrategy.java
 new file mode 100644
-index 0000000000000000000000000000000000000000..ebd193e7d9736021756223d565c8a16a7b1770d2
+index 0000000000000000000000000000000000000000..f59f48654eaa299bcac862991b1e2e622264639b
 --- /dev/null
 +++ b/src/main/java/io/papermc/paper/plugin/entrypoint/strategy/LegacyPluginLoadingStrategy.java
-@@ -0,0 +1,269 @@
+@@ -0,0 +1,271 @@
 +package io.papermc.paper.plugin.entrypoint.strategy;
 +
 +import com.google.common.graph.GraphBuilder;
@@ -2292,6 +2297,7 @@ index 0000000000000000000000000000000000000000..ebd193e7d9736021756223d565c8a16a
 +            PluginMeta configuration = provider.getMeta();
 +
 +            PluginProvider<T> replacedProvider = providersToLoad.put(configuration.getName(), provider);
++            dependencyTree.addDirectDependency(configuration.getName()); // add to dependency tree
 +            if (replacedProvider != null) {
 +                LOGGER.severe(String.format(
 +                    "Ambiguous plugin name `%s' for files `%s' and `%s' in `%s'",
@@ -2324,6 +2330,7 @@ index 0000000000000000000000000000000000000000..ebd193e7d9736021756223d565c8a16a
 +                    ));
 +                } else {
 +                    String replacedPlugin = pluginsProvided.put(provided, configuration.getName());
++                    dependencyTree.addDirectDependency(provided); // add to dependency tree
 +                    if (replacedPlugin != null) {
 +                        LOGGER.warning(String.format(
 +                            "`%s' is provided by both `%s' and `%s'",