From 28c7d403262521d1cee21766d6ba5fe4f583c852 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1=C4=8Dek?= <dawon.cz@gmail.com>
Date: Thu, 15 Dec 2022 20:43:14 +0100
Subject: [PATCH] Add Sneaking API for Entities (#8485)

---
 .../0421-Add-Sneaking-API-for-Entities.patch  | 56 +++++++++++++++++++
 .../0949-Add-Sneaking-API-for-Entities.patch  | 29 ++++++++++
 2 files changed, 85 insertions(+)
 create mode 100644 patches/api/0421-Add-Sneaking-API-for-Entities.patch
 create mode 100644 patches/server/0949-Add-Sneaking-API-for-Entities.patch

diff --git a/patches/api/0421-Add-Sneaking-API-for-Entities.patch b/patches/api/0421-Add-Sneaking-API-for-Entities.patch
new file mode 100644
index 0000000000..5e878c634d
--- /dev/null
+++ b/patches/api/0421-Add-Sneaking-API-for-Entities.patch
@@ -0,0 +1,56 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: dawon <dawon@dawon.eu>
+Date: Wed, 19 Oct 2022 23:36:42 +0200
+Subject: [PATCH] Add Sneaking API for Entities
+
+
+diff --git a/src/main/java/org/bukkit/entity/Entity.java b/src/main/java/org/bukkit/entity/Entity.java
+index 33a6b7a27dc91552799c07a7aad9b3df31ad13f7..cdbc7329cf5f67d66e31eb31e83b9e7997040f72 100644
+--- a/src/main/java/org/bukkit/entity/Entity.java
++++ b/src/main/java/org/bukkit/entity/Entity.java
+@@ -781,6 +781,25 @@ public interface Entity extends Metadatable, CommandSender, Nameable, Persistent
+     @NotNull
+     Pose getPose();
+ 
++    // Paper start
++    /**
++     * Returns if the entity is in sneak mode
++     *
++     * @return true if the entity is in sneak mode
++     */
++    boolean isSneaking();
++
++    /**
++     * Sets the sneak mode the entity.
++     * <p>
++     * Note: For most Entities this does not update Entity's pose
++     * and just makes its name tag less visible.
++     *
++     * @param sneak true if the entity should be sneaking
++     */
++    void setSneaking(boolean sneak);
++    // Paper end
++
+     /**
+      * Get the category of spawn to which this entity belongs.
+      *
+diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
+index 19995314b01f19c312efa2a4584ccfba2d700c52..9f762cf670bf5db9138e468e72e57781d8d22f54 100644
+--- a/src/main/java/org/bukkit/entity/Player.java
++++ b/src/main/java/org/bukkit/entity/Player.java
+@@ -296,6 +296,7 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
+      *
+      * @return true if player is in sneak mode
+      */
++    @Override // Paper
+     public boolean isSneaking();
+ 
+     /**
+@@ -303,6 +304,7 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
+      *
+      * @param sneak true if player should appear sneaking
+      */
++    @Override // Paper
+     public void setSneaking(boolean sneak);
+ 
+     /**
diff --git a/patches/server/0949-Add-Sneaking-API-for-Entities.patch b/patches/server/0949-Add-Sneaking-API-for-Entities.patch
new file mode 100644
index 0000000000..e93f3c5860
--- /dev/null
+++ b/patches/server/0949-Add-Sneaking-API-for-Entities.patch
@@ -0,0 +1,29 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: dawon <dawon@dawon.eu>
+Date: Wed, 19 Oct 2022 23:31:53 +0200
+Subject: [PATCH] Add Sneaking API for Entities
+
+
+diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+index 6cd6cb256bde958416a0e4b13fc1d3df74f230fd..78f53ee557276de85f0431ebcb146445b1f4fb92 100644
+--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+@@ -1160,6 +1160,18 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
+         return Pose.values()[this.getHandle().getPose().ordinal()];
+     }
+ 
++    // Paper start
++    @Override
++    public void setSneaking(boolean sneak) {
++        this.getHandle().setShiftKeyDown(sneak);
++    }
++
++    @Override
++    public boolean isSneaking() {
++        return this.getHandle().isShiftKeyDown();
++    }
++    // Paper end
++
+     @Override
+     public SpawnCategory getSpawnCategory() {
+         return CraftSpawnCategory.toBukkit(this.getHandle().getType().getCategory());