Skip to content

Commit b0e5f45

Browse files
committed
feat: more extensions
1 parent 89c5096 commit b0e5f45

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/main/kotlin/cc/modlabs/kpaper/extensions/PlayerExtensions.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,17 @@ fun Player.sendOpenSound() = playSound(location, "minecraft:block.note_block.chi
3838

3939
fun Player.maxOutHealth() {
4040
health = getAttribute(Attribute.MAX_HEALTH)?.value ?: 20.0
41+
}
42+
43+
44+
fun UUID.toOfflinePlayer(): OfflinePlayer {
45+
return Bukkit.getOfflinePlayer(this)
46+
}
47+
48+
fun String.toOfflinePlayer(): OfflinePlayer {
49+
return Bukkit.getOfflinePlayer(this)
50+
}
51+
52+
fun String.toOfflinePlayerIfCached(): OfflinePlayer? {
53+
return Bukkit.getOfflinePlayerIfCached(this)
4154
}

src/main/kotlin/cc/modlabs/kpaper/extensions/TimeExtension.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import dev.fruxz.ascend.tool.time.clock.TimeDisplay
55
import kotlin.time.Duration
66
import dev.fruxz.ascend.tool.time.calendar.Calendar
77
import java.text.SimpleDateFormat
8+
import java.time.DayOfWeek
9+
import java.time.LocalDateTime
810
import java.util.*
911

1012
fun <T> Iterable<T>.sumOf(selector: (T) -> Duration): Duration {
@@ -29,4 +31,18 @@ fun calendarFromDateString(dateFormat: String): Calendar {
2931

3032
fun Calendar.formatToDay(locale: Locale): String {
3133
return SimpleDateFormat.getDateInstance(Calendar.FormatStyle.FULL.ordinal, locale).format(javaDate)
32-
}
34+
}
35+
36+
fun isWeekend(): Boolean {
37+
val now = LocalDateTime.now()
38+
val dayOfWeek = now.dayOfWeek
39+
val hour = now.hour
40+
41+
return when (dayOfWeek) {
42+
DayOfWeek.FRIDAY -> hour >= 18
43+
DayOfWeek.SATURDAY -> true
44+
DayOfWeek.SUNDAY -> hour < 22
45+
else -> false
46+
}
47+
}
48+

0 commit comments

Comments
 (0)