2011-03-30 04:03:21 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2011-11-21 01:55:26 +00:00
|
|
|
import static com.earth2me.essentials.I18n._;
|
2011-03-30 04:03:21 +00:00
|
|
|
import com.earth2me.essentials.User;
|
2011-05-06 21:08:58 +00:00
|
|
|
import com.earth2me.essentials.Util;
|
2012-03-17 01:43:49 +00:00
|
|
|
import com.earth2me.essentials.craftbukkit.SetExpFix;
|
2011-11-21 01:55:26 +00:00
|
|
|
import java.util.Locale;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
2011-03-30 04:03:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class Commandwhois extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandwhois()
|
|
|
|
{
|
|
|
|
super("whois");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-11-18 19:30:05 +00:00
|
|
|
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
|
|
|
if (args.length < 1)
|
|
|
|
{
|
2011-05-15 01:30:54 +00:00
|
|
|
throw new NotEnoughArgumentsException();
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
2011-07-18 22:09:30 +00:00
|
|
|
boolean showhidden = false;
|
|
|
|
if (sender instanceof Player)
|
|
|
|
{
|
|
|
|
if (ess.getUser(sender).isAuthorized("essentials.list.hidden"))
|
|
|
|
{
|
|
|
|
showhidden = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
showhidden = true;
|
|
|
|
}
|
2011-11-21 01:55:26 +00:00
|
|
|
final String whois = args[0].toLowerCase(Locale.ENGLISH);
|
2012-03-22 22:07:13 +00:00
|
|
|
final int prefixLength = Util.stripFormat(ess.getSettings().getNicknamePrefix()).length();
|
2012-06-10 23:07:22 +00:00
|
|
|
Boolean foundUser = false;
|
2011-11-18 19:30:05 +00:00
|
|
|
for (Player onlinePlayer : server.getOnlinePlayers())
|
2011-03-30 04:03:21 +00:00
|
|
|
{
|
2011-11-18 19:30:05 +00:00
|
|
|
final User user = ess.getUser(onlinePlayer);
|
|
|
|
if (user.isHidden() && !showhidden)
|
2011-07-18 01:42:21 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-22 22:07:13 +00:00
|
|
|
final String nickName = Util.stripFormat(user.getNickname());
|
2011-11-20 15:43:38 +00:00
|
|
|
if (!whois.equalsIgnoreCase(nickName)
|
|
|
|
&& !whois.substring(prefixLength).equalsIgnoreCase(nickName)
|
2011-11-18 19:30:05 +00:00
|
|
|
&& !whois.equalsIgnoreCase(user.getName()))
|
2011-05-01 19:38:25 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2012-06-10 23:07:22 +00:00
|
|
|
foundUser = true;
|
2011-03-30 04:03:21 +00:00
|
|
|
sender.sendMessage("");
|
2012-03-21 23:54:57 +00:00
|
|
|
user.setDisplayNick();
|
2011-11-21 01:55:26 +00:00
|
|
|
sender.sendMessage(_("whoisIs", user.getDisplayName(), user.getName()));
|
|
|
|
sender.sendMessage(_("whoisHealth", user.getHealth()));
|
2012-03-17 01:43:49 +00:00
|
|
|
sender.sendMessage(_("whoisExp", SetExpFix.getTotalExperience(user), user.getLevel()));
|
2011-11-21 01:55:26 +00:00
|
|
|
sender.sendMessage(_("whoisOP", (user.isOp() ? _("true") : _("false"))));
|
|
|
|
sender.sendMessage(_("whoisGod", (user.isGodModeEnabled() ? _("true") : _("false"))));
|
|
|
|
sender.sendMessage(_("whoisGamemode", _(user.getGameMode().toString().toLowerCase(Locale.ENGLISH))));
|
|
|
|
sender.sendMessage(_("whoisLocation", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ()));
|
2011-06-01 10:40:12 +00:00
|
|
|
if (!ess.getSettings().isEcoDisabled())
|
2011-05-01 19:38:25 +00:00
|
|
|
{
|
2012-03-04 10:11:58 +00:00
|
|
|
sender.sendMessage(_("whoisMoney", Util.displayCurrency(user.getMoney(), ess)));
|
2011-05-01 19:38:25 +00:00
|
|
|
}
|
2012-03-12 01:15:10 +00:00
|
|
|
sender.sendMessage(_("whoisJail", (user.isJailed()
|
|
|
|
? user.getJailTimeout() > 0
|
|
|
|
? Util.formatDateDiff(user.getJailTimeout())
|
|
|
|
: _("true")
|
|
|
|
: _("false"))));
|
2011-11-18 19:30:05 +00:00
|
|
|
sender.sendMessage(user.isAfk()
|
2011-11-21 01:55:26 +00:00
|
|
|
? _("whoisStatusAway")
|
|
|
|
: _("whoisStatusAvailable"));
|
|
|
|
sender.sendMessage(_("whoisIPAddress", user.getAddress().getAddress().toString()));
|
2011-11-18 19:30:05 +00:00
|
|
|
final String location = user.getGeoLocation();
|
2011-11-03 23:10:42 +00:00
|
|
|
if (location != null
|
This is a big refactoring of the user class and more.
Many commands have been cleaned.
File changes:
- all user data has been moved from users.yml to userdata folder
- all files in userdata folder are lower case
Both changes should be done automatically.
Class changes:
- Moved all user data functions to UserData class
- Moved all user teleport functions to Teleport class
- Moved the user list to Essentials class
- Less static functions for better testing
- EssentialsCommand now has ess Property (Essentials class)
- New NotEnoughArgumentsException, that will show command description and syntax
New commands:
- /seen, shows the last login or logout
- /tempban, temporarily ban someone
- /tjail and mute, temporarily option added
Other changes:
- ban reason is saved
- don't show "You have xxx mail" on login, if user doesn't have essentials.mail permission
- time will be parsed: years, months (mo), weeks, days, hours, minutes (m), seconds, these can be shortened and combined, example: 2 days 5h 30m
git-svn-id: https://svn.java.net/svn/essentials~svn/trunk@1300 e251c2fe-e539-e718-e476-b85c1f46cddb
2011-05-01 21:07:30 +00:00
|
|
|
&& (sender instanceof Player ? ess.getUser(sender).isAuthorized("essentials.geoip.show") : true))
|
2011-05-01 19:38:25 +00:00
|
|
|
{
|
2011-11-21 01:55:26 +00:00
|
|
|
sender.sendMessage(_("whoisGeoLocation", location));
|
2011-05-01 11:04:34 +00:00
|
|
|
}
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
2012-06-10 23:07:22 +00:00
|
|
|
if (!foundUser)
|
|
|
|
{
|
|
|
|
throw new NoSuchFieldException(_("playerNotFound"));
|
|
|
|
}
|
2011-03-30 04:03:21 +00:00
|
|
|
}
|
|
|
|
}
|