publish getLastItemStackChangeTime, renaming

This commit is contained in:
radsteve 2024-07-15 20:26:08 +02:00
parent 946d15cc3b
commit f417bb7cc9
2 changed files with 22 additions and 8 deletions

View file

@ -5,21 +5,30 @@ Subject: [PATCH] Item stack name tooltip API
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 7c56182acaf827f4b1a986a61cea8e9960604c98..f7d0d7937e86a4a1b51fc2105f072f40ae623396 100644 index 7c56182acaf827f4b1a986a61cea8e9960604c98..9da64bc368b1eac55fad336f58619509542dd5e1 100644
--- a/src/main/java/org/bukkit/entity/Player.java --- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java +++ b/src/main/java/org/bukkit/entity/Player.java
@@ -3855,6 +3855,14 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM @@ -3855,6 +3855,23 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
boolean isChunkSent(long chunkKey); boolean isChunkSent(long chunkKey);
// Paper end // Paper end
+ // Paper start - Item stack name tooltip API
+ /** + /**
+ * Checks whether the currently held item is displaying the item name tooltip on the client. + * Checks whether the currently held item is assumed to be displaying the item name tooltip on the client.
+ * However, this behavior can be changed via the Accessibility Settings, which can lead to inaccuracies. + * However, this behavior can be changed via the Accessibility Settings, which can lead to inaccuracies.
+ * Keep in mind that this assumes default settings and is prone to break. + * Keep in mind that this assumes default settings and is prone to break.
+ * @return true if it is showing with default settings, false if not. + * @return true if it is showing with default settings, false if not.
+ */ + */
+ boolean isItemNameTooltipShown(); // Paper - Item stack name tooltip API + boolean isItemNameTooltipEstimatedToBeVisible();
+ +
+ /**
+ * Gets the last timestamp when the player has changed their selected item stack in their hotbar.
+ * This time is measured using {@link net.minecraft.Util#getMillis}.
+ * @return The last timestamp, or zero, if the player hasn't changed selected item stacks.
+ */
+ long getLastItemStackChangeTime();
+
+ // Paper end - Item stack name tooltip API
@NotNull @NotNull
@Override @Override
Spigot spigot(); Spigot spigot();

View file

@ -42,10 +42,10 @@ index 9d1e68c09fa7093cf0f6fa636f90cb15a44cbb38..4384869b79539c9e424b20bd656b6716
+ // Paper end - Item stack name tooltip API + // Paper end - Item stack name tooltip API
} }
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index d01b45a48d412e3cb591acee101730704574448a..61d9885d87d8a8662b7bde787598db54d0522c14 100644 index d01b45a48d412e3cb591acee101730704574448a..52a985b95d8c6a35f7df52979b7fab84ad673e98 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -3554,4 +3554,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player { @@ -3554,4 +3554,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
((ca.spottedleaf.moonrise.patches.chunk_system.player.ChunkSystemServerPlayer)this.getHandle()) ((ca.spottedleaf.moonrise.patches.chunk_system.player.ChunkSystemServerPlayer)this.getHandle())
.moonrise$getViewDistanceHolder().setSendViewDistance(viewDistance); .moonrise$getViewDistanceHolder().setSendViewDistance(viewDistance);
} }
@ -54,9 +54,14 @@ index d01b45a48d412e3cb591acee101730704574448a..61d9885d87d8a8662b7bde787598db54
+ private static final long DEFAULT_ITEM_TOOLTIP_DURATION_MS = 40 * 50; + private static final long DEFAULT_ITEM_TOOLTIP_DURATION_MS = 40 * 50;
+ +
+ @Override + @Override
+ public boolean isItemNameTooltipShown() { + public long getLastItemStackChangeTime() {
+ return this.getHandle().getLastItemStackChangeTime();
+ }
+
+ @Override
+ public boolean isItemNameTooltipEstimatedToBeVisible() {
+ long currentTime = net.minecraft.Util.getMillis(); + long currentTime = net.minecraft.Util.getMillis();
+ long lastItemStackChange = this.getHandle().getLastItemStackChangeTime(); + long lastItemStackChange = this.getLastItemStackChangeTime();
+ return currentTime - lastItemStackChange < DEFAULT_ITEM_TOOLTIP_DURATION_MS; + return currentTime - lastItemStackChange < DEFAULT_ITEM_TOOLTIP_DURATION_MS;
+ } + }
+ // Paper end - Item stack name tooltip API + // Paper end - Item stack name tooltip API