Skip to content
Merged
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ _Elements 3 - 1.21.4_
- Option to format XP with dots as thousands separators
- Option to change the color of the XP display
- Option to hide the max pet
- Option to show a XP/s indicator
- Option to make a Y-Axis offset for the XP display
- Excalibur Time Display
- Show the time until the next Excalibur is available
- Show the next Player who can pull Excalibur
- Show the time until the next Excalibur is available
- Show the next Player who can pull Excalibur

## Config

Expand Down
21 changes: 17 additions & 4 deletions src/client/java/dev/eposs/elementsutils/ElementsUtilsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.eposs.elementsutils.feature.bosstimer.BossTimerData;
import dev.eposs.elementsutils.feature.bosstimer.BossTimerDisplay;
import dev.eposs.elementsutils.feature.excaliburtimer.ExcaliburTimerData;
import dev.eposs.elementsutils.feature.excaliburtimer.ExcaliburTimerDisplay;
import dev.eposs.elementsutils.feature.loot.LootSound;
import dev.eposs.elementsutils.feature.pet.PetDisplay;
import dev.eposs.elementsutils.feature.playerbase.BaseBorderDisplay;
Expand Down Expand Up @@ -31,7 +32,8 @@

public class ElementsUtilsClient implements ClientModInitializer {
private static KeyBinding baseDisplayToggle;
private static KeyBinding timeDisplaysToggle;
private static KeyBinding bossTimerToggle;
private static KeyBinding excaliburTimeToggle;
private static KeyBinding xpMeasureTrigger;
private static KeyBinding timeMeasureTrigger;
private static KeyBinding devUtils;
Expand Down Expand Up @@ -76,6 +78,8 @@ private void onJoin(ClientPlayNetworkHandler handler, PacketSender sender, Minec
ModConfig.InternalConfig.Servers server = ModConfig.getConfig().internal.server;
if (server != ModConfig.InternalConfig.Servers.UNKNOWN) {
PetDisplay.loadPet(handler.getRegistryManager());
BossTimerData.updateData();
ExcaliburTimerData.updateData();
}
}

Expand Down Expand Up @@ -118,12 +122,18 @@ private void registerKeyBinding() {
category
));

timeDisplaysToggle = KeyBindingHelper.registerKeyBinding(new KeyBinding(
getKeyBindingTranslation("timeDisplaysToggle"),
bossTimerToggle = KeyBindingHelper.registerKeyBinding(new KeyBinding(
getKeyBindingTranslation("bossTimerToggle"),
GLFW.GLFW_KEY_V,
category
));

excaliburTimeToggle = KeyBindingHelper.registerKeyBinding(new KeyBinding(
getKeyBindingTranslation("excaliburTimeToggle"),
GLFW.GLFW_KEY_UNKNOWN,
category
));

xpMeasureTrigger = KeyBindingHelper.registerKeyBinding(new KeyBinding(
getKeyBindingTranslation("xpMeasureTrigger"),
GLFW.GLFW_KEY_UNKNOWN,
Expand All @@ -147,9 +157,12 @@ private void onKeyEvent(MinecraftClient client) {
while (baseDisplayToggle.wasPressed()) {
BaseBorderDisplay.toggleDisplay(client);
}
while (timeDisplaysToggle.wasPressed()) {
while (bossTimerToggle.wasPressed()) {
BossTimerDisplay.toggleDisplay(client);
}
while (excaliburTimeToggle.wasPressed()) {
ExcaliburTimerDisplay.toggleDisplay(client);
}
while (xpMeasureTrigger.wasPressed()) {
XpMeter.startXPMeasurement(client);
}
Expand Down
25 changes: 17 additions & 8 deletions src/client/java/dev/eposs/elementsutils/config/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,31 @@ public enum Position {
BOTTOM_RIGHT
}

public enum TimeFormat {
RELATIVE,
ABSOLUTE,
}

@ConfigEntry.Gui.CollapsibleObject
public TimeDisplaysConfig timeDisplays = new TimeDisplaysConfig();
public static class TimeDisplaysConfig {
public BossTimerConfig bossTimer = new BossTimerConfig();
public static class BossTimerConfig {
public boolean show = true;
public boolean textOutline = true;

public TimeFormat bossTimeFormat = TimeFormat.RELATIVE;
public boolean colorBossNames = true;
public boolean colorBossTime = true;
}

@ConfigEntry.Gui.CollapsibleObject
public ExcaliburTimeConfig excaliburTime = new ExcaliburTimeConfig();
public static class ExcaliburTimeConfig {
public boolean show = true;
public boolean textOutline = true;

public boolean colorExcaliburNames = true;
public boolean colorExcaliburTime = true;
public TimeFormat excaliburTimeFormat = TimeFormat.ABSOLUTE;

public enum TimeFormat {
RELATIVE,
ABSOLUTE,
}

}

public boolean playLootSound = true;
Expand Down Expand Up @@ -131,8 +137,11 @@ public enum KnownColor {
public PlayerXPConfig playerXPConfig = new PlayerXPConfig();
public static class PlayerXPConfig {
public boolean enabled = true;
public boolean showXpPerSecond = false;
public KnownColor xpPerSecondColor = KnownColor.GRAY;
public KnownColor overlayMessageColor = KnownColor.DARK_AQUA;
public boolean hideMaxPetXP = false;
public int overlayMessageYOffset = 0;
}

@ConfigEntry.Gui.CollapsibleObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.text.Text;
import net.minecraft.util.Colors;
import net.minecraft.util.Formatting;
import org.jetbrains.annotations.NotNull;

Expand All @@ -17,16 +16,16 @@ public class BossTimerDisplay {
public static void toggleDisplay(@NotNull MinecraftClient client) {
if (client.player == null || client.world == null) return;

ModConfig.getConfig().timeDisplays.show = !ModConfig.getConfig().timeDisplays.show;
ModConfig.getConfig().bossTimer.show = !ModConfig.getConfig().bossTimer.show;
ModConfig.save();

if (ModConfig.getConfig().timeDisplays.show) {
if (ModConfig.getConfig().bossTimer.show) {
BossTimerData.updateData();
}
}

public static void render(DrawContext context, MinecraftClient client) {
ModConfig.TimeDisplaysConfig config = ModConfig.getConfig().timeDisplays;
ModConfig.BossTimerConfig config = ModConfig.getConfig().bossTimer;
if (!config.show) return;

BossTimerData timerData = BossTimerData.getInstance();
Expand All @@ -41,11 +40,11 @@ public static void render(DrawContext context, MinecraftClient client) {

private static final DateTimeFormatter ABSOLUTE_FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm");

private static Text formattedText(String name, Formatting nameColor, ZonedDateTime time, ModConfig.TimeDisplaysConfig config) {
private static Text formattedText(String name, Formatting nameColor, ZonedDateTime time, ModConfig.BossTimerConfig config) {
return Text.literal("")
.append(Text.literal(name + ": ").formatted(config.colorBossNames ? nameColor : Formatting.WHITE))
.append(time == null ? Text.translatable("elements-utils.unknown") :
config.bossTimeFormat == ModConfig.TimeDisplaysConfig.TimeFormat.RELATIVE
config.bossTimeFormat == ModConfig.TimeFormat.RELATIVE
? toRelativeTime(time)
: Text.literal(time.format(ABSOLUTE_FORMATTER)))
.formatted(config.colorBossTime ? getTimeColor(time) : Formatting.WHITE);
Expand Down Expand Up @@ -100,7 +99,7 @@ private static Text toRelativeTime(@NotNull ZonedDateTime dateTime) {

private static void drawText(MinecraftClient client, DrawContext context, int line, Text text) {
int lineHeight = client.textRenderer.fontHeight + 3;
boolean outline = ModConfig.getConfig().timeDisplays.textOutline;
boolean outline = ModConfig.getConfig().bossTimer.textOutline;
context.drawText(
client.textRenderer,
text,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,37 @@
import java.util.TimerTask;
import java.util.concurrent.atomic.AtomicReference;

/**
* Holds and updates the Excalibur timer data, including the next user and the time.
* Provides thread-safe access and periodic updates.
*/
public class ExcaliburTimerData {
/** The name of the next user. */
private String next_user;
/** The time as an ISO-8601 string. */
private String time;

/** Singleton instance holder. */
private static final AtomicReference<ExcaliburTimerData> INSTANCE = new AtomicReference<>(new ExcaliburTimerData());
/** Timestamp of the last update. */
private static Instant lastUpdate = Instant.MIN;

/**
* Starts a timer that periodically updates the Excalibur timer data every hour.
*/
public static void startUpdateTimers() {
new Timer("Excalibur Timer Update").scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
updateData();
}
}, 0, Duration.ofMinutes(30).toMillis());
}, 0, Duration.ofHours(1).toMillis());
}

/**
* Updates the Excalibur timer data from the API if at least 10 seconds have passed since the last update.
* Runs the update in a virtual thread.
*/
public static void updateData() {
if (lastUpdate.isAfter(Instant.now().minusSeconds(10))) return;

Expand All @@ -36,25 +51,31 @@ public static void updateData() {
});
}

/**
* Returns the current singleton instance of the timer data.
*
* @return The current ExcaliburTimerData instance.
*/
public static ExcaliburTimerData getInstance() {
return INSTANCE.get();
}

/**
* Returns the name of the next user.
*
* @return The next user as a String.
*/
public String getNext_user() {
return next_user;
}

/**
* Returns the time as an Instant, or null if not set or empty.
*
* @return The time as an Instant, or null.
*/
public Instant getTime() {
if (time == null || time.isEmpty()) return null;
return Instant.parse(time);
}

public Duration getTimeUntilNextExcalibur() {
Instant last = getTime();
if (last == null) return Duration.ZERO;
Instant nextExcaliburTime = last.plusSeconds(604940);
return Duration.between(Instant.now(), nextExcaliburTime).isNegative()
? Duration.ZERO
: Duration.between(Instant.now(), nextExcaliburTime);
}
}
Loading