mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 21:17:00 +01:00
1358d1e914
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: 881e06e5 PR-725: Add Item Unlimited Lifetime APIs CraftBukkit Changes: 74c08312 SPIGOT-6962: Call EntityChangeBlockEvent when when FallingBlockEntity starts to fall 64db5126 SPIGOT-6959: Make /loot command ignore empty items for spawn 2d760831 Increase outdated build delay 9ed7e4fb SPIGOT-6138, SPIGOT-6415: Don't call CreatureSpawnEvent after cross-dimensional travel fc4ad813 SPIGOT-6895: Trees grown with applyBoneMeal() don't fire the StructureGrowthEvent 59733a2e SPIGOT-6961: Actually return a copy of the ItemMeta Spigot Changes: ffceeae3 SPIGOT-6956: Drop unload queue patch as attempt at fixing stop issue e19ddabd PR-1011: Add Item Unlimited Lifetime APIs 34d40b0e SPIGOT-2942: give command fires PlayerDropItemEvent, cancelling it causes Item Duplication
119 lines
4.9 KiB
Diff
119 lines
4.9 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Nassim Jahnke <jahnke.nassim@gmail.com>
|
|
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/net/minecraft/server/network/ServerConnectionListener.java b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
|
index 888e863b6d605bf587d0c071795a43d2157afa4d..c36089ead51d2e7dc3369d5f9a1869f58ff5391c 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerConnectionListener.java
|
|
@@ -112,6 +112,7 @@ public class ServerConnectionListener {
|
|
pending.add((Connection) object); // Paper
|
|
channel.pipeline().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
|
|
}
|