mirror of
https://github.com/SparklyPower/SparklyPaper.git
synced 2025-12-19 15:09:27 +00:00
A bunch of new patches that we need for SparklyPower features
This commit is contained in:
84
patches/api/0001-Add-ClientboundPacketPreDispatchEvent.patch
Normal file
84
patches/api/0001-Add-ClientboundPacketPreDispatchEvent.patch
Normal file
@@ -0,0 +1,84 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||
Date: Mon, 10 Jun 2024 12:27:08 -0300
|
||||
Subject: [PATCH] Add ClientboundPacketPreDispatchEvent
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/sparklypower/sparklypaper/event/packet/ClientboundPacketPreDispatchEvent.java b/src/main/java/net/sparklypower/sparklypaper/event/packet/ClientboundPacketPreDispatchEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..6d36dccdc08e7e523771fde4d8d1bb73e430114c
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/net/sparklypower/sparklypaper/event/packet/ClientboundPacketPreDispatchEvent.java
|
||||
@@ -0,0 +1,72 @@
|
||||
+package net.sparklypower.sparklypaper.event.packet;
|
||||
+
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
+import org.bukkit.event.Event;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+
|
||||
+/**
|
||||
+ * Called before a packet is dispatched to a connection.
|
||||
+ * <p>
|
||||
+ * Compared to other solutions like ProtocolLib, this has the advantage that this is called eariler on the packet sending cycle, before the packet is added to the packet queue, allowing for
|
||||
+ * main thread access of resources without worrying about race conditions.
|
||||
+ * <p>
|
||||
+ * The asynchronously state of this event is undefined, the event may be called on an async or on a sync thread, depending on where the packet was sent.
|
||||
+ */
|
||||
+public class ClientboundPacketPreDispatchEvent extends Event implements Cancellable {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+ private boolean isCancelled = false;
|
||||
+ private final Player player;
|
||||
+ private final Object packet;
|
||||
+
|
||||
+ public ClientboundPacketPreDispatchEvent(boolean isAsync, @Nullable Player player, @NotNull Object packet) {
|
||||
+ super(isAsync);
|
||||
+ this.player = player;
|
||||
+ this.packet = packet;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the player associated with this packet.
|
||||
+ * <p>
|
||||
+ * Depending on which phase the packet is from, the player may be null
|
||||
+ *
|
||||
+ * @return the player associated with this packet
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public Player getPlayer() {
|
||||
+ return player;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the packet associated with this event.
|
||||
+ *
|
||||
+ * @return the packet associated with this event
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public Object getPacket() {
|
||||
+ return packet;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ @Override
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return handlers;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean isCancelled() {
|
||||
+ return isCancelled;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setCancelled(boolean cancel) {
|
||||
+ this.isCancelled = cancel;
|
||||
+ }
|
||||
+}
|
||||
Reference in New Issue
Block a user