aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0885-Add-player-idle-duration-API.patch
blob: d715a2ed4a3d305286a5e64ff75c6ae18d5c389b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 ea5e3973a4021a4584d3b8b33c9d50001f4c0fe6..c73089566eccc15aa747e3e3707d089a0f2b8d1d 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -3447,6 +3447,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;