Search in sources :

Example 1 with DiscordMessageRecipient

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());
}
Also used : User(com.earth2me.essentials.User) PlayerNotFoundException(com.earth2me.essentials.commands.PlayerNotFoundException) AtomicReference(java.util.concurrent.atomic.AtomicReference) DiscordMessageRecipient(net.essentialsx.discord.util.DiscordMessageRecipient)

Example 2 with DiscordMessageRecipient

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());
}
Also used : User(com.earth2me.essentials.User) PlayerNotFoundException(com.earth2me.essentials.commands.PlayerNotFoundException) AtomicReference(java.util.concurrent.atomic.AtomicReference) DiscordMessageRecipient(net.essentialsx.discord.util.DiscordMessageRecipient)

Aggregations

User (com.earth2me.essentials.User)2 PlayerNotFoundException (com.earth2me.essentials.commands.PlayerNotFoundException)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 DiscordMessageRecipient (net.essentialsx.discord.util.DiscordMessageRecipient)2