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

Discord: Add start time placeholder for start message #5686

Merged
merged 3 commits into from
Nov 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.entities.Role;
import net.essentialsx.api.v2.ChatType;
import net.essentialsx.discord.util.MessageUtil;
import org.apache.logging.log4j.Level;
import org.bukkit.entity.Player;

import java.io.File;
import java.lang.management.ManagementFactory;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -427,7 +429,12 @@ public MessageFormat getActionFormat(Player player) {
}

public String getStartMessage() {
return config.getString("messages.server-start", ":white_check_mark: The server has started!");
final MessageFormat format = generateMessageFormat(getFormatString("server-start"), ":white_check_mark: The server has started in {starttimeseconds} seconds!", false,
"starttimeseconds");
return MessageUtil.formatMessage(format,
// measures time since the JVM started and converts it to seconds
String.format("%.2f", (float)Math.abs(ManagementFactory.getRuntimeMXBean().getStartTime() - System.currentTimeMillis()) / 1000)
);
}

public String getStopMessage() {
Expand Down
3 changes: 2 additions & 1 deletion EssentialsDiscord/src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ messages:
# ... PlaceholderAPI placeholders are also supported here too!
action: ":person_biking: {displayname} *{action}*"
# This is the message sent to Discord when the server starts.
server-start: ":white_check_mark: The server has started!"
# - {starttimeseconds}: The amount of seconds it took to start the server (measured from JVM start time).
server-start: ":white_check_mark: The server has started in {starttimeseconds} seconds!"
# This is the message sent to Discord when the server stops.
server-stop: ":octagonal_sign: The server has stopped!"
# This is the message sent to Discord when a player is kicked from the server.
Expand Down
Loading