mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-02 17:01:38 +01:00
c0936a71bd
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: 01aa02eb PR-858: Add LivingEntity#playHurtAnimation() 9421320f PR-884: Refinements to new ban API for improved compatibility and correctness 37a60b45 SPIGOT-6455, SPIGOT-7030, PR-750: Improve ban API 4eeb174b All smithing inventories are now the new smithing inventory f2bb168e PR-880: Add methods to get/set FallingBlock CancelDrop e7a807fa PR-879: Add Player#sendHealthUpdate() 692b8e96 SPIGOT-7370: Remove float value conversion in plugin.yml 2d033390 SPIGOT-7403: Add direct API for waxed signs 16a08373 PR-876: Add missing Raider API and 'no action ticks' CraftBukkit Changes: b60a95c8c PR-1189: Add LivingEntity#playHurtAnimation() 95c335c63 PR-1226: Fix VehicleEnterEvent not being called for certain entities 0a0fc3bee PR-1227: Refinements to new ban API for improved compatibility and correctness 0d0b1e5dc Revert bad change to PathfinderGoalSit causing all cats to sit 648196070 SPIGOT-6455, SPIGOT-7030, PR-1054: Improve ban API 31fe848d6 All smithing inventories are now the new smithing inventory 9a919a143 SPIGOT-7416: SmithItemEvent not firing in Smithing Table 9f64f0d22 PR-1221: Add methods to get/set FallingBlock CancelDrop 3be9ac171 PR-1220: Add Player#sendHealthUpdate() c1279f775 PR-1209: Clean up various patches c432e4397 Fix Raider#setCelebrating() implementation 504d96665 SPIGOT-7403: Add direct API for waxed signs c68c1f1b3 PR-1216: Add missing Raider API and 'no action ticks' 85b89c3dd Increase outdated build delay Spigot Changes: 9ebce8af Rebuild patches 64b565e6 Rebuild patches
156 lines
6.6 KiB
Diff
156 lines
6.6 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 a1467e8edd3ca66c306d01e0688a9fece69652f3..0968827df66057ec73185ce688a62e8b27abba0c 100644
|
|
--- a/src/main/java/net/minecraft/network/Connection.java
|
|
+++ b/src/main/java/net/minecraft/network/Connection.java
|
|
@@ -644,6 +644,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
|
|
} else {
|
|
if (this.channel.pipeline().get("decompress") instanceof CompressionDecoder) {
|
|
this.channel.pipeline().remove("decompress");
|
|
@@ -652,6 +653,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
|
|
}
|
|
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
|
index bb9e65eee7e0ca0f715cd5791c47579a57b1b577..29a0a720f22f56ca3d844efef1ecde3980fb1c12 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
|
|
channelpipeline.addLast("packet_handler", (ChannelHandler) object);
|
|
((Connection) object).setListener(new ServerHandshakePacketListenerImpl(ServerConnectionListener.this.server, (Connection) object));
|
|
+ io.papermc.paper.network.ChannelInitializeListenerHolder.callListeners(channel); // Paper
|
|
}
|
|
}).group((EventLoopGroup) lazyinitvar.get()).localAddress(address, port)).option(ChannelOption.AUTO_READ, false).bind().syncUninterruptibly()); // CraftBukkit
|
|
}
|