Fix sleep

This commit is contained in:
Minecon724 2025-01-20 11:16:01 +01:00
parent b9b0484d24
commit 6e0d7e5a40
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8

View file

@ -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));
}
}