Upstream has released updates that appear to apply and compile correctly. [Purpur Changes] PurpurMC/Purpur@a52426c: Updated Upstream (Paper) PurpurMC/Purpur@86ad0b3: Updated Upstream (Paper) PurpurMC/Purpur@79d199c: Updated Upstream (Paper) PurpurMC/Purpur@7708a4c: don't send keepalive packet early, closes #1520 PurpurMC/Purpur@4873495: add config to reverse bubble column flow for soulsand and magma blocks PurpurMC/Purpur@eac4198: Updated Upstream (Paper) PurpurMC/Purpur@7219263: [ci skip] inline fqn imports PurpurMC/Purpur@cc56332: Final 1.20.6 Paper Upstream \o/ PurpurMC/Purpur@f1c87e4: add missing armadillo & bogged options, closes #1527 PurpurMC/Purpur@d259ed5: prepare for update PurpurMC/Purpur@1544081: Updated Upstream (Paper) PurpurMC/Purpur@e2b5e14: apply API patches PurpurMC/Purpur@7c38d97: first 5 patches! PurpurMC/Purpur@0ab7756: ridables patch \o/ PurpurMC/Purpur@085de5a: first 50 patches \o/ PurpurMC/Purpur@b191556: 100 patches \o/ PurpurMC/Purpur@2a4d2e5: 150 patches \o/ PurpurMC/Purpur@c716c80: 200 patches \o/ PurpurMC/Purpur@699969f: 250 patches \o/ PurpurMC/Purpur@cfc96e0: all patches apply \o/ PurpurMC/Purpur@59c536c: Updated Upstream (Paper) PurpurMC/Purpur@20e182a: Updated Upstream (Paper) PurpurMC/Purpur@973bcd4: drop damage-with-frost-walker option - can be done with a datapack PurpurMC/Purpur@331c216: re-add timings/mojang profiler removal patches PurpurMC/Purpur@b27c8b2: add back leashable villagers option PurpurMC/Purpur@6b2acdc: infinity on crossbows can be done with datapacks now PurpurMC/Purpur@c3829f2: add back portal permission bypass patch PurpurMC/Purpur@0510294: add back fix-stuck-in-portal patch PurpurMC/Purpur@dedcdd0: re-add generated api patches PurpurMC/Purpur@00126e8: re-add removing curse of binding with weakness patch PurpurMC/Purpur@09ec31b: infinity bow settings can be done through a datapack PurpurMC/Purpur@cdb192f: mending muliplier is better done through a datapack PurpurMC/Purpur@bf6dbdd: fix timings/profiler compilation issues PurpurMC/Purpur@6e1147f: Updated Upstream (Paper) PurpurMC/Purpur@c991735: Fix compilation issues (#1530) PurpurMC/Purpur@25ecbc4: rename enchantment convenience patch PurpurMC/Purpur@ea406a0: use matchingSlot helper method PurpurMC/Purpur@4dca11b: elytra.ignore-unbreaking option can probably be done through datapacks now PurpurMC/Purpur@fa88174: clear out TODOs PurpurMC/Purpur@04a9fec: reuse extrainfo in crash report PurpurMC/Purpur@45774b4: apply the rest of the unapplied patches PurpurMC/Purpur@dd826a3: Updated Upstream (Paper) PurpurMC/Purpur@778995d: Updated Upstream (Paper) PurpurMC/Purpur@9ff84cb: Updated Upstream (Paper) PurpurMC/Purpur@bd49055: [ci skip] replace paper with purpur in log message PurpurMC/Purpur@a122fd7: Updated Upstream (Paper) PurpurMC/Purpur@783acfe: Updated Upstream (Paper) PurpurMC/Purpur@b5f1c48: Updated Upstream (Paper) PurpurMC/Purpur@c0f5e78: add default silverfish movement speed & attack damage attributes PurpurMC/Purpur@b82f693: configurable mob size attribute (#1538) PurpurMC/Purpur@e05f91b: [ci skip] move import to config patch PurpurMC/Purpur@2ba7bee: Updated Upstream (Paper) PurpurMC/Purpur@19da21c: Updated Upstream (Paper) PurpurMC/Purpur@21ec259: fix kickForOutOfOrderChat being applied in the incorrect spot PurpurMC/Purpur@9efd5fc: Updated Upstream (Paper) PurpurMC/Purpur@ad910f8: Updated Upstream (Paper) PurpurMC/Purpur@39617d5: entities with passengers can go through portals now, closes #1540 PurpurMC/Purpur@7d59f25: fix blast resistence config not accepting namespaced values PurpurMC/Purpur@1615793: set burp delay in the correct spot PurpurMC/Purpur@797ce6b: Updated Upstream (Paper) PurpurMC/Purpur@ac6c312: Updated Upstream (Paper) PurpurMC/Purpur@d5c06b4: fix summon_entity effect attempting to add incorrect entity, closes #1545 PurpurMC/Purpur@faa1f93: add PlayerSetTrialSpawnerTypeWithEggEvent, fixes #1546 (#1547) PurpurMC/Purpur@1ab7990: Updated Upstream (Paper) PurpurMC/Purpur@8b987b1: fix infinityWorksWithoutArrows not working PurpurMC/Purpur@de2e7a7: Updated Upstream (Paper) PurpurMC/Purpur@cb0f04b: Updated Upstream (Paper) PurpurMC/Purpur@ff19bcc: Updated Upstream (Paper) PurpurMC/Purpur@b3709b1: Updated Upstream (Paper) PurpurMC/Purpur@5e70800: Updated Upstream (Paper) PurpurMC/Purpur@14136b8: Updated Upstream (Paper) PurpurMC/Purpur@458dc18: Updated Upstream (Paper), closes #1556 PurpurMC/Purpur@87cf9f1: Updated Upstream (Paper) PurpurMC/Purpur@bf63cfa: Updated Upstream (Paper) PurpurMC/Purpur@8f0f20d: Updated Upstream (Paper) PurpurMC/Purpur@86a6543: Updated Upstream (Paper) PurpurMC/Purpur@2e39567: Re-add missing chunk api calls, fixes #1560 PurpurMC/Purpur@eadfff7: Updated Upstream (Paper) PurpurMC/Purpur@65d3665: Updated Upstream (Paper) PurpurMC/Purpur@936c29a: Updated Upstream (Paper) PurpurMC/Purpur@032697e: Updated Upstream (Paper) PurpurMC/Purpur@b2d1fea: always output bukkit/paper plugin header in plugin command PurpurMC/Purpur@61b63b1: Updated Upstream (Paper) PurpurMC/Purpur@c3849be: Fire EntityTeleportHinderedEvent when attempting to teleport a player with passengers (#1563) PurpurMC/Purpur@7e0ca92: [ci skip] missed rebranding PurpurMC/Purpur@82ccc76: Updated Upstream (Paper) PurpurMC/Purpur@72ccfbd: Updated Upstream (Paper) PurpurMC/Purpur@0bd5579: Updated Upstream (Paper) PurpurMC/Purpur@b3623fa: Updated Upstream (Paper) PurpurMC/Purpur@9e444c5: Add Entities can use portals patch back (#1571) PurpurMC/Purpur@930003b: Updated Upstream (Paper) PurpurMC/Purpur@7950960: Updated Upstream (Paper) PurpurMC/Purpur@02e4e76: Updated Upstream (Paper) PurpurMC/Purpur@afabbc9: missed these PurpurMC/Purpur@73a90e8: Updated Upstream (Paper) PurpurMC/Purpur@75e81d8: deprecate old anvil api methods PurpurMC/Purpur@699448c: Merge branch 'ver/1.21' into ver/1.21.1 PurpurMC/Purpur@4e55e26: final 1.21 Paper upstream PurpurMC/Purpur@edd9be7: Merge branch 'ver/1.21' into ver/1.21.1 PurpurMC/Purpur@abf2f21: Updated Upstream (Paper) PurpurMC/Purpur@366af80: Updated Upstream (Paper) PurpurMC/Purpur@07979c3: Updated Upstream (Paper) PurpurMC/Purpur@3f790ac: Updated Upstream (Paper) PurpurMC/Purpur@201e928: Updated Upstream (Pufferfish) (#1575) PurpurMC/Purpur@f2307b8: Updated Upstream (Paper) PurpurMC/Purpur@bba87bf: Updated Upstream (Paper) PurpurMC/Purpur@f530395: Fix no exp drops from spawners using silk touch pickaxe without option enabled (#1582) PurpurMC/Purpur@3510a9e: Updated Upstream (Paper) PurpurMC/Purpur@1d3cef7: Updated Upstream (Paper) PurpurMC/Purpur@c4a6f63: Updated Upstream (Paper) PurpurMC/Purpur@568a028: Updated Upstream (Paper) PurpurMC/Purpur@ef12ede: Updated Upstream (Paper) PurpurMC/Purpur@a61db94: Updated Upstream (Paper) PurpurMC/Purpur@5c0d2f7: Updated Upstream (Paper) PurpurMC/Purpur@49db849: Updated Upstream (Paper) PurpurMC/Purpur@a43711d: Updated Upstream (Paper) PurpurMC/Purpur@0a9941e: Updated Upstream (Paper) PurpurMC/Purpur@88352c3: Updated Upstream (Paper) PurpurMC/Purpur@dee41bc: Updated Upstream (Paper) PurpurMC/Purpur@fdfc12e: Updated Upstream (Paper) PurpurMC/Purpur@bc7bcbb: Fix elytra durability setting not working properly (#1589) PurpurMC/Purpur@8af4ea6: Updated Upstream (Paper) PurpurMC/Purpur@8332fa4: Updated Upstream (Paper) PurpurMC/Purpur@be61a07: Updated Upstream (Paper) PurpurMC/Purpur@f154903: Updated Upstream (Paper) PurpurMC/Purpur@0fa9a50: Updated Upstream (Paper) PurpurMC/Purpur@d7a7c91: Updated Upstream (Paper) PurpurMC/Purpur@20fa61e: Updated Upstream (Paper) PurpurMC/Purpur@501e7c5: Updated Upstream (Paper) PurpurMC/Purpur@2a50638: Updated Upstream (Paper) PurpurMC/Purpur@639bcbd: Updated Upstream (Paper) PurpurMC/Purpur@bcf8103: remove obsolete allowUnsafeEnchants config option PurpurMC/Purpur@51f15ee: fully remove obsolete allowUnsafeEnchants config option PurpurMC/Purpur@3d0716d: Fix colored shulker box contents not dropping when destroyed, supercedes #1594 PurpurMC/Purpur@12e2926: [ci skip] drop old migration patch PurpurMC/Purpur@212c942: delegate itemstack convenience methods PurpurMC/Purpur@2eaea6a: switch to JSpecify annotations PurpurMC/Purpur@4565f41: these options should be off by default PurpurMC/Purpur@4671e1e: show a message stating the removal of mojang profiler when running perf comamnd, closes #1591 PurpurMC/Purpur@e12a4de: Updated Upstream (Paper) PurpurMC/Purpur@7f490a6: Updated Upstream (Paper) PurpurMC/Purpur@4f2fe31: Updated Upstream (Paper) PurpurMC/Purpur@4b57bed: Updated Upstream (Paper)
528 lines
21 KiB
Diff
528 lines
21 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Kevin Raneri <kevin.raneri@gmail.com>
|
|
Date: Tue, 22 Oct 2024 07:31:43 +0900
|
|
Subject: [PATCH] Pufferfish API Changes
|
|
|
|
Pufferfish
|
|
Copyright (C) 2024 Pufferfish Studios LLC
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
diff --git a/build.gradle.kts b/build.gradle.kts
|
|
index e7c96be769fde8375b9a1b128cc7ce474144d16d..f9b44a03fe8d9a2fea2d968f4e944a6663c6f9c9 100644
|
|
--- a/build.gradle.kts
|
|
+++ b/build.gradle.kts
|
|
@@ -52,6 +52,7 @@ dependencies {
|
|
apiAndDocs("net.kyori:adventure-text-logger-slf4j")
|
|
api("org.apache.logging.log4j:log4j-api:$log4jVersion")
|
|
api("org.slf4j:slf4j-api:$slf4jVersion")
|
|
+ api("io.sentry:sentry:5.4.0") // Pufferfish
|
|
|
|
implementation("org.ow2.asm:asm:9.7.1")
|
|
implementation("org.ow2.asm:asm-commons:9.7.1")
|
|
@@ -131,6 +132,13 @@ val generateApiVersioningFile by tasks.registering {
|
|
}
|
|
}
|
|
|
|
+// Pufferfish Start
|
|
+tasks.withType<JavaCompile> {
|
|
+ val compilerArgs = options.compilerArgs
|
|
+ compilerArgs.add("--add-modules=jdk.incubator.vector")
|
|
+}
|
|
+// Pufferfish End
|
|
+
|
|
tasks.jar {
|
|
from(generateApiVersioningFile.map { it.outputs.files.singleFile }) {
|
|
into("META-INF/maven/${project.group}/${project.name}")
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/sentry/SentryContext.java b/src/main/java/gg/pufferfish/pufferfish/sentry/SentryContext.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..10310fdd53de28efb8a8250f6d3b0c8eb08fb68a
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/sentry/SentryContext.java
|
|
@@ -0,0 +1,161 @@
|
|
+package gg.pufferfish.pufferfish.sentry;
|
|
+
|
|
+import com.google.gson.Gson;
|
|
+import java.lang.reflect.Field;
|
|
+import java.lang.reflect.Modifier;
|
|
+import java.util.Map;
|
|
+import java.util.TreeMap;
|
|
+import org.apache.logging.log4j.ThreadContext;
|
|
+import org.bukkit.command.Command;
|
|
+import org.bukkit.command.CommandSender;
|
|
+import org.bukkit.entity.Player;
|
|
+import org.bukkit.event.Event;
|
|
+import org.bukkit.event.player.PlayerEvent;
|
|
+import org.bukkit.plugin.Plugin;
|
|
+import org.bukkit.plugin.RegisteredListener;
|
|
+import org.jetbrains.annotations.Nullable;
|
|
+
|
|
+public class SentryContext {
|
|
+
|
|
+ private static final Gson GSON = new Gson();
|
|
+
|
|
+ public static void setPluginContext(@Nullable Plugin plugin) {
|
|
+ if (plugin != null) {
|
|
+ ThreadContext.put("pufferfishsentry_pluginname", plugin.getName());
|
|
+ ThreadContext.put("pufferfishsentry_pluginversion", plugin.getDescription().getVersion());
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static void removePluginContext() {
|
|
+ ThreadContext.remove("pufferfishsentry_pluginname");
|
|
+ ThreadContext.remove("pufferfishsentry_pluginversion");
|
|
+ }
|
|
+
|
|
+ public static void setSenderContext(@Nullable CommandSender sender) {
|
|
+ if (sender != null) {
|
|
+ ThreadContext.put("pufferfishsentry_playername", sender.getName());
|
|
+ if (sender instanceof Player player) {
|
|
+ ThreadContext.put("pufferfishsentry_playerid", player.getUniqueId().toString());
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static void removeSenderContext() {
|
|
+ ThreadContext.remove("pufferfishsentry_playername");
|
|
+ ThreadContext.remove("pufferfishsentry_playerid");
|
|
+ }
|
|
+
|
|
+ public static void setEventContext(Event event, RegisteredListener registration) {
|
|
+ setPluginContext(registration.getPlugin());
|
|
+
|
|
+ try {
|
|
+ // Find the player that was involved with this event
|
|
+ Player player = null;
|
|
+ if (event instanceof PlayerEvent) {
|
|
+ player = ((PlayerEvent) event).getPlayer();
|
|
+ } else {
|
|
+ Class<? extends Event> eventClass = event.getClass();
|
|
+
|
|
+ Field playerField = null;
|
|
+
|
|
+ for (Field field : eventClass.getDeclaredFields()) {
|
|
+ if (field.getType().equals(Player.class)) {
|
|
+ playerField = field;
|
|
+ break;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (playerField != null) {
|
|
+ playerField.setAccessible(true);
|
|
+ player = (Player) playerField.get(event);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (player != null) {
|
|
+ setSenderContext(player);
|
|
+ }
|
|
+ } catch (Exception e) {} // We can't really safely log exceptions.
|
|
+
|
|
+ ThreadContext.put("pufferfishsentry_eventdata", GSON.toJson(serializeFields(event)));
|
|
+ }
|
|
+
|
|
+ public static void removeEventContext() {
|
|
+ removePluginContext();
|
|
+ removeSenderContext();
|
|
+ ThreadContext.remove("pufferfishsentry_eventdata");
|
|
+ }
|
|
+
|
|
+ private static Map<String, String> serializeFields(Object object) {
|
|
+ Map<String, String> fields = new TreeMap<>();
|
|
+ fields.put("_class", object.getClass().getName());
|
|
+ for (Field declaredField : object.getClass().getDeclaredFields()) {
|
|
+ try {
|
|
+ if (Modifier.isStatic(declaredField.getModifiers())) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ String fieldName = declaredField.getName();
|
|
+ if (fieldName.equals("handlers")) {
|
|
+ continue;
|
|
+ }
|
|
+ declaredField.setAccessible(true);
|
|
+ Object value = declaredField.get(object);
|
|
+ if (value != null) {
|
|
+ fields.put(fieldName, value.toString());
|
|
+ } else {
|
|
+ fields.put(fieldName, "<null>");
|
|
+ }
|
|
+ } catch (Exception e) {} // We can't really safely log exceptions.
|
|
+ }
|
|
+ return fields;
|
|
+ }
|
|
+
|
|
+ public static class State {
|
|
+
|
|
+ private Plugin plugin;
|
|
+ private Command command;
|
|
+ private String commandLine;
|
|
+ private Event event;
|
|
+ private RegisteredListener registeredListener;
|
|
+
|
|
+ public Plugin getPlugin() {
|
|
+ return plugin;
|
|
+ }
|
|
+
|
|
+ public void setPlugin(Plugin plugin) {
|
|
+ this.plugin = plugin;
|
|
+ }
|
|
+
|
|
+ public Command getCommand() {
|
|
+ return command;
|
|
+ }
|
|
+
|
|
+ public void setCommand(Command command) {
|
|
+ this.command = command;
|
|
+ }
|
|
+
|
|
+ public String getCommandLine() {
|
|
+ return commandLine;
|
|
+ }
|
|
+
|
|
+ public void setCommandLine(String commandLine) {
|
|
+ this.commandLine = commandLine;
|
|
+ }
|
|
+
|
|
+ public Event getEvent() {
|
|
+ return event;
|
|
+ }
|
|
+
|
|
+ public void setEvent(Event event) {
|
|
+ this.event = event;
|
|
+ }
|
|
+
|
|
+ public RegisteredListener getRegisteredListener() {
|
|
+ return registeredListener;
|
|
+ }
|
|
+
|
|
+ public void setRegisteredListener(RegisteredListener registeredListener) {
|
|
+ this.registeredListener = registeredListener;
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..3441cdad70da1bd523c5933b1a914688718c2657
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java
|
|
@@ -0,0 +1,40 @@
|
|
+package gg.pufferfish.pufferfish.simd;
|
|
+
|
|
+import java.util.logging.Level;
|
|
+import java.util.logging.Logger;
|
|
+import jdk.incubator.vector.FloatVector;
|
|
+import jdk.incubator.vector.IntVector;
|
|
+import jdk.incubator.vector.VectorSpecies;
|
|
+
|
|
+/**
|
|
+ * Basically, java is annoying and we have to push this out to its own class.
|
|
+ */
|
|
+@Deprecated
|
|
+public class SIMDChecker {
|
|
+
|
|
+ @Deprecated
|
|
+ public static boolean canEnable(Logger logger) {
|
|
+ try {
|
|
+ if (SIMDDetection.getJavaVersion() < 17 || SIMDDetection.getJavaVersion() > 21) {
|
|
+ return false;
|
|
+ } else {
|
|
+ SIMDDetection.testRun = true;
|
|
+
|
|
+ VectorSpecies<Integer> ISPEC = IntVector.SPECIES_PREFERRED;
|
|
+ VectorSpecies<Float> FSPEC = FloatVector.SPECIES_PREFERRED;
|
|
+
|
|
+ logger.log(Level.INFO, "Max SIMD vector size on this system is " + ISPEC.vectorBitSize() + " bits (int)");
|
|
+ logger.log(Level.INFO, "Max SIMD vector size on this system is " + FSPEC.vectorBitSize() + " bits (float)");
|
|
+
|
|
+ if (ISPEC.elementSize() < 2 || FSPEC.elementSize() < 2) {
|
|
+ logger.log(Level.WARNING, "SIMD is not properly supported on this system!");
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ return true;
|
|
+ }
|
|
+ } catch (NoClassDefFoundError | Exception ignored) {} // Basically, we don't do anything. This lets us detect if it's not functional and disable it.
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/simd/SIMDDetection.java b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDDetection.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..a84889d3e9cfc4d7ab5f867820a6484c6070711b
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDDetection.java
|
|
@@ -0,0 +1,35 @@
|
|
+package gg.pufferfish.pufferfish.simd;
|
|
+
|
|
+import java.util.logging.Logger;
|
|
+
|
|
+@Deprecated
|
|
+public class SIMDDetection {
|
|
+
|
|
+ public static boolean isEnabled = false;
|
|
+ public static boolean versionLimited = false;
|
|
+ public static boolean testRun = false;
|
|
+
|
|
+ @Deprecated
|
|
+ public static boolean canEnable(Logger logger) {
|
|
+ try {
|
|
+ return SIMDChecker.canEnable(logger);
|
|
+ } catch (NoClassDefFoundError | Exception ignored) {
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ @Deprecated
|
|
+ public static int getJavaVersion() {
|
|
+ // https://stackoverflow.com/a/2591122
|
|
+ String version = System.getProperty("java.version");
|
|
+ if(version.startsWith("1.")) {
|
|
+ version = version.substring(2, 3);
|
|
+ } else {
|
|
+ int dot = version.indexOf(".");
|
|
+ if(dot != -1) { version = version.substring(0, dot); }
|
|
+ }
|
|
+ version = version.split("-")[0]; // Azul is stupid
|
|
+ return Integer.parseInt(version);
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/gg/pufferfish/pufferfish/simd/VectorMapPalette.java b/src/main/java/gg/pufferfish/pufferfish/simd/VectorMapPalette.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..ae2464920c9412ac90b819a540ee58be0741465f
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/VectorMapPalette.java
|
|
@@ -0,0 +1,83 @@
|
|
+package gg.pufferfish.pufferfish.simd;
|
|
+
|
|
+import java.awt.Color;
|
|
+import jdk.incubator.vector.FloatVector;
|
|
+import jdk.incubator.vector.IntVector;
|
|
+import jdk.incubator.vector.VectorMask;
|
|
+import jdk.incubator.vector.VectorSpecies;
|
|
+import org.bukkit.map.MapPalette;
|
|
+
|
|
+@Deprecated
|
|
+public class VectorMapPalette {
|
|
+
|
|
+ private static final VectorSpecies<Integer> I_SPEC = IntVector.SPECIES_PREFERRED;
|
|
+ private static final VectorSpecies<Float> F_SPEC = FloatVector.SPECIES_PREFERRED;
|
|
+
|
|
+ @Deprecated
|
|
+ public static void matchColorVectorized(int[] in, byte[] out) {
|
|
+ int speciesLength = I_SPEC.length();
|
|
+ int i;
|
|
+ for (i = 0; i < in.length - speciesLength; i += speciesLength) {
|
|
+ float[] redsArr = new float[speciesLength];
|
|
+ float[] bluesArr = new float[speciesLength];
|
|
+ float[] greensArr = new float[speciesLength];
|
|
+ int[] alphasArr = new int[speciesLength];
|
|
+
|
|
+ for (int j = 0; j < speciesLength; j++) {
|
|
+ alphasArr[j] = (in[i + j] >> 24) & 0xFF;
|
|
+ redsArr[j] = (in[i + j] >> 16) & 0xFF;
|
|
+ greensArr[j] = (in[i + j] >> 8) & 0xFF;
|
|
+ bluesArr[j] = (in[i + j] >> 0) & 0xFF;
|
|
+ }
|
|
+
|
|
+ IntVector alphas = IntVector.fromArray(I_SPEC, alphasArr, 0);
|
|
+ FloatVector reds = FloatVector.fromArray(F_SPEC, redsArr, 0);
|
|
+ FloatVector greens = FloatVector.fromArray(F_SPEC, greensArr, 0);
|
|
+ FloatVector blues = FloatVector.fromArray(F_SPEC, bluesArr, 0);
|
|
+ IntVector resultIndex = IntVector.zero(I_SPEC);
|
|
+ VectorMask<Integer> modificationMask = VectorMask.fromLong(I_SPEC, 0xffffffff);
|
|
+
|
|
+ modificationMask = modificationMask.and(alphas.lt(128).not());
|
|
+ FloatVector bestDistances = FloatVector.broadcast(F_SPEC, Float.MAX_VALUE);
|
|
+
|
|
+ for (int c = 4; c < MapPalette.colors.length; c++) {
|
|
+ // We're using 32-bit floats here because it's 2x faster and nobody will know the difference.
|
|
+ // For correctness, the original algorithm uses 64-bit floats instead. Completely unnecessary.
|
|
+ FloatVector compReds = FloatVector.broadcast(F_SPEC, MapPalette.colors[c].getRed());
|
|
+ FloatVector compGreens = FloatVector.broadcast(F_SPEC, MapPalette.colors[c].getGreen());
|
|
+ FloatVector compBlues = FloatVector.broadcast(F_SPEC, MapPalette.colors[c].getBlue());
|
|
+
|
|
+ FloatVector rMean = reds.add(compReds).div(2.0f);
|
|
+ FloatVector rDiff = reds.sub(compReds);
|
|
+ FloatVector gDiff = greens.sub(compGreens);
|
|
+ FloatVector bDiff = blues.sub(compBlues);
|
|
+
|
|
+ FloatVector weightR = rMean.div(256.0f).add(2);
|
|
+ FloatVector weightG = FloatVector.broadcast(F_SPEC, 4.0f);
|
|
+ FloatVector weightB = FloatVector.broadcast(F_SPEC, 255.0f).sub(rMean).div(256.0f).add(2.0f);
|
|
+
|
|
+ FloatVector distance = weightR.mul(rDiff).mul(rDiff).add(weightG.mul(gDiff).mul(gDiff)).add(weightB.mul(bDiff).mul(bDiff));
|
|
+
|
|
+ // Now we compare to the best distance we've found.
|
|
+ // This mask contains a "1" if better, and a "0" otherwise.
|
|
+ VectorMask<Float> bestDistanceMask = distance.lt(bestDistances);
|
|
+ bestDistances = bestDistances.blend(distance, bestDistanceMask); // Update the best distances
|
|
+
|
|
+ // Update the result array
|
|
+ // We also AND with the modification mask because we don't want to interfere if the alpha value isn't large enough.
|
|
+ resultIndex = resultIndex.blend(c, bestDistanceMask.cast(I_SPEC).and(modificationMask)); // Update the results
|
|
+ }
|
|
+
|
|
+ for (int j = 0; j < speciesLength; j++) {
|
|
+ int index = resultIndex.lane(j);
|
|
+ out[i + j] = (byte) (index < 128 ? index : -129 + (index - 127));
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // For the final ones, fall back to the regular method
|
|
+ for (; i < in.length; i++) {
|
|
+ out[i] = MapPalette.matchColor(new Color(in[i], true));
|
|
+ }
|
|
+ }
|
|
+
|
|
+}
|
|
diff --git a/src/main/java/org/bukkit/map/MapPalette.java b/src/main/java/org/bukkit/map/MapPalette.java
|
|
index c80faa079eca1564847070f0338fc98024639829..e632d51d3487eb4807243b6705999ad124466bf5 100644
|
|
--- a/src/main/java/org/bukkit/map/MapPalette.java
|
|
+++ b/src/main/java/org/bukkit/map/MapPalette.java
|
|
@@ -1,6 +1,7 @@
|
|
package org.bukkit.map;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
+import gg.pufferfish.pufferfish.simd.SIMDDetection; // Pufferfish
|
|
import java.awt.Color;
|
|
import java.awt.Graphics2D;
|
|
import java.awt.Image;
|
|
@@ -40,7 +41,7 @@ public final class MapPalette {
|
|
}
|
|
|
|
@NotNull
|
|
- static final Color[] colors = {
|
|
+ public static final Color[] colors = { // Pufferfish - public access
|
|
c(0, 0, 0, 0), c(0, 0, 0, 0), c(0, 0, 0, 0), c(0, 0, 0, 0),
|
|
c(89, 125, 39), c(109, 153, 48), c(127, 178, 56), c(67, 94, 29),
|
|
c(174, 164, 115), c(213, 201, 140), c(247, 233, 163), c(130, 123, 86),
|
|
@@ -211,9 +212,15 @@ public final class MapPalette {
|
|
temp.getRGB(0, 0, temp.getWidth(), temp.getHeight(), pixels, 0, temp.getWidth());
|
|
|
|
byte[] result = new byte[temp.getWidth() * temp.getHeight()];
|
|
+ // Pufferfish start
|
|
+ if (!SIMDDetection.isEnabled) {
|
|
for (int i = 0; i < pixels.length; i++) {
|
|
result[i] = matchColor(new Color(pixels[i], true));
|
|
}
|
|
+ } else {
|
|
+ gg.pufferfish.pufferfish.simd.VectorMapPalette.matchColorVectorized(pixels, result);
|
|
+ }
|
|
+ // Pufferfish end
|
|
return result;
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
index 003bece642b682985625db93cad93026352bfc66..e8ba4f1108f2548a487877027e37d81fc150e042 100644
|
|
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
|
|
@@ -597,7 +597,9 @@ public final class SimplePluginManager implements PluginManager {
|
|
|
|
// Paper start
|
|
private void handlePluginException(String msg, Throwable ex, Plugin plugin) {
|
|
+ gg.pufferfish.pufferfish.sentry.SentryContext.setPluginContext(plugin); // Pufferfish
|
|
server.getLogger().log(Level.SEVERE, msg, ex);
|
|
+ gg.pufferfish.pufferfish.sentry.SentryContext.removePluginContext(); // Pufferfish
|
|
callEvent(new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerPluginEnableDisableException(msg, ex, plugin)));
|
|
}
|
|
// Paper end
|
|
@@ -667,9 +669,11 @@ public final class SimplePluginManager implements PluginManager {
|
|
));
|
|
}
|
|
} catch (Throwable ex) {
|
|
+ gg.pufferfish.pufferfish.sentry.SentryContext.setEventContext(event, registration); // Pufferfish
|
|
// Paper start - error reporting
|
|
String msg = "Could not pass event " + event.getEventName() + " to " + registration.getPlugin().getDescription().getFullName();
|
|
server.getLogger().log(Level.SEVERE, msg, ex);
|
|
+ gg.pufferfish.pufferfish.sentry.SentryContext.removeEventContext(); // Pufferfish
|
|
if (!(event instanceof com.destroystokyo.paper.event.server.ServerExceptionEvent)) { // We don't want to cause an endless event loop
|
|
callEvent(new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerEventException(msg, ex, registration.getPlugin(), registration.getListener(), event)));
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
index eaefbb00e9993d54906cc8cf35cf753c0d6c7707..301e82369603f3dd6e6c1bd380da4bacacd7ef6c 100644
|
|
--- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
+++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java
|
|
@@ -336,7 +336,13 @@ public final class JavaPluginLoader implements PluginLoader {
|
|
try {
|
|
jPlugin.setEnabled(true);
|
|
} catch (Throwable ex) {
|
|
+ gg.pufferfish.pufferfish.sentry.SentryContext.setPluginContext(plugin); // Pufferfish
|
|
server.getLogger().log(Level.SEVERE, "Error occurred while enabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
|
+ gg.pufferfish.pufferfish.sentry.SentryContext.removePluginContext(); // Pufferfish
|
|
+ // Paper start - Disable plugins that fail to load
|
|
+ this.server.getPluginManager().disablePlugin(jPlugin);
|
|
+ return;
|
|
+ // Paper end
|
|
}
|
|
|
|
// Perhaps abort here, rather than continue going, but as it stands,
|
|
@@ -361,7 +367,9 @@ public final class JavaPluginLoader implements PluginLoader {
|
|
try {
|
|
jPlugin.setEnabled(false);
|
|
} catch (Throwable ex) {
|
|
+ gg.pufferfish.pufferfish.sentry.SentryContext.setPluginContext(plugin); // Pufferfish
|
|
server.getLogger().log(Level.SEVERE, "Error occurred while disabling " + plugin.getDescription().getFullName() + " (Is it up to date?)", ex);
|
|
+ gg.pufferfish.pufferfish.sentry.SentryContext.removePluginContext(); // Pufferfish
|
|
}
|
|
|
|
if (cloader instanceof PluginClassLoader) {
|
|
diff --git a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
|
index 7e4f7cb2afbc145e532285c793573ad107bc3033..12449e18180d604e9cbbc744da74a8b222a18e1f 100644
|
|
--- a/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
|
+++ b/src/main/java/org/bukkit/plugin/java/PluginClassLoader.java
|
|
@@ -50,6 +50,8 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
|
private io.papermc.paper.plugin.provider.classloader.PluginClassLoaderGroup classLoaderGroup; // Paper
|
|
public io.papermc.paper.plugin.provider.entrypoint.DependencyContext dependencyContext; // Paper
|
|
|
|
+ private boolean closed = false; // Pufferfish
|
|
+
|
|
static {
|
|
ClassLoader.registerAsParallelCapable();
|
|
}
|
|
@@ -197,6 +199,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
|
throw new ClassNotFoundException(name);
|
|
}
|
|
|
|
+ public boolean _airplane_hasClass(@NotNull String name) { return this.classes.containsKey(name); } // Pufferfish
|
|
@Override
|
|
protected Class<?> findClass(String name) throws ClassNotFoundException {
|
|
if (name.startsWith("org.bukkit.") || name.startsWith("net.minecraft.")) {
|
|
@@ -204,7 +207,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
|
}
|
|
Class<?> result = classes.get(name);
|
|
|
|
- if (result == null) {
|
|
+ if (result == null && !this.closed) { // Pufferfish
|
|
String path = name.replace('.', '/').concat(".class");
|
|
JarEntry entry = jar.getJarEntry(path);
|
|
|
|
@@ -251,6 +254,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
|
this.setClass(name, result); // Paper
|
|
}
|
|
|
|
+ if (result == null) throw new ClassNotFoundException(name); // Pufferfish
|
|
return result;
|
|
}
|
|
|
|
@@ -265,6 +269,7 @@ public final class PluginClassLoader extends URLClassLoader implements io.paperm
|
|
// Paper end
|
|
super.close();
|
|
} finally {
|
|
+ this.closed = true; // Pufferfish
|
|
jar.close();
|
|
}
|
|
}
|