Skip to content

Commit c9016fd

Browse files
committed
properly implement ProviderSource for our spark jar provider
1 parent 03a732c commit c9016fd

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

patches/server/0256-Spark-Profiler.patch

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ index 708e5bb9bbf0476fcc2c4b92c6830b094703b43e..6141f716b15ad47ac2ac4c9ce92a3897
1919
// This will be the end of me...
2020
diff --git a/src/main/java/io/papermc/paper/plugin/provider/source/SparkProviderSource.java b/src/main/java/io/papermc/paper/plugin/provider/source/SparkProviderSource.java
2121
new file mode 100644
22-
index 0000000000000000000000000000000000000000..a7d1ae53eac94bc2dcf8bc78ef1da0d3b8554736
22+
index 0000000000000000000000000000000000000000..cb78dac8e072b5cb3c6e52e17c9ecdf708aeedc1
2323
--- /dev/null
2424
+++ b/src/main/java/io/papermc/paper/plugin/provider/source/SparkProviderSource.java
25-
@@ -0,0 +1,102 @@
25+
@@ -0,0 +1,115 @@
2626
+package io.papermc.paper.plugin.provider.source;
2727
+
2828
+import com.mojang.logging.LogUtils;
@@ -44,26 +44,23 @@ index 0000000000000000000000000000000000000000..a7d1ae53eac94bc2dcf8bc78ef1da0d3
4444
+import org.bukkit.plugin.java.JavaPlugin;
4545
+import org.slf4j.Logger;
4646
+
47-
+public class SparkProviderSource extends FileProviderSource {
48-
+ public static final SparkProviderSource INSTANCE = new SparkProviderSource();
47+
+public class SparkProviderSource implements ProviderSource<Path, Path> {
4948
+
49+
+ public static final SparkProviderSource INSTANCE = new SparkProviderSource();
50+
+ private static final FileProviderSource FILE_PROVIDER_SOURCE = new FileProviderSource("File '%s' specified by Purpur"::formatted);
5051
+ private static final Logger LOGGER = LogUtils.getClassLogger();
5152
+
52-
+ public SparkProviderSource() {
53-
+ super("File '%s' specified by Purpur"::formatted);
54-
+ }
55-
+
5653
+ @Override
57-
+ public void registerProviders(EntrypointHandler entrypointHandler, Path context) throws Exception {
54+
+ public Path prepareContext(Path context) {
5855
+ // first, check if user doesn't want spark at all
5956
+ if (Boolean.getBoolean("Purpur.IReallyDontWantSpark")) {
60-
+ return; // boo!
57+
+ return null; // boo!
6158
+ }
6259
+
6360
+ // second, check if user has their own spark
6461
+ if (hasSpark()) {
6562
+ LOGGER.info("Purpur: Using user-provided spark plugin instead of our own.");
66-
+ return; // let's hope it's at least the modern version :3
63+
+ return null; // let's hope it's at least the modern version :3
6764
+ }
6865
+
6966
+ // you can't have errors in your code if you wrap the entire codebase in a try/catch block
@@ -109,11 +106,27 @@ index 0000000000000000000000000000000000000000..a7d1ae53eac94bc2dcf8bc78ef1da0d3
109106
+ }
110107
+
111108
+ // register the spark, newly downloaded or existing
112-
+ super.registerProviders(entrypointHandler, context);
109+
+ return FILE_PROVIDER_SOURCE.prepareContext(context);
113110
+
114111
+ } catch (Throwable e) {
115112
+ LOGGER.error("Purpur: Failed to download and install spark plugin", e);
116113
+ }
114+
+ return null;
115+
+ }
116+
+
117+
+ @Override
118+
+ public void registerProviders(final EntrypointHandler entrypointHandler, final Path context) {
119+
+ if (context == null) {
120+
+ return;
121+
+ }
122+
+
123+
+ try {
124+
+ FILE_PROVIDER_SOURCE.registerProviders(entrypointHandler, context);
125+
+ } catch (IllegalArgumentException ignored) {
126+
+ // Ignore illegal argument exceptions from jar checking
127+
+ } catch (Exception e) {
128+
+ LOGGER.error("Error loading our spark plugin: " + e.getMessage(), e);
129+
+ }
117130
+ }
118131
+
119132
+ private static boolean hasSpark() {

0 commit comments

Comments
 (0)