Skip to content

Commit 62f1688

Browse files
finreinhardclaude
andcommitted
Add world time and dimension display to action bar
Players now see the in-game time or dimension name next to the timer: - Overworld: Shows colored time (e.g., "8 am", "6 pm") - Morning (6 AM-12 PM): Gold color - Day (12 PM-6 PM): Yellow color - Evening (6 PM-12 AM): Red/Orange color - Night (12 AM-6 AM): Gray color - Nether: Shows "Nether" in red - End: Shows "End" in light purple 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 80cae44 commit 62f1688

File tree

4 files changed

+93
-3
lines changed

4 files changed

+93
-3
lines changed

src/main/kotlin/li/angu/challengeplugin/tasks/TimerTask.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package li.angu.challengeplugin.tasks
22

33
import li.angu.challengeplugin.ChallengePluginPlugin
4+
import li.angu.challengeplugin.utils.WorldTimeFormatter
45
import net.md_5.bungee.api.ChatMessageType
56
import net.md_5.bungee.api.chat.TextComponent
67
import org.bukkit.Bukkit
@@ -19,10 +20,13 @@ class TimerTask(private val plugin: ChallengePluginPlugin) : BukkitRunnable() {
1920
// Get the formatted duration for the challenge
2021
val formattedTime = challenge.getFormattedDuration()
2122

23+
// Get the world info (time for overworld, dimension name for nether/end)
24+
val worldInfo = WorldTimeFormatter.getWorldInfo(player.world)
25+
2226
// Send action bar message with localized text
2327
player.spigot().sendMessage(
2428
ChatMessageType.ACTION_BAR,
25-
TextComponent(plugin.languageManager.getMessage("challenge.duration_display", player, "time" to formattedTime))
29+
TextComponent(plugin.languageManager.getMessage("challenge.duration_display", player, "time" to formattedTime, "world_info" to worldInfo))
2630
)
2731
}
2832
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package li.angu.challengeplugin.utils
2+
3+
import org.bukkit.World
4+
5+
/**
6+
* Utility class for formatting Minecraft world time into human-readable format.
7+
* Minecraft time: 0-24000 ticks per day
8+
* - 0 ticks = 6:00 AM (sunrise)
9+
* - 6000 ticks = 12:00 PM (noon)
10+
* - 12000 ticks = 6:00 PM (sunset)
11+
* - 18000 ticks = 12:00 AM (midnight)
12+
*/
13+
object WorldTimeFormatter {
14+
15+
/**
16+
* Formats the world's time into a colored string representing the time of day.
17+
* Returns format like "§68 am" with appropriate color codes.
18+
*
19+
* Colors:
20+
* - Morning (6 AM - 12 PM): §6 (Gold)
21+
* - Day (12 PM - 6 PM): §e (Yellow)
22+
* - Evening (6 PM - 12 AM): §c (Red/Orange)
23+
* - Night (12 AM - 6 AM): §7 (Gray)
24+
*/
25+
fun getFormattedTime(world: World): String {
26+
val ticks = world.time
27+
val normalizedTicks = ticks % 24000 // Ensure we're in 0-24000 range
28+
29+
// Convert ticks to hours (ticks offset by 6000 since 0 ticks = 6 AM)
30+
val totalMinutes = ((normalizedTicks + 6000) % 24000) * 24 * 60 / 24000
31+
val hours = totalMinutes / 60
32+
val minutes = totalMinutes % 60
33+
34+
// Determine 12-hour format
35+
val displayHour = when {
36+
hours == 0L -> 12
37+
hours > 12 -> hours - 12
38+
else -> hours.toInt()
39+
}
40+
val amPm = if (hours < 12) "am" else "pm"
41+
42+
// Determine color based on time of day
43+
val color = getTimeColor(normalizedTicks)
44+
45+
// Format: "8 am" or "3 pm"
46+
return "$color$displayHour $amPm"
47+
}
48+
49+
/**
50+
* Gets the formatted dimension name with appropriate color.
51+
* - Nether: §c (Red)
52+
* - End: §d (Light Purple)
53+
*/
54+
fun getFormattedDimension(environment: World.Environment): String {
55+
return when (environment) {
56+
World.Environment.NETHER -> "§cNether"
57+
World.Environment.THE_END -> "§dEnd"
58+
else -> "" // Should not happen, but return empty string for safety
59+
}
60+
}
61+
62+
/**
63+
* Gets the color code based on the time of day.
64+
*/
65+
private fun getTimeColor(ticks: Long): String {
66+
return when (ticks) {
67+
in 0..5999 -> "§6" // Morning (6 AM - 12 PM): Gold
68+
in 6000..11999 -> "§e" // Day (12 PM - 6 PM): Yellow
69+
in 12000..17999 -> "§c" // Evening (6 PM - 12 AM): Red/Orange
70+
else -> "§7" // Night (12 AM - 6 AM): Gray
71+
}
72+
}
73+
74+
/**
75+
* Gets the world info string to append to the timer display.
76+
* Returns either formatted time for overworld or dimension name for nether/end.
77+
*/
78+
fun getWorldInfo(world: World): String {
79+
return when (world.environment) {
80+
World.Environment.NORMAL -> getFormattedTime(world)
81+
World.Environment.NETHER -> getFormattedDimension(World.Environment.NETHER)
82+
World.Environment.THE_END -> getFormattedDimension(World.Environment.THE_END)
83+
else -> getFormattedTime(world) // Fallback for CUSTOM or other environments
84+
}
85+
}
86+
}

src/main/resources/lang/de.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ challenge:
4242
dragon_defeated_title: "§6Herausforderung Abgeschlossen!"
4343
dragon_defeated_subtitle: "§eDer Enderdrache wurde besiegt!"
4444
completed: "§aGlückwunsch! Die Herausforderung '§f%name%§a' wurde abgeschlossen!"
45-
duration_display: "§e§l%time%"
45+
duration_display: "§e§l%time% §f- %world_info%"
4646
reconnected: "§aWillkommen zurück! Dein Inventar und deine Position in der Herausforderung '§f%name%§a' wurden wiederhergestellt."
4747
create_cancelled: "§cErstellung der Herausforderung abgebrochen."
4848
create_failed: "§cErstellung der Herausforderungswelt fehlgeschlagen."

src/main/resources/lang/en.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ challenge:
4242
dragon_defeated_title: "§6Challenge Complete!"
4343
dragon_defeated_subtitle: "§eThe Ender Dragon has been defeated!"
4444
completed: "§aCongratulations! The challenge '§f%name%§a' has been completed!"
45-
duration_display: "§e§l%time%"
45+
duration_display: "§e§l%time% §f- %world_info%"
4646
reconnected: "§aWelcome back! Your inventory and location in challenge '§f%name%§a' have been restored."
4747
create_cancelled: "§cChallenge creation cancelled."
4848
create_failed: "§cFailed to create challenge world."

0 commit comments

Comments
 (0)