|
| 1 | +package com.earth2me.essentials.commands; |
| 2 | + |
| 3 | +import static com.earth2me.essentials.I18n.tl; |
| 4 | + |
| 5 | +import java.util.Collections; |
| 6 | +import java.util.List; |
| 7 | + |
| 8 | +import org.bukkit.Server; |
| 9 | +import org.bukkit.Statistic; |
| 10 | + |
| 11 | +import com.earth2me.essentials.CommandSource; |
| 12 | +import com.earth2me.essentials.IUser; |
| 13 | +import com.earth2me.essentials.utils.DateUtil; |
| 14 | +import com.earth2me.essentials.utils.EnumUtil; |
| 15 | + |
| 16 | +public class Commandplaytime extends EssentialsCommand { |
| 17 | + // For some reason, in 1.13 PLAY_ONE_MINUTE = ticks played = what used to be PLAY_ONE_TICK |
| 18 | + // https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/commits/b848d8ce633871b52115247b089029749c02f579 |
| 19 | + private static final Statistic PLAY_ONE_TICK = EnumUtil.getStatistic("PLAY_ONE_MINUTE", "PLAY_ONE_TICK"); |
| 20 | + |
| 21 | + public Commandplaytime() { |
| 22 | + super("playtime"); |
| 23 | + } |
| 24 | + |
| 25 | + @Override |
| 26 | + protected void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception { |
| 27 | + final IUser target; |
| 28 | + final String key; |
| 29 | + |
| 30 | + if (args.length > 0 && sender.isAuthorized("essentials.playtime.others", ess)) { |
| 31 | + target = getPlayer(server, sender, args, 0); |
| 32 | + key = "playtimeOther"; |
| 33 | + } else if (sender.isPlayer()) { |
| 34 | + target = sender.getUser(ess); |
| 35 | + key = "playtime"; |
| 36 | + } else { |
| 37 | + throw new NotEnoughArgumentsException(); |
| 38 | + } |
| 39 | + |
| 40 | + final long playtimeMs = System.currentTimeMillis() - (target.getBase().getStatistic(PLAY_ONE_TICK) * 50); |
| 41 | + sender.sendMessage(tl(key, DateUtil.formatDateDiff(playtimeMs), target.getDisplayName())); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) { |
| 46 | + if (args.length == 1 && sender.isAuthorized("essentials.playtime.others", ess)) { |
| 47 | + return getPlayers(server, sender); |
| 48 | + } else { |
| 49 | + return Collections.emptyList(); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | +} |
0 commit comments