TF-EssentialsX/Essentials/src/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 < 1) {
throw new NotEnoughArgumentsException();
}
final String whois = args[0].toLowerCase(Locale.ENGLISH);
boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
boolean foundUser = false;
for (User u : ess.getOnlineUsers()) {
if (skipHidden && u.isHidden(sender.getPlayer()) && !sender.getPlayer().canSee(u.getBase())) {
continue;
}
u.setDisplayNick();
final String displayName = FormatUtil.stripFormat(u.getDisplayName()).toLowerCase(Locale.ENGLISH);
if (displayName.contains(whois)) {
foundUser = true;
sender.sendMessage(u.getDisplayName() + " " + tl("is") + " " + u.getName());
}
}
if (!foundUser) {
throw new PlayerNotFoundException();
}
}
}