Skip to content

Commit

Permalink
More Configurability (#31)
Browse files Browse the repository at this point in the history
Co-authored-by: Steveplays28 <djspaargaren@outlook.com>
(cherry picked from commit 3420dc9)
  • Loading branch information
machiecodes authored and Steveplays28 committed Jul 28, 2023
1 parent b9bad80 commit 4d74ac6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@

@Config(name = "realisticsleep")
public class RealisticSleepConfig implements ConfigData {
@ConfigEntry.Gui.Tooltip
public boolean sendDawnMessage = true;
@ConfigEntry.Gui.Tooltip
public String dawnMessage = "The sun rises.";

@ConfigEntry.Gui.Tooltip
public boolean sendSleepingMessage = true;
@ConfigEntry.Gui.Tooltip
public boolean showTimeUntilDawn = true;
@ConfigEntry.Gui.Tooltip
public boolean sendNotEnoughPlayersSleepingMessage = true;

@ConfigEntry.Gui.Tooltip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public abstract class ServerWorldMixin extends World {
public double nightTimeStepPerTick = 1;
public int nightTimeStepPerTickRounded = 1;
public long tickDelay;
public long lastFluidTick;
public String sleepMessage;

@Shadow
@Final
Expand Down Expand Up @@ -149,18 +151,11 @@ public void tickInject(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
// Check if players are still supposed to be sleeping, and send a HUD message if so
if (secondsUntilAwake >= 2) {
if (config.sendSleepingMessage) {
sleepMessage = String.format("%d/%d players are sleeping through this %s", sleepingPlayerCount, playerCount, worldProperties.isThundering() ? "thunderstorm" : "night");
if (config.showTimeUntilDawn) sleepMessage += String.format(" (Time until dawn: %d", secondsUntilAwake) + "s)";

for (ServerPlayerEntity player : players) {
if (worldProperties.isThundering()) {
player.sendMessage(
Text.of(sleepingPlayerCount + "/" + playerCount + " players are sleeping through this thunderstorm (time until dawn: " + secondsUntilAwake + "s)"),
true
);
} else {
player.sendMessage(
Text.of(sleepingPlayerCount + "/" + playerCount + " players are sleeping through this night (time until dawn: " + secondsUntilAwake + "s)"),
true
);
}
player.sendMessage(Text.of(sleepMessage), true);
}
}
}
Expand All @@ -178,10 +173,9 @@ public void tickInject(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
// Wake up sleeping players
wakeSleepingPlayers();

// Check if dawn message isn't set to nothing
if (config.dawnMessage.equals("")) {
return;
}
// Return if we shouldn't send the dawn message
if (!config.sendDawnMessage || config.dawnMessage.equals("")) return;

// Send HUD message to all players
for (ServerPlayerEntity player : players) {
player.sendMessage(Text.of(config.dawnMessage), true);
Expand Down

0 comments on commit 4d74ac6

Please sign in to comment.