use of com.earth2me.essentials.commands.PlayerNotFoundException in project Essentials by EssentialsX.
the class Essentials method matchUser.
@Override
public User matchUser(final Server server, final User sourceUser, final String searchTerm, final Boolean getHidden, final boolean getOffline) throws PlayerNotFoundException {
final User user;
Player exPlayer;
try {
exPlayer = server.getPlayer(UUID.fromString(searchTerm));
} catch (final IllegalArgumentException ex) {
if (getOffline) {
exPlayer = server.getPlayerExact(searchTerm);
} else {
exPlayer = server.getPlayer(searchTerm);
}
}
if (exPlayer != null) {
user = getUser(exPlayer);
} else {
user = getUser(searchTerm);
}
if (user != null) {
if (!getOffline && !user.getBase().isOnline()) {
throw new PlayerNotFoundException();
}
if (getHidden || canInteractWith(sourceUser, user)) {
return user;
} else {
// not looking for hidden and cannot interact (i.e is hidden)
if (getOffline && user.getName().equalsIgnoreCase(searchTerm)) {
// if looking for offline and got an exact match
return user;
}
}
throw new PlayerNotFoundException();
}
final List<Player> matches = server.matchPlayer(searchTerm);
if (matches.isEmpty()) {
final String matchText = searchTerm.toLowerCase(Locale.ENGLISH);
for (final User userMatch : getOnlineUsers()) {
if (getHidden || canInteractWith(sourceUser, userMatch)) {
final String displayName = FormatUtil.stripFormat(userMatch.getDisplayName()).toLowerCase(Locale.ENGLISH);
if (displayName.contains(matchText)) {
return userMatch;
}
}
}
} else {
for (final Player player : matches) {
final User userMatch = getUser(player);
if (userMatch.getDisplayName().startsWith(searchTerm) && (getHidden || canInteractWith(sourceUser, userMatch))) {
return userMatch;
}
}
final User userMatch = getUser(matches.get(0));
if (getHidden || canInteractWith(sourceUser, userMatch)) {
return userMatch;
}
}
throw new PlayerNotFoundException();
}
use of com.earth2me.essentials.commands.PlayerNotFoundException in project Essentials by drtshock.
the class Essentials method matchUser.
@Override
public User matchUser(final Server server, final User sourceUser, final String searchTerm, final Boolean getHidden, final boolean getOffline) throws PlayerNotFoundException {
final User user;
Player exPlayer;
try {
exPlayer = server.getPlayer(UUID.fromString(searchTerm));
} catch (final IllegalArgumentException ex) {
if (getOffline) {
exPlayer = server.getPlayerExact(searchTerm);
} else {
exPlayer = server.getPlayer(searchTerm);
}
}
if (exPlayer != null) {
user = getUser(exPlayer);
} else {
user = getUser(searchTerm);
}
if (user != null) {
if (!getOffline && !user.getBase().isOnline()) {
throw new PlayerNotFoundException();
}
if (getHidden || canInteractWith(sourceUser, user)) {
return user;
} else {
// not looking for hidden and cannot interact (i.e is hidden)
if (getOffline && user.getName().equalsIgnoreCase(searchTerm)) {
// if looking for offline and got an exact match
return user;
}
}
throw new PlayerNotFoundException();
}
final List<Player> matches = server.matchPlayer(searchTerm);
if (matches.isEmpty()) {
final String matchText = searchTerm.toLowerCase(Locale.ENGLISH);
for (final User userMatch : getOnlineUsers()) {
if (getHidden || canInteractWith(sourceUser, userMatch)) {
final String displayName = FormatUtil.stripFormat(userMatch.getDisplayName()).toLowerCase(Locale.ENGLISH);
if (displayName.contains(matchText)) {
return userMatch;
}
}
}
} else {
for (final Player player : matches) {
final User userMatch = getUser(player);
if (userMatch.getDisplayName().startsWith(searchTerm) && (getHidden || canInteractWith(sourceUser, userMatch))) {
return userMatch;
}
}
final User userMatch = getUser(matches.get(0));
if (getHidden || canInteractWith(sourceUser, userMatch)) {
return userMatch;
}
}
throw new PlayerNotFoundException();
}
use of com.earth2me.essentials.commands.PlayerNotFoundException in project Essentials by drtshock.
the class MessageCommand method onCommand.
@Override
public void onCommand(InteractionEvent event) {
final boolean getHidden = event.getMember().hasRoles(getAdminSnowflakes());
final User user;
try {
user = jda.getPlugin().getEss().matchUser(Bukkit.getServer(), null, event.getStringArgument("username"), getHidden, false);
} catch (PlayerNotFoundException e) {
event.reply(tl("errorWithMessage", e.getMessage()));
return;
}
if (!getHidden && user.isIgnoreMsg()) {
event.reply(tl("msgIgnore", user.getDisplayName()));
return;
}
if (user.isAfk()) {
if (user.getAfkMessage() != null) {
event.reply(tl("userAFKWithMessage", user.getDisplayName(), user.getAfkMessage()));
} else {
event.reply(tl("userAFK", user.getDisplayName()));
}
}
final String message = event.getMember().hasRoles(jda.getSettings().getPermittedFormattingRoles()) ? FormatUtil.replaceFormat(event.getStringArgument("message")) : FormatUtil.stripFormat(event.getStringArgument("message"));
event.reply(tl("msgFormat", tl("meSender"), user.getDisplayName(), message));
user.sendMessage(tl("msgFormat", event.getMember().getTag(), tl("meRecipient"), message));
// We use an atomic reference here so that java will garbage collect the recipient
final AtomicReference<DiscordMessageRecipient> ref = new AtomicReference<>(new DiscordMessageRecipient(event.getMember()));
// Expires after 5 minutes
jda.getPlugin().getEss().runTaskLaterAsynchronously(() -> ref.set(null), 6000);
user.setReplyRecipient(ref.get());
}
use of com.earth2me.essentials.commands.PlayerNotFoundException in project Essentials by EssentialsX.
the class MessageCommand method onCommand.
@Override
public void onCommand(InteractionEvent event) {
final boolean getHidden = event.getMember().hasRoles(getAdminSnowflakes());
final User user;
try {
user = jda.getPlugin().getEss().matchUser(Bukkit.getServer(), null, event.getStringArgument("username"), getHidden, false);
} catch (PlayerNotFoundException e) {
event.reply(tl("errorWithMessage", e.getMessage()));
return;
}
if (!getHidden && user.isIgnoreMsg()) {
event.reply(tl("msgIgnore", user.getDisplayName()));
return;
}
if (user.isAfk()) {
if (user.getAfkMessage() != null) {
event.reply(tl("userAFKWithMessage", user.getDisplayName(), user.getAfkMessage()));
} else {
event.reply(tl("userAFK", user.getDisplayName()));
}
}
final String message = event.getMember().hasRoles(jda.getSettings().getPermittedFormattingRoles()) ? FormatUtil.replaceFormat(event.getStringArgument("message")) : FormatUtil.stripFormat(event.getStringArgument("message"));
event.reply(tl("msgFormat", tl("meSender"), user.getDisplayName(), message));
user.sendMessage(tl("msgFormat", event.getMember().getTag(), tl("meRecipient"), message));
// We use an atomic reference here so that java will garbage collect the recipient
final AtomicReference<DiscordMessageRecipient> ref = new AtomicReference<>(new DiscordMessageRecipient(event.getMember()));
// Expires after 5 minutes
jda.getPlugin().getEss().runTaskLaterAsynchronously(() -> ref.set(null), 6000);
user.setReplyRecipient(ref.get());
}
Aggregations