use of com.earth2me.essentials.User in project Essentials by drtshock.
the class UserNameComparator method getUsers.
/**
* Used to parse an argument of the type "users(s) selector"
*/
private Set<User> getUsers(final Server server, final CommandSource sender, final String selector) throws Exception {
final Set<User> users = new TreeSet<>(new UserNameComparator());
// If there is no selector we want the sender itself. Or all users if sender isn't a user.
if (selector == null) {
if (sender.isPlayer()) {
final User user = ess.getUser(sender.getPlayer());
users.add(user);
} else {
for (User user : ess.getOnlineUsers()) {
users.add(user);
}
}
return users;
}
// Try to find the user with name = selector
User user = null;
final List<Player> matchedPlayers = server.matchPlayer(selector);
if (!matchedPlayers.isEmpty()) {
user = ess.getUser(matchedPlayers.get(0));
}
if (user != null) {
users.add(user);
} else // If that fails, Is the argument something like "*" or "all"?
if (selector.equalsIgnoreCase("*") || selector.equalsIgnoreCase("all")) {
for (User u : ess.getOnlineUsers()) {
users.add(u);
}
} else // We failed to understand the world target...
{
throw new PlayerNotFoundException();
}
return users;
}
use of com.earth2me.essentials.User in project Essentials by drtshock.
the class Commandpweather method run.
@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
// Which Players(s) / Users(s) are we interested in?
String userSelector = null;
if (args.length == 2) {
userSelector = args[1];
}
Set<User> users = getUsers(server, sender, userSelector);
if (args.length == 0) {
getUsersWeather(sender, users);
return;
}
if (getAliases.contains(args[0])) {
getUsersWeather(sender, users);
return;
}
if (sender.isPlayer()) {
User user = ess.getUser(sender.getPlayer());
if (user != null && (!users.contains(user) || users.size() > 1) && !user.isAuthorized("essentials.pweather.others")) {
user.sendMessage(tl("pWeatherOthersPermission"));
return;
}
}
setUsersWeather(sender, users, args[0].toLowerCase());
}
use of com.earth2me.essentials.User in project Essentials by drtshock.
the class Commandseen method seen.
protected void seen(final Server server, final CommandSource sender, final String commandLabel, final String[] args, final boolean showBan, final boolean extra, final boolean ipLookup) throws Exception {
if (args.length < 1) {
throw new NotEnoughArgumentsException();
}
User player;
// Check by uuid, if it fails check by name.
try {
UUID uuid = UUID.fromString(args[0]);
player = ess.getUser(uuid);
} catch (IllegalArgumentException ignored) {
// Thrown if invalid UUID from string, check by name.
player = ess.getOfflineUser(args[0]);
}
if (player == null) {
if (ipLookup && FormatUtil.validIP(args[0])) {
seenIP(server, sender, args[0]);
return;
} else if (ess.getServer().getBanList(BanList.Type.IP).isBanned(args[0])) {
sender.sendMessage(tl("isIpBanned", args[0]));
return;
} else if (BanLookup.isBanned(ess, args[0])) {
sender.sendMessage(tl("whoisBanned", showBan ? BanLookup.getBanEntry(ess, args[0]).getReason() : tl("true")));
return;
}
ess.getScheduler().runTaskAsynchronously(ess, new Runnable() {
@Override
public void run() {
User userFromBukkit = ess.getUserMap().getUserFromBukkit(args[0]);
try {
if (userFromBukkit != null) {
showUserSeen(userFromBukkit);
} else {
showUserSeen(getPlayer(server, sender, args, 0));
}
} catch (Exception e) {
ess.showError(sender, e, commandLabel);
}
}
private void showUserSeen(User user) throws Exception {
if (user == null) {
throw new PlayerNotFoundException();
}
showSeenMessage(server, sender, user, showBan, extra);
}
});
} else {
showSeenMessage(server, sender, player, showBan, extra);
}
}
use of com.earth2me.essentials.User in project Essentials by drtshock.
the class Commandseen method seenIP.
private void seenIP(final Server server, final CommandSource sender, final String ipAddress) throws Exception {
final UserMap userMap = ess.getUserMap();
if (ess.getServer().getBanList(BanList.Type.IP).isBanned(ipAddress)) {
sender.sendMessage(tl("isIpBanned", ipAddress));
}
sender.sendMessage(tl("runningPlayerMatch", ipAddress));
ess.runTaskAsynchronously(new Runnable() {
@Override
public void run() {
final List<String> matches = new ArrayList<>();
for (final UUID u : userMap.getAllUniqueUsers()) {
final User user = ess.getUserMap().getUser(u);
if (user == null) {
continue;
}
final String uIPAddress = user.getLastLoginAddress();
if (!uIPAddress.isEmpty() && uIPAddress.equalsIgnoreCase(ipAddress)) {
matches.add(user.getName());
}
}
if (matches.size() > 0) {
sender.sendMessage(tl("matchingIPAddress"));
sender.sendMessage(StringUtil.joinList(matches));
} else {
sender.sendMessage(tl("noMatchingPlayers"));
}
}
});
}
use of com.earth2me.essentials.User in project Essentials by drtshock.
the class Commandsethome method run.
@Override
public void run(final Server server, final User user, final String commandLabel, String[] args) throws Exception {
User usersHome = user;
String name = "home";
final Location location = user.getLocation();
if (args.length > 0) {
//Allowing both formats /sethome khobbits house | /sethome khobbits:house
final String[] nameParts = args[0].split(":");
if (nameParts[0].length() != args[0].length()) {
args = nameParts;
}
if (args.length < 2) {
name = args[0].toLowerCase(Locale.ENGLISH);
} else {
name = args[1].toLowerCase(Locale.ENGLISH);
if (user.isAuthorized("essentials.sethome.others")) {
usersHome = getPlayer(server, args[0], true, true);
if (usersHome == null) {
throw new PlayerNotFoundException();
}
}
}
}
if (checkHomeLimit(user, usersHome, name)) {
name = "home";
}
if ("bed".equals(name) || NumberUtil.isInt(name)) {
throw new NoSuchFieldException(tl("invalidHomeName"));
}
if (!ess.getSettings().isTeleportSafetyEnabled() && LocationUtil.isBlockUnsafeForUser(usersHome, location.getWorld(), location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
throw new Exception(tl("unsafeTeleportDestination", location.getWorld().getName(), location.getBlockX(), location.getBlockY(), location.getBlockZ()));
}
usersHome.setHome(name, location);
user.sendMessage(tl("homeSet", user.getLocation().getWorld().getName(), user.getLocation().getBlockX(), user.getLocation().getBlockY(), user.getLocation().getBlockZ(), name));
}
Aggregations