Fix sleep
This commit is contained in:
parent
b9b0484d24
commit
6e0d7e5a40
1 changed files with 7 additions and 6 deletions
|
@ -8,7 +8,7 @@ package eu.m724.tweaks.sleep;
|
||||||
|
|
||||||
import eu.m724.tweaks.TweaksConfig;
|
import eu.m724.tweaks.TweaksConfig;
|
||||||
import org.bukkit.GameRule;
|
import org.bukkit.GameRule;
|
||||||
import org.bukkit.World;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
@ -31,20 +31,21 @@ public class SleepListener implements Listener {
|
||||||
if (event.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) {
|
if (event.getBedEnterResult() == PlayerBedEnterEvent.BedEnterResult.OK) {
|
||||||
SleepState.playersSleeping++;
|
SleepState.playersSleeping++;
|
||||||
|
|
||||||
World world = event.getPlayer().getWorld();
|
var player = event.getPlayer();
|
||||||
|
var world = player.getWorld();
|
||||||
|
|
||||||
long day = world.getFullTime() / 24000;
|
long day = world.getFullTime() / 24000;
|
||||||
if (day != lastDay) skippedCurrentNight.clear();
|
if (day != lastDay) skippedCurrentNight.clear();
|
||||||
lastDay = day;
|
lastDay = day;
|
||||||
|
|
||||||
if (!skippedCurrentNight.contains(event.getPlayer())) {
|
if (skippedCurrentNight.add(player)) {
|
||||||
if (instant) {
|
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));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue