Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time module implementation #168

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public final class ModuleType<T extends Module> {
public static final ModuleType<TPSModule> TPS = withoutPlayer(TPSModule.class, TPSModule::new, "tps");
public static final ModuleType<PingModule> PING = withPlayer(PingModule.class, PingModule::new, "ping");
public static final ModuleType<PlayerCountModule> PLAYER_COUNT = withoutPlayer(PlayerCountModule.class, PlayerCountModule::new, "players");
public static final ModuleType<TimeModule> TIME = withoutPlayer(TimeModule.class, TimeModule::new, "time");

public static Collection<ModuleType<?>> moduleTypes() {
return Collections.unmodifiableCollection(TYPES_BY_NAME.values());
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
60 changes: 60 additions & 0 deletions common/src/main/java/xyz/jpenilla/tabtps/common/util/TimeUtil.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 Справка
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ label.minimum=最小值
label.maximum=最大值
label.maximum_short_lower=最大
label.initial_amount=初始值
label.time=Time

# Command help menu
help.help=TabTPS 帮助
Expand Down Expand Up @@ -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!
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ label.minimum=最小值
label.maximum=最大值
label.maximum_short_lower=最大值
label.initial_amount=初始值
label.time=Time

# Command help menu
help.help=TabTPS 幫助
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ label.minimum=最小值
label.maximum=最大值
label.maximum_short_lower=最大
label.initial_amount=預設值
label.time=Time

# Command help menu
help.help=TabTPS 幫助
Expand Down