mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-17 16:37:43 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@d129162 Properly handle BlockBreakEvent#isDropItems (#8936) PaperMC/Paper@67a1a8c Fix Inventory#getLocation not working for the composter (#9596) PaperMC/Paper@5b34a09 Add option to disable chorus plant and mushroom block updates (#9442) PaperMC/Paper@ed8401c Fix rotation for spawning display entities (#9552) PaperMC/Paper@bd67b83 Determine lava and water fluid explosion resistance by their block explosion resistance (#9482) PaperMC/Paper@d928dda Don't tab-complete namespaced commands if `send-namespaced` is false (#9366) PaperMC/Paper@f43a19c Fix CME in CraftPersistentDataTypeRegistry (#6701) PaperMC/Paper@45ba652 [ci skip] Rebuild patches PaperMC/Paper@990765b Fire entity death event for ender dragon (#9495) PaperMC/Paper@1259b93 Fixed CraftItemStack/CraftItemMeta enchantment level inconsistency (#8792) PaperMC/Paper@88891c3 Add Entity Coordinate and Rotation API (#9461) PaperMC/Paper@5bf82aa Add cancellability to PlayerTrackEntityEvent (#8605) PaperMC/Paper@1b96c64 Improve cancelling PreCreatureSpawnEvent with per player mob spawns (#9400) PaperMC/Paper@7232506 Add entity tracker min Y distance config option (#9406) PaperMC/Paper@00a68b1 Player listing API (#8782) PaperMC/Paper@af6142e [ci skip] Update Gradle wrapper PaperMC/Paper@281855c Remove unused lag-compensate-block-breaking option (#9635) PaperMC/Paper@35ef053 [ci skip] update editorconfig and gitattributes (#9608) PaperMC/Paper@97b9c4a Fix NPE on Boat#getStatus (#9115) PaperMC/Paper@2be57c6 Expand Pose API (#8781) PaperMC/Paper@b29ecd4 Expose clicked BlockFace during BlockDamageEvent (#9632) PaperMC/Paper@e3f29f4 MerchantRecipe: add copy constructor (#8703) PaperMC/Paper@fed9042 More DragonBattle API (#5655) PaperMC/Paper@27d39ca Properly clone custom nbt tags inside ItemMeta (#7849) PaperMC/Paper@0c7385b Add PlayerPickItemEvent (#5590) PaperMC/Paper@9395aa6 Improve performance of mass crafts (#9603) PaperMC/Paper@7386a13 Fix endgateway teleportation offset (#9517) PaperMC/Paper@a712766 Allow custom damage for trident (#8132) PaperMC/Paper@3716832 Prevent overfilled bundles from duplicating items (#9633) PaperMC/Paper@9cbad8e Expose Hand during BlockCanBuildEvent (#9636)
128 lines
5.8 KiB
Diff
128 lines
5.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Ben Kerllenevich <ben@omega24.dev>
|
|
Date: Sat, 25 Jun 2022 19:40:36 -0400
|
|
Subject: [PATCH] Spark Profiler
|
|
|
|
Co-authored-by: granny <granny@purpurmc.org>
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/plugin/PluginInitializerManager.java b/src/main/java/io/papermc/paper/plugin/PluginInitializerManager.java
|
|
index 89bf48fd581ee6580b91e2eb31dd532cb622df5e..e35da199be67e04c34df6bc09afd8d8122cb0487 100644
|
|
--- a/src/main/java/io/papermc/paper/plugin/PluginInitializerManager.java
|
|
+++ b/src/main/java/io/papermc/paper/plugin/PluginInitializerManager.java
|
|
@@ -102,6 +102,7 @@ public class PluginInitializerManager {
|
|
java.util.List<File> files = (java.util.List<File>) optionSet.valuesOf("add-plugin");
|
|
// Register plugins from the flag
|
|
io.papermc.paper.plugin.util.EntrypointUtil.registerProvidersFromSource(io.papermc.paper.plugin.provider.source.PluginFlagProviderSource.INSTANCE, files);
|
|
+ io.papermc.paper.plugin.util.EntrypointUtil.registerProvidersFromSource(io.papermc.paper.plugin.provider.source.SparkProviderSource.INSTANCE, new File("cache", "spark.jar").toPath()); // Purpur
|
|
}
|
|
|
|
// 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
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..a7d1ae53eac94bc2dcf8bc78ef1da0d3b8554736
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/plugin/provider/source/SparkProviderSource.java
|
|
@@ -0,0 +1,102 @@
|
|
+package io.papermc.paper.plugin.provider.source;
|
|
+
|
|
+import com.mojang.logging.LogUtils;
|
|
+import io.papermc.paper.plugin.entrypoint.Entrypoint;
|
|
+import io.papermc.paper.plugin.entrypoint.EntrypointHandler;
|
|
+import io.papermc.paper.plugin.entrypoint.LaunchEntryPointHandler;
|
|
+import io.papermc.paper.plugin.provider.PluginProvider;
|
|
+import java.io.BufferedReader;
|
|
+import java.io.File;
|
|
+import java.io.InputStreamReader;
|
|
+import java.math.BigInteger;
|
|
+import java.net.URL;
|
|
+import java.net.URLConnection;
|
|
+import java.nio.file.Files;
|
|
+import java.nio.file.Path;
|
|
+import java.nio.file.StandardCopyOption;
|
|
+import java.security.MessageDigest;
|
|
+import java.util.stream.Collectors;
|
|
+import org.bukkit.plugin.java.JavaPlugin;
|
|
+import org.slf4j.Logger;
|
|
+
|
|
+public class SparkProviderSource extends FileProviderSource {
|
|
+ public static final SparkProviderSource INSTANCE = new SparkProviderSource();
|
|
+
|
|
+ private static final Logger LOGGER = LogUtils.getClassLogger();
|
|
+
|
|
+ public SparkProviderSource() {
|
|
+ super("File '%s' specified by Purpur"::formatted);
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void registerProviders(EntrypointHandler entrypointHandler, Path context) throws Exception {
|
|
+ // first, check if user doesn't want spark at all
|
|
+ if (Boolean.getBoolean("Purpur.IReallyDontWantSpark")) {
|
|
+ return; // boo!
|
|
+ }
|
|
+
|
|
+ // second, check if user has their own spark
|
|
+ if (hasSpark()) {
|
|
+ LOGGER.info("Purpur: Using user-provided spark plugin instead of our own.");
|
|
+ return; // 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
|
|
+ try {
|
|
+
|
|
+ // make sure the directory exists where we want to keep spark
|
|
+ File file = context.toFile();
|
|
+ file.getParentFile().mkdirs();
|
|
+
|
|
+ boolean shouldDownload;
|
|
+
|
|
+ // check if our spark exists
|
|
+ if (!file.exists()) {
|
|
+ // it does not, so let's download it
|
|
+ shouldDownload = true;
|
|
+ } else {
|
|
+ // we have a spark file, let's see if it's up-to-date by comparing shas
|
|
+ String fileSha1 = String.format("%040x", new BigInteger(1, MessageDigest.getInstance("SHA-1").digest(Files.readAllBytes(file.toPath()))));
|
|
+ String sparkSha1;
|
|
+
|
|
+ // luck has a nifty endpoint containing the sha of the newest version
|
|
+ URLConnection urlConnection = new URL("https://sparkapi.lucko.me/download/bukkit/sha1").openConnection();
|
|
+
|
|
+ // set a reasonable timeout to prevent servers without internet from hanging for 60+ seconds on startup
|
|
+ urlConnection.setReadTimeout(5000);
|
|
+ urlConnection.setConnectTimeout(5000);
|
|
+
|
|
+ // read it
|
|
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()))) {
|
|
+ sparkSha1 = reader.lines().collect(Collectors.joining(""));
|
|
+ }
|
|
+
|
|
+ // compare; we only download a new spark if the shas don't match
|
|
+ shouldDownload = !fileSha1.equals(sparkSha1);
|
|
+ }
|
|
+
|
|
+ // ok, finally we can download spark if we need it
|
|
+ if (shouldDownload) {
|
|
+ URLConnection urlConnection = new URL("https://sparkapi.lucko.me/download/bukkit").openConnection();
|
|
+ urlConnection.setReadTimeout(5000);
|
|
+ urlConnection.setConnectTimeout(5000);
|
|
+ Files.copy(urlConnection.getInputStream(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
+ }
|
|
+
|
|
+ // register the spark, newly downloaded or existing
|
|
+ super.registerProviders(entrypointHandler, context);
|
|
+
|
|
+ } catch (Throwable e) {
|
|
+ LOGGER.error("Purpur: Failed to download and install spark plugin", e);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ private static boolean hasSpark() {
|
|
+ for (PluginProvider<JavaPlugin> provider : LaunchEntryPointHandler.INSTANCE.get(Entrypoint.PLUGIN).getRegisteredProviders()) {
|
|
+ if (provider.getMeta().getName().equalsIgnoreCase("spark")) {
|
|
+ return true;
|
|
+ }
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+}
|