forked from foncused/LongerDays
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make night skipping behave like in vanilla
- Loading branch information
1 parent
9880a59
commit 6b6e1d0
Showing
9 changed files
with
232 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/main/java/net/pupskuchen/timecontrol/util/NightSkipGuard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package net.pupskuchen.timecontrol.util; | ||
|
||
import org.bukkit.plugin.java.JavaPlugin; | ||
import org.bukkit.scheduler.BukkitRunnable; | ||
import org.bukkit.scheduler.BukkitTask; | ||
|
||
public class NightSkipGuard { | ||
private static final int DEFAULT_SLEEP_TICKS = 101; | ||
|
||
private final long skippableTickThreshold = DEFAULT_SLEEP_TICKS; | ||
private final JavaPlugin plugin; | ||
|
||
private boolean canSkip = false; | ||
private BukkitTask waitForSkippable; | ||
|
||
public NightSkipGuard(final JavaPlugin plugin) { | ||
this.plugin = plugin; | ||
} | ||
|
||
public void makeSkippable() { | ||
this.cancel(); | ||
|
||
waitForSkippable = new BukkitRunnable() { | ||
@Override | ||
public void run() { | ||
canSkip = true; | ||
} | ||
}.runTaskLater(plugin, skippableTickThreshold); | ||
} | ||
|
||
public void cancel() { | ||
if (waitForSkippable == null) { | ||
return; | ||
} | ||
|
||
waitForSkippable.cancel(); | ||
canSkip = false; | ||
} | ||
|
||
public boolean isSkippable() { | ||
return canSkip; | ||
} | ||
} |
Oops, something went wrong.