mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 23:57:43 +01:00
Add player idle duration API (#9833)
* Add player idle duration API Implements API for getting, setting and resetting a player's idle duration. * Remove idle duration setter * Rebase
This commit is contained in:
parent
c6fac381ed
commit
5bdfb29ba1
2 changed files with 71 additions and 0 deletions
41
patches/api/0442-Add-player-idle-duration-API.patch
Normal file
41
patches/api/0442-Add-player-idle-duration-API.patch
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: booky10 <boooky10@gmail.com>
|
||||||
|
Date: Sat, 14 Oct 2023 03:11:11 +0200
|
||||||
|
Subject: [PATCH] Add player idle duration API
|
||||||
|
|
||||||
|
Implements API for getting and resetting a player's idle duration.
|
||||||
|
|
||||||
|
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
|
||||||
|
index 20fa1024f9ad8f478a347be5c554b5e45b398a1c..2996db88343060624d6aab7889290ae74a973fe8 100644
|
||||||
|
--- a/src/main/java/org/bukkit/entity/Player.java
|
||||||
|
+++ b/src/main/java/org/bukkit/entity/Player.java
|
||||||
|
@@ -3274,6 +3274,29 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
|
||||||
|
void increaseWardenWarningLevel();
|
||||||
|
// Paper end
|
||||||
|
|
||||||
|
+ // Paper start
|
||||||
|
+ /**
|
||||||
|
+ * The idle duration is reset when the player
|
||||||
|
+ * sends specific action packets.
|
||||||
|
+ * <p>
|
||||||
|
+ * After the idle duration exceeds {@link org.bukkit.Bukkit#getIdleTimeout()}, the
|
||||||
|
+ * player will be kicked for {@link org.bukkit.event.player.PlayerKickEvent.Cause#IDLING}.
|
||||||
|
+ *
|
||||||
|
+ * @return the current idle duration of this player
|
||||||
|
+ */
|
||||||
|
+ @NotNull Duration getIdleDuration();
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Resets this player's idle duration.
|
||||||
|
+ * <p>
|
||||||
|
+ * After the idle duration exceeds {@link org.bukkit.Bukkit#getIdleTimeout()}, the
|
||||||
|
+ * player will be kicked for {@link org.bukkit.event.player.PlayerKickEvent.Cause#IDLING}.
|
||||||
|
+ *
|
||||||
|
+ * @see #getIdleDuration()
|
||||||
|
+ */
|
||||||
|
+ void resetIdleDuration();
|
||||||
|
+ // Paper end
|
||||||
|
+
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
Spigot spigot();
|
30
patches/server/1039-Add-player-idle-duration-API.patch
Normal file
30
patches/server/1039-Add-player-idle-duration-API.patch
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: booky10 <boooky10@gmail.com>
|
||||||
|
Date: Sat, 14 Oct 2023 03:11:11 +0200
|
||||||
|
Subject: [PATCH] Add player idle duration API
|
||||||
|
|
||||||
|
Implements API for getting and resetting a player's idle duration.
|
||||||
|
|
||||||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||||
|
index 604ed1f6742a6b028b9db2809f7bd4b9a3b38f4d..bd2cb9080a5a215c97d4dc038ab8e8d1f7c20f8f 100644
|
||||||
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||||
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||||
|
@@ -3278,6 +3278,18 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||||
|
}
|
||||||
|
// Paper end
|
||||||
|
|
||||||
|
+ // Paper start
|
||||||
|
+ @Override
|
||||||
|
+ public Duration getIdleDuration() {
|
||||||
|
+ return Duration.ofMillis(net.minecraft.Util.getMillis() - this.getHandle().getLastActionTime());
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public void resetIdleDuration() {
|
||||||
|
+ this.getHandle().resetLastActionTime();
|
||||||
|
+ }
|
||||||
|
+ // Paper end
|
||||||
|
+
|
||||||
|
public Player.Spigot spigot()
|
||||||
|
{
|
||||||
|
return this.spigot;
|
Loading…
Reference in a new issue