mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 15:30:19 +01:00
31699ae9a8
* Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: a6a9d2a4 Remove some old ApiStatus.Experimental annotations be72314c SPIGOT-7300, PR-829: Add new DamageSource API providing enhanced information about entity damage b252cf05 SPIGOT-7576, PR-970: Add methods in MushroomCow to change stew effects b1c689bd PR-902: Add Server#isLoggingIPs to get log-ips configuration 08f86d1c PR-971: Add Player methods for client-side potion effects 2e3024a9 PR-963: Add API for in-world structures a23292a7 SPIGOT-7530, PR-948: Improve Resource Pack API with new 1.20.3 functionality 1851857b SPIGOT-3071, PR-969: Add entity spawn method with spawn reason cde4c52a SPIGOT-5553, PR-964: Add EntityKnockbackEvent CraftBukkit Changes: 38fd4bd50 Fix accidentally renamed internal damage method 80f0ce4be SPIGOT-7300, PR-1180: Add new DamageSource API providing enhanced information about entity damage 7e43f3b16 SPIGOT-7581: Fix typo in BlockMushroom ea14b7d90 SPIGOT-7576, PR-1347: Add methods in MushroomCow to change stew effects 4c687f243 PR-1259: Add Server#isLoggingIPs to get log-ips configuration 22a541a29 Improve support for per-world game rules cb7dccce2 PR-1348: Add Player methods for client-side potion effects b8d6109f0 PR-1335: Add API for in-world structures 4398a1b5b SPIGOT-7577: Make CraftWindCharge#explode discard the entity e74107678 Fix Crafter maximum stack size 0bb0f4f6a SPIGOT-7530, PR-1314: Improve Resource Pack API with new 1.20.3 functionality 4949f556d SPIGOT-3071, PR-1345: Add entity spawn method with spawn reason 20ac73ca2 PR-1353: Fix Structure#place not working as documented with 0 palette 3c1b77871 SPIGOT-6911, PR-1349: Change max book length in CraftMetaBook 333701839 SPIGOT-7572: Bee nests generated without bees f48f4174c SPIGOT-5553, PR-1336: Add EntityKnockbackEvent
155 lines
6.8 KiB
Diff
155 lines
6.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Nassim Jahnke <nassim@njahnke.dev>
|
|
Date: Thu, 29 Apr 2021 21:19:33 +0200
|
|
Subject: [PATCH] Add Channel initialization listeners
|
|
|
|
|
|
diff --git a/src/main/java/io/papermc/paper/network/ChannelInitializeListener.java b/src/main/java/io/papermc/paper/network/ChannelInitializeListener.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..88099df34c2d74daba9645aadf65b446ca795a91
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/network/ChannelInitializeListener.java
|
|
@@ -0,0 +1,15 @@
|
|
+package io.papermc.paper.network;
|
|
+
|
|
+import io.netty.channel.Channel;
|
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
|
+
|
|
+/**
|
|
+ * Internal API to register channel initialization listeners.
|
|
+ * <p>
|
|
+ * This is not officially supported API and we make no guarantees to the existence or state of this interface.
|
|
+ */
|
|
+@FunctionalInterface
|
|
+public interface ChannelInitializeListener {
|
|
+
|
|
+ void afterInitChannel(@NonNull Channel channel);
|
|
+}
|
|
diff --git a/src/main/java/io/papermc/paper/network/ChannelInitializeListenerHolder.java b/src/main/java/io/papermc/paper/network/ChannelInitializeListenerHolder.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..30e62719e0a83525daa33cf41cb61df360c0e046
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/network/ChannelInitializeListenerHolder.java
|
|
@@ -0,0 +1,74 @@
|
|
+package io.papermc.paper.network;
|
|
+
|
|
+import io.netty.channel.Channel;
|
|
+import net.kyori.adventure.key.Key;
|
|
+import org.checkerframework.checker.nullness.qual.NonNull;
|
|
+import org.checkerframework.checker.nullness.qual.Nullable;
|
|
+
|
|
+import java.util.Collections;
|
|
+import java.util.HashMap;
|
|
+import java.util.Map;
|
|
+
|
|
+/**
|
|
+ * Internal API to register channel initialization listeners.
|
|
+ * <p>
|
|
+ * This is not officially supported API and we make no guarantees to the existence or state of this class.
|
|
+ */
|
|
+public final class ChannelInitializeListenerHolder {
|
|
+
|
|
+ private static final Map<Key, ChannelInitializeListener> LISTENERS = new HashMap<>();
|
|
+ private static final Map<Key, ChannelInitializeListener> IMMUTABLE_VIEW = Collections.unmodifiableMap(LISTENERS);
|
|
+
|
|
+ private ChannelInitializeListenerHolder() {
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Registers whether an initialization listener is registered under the given key.
|
|
+ *
|
|
+ * @param key key
|
|
+ * @return whether an initialization listener is registered under the given key
|
|
+ */
|
|
+ public static boolean hasListener(@NonNull Key key) {
|
|
+ return LISTENERS.containsKey(key);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Registers a channel initialization listener called after ServerConnection is initialized.
|
|
+ *
|
|
+ * @param key key
|
|
+ * @param listener initialization listeners
|
|
+ */
|
|
+ public static void addListener(@NonNull Key key, @NonNull ChannelInitializeListener listener) {
|
|
+ LISTENERS.put(key, listener);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Removes and returns an initialization listener registered by the given key if present.
|
|
+ *
|
|
+ * @param key key
|
|
+ * @return removed initialization listener if present
|
|
+ */
|
|
+ public static @Nullable ChannelInitializeListener removeListener(@NonNull Key key) {
|
|
+ return LISTENERS.remove(key);
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Returns an immutable map of registered initialization listeners.
|
|
+ *
|
|
+ * @return immutable map of registered initialization listeners
|
|
+ */
|
|
+ public static @NonNull Map<Key, ChannelInitializeListener> getListeners() {
|
|
+ return IMMUTABLE_VIEW;
|
|
+ }
|
|
+
|
|
+ /**
|
|
+ * Calls the registered listeners with the given channel.
|
|
+ *
|
|
+ * @param channel channel
|
|
+ */
|
|
+ public static void callListeners(@NonNull Channel channel) {
|
|
+ for (ChannelInitializeListener listener : LISTENERS.values()) {
|
|
+ listener.afterInitChannel(channel);
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/io/papermc/paper/network/ConnectionEvent.java b/src/main/java/io/papermc/paper/network/ConnectionEvent.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..0d7e7db9e37ef0183c32b217bd944fb4f41ab83a
|
|
--- /dev/null
|
|
+++ b/src/main/java/io/papermc/paper/network/ConnectionEvent.java
|
|
@@ -0,0 +1,10 @@
|
|
+package io.papermc.paper.network;
|
|
+
|
|
+/**
|
|
+ * Internal connection pipeline events.
|
|
+ */
|
|
+public enum ConnectionEvent {
|
|
+
|
|
+ COMPRESSION_THRESHOLD_SET,
|
|
+ COMPRESSION_DISABLED
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/network/Connection.java b/src/main/java/net/minecraft/network/Connection.java
|
|
index ddc84de84c8a503a01e40c42fe83558af7159f8f..37b16918451859c22f92bcbcbce05c16b8beff75 100644
|
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
|
@@ -633,6 +633,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
} else {
|
|
this.channel.pipeline().addBefore("encoder", "compress", new CompressionEncoder(compressionThreshold));
|
|
}
|
|
+ this.channel.pipeline().fireUserEventTriggered(io.papermc.paper.network.ConnectionEvent.COMPRESSION_THRESHOLD_SET); // Paper - Add Channel initialization listeners
|
|
} else {
|
|
if (this.channel.pipeline().get("decompress") instanceof CompressionDecoder) {
|
|
this.channel.pipeline().remove("decompress");
|
|
@@ -641,6 +642,7 @@ public class Connection extends SimpleChannelInboundHandler<Packet<?>> {
|
|
if (this.channel.pipeline().get("compress") instanceof CompressionEncoder) {
|
|
this.channel.pipeline().remove("compress");
|
|
}
|
|
+ this.channel.pipeline().fireUserEventTriggered(io.papermc.paper.network.ConnectionEvent.COMPRESSION_DISABLED); // Paper - Add Channel initialization listeners
|
|
}
|
|
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
|
index 3b6bafb242d2623c15f26acdacd036478c7dc214..25ddfe8e5da65e4ac70be2820ba139e7f3852c0c 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
|
@@ -113,6 +113,7 @@ public class ServerConnectionListener {
|
|
pending.add(object); // Paper - prevent blocking on adding a new connection while the server is ticking
|
|
((Connection) object).configurePacketHandler(channelpipeline);
|
|
((Connection) object).setListenerForServerboundHandshake(new ServerHandshakePacketListenerImpl(ServerConnectionListener.this.server, (Connection) object));
|
|
+ io.papermc.paper.network.ChannelInitializeListenerHolder.callListeners(channel); // Paper - Add Channel initialization listeners
|
|
}
|
|
}).group(eventloopgroup).localAddress(address, port)).option(ChannelOption.AUTO_READ, false).bind().syncUninterruptibly()); // CraftBukkit
|
|
}
|