summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-05-26 17:37:11 +0100
committerKHobbits <rob@khobbits.co.uk>2013-05-26 17:37:11 +0100
commit423c8c54dcf0a752f793039b88feb79cda9dec7d (patch)
tree03873bef00ec8ead3199d2356994ea7c171022b9
parent160a1a04eb5e8c7d343bd1b934bdabf8f26947be (diff)
downloadEssentials-423c8c54dcf0a752f793039b88feb79cda9dec7d.tar
Essentials-423c8c54dcf0a752f793039b88feb79cda9dec7d.tar.gz
Essentials-423c8c54dcf0a752f793039b88feb79cda9dec7d.tar.lz
Essentials-423c8c54dcf0a752f793039b88feb79cda9dec7d.tar.xz
Essentials-423c8c54dcf0a752f793039b88feb79cda9dec7d.zip
Simplify player matching.
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandwhois.java98
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java30
2 files changed, 57 insertions, 71 deletions
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
index 60ec68aa2..ad549cb0a 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandwhois.java
@@ -24,74 +24,42 @@ public class Commandwhois extends EssentialsCommand
{
throw new NotEnoughArgumentsException();
}
- boolean showhidden = false;
- if (sender instanceof Player)
- {
- if (ess.getUser(sender).isAuthorized("essentials.vanish.interact"))
- {
- showhidden = true;
- }
- }
- else
- {
- showhidden = true;
- }
- final String whois = args[0].toLowerCase(Locale.ENGLISH);
- final int prefixLength = Util.stripFormat(ess.getSettings().getNicknamePrefix()).length();
- boolean foundUser = false;
- for (Player onlinePlayer : server.getOnlinePlayers())
+
+ User user = getPlayer(server, sender, args, 0);
+
+ sender.sendMessage(_("whoisTop", user.getName()));
+ user.setDisplayNick();
+ sender.sendMessage(_("whoisNick", user.getDisplayName()));
+ sender.sendMessage(_("whoisHealth", user.getHealth()));
+ sender.sendMessage(_("whoisHunger", user.getFoodLevel(), user.getSaturation()));
+ sender.sendMessage(_("whoisExp", SetExpFix.getTotalExperience(user), user.getLevel()));
+ sender.sendMessage(_("whoisLocation", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ()));
+ if (!ess.getSettings().isEcoDisabled())
{
- final User user = ess.getUser(onlinePlayer);
- if (user.isHidden() && !showhidden)
- {
- continue;
- }
- final String nickName = Util.stripFormat(user.getNickname());
- if (!whois.equalsIgnoreCase(nickName)
- && !whois.substring(prefixLength).equalsIgnoreCase(nickName)
- && !whois.equalsIgnoreCase(user.getName()))
- {
- continue;
- }
- foundUser = true;
- sender.sendMessage(_("whoisTop", user.getName()));
- user.setDisplayNick();
- sender.sendMessage(_("whoisNick", user.getDisplayName()));
- sender.sendMessage(_("whoisHealth", user.getHealth()));
- sender.sendMessage(_("whoisHunger", user.getFoodLevel(), user.getSaturation()));
- sender.sendMessage(_("whoisExp", SetExpFix.getTotalExperience(user), user.getLevel()));
- sender.sendMessage(_("whoisLocation", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ()));
- if (!ess.getSettings().isEcoDisabled())
- {
- sender.sendMessage(_("whoisMoney", Util.displayCurrency(user.getMoney(), ess)));
- }
- sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString()));
- final String location = user.getGeoLocation();
- if (location != null
- && (sender instanceof Player ? ess.getUser(sender).isAuthorized("essentials.geoip.show") : true))
- {
- sender.sendMessage(_("whoisGeoLocation", location));
- }
- sender.sendMessage(_("whoisGamemode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH))));
- sender.sendMessage(_("whoisGod", (user.isGodModeEnabled() ? _("true") : _("false"))));
- sender.sendMessage(_("whoisOp", (user.isOp() ? _("true") : _("false"))));
- sender.sendMessage(_("whoisFly", user.getAllowFlight() ? _("true") : _("false"), user.isFlying() ? _("flying") : _("notFlying")));
- sender.sendMessage(_("whoisAFK", (user.isAfk() ? _("true") : _("false"))));
- sender.sendMessage(_("whoisJail", (user.isJailed()
- ? user.getJailTimeout() > 0
- ? Util.formatDateDiff(user.getJailTimeout())
- : _("true")
- : _("false"))));
- sender.sendMessage(_("whoisMuted", (user.isMuted()
- ? user.getMuteTimeout() > 0
- ? Util.formatDateDiff(user.getMuteTimeout())
- : _("true")
- : _("false"))));
-
+ sender.sendMessage(_("whoisMoney", Util.displayCurrency(user.getMoney(), ess)));
}
- if (!foundUser)
+ sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString()));
+ final String location = user.getGeoLocation();
+ if (location != null
+ && (sender instanceof Player ? ess.getUser(sender).isAuthorized("essentials.geoip.show") : true))
{
- throw new NoSuchFieldException(_("playerNotFound"));
+ sender.sendMessage(_("whoisGeoLocation", location));
}
+ sender.sendMessage(_("whoisGamemode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH))));
+ sender.sendMessage(_("whoisGod", (user.isGodModeEnabled() ? _("true") : _("false"))));
+ sender.sendMessage(_("whoisOp", (user.isOp() ? _("true") : _("false"))));
+ sender.sendMessage(_("whoisFly", user.getAllowFlight() ? _("true") : _("false"), user.isFlying() ? _("flying") : _("notFlying")));
+ sender.sendMessage(_("whoisAFK", (user.isAfk() ? _("true") : _("false"))));
+ sender.sendMessage(_("whoisJail", (user.isJailed()
+ ? user.getJailTimeout() > 0
+ ? Util.formatDateDiff(user.getJailTimeout())
+ : _("true")
+ : _("false"))));
+ sender.sendMessage(_("whoisMuted", (user.isMuted()
+ ? user.getMuteTimeout() > 0
+ ? Util.formatDateDiff(user.getMuteTimeout())
+ : _("true")
+ : _("false"))));
+
}
}
diff --git a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java
index 9891c4746..26146f629 100644
--- a/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java
+++ b/Essentials/src/com/earth2me/essentials/commands/EssentialsCommand.java
@@ -1,11 +1,9 @@
package com.earth2me.essentials.commands;
+import com.earth2me.essentials.*;
import static com.earth2me.essentials.I18n._;
-import com.earth2me.essentials.IEssentials;
-import com.earth2me.essentials.IEssentialsModule;
-import com.earth2me.essentials.Trade;
-import com.earth2me.essentials.User;
import java.util.List;
+import java.util.Locale;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.command.Command;
@@ -88,7 +86,23 @@ public abstract class EssentialsCommand implements IEssentialsCommand
}
final List<Player> matches = server.matchPlayer(args[pos]);
- if (!matches.isEmpty())
+ if (matches.isEmpty())
+ {
+ final String matchText = args[pos].toLowerCase(Locale.ENGLISH);
+ for (Player onlinePlayer : server.getOnlinePlayers())
+ {
+ final User userMatch = ess.getUser(onlinePlayer);
+ if (getHidden || !userMatch.isHidden() || userMatch.equals(sourceUser))
+ {
+ final String displayName = Util.stripFormat(userMatch.getDisplayName()).toLowerCase(Locale.ENGLISH);
+ if (displayName.contains(matchText))
+ {
+ return userMatch;
+ }
+ }
+ }
+ }
+ else
{
for (Player player : matches)
{
@@ -108,7 +122,11 @@ public abstract class EssentialsCommand implements IEssentialsCommand
}
@Override
- public final void run(final Server server, final User user, final String commandLabel, final Command cmd, final String[] args) throws Exception
+ public final void run(final Server server,
+ final User user,
+ final String commandLabel,
+ final Command cmd,
+ final String[] args) throws Exception
{
final Trade charge = new Trade(this.getName(), ess);
charge.isAffordableFor(user);