Add /alts alias for /seen (#3931)

Adds `essentials.alts` also to allow server admins to not give mods the ips of users.

Co-authored-by: Josh Roy <10731363+JRoy@users.noreply.github.com>
This commit is contained in:
Daniil 2021-01-28 17:29:50 +03:00 committed by GitHub
parent 89c1e3b60d
commit 79406613c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 23 deletions

View File

@ -27,12 +27,14 @@ public class Commandseen extends EssentialsCommand {
@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
final boolean showBan = sender.isAuthorized("essentials.seen.banreason", ess);
final boolean showIp = sender.isAuthorized("essentials.seen.ip", ess);
final boolean showLocation = sender.isAuthorized("essentials.seen.location", ess);
if (args.length < 1) {
throw new NotEnoughArgumentsException();
}
final boolean showBan = sender.isAuthorized("essentials.seen.banreason", ess);
final boolean showIp = sender.isAuthorized("essentials.seen.ip", ess);
final boolean showLocation = sender.isAuthorized("essentials.seen.location", ess);
final boolean searchAccounts = commandLabel.contains("alts") && sender.isAuthorized("essentials.seen.alts", ess);
User player;
// Check by uuid, if it fails check by name.
try {
@ -43,15 +45,20 @@ public class Commandseen extends EssentialsCommand {
}
if (player == null) {
if (sender.isAuthorized("essentials.seen.ipsearch", ess) && FormatUtil.validIP(args[0])) {
seenIP(sender, args[0]);
return;
} else if (ess.getServer().getBanList(BanList.Type.IP).isBanned(args[0])) {
sender.sendMessage(tl("isIpBanned", args[0]));
return;
} else if (BanLookup.isBanned(ess, args[0])) {
sender.sendMessage(tl("whoisBanned", showBan ? BanLookup.getBanEntry(ess, args[0]).getReason() : tl("true")));
return;
if (!searchAccounts) {
if (sender.isAuthorized("essentials.seen.ipsearch", ess) && FormatUtil.validIP(args[0])) {
if (ess.getServer().getBanList(BanList.Type.IP).isBanned(args[0])) {
sender.sendMessage(tl("isIpBanned", args[0]));
}
seenIP(sender, args[0], args[0]);
return;
} else if (ess.getServer().getBanList(BanList.Type.IP).isBanned(args[0])) {
sender.sendMessage(tl("isIpBanned", args[0]));
return;
} else if (BanLookup.isBanned(ess, args[0])) {
sender.sendMessage(tl("whoisBanned", showBan ? BanLookup.getBanEntry(ess, args[0]).getReason() : tl("true")));
return;
}
}
ess.getScheduler().runTaskAsynchronously(ess, new Runnable() {
@Override
@ -73,16 +80,18 @@ public class Commandseen extends EssentialsCommand {
}
private void showUserSeen(final User user) throws Exception {
showSeenMessage(sender, user, showBan, showIp, showLocation);
showSeenMessage(sender, user, searchAccounts, showBan, showIp, showLocation);
}
});
} else {
showSeenMessage(sender, player, showBan, showIp, showLocation);
showSeenMessage(sender, player, searchAccounts, showBan, showIp, showLocation);
}
}
private void showSeenMessage(final CommandSource sender, final User player, final boolean showBan, final boolean showIp, final boolean showLocation) {
if (player.getBase().isOnline() && canInteractWith(sender, player)) {
private void showSeenMessage(final CommandSource sender, final User player, final boolean searchAccounts, final boolean showBan, final boolean showIp, final boolean showLocation) {
if (searchAccounts) {
seenIP(sender, player.getLastLoginAddress(), player.getDisplayName());
} else if (player.getBase().isOnline() && canInteractWith(sender, player)) {
seenOnline(sender, player, showIp);
} else {
seenOffline(sender, player, showBan, showIp, showLocation);
@ -183,14 +192,10 @@ public class Commandseen extends EssentialsCommand {
}
}
private void seenIP(final CommandSource sender, final String ipAddress) {
private void seenIP(final CommandSource sender, final String ipAddress, final String display) {
final UserMap userMap = ess.getUserMap();
if (ess.getServer().getBanList(BanList.Type.IP).isBanned(ipAddress)) {
sender.sendMessage(tl("isIpBanned", ipAddress));
}
sender.sendMessage(tl("runningPlayerMatch", ipAddress));
sender.sendMessage(tl("runningPlayerMatch", display));
ess.runTaskAsynchronously(() -> {
final List<String> matches = new ArrayList<>();

View File

@ -391,7 +391,7 @@ commands:
seen:
description: Shows the last logout time of a player.
usage: /<command> <playername>
aliases: [eseen]
aliases: [eseen, ealts, alts]
sell:
description: Sells the item currently in your hand.
usage: /<command> <<itemname>|<id>|hand|inventory|blocks> [-][amount]