TF-EssentialsX/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrealname.java

42 lines
1.4 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
2013-06-08 21:31:19 +00:00
import com.earth2me.essentials.utils.FormatUtil;
2011-11-18 17:42:26 +00:00
import org.bukkit.Server;
2015-04-15 04:06:16 +00:00
import java.util.Locale;
import static com.earth2me.essentials.I18n.tl;
2015-04-15 04:06:16 +00:00
public class Commandrealname extends EssentialsCommand {
public Commandrealname() {
super("realname");
}
2011-10-19 12:47:32 +00:00
2015-04-15 04:06:16 +00:00
@Override
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
if (args.length == 0) {
2015-04-15 04:06:16 +00:00
throw new NotEnoughArgumentsException();
}
final String lookup = args[0].toLowerCase(Locale.ENGLISH);
2020-10-03 17:46:05 +00:00
final boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
2015-04-15 04:06:16 +00:00
boolean foundUser = false;
2020-10-03 17:46:05 +00:00
for (final User u : ess.getOnlineUsers()) {
2015-04-15 04:06:16 +00:00
if (skipHidden && u.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(u.getBase())) {
continue;
}
u.setDisplayNick();
if (FormatUtil.stripFormat(u.getDisplayName()).toLowerCase(Locale.ENGLISH).contains(lookup)) {
2015-04-15 04:06:16 +00:00
foundUser = true;
sender.sendMessage(tl("realName", u.getDisplayName(), u.getName()));
2015-04-15 04:06:16 +00:00
}
}
if (!foundUser) {
throw new PlayerNotFoundException();
}
}
}