Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
plugins {
id 'java'
id 'com.gradleup.shadow' version '8.3.0'
id 'com.gradleup.shadow' version '9.3.1'
id("xyz.jpenilla.run-paper") version "2.3.1"
}

group = 'xyz.mayahive'
version = '1.1.2'
version = '1.1.3'

repositories {
mavenCentral()
Expand All @@ -16,7 +16,7 @@ repositories {
}

dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
compileOnly("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
implementation 'org.bstats:bstats-bukkit:3.1.0'
}

Expand Down
29 changes: 21 additions & 8 deletions src/main/java/xyz/mayahive/customDaytime/Tasks/TimeTickTask.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package xyz.mayahive.customDaytime.Tasks;

import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.GameRules;
import xyz.mayahive.customDaytime.CustomDaytime;
import xyz.mayahive.customDaytime.Utils.TimeUtils;
import org.bukkit.World;
Expand All @@ -13,6 +12,7 @@ public class TimeTickTask implements Runnable {
private double carry = 0.0;
private long customTime = 0;
private boolean initialized = false;
private long baseDay = -1;

@Override
public void run() {
Expand All @@ -22,15 +22,19 @@ public void run() {
if (world == null) return; // If world isn't loaded, return

// Only proceed if daylight cycle is enabled
Boolean daylightCycle = world.getGameRuleValue(GameRule.DO_DAYLIGHT_CYCLE);
boolean cycleOn = daylightCycle != null && daylightCycle;
boolean cycleOn = Boolean.TRUE.equals(
world.getGameRuleValue(GameRules.ADVANCE_TIME)
);


if (!initialized) {
// Initialize to current world time
customTime = world.getFullTime() % TICKS_PER_DAY;
long full = world.getFullTime();
baseDay = (full / TICKS_PER_DAY) * TICKS_PER_DAY;
customTime = full % TICKS_PER_DAY;
initialized = true;
}


long currentWorldTime = world.getFullTime() % TICKS_PER_DAY;

// Detect manual changes and sync time
Expand All @@ -55,9 +59,18 @@ public void run() {
if (carry >= 1.0) {
long ticksToAdd = (long) carry;
carry -= ticksToAdd;
customTime = (customTime + ticksToAdd) % TICKS_PER_DAY;

long newTime = customTime + ticksToAdd;
if (newTime >= TICKS_PER_DAY) {
baseDay += TICKS_PER_DAY;
newTime %= TICKS_PER_DAY;
}

customTime = newTime;
}

}
world.setFullTime(customTime);
world.setFullTime(baseDay + customTime);

}
}
4 changes: 2 additions & 2 deletions src/main/java/xyz/mayahive/customDaytime/Utils/TimeUtils.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package xyz.mayahive.customDaytime.Utils;

import org.bukkit.GameRules;
import xyz.mayahive.customDaytime.CustomDaytime;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.GameRule;
import org.bukkit.World;
import org.bukkit.entity.Player;

Expand Down Expand Up @@ -47,7 +47,7 @@ public static boolean isEnoughPlayersSleeping(World world) {
if (!CustomDaytime.getInstance().getConfig().getBoolean("enableNightFastForward", true)) {return false;}

// Get player sleeping percentage game rule value
Integer ruleValue = world.getGameRuleValue(GameRule.PLAYERS_SLEEPING_PERCENTAGE);
Integer ruleValue = world.getGameRuleValue(GameRules.PLAYERS_SLEEPING_PERCENTAGE);
if (ruleValue == null) ruleValue = 100; // fallback

double percentage = ruleValue / 100.0;
Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/paper-plugin.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: CustomDaytime
version: '1.1.2'
version: '1.1.3'
main: xyz.mayahive.customDaytime.CustomDaytime
api-version: '1.21'
authors:
- Seedim
contributors:
- PureLove
description: Customise Minecraft's day-night-cycle
folia-supported: true
folia-supported: true