diff --git a/common/src/main/java/xyz/jpenilla/tabtps/common/module/ModuleType.java b/common/src/main/java/xyz/jpenilla/tabtps/common/module/ModuleType.java index 46daef64..94c38a1a 100644 --- a/common/src/main/java/xyz/jpenilla/tabtps/common/module/ModuleType.java +++ b/common/src/main/java/xyz/jpenilla/tabtps/common/module/ModuleType.java @@ -44,6 +44,7 @@ public final class ModuleType { public static final ModuleType TPS = withoutPlayer(TPSModule.class, TPSModule::new, "tps"); public static final ModuleType PING = withPlayer(PingModule.class, PingModule::new, "ping"); public static final ModuleType PLAYER_COUNT = withoutPlayer(PlayerCountModule.class, PlayerCountModule::new, "players"); + public static final ModuleType TIME = withoutPlayer(TimeModule.class, TimeModule::new, "time"); public static Collection> moduleTypes() { return Collections.unmodifiableCollection(TYPES_BY_NAME.values()); diff --git a/common/src/main/java/xyz/jpenilla/tabtps/common/module/TimeModule.java b/common/src/main/java/xyz/jpenilla/tabtps/common/module/TimeModule.java new file mode 100644 index 00000000..52e14181 --- /dev/null +++ b/common/src/main/java/xyz/jpenilla/tabtps/common/module/TimeModule.java @@ -0,0 +1,48 @@ +/* + * This file is part of TabTPS, licensed under the MIT License. + * + * Copyright (c) 2020-2024 Jason Penilla + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package xyz.jpenilla.tabtps.common.module; + +import java.time.LocalDateTime; // Standard library imports should come first +import net.kyori.adventure.text.Component; // External library imports +import org.checkerframework.checker.nullness.qual.NonNull; +import xyz.jpenilla.tabtps.common.Messages; // Your project imports +import xyz.jpenilla.tabtps.common.TabTPS; +import xyz.jpenilla.tabtps.common.config.Theme; +import xyz.jpenilla.tabtps.common.util.TimeUtil; + +public class TimeModule extends AbstractModule { + public TimeModule(final @NonNull TabTPS tabTPS, final @NonNull Theme theme) { + super(tabTPS, theme); + } + + @Override + public @NonNull Component label() { + return Messages.LABEL_TIME.styled(this.theme.colorScheme().text()); + } + + @Override + public @NonNull Component display() { + return TimeUtil.coloredTime(LocalDateTime.now(), this.theme.colorScheme()); + } +} diff --git a/common/src/main/java/xyz/jpenilla/tabtps/common/util/TimeUtil.java b/common/src/main/java/xyz/jpenilla/tabtps/common/util/TimeUtil.java new file mode 100644 index 00000000..7d4207cc --- /dev/null +++ b/common/src/main/java/xyz/jpenilla/tabtps/common/util/TimeUtil.java @@ -0,0 +1,60 @@ +/* + * This file is part of TabTPS, licensed under the MIT License. + * + * Copyright (c) 2020-2024 Jason Penilla + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package xyz.jpenilla.tabtps.common.util; + +import java.time.LocalDateTime; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.TextColor; +import org.checkerframework.checker.nullness.qual.NonNull; +import xyz.jpenilla.tabtps.common.config.Theme; + +import static xyz.jpenilla.tabtps.common.util.Components.gradient; + +public final class TimeUtil { + private TimeUtil() { + } + + public static @NonNull Component coloredTime(final LocalDateTime time, final Theme.@NonNull Colors colors) { + final TextColor color1; + final TextColor color2; + final int hour = time.getHour(); + if (hour > 22 || hour < 7) { + color1 = TextColor.color(255, 0, 0); + color2 = TextColor.color(139, 0, 0); + } else if (hour < 16) { + color1 = TextColor.color(0, 255, 0); + color2 = TextColor.color(144, 238, 144); + } else { + color1 = TextColor.color(255, 69, 0); + color2 = TextColor.color(255, 140, 0); + } + return gradient(formatTime(time), color1, color2); + } + + private static String formatTime(final LocalDateTime time) { + return String.format("%02d", time.getHour()) + ":" + String.format("%02d", time.getMinute()) + ":" + + String.format("%02d", time.getSecond()); + } +} + diff --git a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages.properties b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages.properties index 51396a4a..63907234 100644 --- a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages.properties +++ b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages.properties @@ -15,6 +15,7 @@ label.minimum=Minimum label.maximum=Maximum label.maximum_short_lower=max. label.initial_amount=Initial +label.time=Time # Command help menu help.help=TabTPS Help @@ -85,3 +86,4 @@ command.caption.argument.parse.failure.selector.non_player_in_player_selector=No # Misc misc.text.click_to_copy=Click to copy misc.text.click_to_toggle=Click to toggle +misc.sleep=Go sleep! diff --git a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_es_ES.properties b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_es_ES.properties index 99b18ce0..22d755fe 100644 --- a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_es_ES.properties +++ b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_es_ES.properties @@ -15,6 +15,7 @@ label.minimum=Mínimo label.maximum=Máximo label.maximum_short_lower=max. label.initial_amount=Inicial +label.time=Tiempo # Command help menu help.help=Ayuda TabTPS diff --git a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_ru_RU.properties b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_ru_RU.properties index 1d26c4bd..b3336b88 100644 --- a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_ru_RU.properties +++ b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_ru_RU.properties @@ -15,6 +15,7 @@ label.minimum=Минимум label.maximum=Максимум label.maximum_short_lower=max. label.initial_amount=Исходный +label.time=Time # Command help menu help.help=TabTPS Справка diff --git a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_CN.properties b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_CN.properties index 2c24d9f8..12a77652 100644 --- a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_CN.properties +++ b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_CN.properties @@ -15,6 +15,7 @@ label.minimum=最小值 label.maximum=最大值 label.maximum_short_lower=最大 label.initial_amount=初始值 +label.time=Time # Command help menu help.help=TabTPS 帮助 @@ -85,3 +86,4 @@ command.caption.argument.parse.failure.selector.non_player_in_player_selector= # Misc misc.text.click_to_copy=点击复制 misc.text.click_to_toggle=点击切换 +misc.sleep=Go sleep! diff --git a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_HK.properties b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_HK.properties index a293b4ed..fc21a40a 100644 --- a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_HK.properties +++ b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_HK.properties @@ -15,6 +15,7 @@ label.minimum=最小值 label.maximum=最大值 label.maximum_short_lower=最大值 label.initial_amount=初始值 +label.time=Time # Command help menu help.help=TabTPS 幫助 diff --git a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_TW.properties b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_TW.properties index 8decbe47..098b6966 100644 --- a/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_TW.properties +++ b/common/src/main/messages/xyz/jpenilla/tabtps/common/messages_zh_TW.properties @@ -15,6 +15,7 @@ label.minimum=最小值 label.maximum=最大值 label.maximum_short_lower=最大 label.initial_amount=預設值 +label.time=Time # Command help menu help.help=TabTPS 幫助