1
0
mirror of https://github.com/nkomarn/harbor.git synced 2024-11-27 20:35:21 +01:00
This commit is contained in:
Mykyta Komarnytskyy 2020-12-11 11:26:01 -08:00
parent 925d1ab391
commit 81563404db
2 changed files with 25 additions and 16 deletions

View File

@ -1,9 +1,7 @@
package xyz.nkomarn.harbor.task; package xyz.nkomarn.harbor.task;
import org.bukkit.Bukkit;
import org.bukkit.Statistic; import org.bukkit.Statistic;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.LivingEntity;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.nkomarn.harbor.Harbor; import xyz.nkomarn.harbor.Harbor;
@ -43,15 +41,7 @@ public class AccelerateNightTask extends BukkitRunnable {
world.getPlayers().forEach(player -> player.setStatistic(Statistic.TIME_SINCE_REST, 0)); world.getPlayers().forEach(player -> player.setStatistic(Statistic.TIME_SINCE_REST, 0));
} }
world.getPlayers().stream()
.filter(LivingEntity::isSleeping)
.forEach(player -> player.wakeup(true));
harbor.getServer().getScheduler().runTaskLater(harbor, () -> {
checker.resetStatus(world); checker.resetStatus(world);
harbor.getPlayerManager().clearCooldowns();
harbor.getMessages().sendRandomChatMessage(world, "messages.chat.night-skipped");
}, 20L);
cancel(); cancel();
return; return;
} }

View File

@ -4,6 +4,7 @@ import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
@ -84,9 +85,11 @@ public class Checker extends BukkitRunnable {
} }
if (config.getBoolean("night-skip.instant-skip")) { if (config.getBoolean("night-skip.instant-skip")) {
messages.sendRandomChatMessage(world, "messages.chat.night-skipped"); Bukkit.getScheduler().runTask(harbor, () -> {
world.setTime(config.getInteger("night-skip.daytime-ticks"));
clearWeather(world); clearWeather(world);
Bukkit.getScheduler().runTask(harbor, () -> world.setTime(config.getInteger("night-skip.daytime-ticks"))); resetStatus(world);
});
return; return;
} }
@ -247,7 +250,23 @@ public class Checker extends BukkitRunnable {
* @param world The world for which to reset status. * @param world The world for which to reset status.
*/ */
public void resetStatus(@NotNull World world) { public void resetStatus(@NotNull World world) {
wakeUpPlayers(world);
harbor.getServer().getScheduler().runTaskLater(harbor, () -> {
skippingWorlds.remove(world.getUID()); skippingWorlds.remove(world.getUID());
harbor.getPlayerManager().clearCooldowns();
harbor.getMessages().sendRandomChatMessage(world, "messages.chat.night-skipped");
}, 20L);
}
/**
* Kicks all sleeping players out of bed in the provided world.
*
* @param world The world for which to kick players out of bed.
*/
public void wakeUpPlayers(@NotNull World world) {
ensureMain(() -> world.getPlayers().stream()
.filter(LivingEntity::isSleeping)
.forEach(player -> player.wakeup(true)));
} }
/** /**
@ -256,7 +275,7 @@ public class Checker extends BukkitRunnable {
* @param world The world for which to clear weather. * @param world The world for which to clear weather.
*/ */
public void clearWeather(@NotNull World world) { public void clearWeather(@NotNull World world) {
Bukkit.getScheduler().runTask(harbor, () -> { ensureMain(() -> {
Config config = harbor.getConfiguration(); Config config = harbor.getConfiguration();
if (world.hasStorm() && config.getBoolean("night-skip.clear-rain")) { if (world.hasStorm() && config.getBoolean("night-skip.clear-rain")) {