Essentials/Essentials/src/main/java/com/earth2me/essentials/commands/Commandrealname.java

40 lines
1.3 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
2013-06-08 23:31:19 +02:00
import com.earth2me.essentials.utils.FormatUtil;
2011-11-18 18:42:26 +01:00
import org.bukkit.Server;
2015-04-15 06:06:16 +02:00
import java.util.Locale;
public class Commandrealname extends EssentialsCommand {
public Commandrealname() {
super("realname");
}
2011-10-19 14:47:32 +02:00
2015-04-15 06:06:16 +02: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 06:06:16 +02:00
throw new NotEnoughArgumentsException();
}
final String lookup = args[0].toLowerCase(Locale.ENGLISH);
2020-10-03 19:46:05 +02:00
final boolean skipHidden = sender.isPlayer() && !ess.getUser(sender.getPlayer()).canInteractVanished();
2015-04-15 06:06:16 +02:00
boolean foundUser = false;
2020-10-03 19:46:05 +02:00
for (final User u : ess.getOnlineUsers()) {
if (skipHidden && u.isHidden(sender.getPlayer()) && u.isHiddenFrom(sender.getPlayer())) {
2015-04-15 06:06:16 +02:00
continue;
}
u.setDisplayNick();
if (FormatUtil.stripFormat(u.getDisplayName()).toLowerCase(Locale.ENGLISH).contains(lookup)) {
2015-04-15 06:06:16 +02:00
foundUser = true;
sender.sendTl("realName", u.getDisplayName(), u.getName());
2015-04-15 06:06:16 +02:00
}
}
if (!foundUser) {
throw new PlayerNotFoundException();
}
}
}