diff --git a/Essentials/src/main/java/com/earth2me/essentials/commands/Commandplaytime.java b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandplaytime.java new file mode 100644 index 000000000..0ecfa8325 --- /dev/null +++ b/Essentials/src/main/java/com/earth2me/essentials/commands/Commandplaytime.java @@ -0,0 +1,53 @@ +package com.earth2me.essentials.commands; + +import static com.earth2me.essentials.I18n.tl; + +import java.util.Collections; +import java.util.List; + +import org.bukkit.Server; +import org.bukkit.Statistic; + +import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.IUser; +import com.earth2me.essentials.utils.DateUtil; +import com.earth2me.essentials.utils.EnumUtil; + +public class Commandplaytime extends EssentialsCommand { + // For some reason, in 1.13 PLAY_ONE_MINUTE = ticks played = what used to be PLAY_ONE_TICK + // https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/b848d8ce633871b52115247b089029749c02f579 + private static final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK"); + + public Commandplaytime() { + super("playtime"); + } + + @Override + protected void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception { + final IUser target; + final String key; + + if (args.length > 0 && sender.isAuthorized("essentials.playtime.others", ess)) { + target = getPlayer(server, sender, args, 0); + key = "playtimeOther"; + } else if (sender.isPlayer()) { + target = sender.getUser(ess); + key = "playtime"; + } else { + throw new NotEnoughArgumentsException(); + } + + final long playtimeMs = System.currentTimeMillis() - (target.getBase().getStatistic(PLAY_ONE_TICK) * 50); + sender.sendMessage(tl(key, DateUtil.formatDateDiff(playtimeMs), target.getDisplayName())); + } + + @Override + protected List getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) { + if (args.length == 1 && sender.isAuthorized("essentials.playtime.others", ess)) { + return getPlayers(server, sender); + } else { + return Collections.emptyList(); + } + } + +} diff --git a/Essentials/src/main/resources/messages.properties b/Essentials/src/main/resources/messages.properties index d373a4f27..ecabac9d1 100644 --- a/Essentials/src/main/resources/messages.properties +++ b/Essentials/src/main/resources/messages.properties @@ -884,6 +884,14 @@ playerTempBanned=\u00a76Player \u00a7c{0}\u00a76 temporarily banned \u00a7c{1}\u playerUnbanIpAddress=\u00a76Player\u00a7c {0} \u00a76unbanned IP\:\u00a7c {1} playerUnbanned=\u00a76Player\u00a7c {0} \u00a76unbanned\u00a7c {1} playerUnmuted=\u00a76You have been unmuted. +playtimeCommandDescription=Shows a player''s time played in game +playtimeCommandUsage=/ [player] +playtimeCommandUsage1=/ +playtimeCommandUsage1Description=Shows your time played in game +playtimeCommandUsage2=/ +playtimeCommandUsage2Description=Shows the specified player''s time played in game +playtime=\u00a76Playtime\:\u00a7c {0} +playtimeOther=\u00a76Playtime of {1}\u00a76\:\u00a7c {0} pong=Pong\! posPitch=\u00a76Pitch\: {0} (Head angle) possibleWorlds=\u00a76Possible worlds are the numbers \u00a7c0\u00a76 through \u00a7c{0}\u00a76. diff --git a/Essentials/src/main/resources/plugin.yml b/Essentials/src/main/resources/plugin.yml index 502ee1325..45f2607fc 100644 --- a/Essentials/src/main/resources/plugin.yml +++ b/Essentials/src/main/resources/plugin.yml @@ -344,6 +344,10 @@ commands: description: Pong! usage: / aliases: [echo,eecho,eping,pong,epong] + playtime: + description: Shows a player's time played in game + usage: / [player] + aliases: [eplaytime] potion: description: Adds custom potion effects to a potion. usage: / power: duration:>