use of net.essentialsx.discord.util.DiscordMessageRecipient 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 net.essentialsx.discord.util.DiscordMessageRecipient 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