From 6e0d7e5a40c7f2ff5e21a93d0f05f6c09f681bdd Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Mon, 20 Jan 2025 11:16:01 +0100 Subject: [PATCH] Fix sleep --- .../java/eu/m724/tweaks/sleep/SleepListener.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/m724/tweaks/sleep/SleepListener.java b/src/main/java/eu/m724/tweaks/sleep/SleepListener.java index 8aa5579..129a02b 100644 --- a/src/main/java/eu/m724/tweaks/sleep/SleepListener.java +++ b/src/main/java/eu/m724/tweaks/sleep/SleepListener.java @@ -8,7 +8,7 @@ package eu.m724.tweaks.sleep; import eu.m724.tweaks.TweaksConfig; import org.bukkit.GameRule; -import org.bukkit.World; +import org.bukkit.attribute.Attribute; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -31,20 +31,21 @@ public class SleepListener implements Listener { if (event.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) { SleepState.playersSleeping++; - World world = event.getPlayer().getWorld(); + var player = event.getPlayer(); + var world = player.getWorld(); long day = world.getFullTime() / 24000; if (day != lastDay) skippedCurrentNight.clear(); lastDay = day; - if (!skippedCurrentNight.contains(event.getPlayer())) { + if (skippedCurrentNight.add(player)) { if (instant) { - double onePlayerRatio = 1 / (event.getPlayer().getServer().getOnlinePlayers().size() * (world.getGameRuleValue(GameRule.PLAYERS_SLEEPING_PERCENTAGE) / 100.0)); + double onePlayerRatio = 1 / (player.getServer().getOnlinePlayers().size() * (world.getGameRuleValue(GameRule.PLAYERS_SLEEPING_PERCENTAGE) / 100.0)); world.setTime(Math.min(world.getTime() + (long) (10917 * onePlayerRatio), 23459)); - skippedCurrentNight.add(event.getPlayer()); } - event.getPlayer().setHealth(event.getPlayer().getHealth() + heal); + var maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue(); + player.setHealth(Math.min(player.getHealth() + heal, maxHealth)); } }