mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-14 21:22:09 +00:00
Simplify player matching.
This commit is contained in:
parent
160a1a04eb
commit
423c8c54dc
2 changed files with 57 additions and 71 deletions
|
@ -24,74 +24,42 @@ public class Commandwhois extends EssentialsCommand
|
||||||
{
|
{
|
||||||
throw new NotEnoughArgumentsException();
|
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())
|
|
||||||
{
|
|
||||||
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"))));
|
|
||||||
|
|
||||||
}
|
User user = getPlayer(server, sender, args, 0);
|
||||||
if (!foundUser)
|
|
||||||
|
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())
|
||||||
{
|
{
|
||||||
throw new NoSuchFieldException(_("playerNotFound"));
|
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"))));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.*;
|
||||||
import static com.earth2me.essentials.I18n._;
|
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.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
|
@ -88,7 +86,23 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||||
}
|
}
|
||||||
final List<Player> matches = server.matchPlayer(args[pos]);
|
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)
|
for (Player player : matches)
|
||||||
{
|
{
|
||||||
|
@ -108,7 +122,11 @@ public abstract class EssentialsCommand implements IEssentialsCommand
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
final Trade charge = new Trade(this.getName(), ess);
|
||||||
charge.isAffordableFor(user);
|
charge.isAffordableFor(user);
|
||||||
|
|
Loading…
Reference in a new issue