2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.command.impl;
|
2020-11-05 13:40:48 +00:00
|
|
|
|
2020-11-05 21:17:14 +00:00
|
|
|
import com.google.common.collect.ImmutableList;
|
2022-01-27 09:00:50 +00:00
|
|
|
import com.google.common.collect.Lists;
|
2022-01-04 03:04:39 +00:00
|
|
|
import dev.plex.command.PlexCommand;
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.command.annotation.CommandParameters;
|
|
|
|
import dev.plex.command.annotation.CommandPermissions;
|
|
|
|
import dev.plex.rank.enums.Rank;
|
2022-02-07 05:06:55 +00:00
|
|
|
import dev.plex.util.AshconInfo;
|
2022-01-27 09:00:50 +00:00
|
|
|
import dev.plex.util.MojangUtils;
|
|
|
|
import dev.plex.util.PlexLog;
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.util.PlexUtils;
|
2022-01-27 21:23:01 +00:00
|
|
|
import java.time.format.DateTimeFormatter;
|
2022-02-07 05:06:55 +00:00
|
|
|
import java.util.Arrays;
|
2022-01-27 21:23:01 +00:00
|
|
|
import java.util.List;
|
2022-01-27 09:00:50 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
|
|
|
import net.kyori.adventure.text.format.NamedTextColor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2022-02-04 04:01:30 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2022-01-27 09:00:50 +00:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
2022-02-04 04:49:05 +00:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2020-11-05 13:40:48 +00:00
|
|
|
|
2022-01-27 09:00:50 +00:00
|
|
|
@CommandParameters(name = "namehistory", description = "Get the name history of a player", usage = "/<command> <player>", aliases = "nh")
|
2022-01-30 01:31:10 +00:00
|
|
|
@CommandPermissions(level = Rank.OP, permission = "plex.namehistory")
|
2020-11-05 13:40:48 +00:00
|
|
|
public class NameHistoryCMD extends PlexCommand
|
|
|
|
{
|
2022-02-07 05:53:57 +00:00
|
|
|
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mm:ss a");
|
2020-11-05 13:40:48 +00:00
|
|
|
|
|
|
|
@Override
|
2022-02-04 04:49:05 +00:00
|
|
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
|
2020-11-05 13:40:48 +00:00
|
|
|
{
|
|
|
|
if (args.length != 1)
|
2020-11-06 01:29:38 +00:00
|
|
|
{
|
2022-02-14 05:55:50 +00:00
|
|
|
return usage();
|
2020-11-06 01:29:38 +00:00
|
|
|
}
|
2020-11-05 13:40:48 +00:00
|
|
|
String username = args[0];
|
2022-01-27 09:00:50 +00:00
|
|
|
|
2022-02-07 05:06:55 +00:00
|
|
|
AshconInfo info = MojangUtils.getInfo(username);
|
|
|
|
if (info == null)
|
2022-01-27 09:00:50 +00:00
|
|
|
{
|
2022-02-25 07:09:55 +00:00
|
|
|
return messageComponent("nameHistoryDoesntExist");
|
2022-01-27 09:00:50 +00:00
|
|
|
}
|
2022-02-07 05:06:55 +00:00
|
|
|
PlexLog.debug("NameHistory UUID: " + info.getUuid());
|
|
|
|
PlexLog.debug("NameHistory Size: " + info.getUsernameHistories().length);
|
2022-01-27 09:00:50 +00:00
|
|
|
List<Component> historyList = Lists.newArrayList();
|
2022-02-07 05:06:55 +00:00
|
|
|
Arrays.stream(info.getUsernameHistories()).forEach(history ->
|
2020-11-05 13:40:48 +00:00
|
|
|
{
|
2022-02-07 05:06:55 +00:00
|
|
|
if (history.getLocalDateTime() != null)
|
2020-11-06 01:29:38 +00:00
|
|
|
{
|
2022-01-27 09:00:50 +00:00
|
|
|
historyList.add(
|
2022-03-03 21:45:19 +00:00
|
|
|
messageComponent("nameHistoryBody",
|
|
|
|
history.getUsername(),
|
|
|
|
DATE_FORMAT.format(history.getLocalDateTime())));
|
2022-01-30 21:03:47 +00:00
|
|
|
}
|
|
|
|
else
|
2020-11-06 01:29:38 +00:00
|
|
|
{
|
2022-01-27 09:00:50 +00:00
|
|
|
historyList.add(
|
2022-02-07 05:06:55 +00:00
|
|
|
Component.text(history.getUsername()).color(NamedTextColor.GOLD)
|
2022-01-27 09:00:50 +00:00
|
|
|
.append(Component.space()));
|
2020-11-06 01:29:38 +00:00
|
|
|
}
|
2022-01-27 09:00:50 +00:00
|
|
|
});
|
2022-03-03 21:45:19 +00:00
|
|
|
send(sender, messageComponent("nameHistoryTitle", username));
|
|
|
|
send(sender, messageComponent("nameHistorySeparator"));
|
2022-01-27 09:00:50 +00:00
|
|
|
historyList.forEach(component -> send(sender, component));
|
|
|
|
return null;
|
2020-11-05 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-01-27 09:00:50 +00:00
|
|
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
2020-11-05 13:40:48 +00:00
|
|
|
{
|
2020-11-05 21:17:14 +00:00
|
|
|
return args.length == 1 ? PlexUtils.getPlayerNameList() : ImmutableList.of();
|
2020-11-05 13:40:48 +00:00
|
|
|
}
|
|
|
|
}
|