mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-20 18:07:43 +01:00
properly implement ProviderSource for our spark jar provider
This commit is contained in:
@@ -19,10 +19,10 @@ index 708e5bb9bbf0476fcc2c4b92c6830b094703b43e..6141f716b15ad47ac2ac4c9ce92a3897
|
|||||||
// This will be the end of me...
|
// This will be the end of me...
|
||||||
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
|
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
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..a7d1ae53eac94bc2dcf8bc78ef1da0d3b8554736
|
index 0000000000000000000000000000000000000000..cb78dac8e072b5cb3c6e52e17c9ecdf708aeedc1
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/io/papermc/paper/plugin/provider/source/SparkProviderSource.java
|
+++ b/src/main/java/io/papermc/paper/plugin/provider/source/SparkProviderSource.java
|
||||||
@@ -0,0 +1,102 @@
|
@@ -0,0 +1,115 @@
|
||||||
+package io.papermc.paper.plugin.provider.source;
|
+package io.papermc.paper.plugin.provider.source;
|
||||||
+
|
+
|
||||||
+import com.mojang.logging.LogUtils;
|
+import com.mojang.logging.LogUtils;
|
||||||
@@ -44,26 +44,23 @@ index 0000000000000000000000000000000000000000..a7d1ae53eac94bc2dcf8bc78ef1da0d3
|
|||||||
+import org.bukkit.plugin.java.JavaPlugin;
|
+import org.bukkit.plugin.java.JavaPlugin;
|
||||||
+import org.slf4j.Logger;
|
+import org.slf4j.Logger;
|
||||||
+
|
+
|
||||||
+public class SparkProviderSource extends FileProviderSource {
|
+public class SparkProviderSource implements ProviderSource<Path, Path> {
|
||||||
+ public static final SparkProviderSource INSTANCE = new SparkProviderSource();
|
|
||||||
+
|
+
|
||||||
|
+ public static final SparkProviderSource INSTANCE = new SparkProviderSource();
|
||||||
|
+ private static final FileProviderSource FILE_PROVIDER_SOURCE = new FileProviderSource("File '%s' specified by Purpur"::formatted);
|
||||||
+ private static final Logger LOGGER = LogUtils.getClassLogger();
|
+ private static final Logger LOGGER = LogUtils.getClassLogger();
|
||||||
+
|
+
|
||||||
+ public SparkProviderSource() {
|
|
||||||
+ super("File '%s' specified by Purpur"::formatted);
|
|
||||||
+ }
|
|
||||||
+
|
|
||||||
+ @Override
|
+ @Override
|
||||||
+ public void registerProviders(EntrypointHandler entrypointHandler, Path context) throws Exception {
|
+ public Path prepareContext(Path context) {
|
||||||
+ // first, check if user doesn't want spark at all
|
+ // first, check if user doesn't want spark at all
|
||||||
+ if (Boolean.getBoolean("Purpur.IReallyDontWantSpark")) {
|
+ if (Boolean.getBoolean("Purpur.IReallyDontWantSpark")) {
|
||||||
+ return; // boo!
|
+ return null; // boo!
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ // second, check if user has their own spark
|
+ // second, check if user has their own spark
|
||||||
+ if (hasSpark()) {
|
+ if (hasSpark()) {
|
||||||
+ LOGGER.info("Purpur: Using user-provided spark plugin instead of our own.");
|
+ LOGGER.info("Purpur: Using user-provided spark plugin instead of our own.");
|
||||||
+ return; // let's hope it's at least the modern version :3
|
+ return null; // let's hope it's at least the modern version :3
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ // you can't have errors in your code if you wrap the entire codebase in a try/catch block
|
+ // 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
|
|||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ // register the spark, newly downloaded or existing
|
+ // register the spark, newly downloaded or existing
|
||||||
+ super.registerProviders(entrypointHandler, context);
|
+ return FILE_PROVIDER_SOURCE.prepareContext(context);
|
||||||
+
|
+
|
||||||
+ } catch (Throwable e) {
|
+ } catch (Throwable e) {
|
||||||
+ LOGGER.error("Purpur: Failed to download and install spark plugin", e);
|
+ LOGGER.error("Purpur: Failed to download and install spark plugin", e);
|
||||||
+ }
|
+ }
|
||||||
|
+ return null;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public void registerProviders(final EntrypointHandler entrypointHandler, final Path context) {
|
||||||
|
+ if (context == null) {
|
||||||
|
+ return;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ try {
|
||||||
|
+ FILE_PROVIDER_SOURCE.registerProviders(entrypointHandler, context);
|
||||||
|
+ } catch (IllegalArgumentException ignored) {
|
||||||
|
+ // Ignore illegal argument exceptions from jar checking
|
||||||
|
+ } catch (Exception e) {
|
||||||
|
+ LOGGER.error("Error loading our spark plugin: " + e.getMessage(), e);
|
||||||
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ private static boolean hasSpark() {
|
+ private static boolean hasSpark() {
|
||||||
|
|||||||
Reference in New Issue
Block a user