From b83f71ccf27c9e239282919474deee7355c06fc1 Mon Sep 17 00:00:00 2001 From: good777LUCKY <43497313+good777LUCKY@users.noreply.github.com> Date: Fri, 30 Oct 2020 21:46:23 +0900 Subject: [PATCH] Add TimeSinceRest --- src/main/java/cn/nukkit/Player.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/cn/nukkit/Player.java b/src/main/java/cn/nukkit/Player.java index 3c763b38662..969feddff47 100644 --- a/src/main/java/cn/nukkit/Player.java +++ b/src/main/java/cn/nukkit/Player.java @@ -251,6 +251,8 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde protected double lastRightClickTime = 0.0; protected Vector3 lastRightClickPos = null; + private int timeSinceRest; + public int getStartActionTick() { return startAction; } @@ -1129,6 +1131,8 @@ public boolean sleepOn(Vector3 pos) { this.level.sleepTicks = 60; + this.timeSinceRest = 0; + return true; } @@ -1731,6 +1735,10 @@ public boolean onUpdate(int currentTick) { if (this.getFoodData() != null) this.getFoodData().update(tickDiff); } } + + if (!this.isSleeping()) { + this.timeSinceRest++; + } } this.checkTeleportPosition(); @@ -1983,6 +1991,11 @@ protected void processLogin() { this.forceMovement = this.teleportPosition = this.getPosition(); + if (!this.namedTag.contains("TimeSinceRest")) { + this.namedTag.putInt("TimeSinceRest", 0); + } + this.timeSinceRest = this.namedTag.getInt("TimeSinceRest"); + ResourcePacksInfoPacket infoPacket = new ResourcePacksInfoPacket(); infoPacket.resourcePackEntries = this.server.getResourcePackManager().getResourceStack(); infoPacket.mustAccept = this.server.getForceResources(); @@ -3769,6 +3782,8 @@ public void save(boolean async) { this.namedTag.putInt("foodLevel", this.getFoodData().getLevel()); this.namedTag.putFloat("foodSaturationLevel", this.getFoodData().getFoodSaturationLevel()); + this.namedTag.putInt("TimeSinceRest", this.timeSinceRest); + if (!this.username.isEmpty() && this.namedTag != null) { this.server.saveOfflinePlayerData(this.uuid, this.namedTag, async); } @@ -3972,6 +3987,8 @@ public void kill() { this.setExperience(0, 0); } + this.timeSinceRest = 0; + if (showMessages && !ev.getDeathMessage().toString().isEmpty()) { this.server.broadcast(ev.getDeathMessage(), Server.BROADCAST_CHANNEL_USERS); } @@ -5103,4 +5120,12 @@ public String toString() { "', location=" + super.toString() + ')'; } + + public int getTimeSinceRest() { + return timeSinceRest; + } + + public void setTimeSinceRest(int timeSinceRest) { + this.timeSinceRest = timeSinceRest; + } }