Skip to content

Commit

Permalink
Updated Upstream (Paper)
Browse files Browse the repository at this point in the history
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@e6ef1ba [ci skip] Update download urls (#9100)
PaperMC/Paper@9367e6e Prevent GameEvents being fired from unloaded chunks
PaperMC/Paper@9b77660 Port airplane's use array for gamerule storage patch (#9087)
  • Loading branch information
encode42 committed Apr 6, 2023
1 parent 285f9f6 commit 4155131
Show file tree
Hide file tree
Showing 7 changed files with 984 additions and 269 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
group = org.purpurmc.purpur
version = 1.19.4-R0.1-SNAPSHOT

paperCommit = 497b91939cf2972bac5337487f9f71770044fbc8
paperCommit = 9b77660f070a0ea2c0d82293d731ff19f60e9787

org.gradle.caching = true
org.gradle.parallel = true
Expand Down
110 changes: 55 additions & 55 deletions patches/api/0001-Pufferfish-API-Changes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ index cad12a2632b9ebb569280441c42869685db1f31a..b83e2c5a0a094002d12aee55ec0cf8d1
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..6fbaf2a232745db0a41394b1c2cc0cc90cefc4ee
index 0000000000000000000000000000000000000000..10310fdd53de28efb8a8250f6d3b0c8eb08fb68a
--- /dev/null
+++ b/src/main/java/gg/pufferfish/pufferfish/sentry/SentryContext.java
@@ -0,0 +1,161 @@
Expand All @@ -69,21 +69,21 @@ index 0000000000000000000000000000000000000000..6fbaf2a232745db0a41394b1c2cc0cc9
+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());
Expand All @@ -92,52 +92,52 @@ index 0000000000000000000000000000000000000000..6fbaf2a232745db0a41394b1c2cc0cc9
+ }
+ }
+ }
+
+
+ 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());
Expand All @@ -146,7 +146,7 @@ index 0000000000000000000000000000000000000000..6fbaf2a232745db0a41394b1c2cc0cc9
+ if (Modifier.isStatic(declaredField.getModifiers())) {
+ continue;
+ }
+
+
+ String fieldName = declaredField.getName();
+ if (fieldName.equals("handlers")) {
+ continue;
Expand All @@ -162,59 +162,59 @@ index 0000000000000000000000000000000000000000..6fbaf2a232745db0a41394b1c2cc0cc9
+ }
+ 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..6d266ebf5e52745ad13e90e5754b524383fa9b29
index 0000000000000000000000000000000000000000..ab5fea0b03224bf249352ce340e94704ff713345
--- /dev/null
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDChecker.java
@@ -0,0 +1,40 @@
Expand All @@ -231,21 +231,21 @@ index 0000000000000000000000000000000000000000..6d266ebf5e52745ad13e90e5754b5243
+ */
+@Deprecated
+public class SIMDChecker {
+
+
+ @Deprecated
+ public static boolean canEnable(Logger logger) {
+ try {
+ if (SIMDDetection.getJavaVersion() != 17 && SIMDDetection.getJavaVersion() != 18 && SIMDDetection.getJavaVersion() != 19) {
+ 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;
Expand All @@ -256,11 +256,11 @@ index 0000000000000000000000000000000000000000..6d266ebf5e52745ad13e90e5754b5243
+ } 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..fd708554d6dab2ddcd24c3024330b8ebf9462111
index 0000000000000000000000000000000000000000..a84889d3e9cfc4d7ab5f867820a6484c6070711b
--- /dev/null
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/SIMDDetection.java
@@ -0,0 +1,35 @@
Expand All @@ -270,11 +270,11 @@ index 0000000000000000000000000000000000000000..fd708554d6dab2ddcd24c3024330b8eb
+
+@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 {
Expand All @@ -283,7 +283,7 @@ index 0000000000000000000000000000000000000000..fd708554d6dab2ddcd24c3024330b8eb
+ return false;
+ }
+ }
+
+
+ @Deprecated
+ public static int getJavaVersion() {
+ // https://stackoverflow.com/a/2591122
Expand All @@ -297,11 +297,11 @@ index 0000000000000000000000000000000000000000..fd708554d6dab2ddcd24c3024330b8eb
+ 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..20ec3b29b0cb4061cc89d635b3929ffe71008e22
index 0000000000000000000000000000000000000000..ae2464920c9412ac90b819a540ee58be0741465f
--- /dev/null
+++ b/src/main/java/gg/pufferfish/pufferfish/simd/VectorMapPalette.java
@@ -0,0 +1,83 @@
Expand All @@ -316,10 +316,10 @@ index 0000000000000000000000000000000000000000..20ec3b29b0cb4061cc89d635b3929ffe
+
+@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();
Expand All @@ -329,64 +329,64 @@ index 0000000000000000000000000000000000000000..20ec3b29b0cb4061cc89d635b3929ffe
+ 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 3a9aaca2e76411a9c27f9f5e0f22d060d5a66d06..9584e245144b561b4f6745b2f26a4f69a6f92891 100644
Expand Down Expand Up @@ -426,7 +426,7 @@ index 3a9aaca2e76411a9c27f9f5e0f22d060d5a66d06..9584e245144b561b4f6745b2f26a4f69
}

diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
index 2b8308989fce7f8a16907f8711b362e671fdbfb6..bd4d1a40f53784662174d426533ef4b5433a15b7 100644
index fc2dae69165776d08274e34a69962cc70445f411..899d67fa782fac639fe7fb096e05c551d75bd647 100644
--- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java
+++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java
@@ -584,7 +584,9 @@ public final class SimplePluginManager implements PluginManager {
Expand Down
Loading

0 comments on commit 4155131

Please sign in to comment.