diff --git a/src/de/steamwar/velocitycore/commands/PollCommand.java b/src/de/steamwar/velocitycore/commands/PollCommand.java index a594c43a..72646164 100644 --- a/src/de/steamwar/velocitycore/commands/PollCommand.java +++ b/src/de/steamwar/velocitycore/commands/PollCommand.java @@ -32,7 +32,7 @@ public class PollCommand extends SWCommand { } @Register - public void genericCommand(Chatter sender) { + public void genericCommand(@Validator Chatter sender) { PollSystem.sendPoll(sender); } diff --git a/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java b/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java index aac92062..304e2d0f 100644 --- a/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java +++ b/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java @@ -51,10 +51,6 @@ public class DiscordChannel extends Chatter.PlayerlessChatter { this(userOrPublic(user), user.openPrivateChannel().complete()); } - public DiscordChannel(SteamwarUser user) { - this(user, DiscordBot.getInstance().getJda().getUserById(user.getDiscordId()).openPrivateChannel().complete()); - } - public DiscordChannel(String channel) { this(SteamwarUser.get(-1), DiscordBot.getGuild().getTextChannelById(channel)); ChannelListener.getChannels().put(this.channel, this); diff --git a/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java b/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java index 115be4fe..2fffa1ae 100644 --- a/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java +++ b/src/de/steamwar/velocitycore/discord/listeners/ChannelListener.java @@ -37,7 +37,6 @@ import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; -import java.util.Optional; import java.util.logging.Level; public class ChannelListener extends ListenerAdapter { @@ -81,7 +80,12 @@ public class ChannelListener extends ListenerAdapter { if(permission != null && !sender.user().perms().contains(permission)) return; - command.execute(sender, Optional.ofNullable(event.getOption(DiscordBot.ARGUMENT_NAME)).map(OptionMapping::getAsString).orElse("").split(" ")); + OptionMapping option = event.getOption(DiscordBot.ARGUMENT_NAME); + String args = ""; + if(option != null) + args = option.getAsString(); + + command.execute(sender, args.split(" ")); }); } } diff --git a/src/de/steamwar/velocitycore/discord/util/DiscordAlert.java b/src/de/steamwar/velocitycore/discord/util/DiscordAlert.java index 5f65f998..0b115d41 100644 --- a/src/de/steamwar/velocitycore/discord/util/DiscordAlert.java +++ b/src/de/steamwar/velocitycore/discord/util/DiscordAlert.java @@ -19,14 +19,15 @@ package de.steamwar.velocitycore.discord.util; +import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; import de.steamwar.velocitycore.discord.DiscordBot; import de.steamwar.velocitycore.discord.channels.DiscordChannel; -import de.steamwar.messages.Chatter; import lombok.experimental.UtilityClass; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.Emoji; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.Button; @@ -37,21 +38,27 @@ import java.time.Instant; public class DiscordAlert { public static void send(Chatter player, Color color, Message title, Message description, boolean success) { - Long discordId = player.user().getDiscordId(); - if(DiscordBot.getInstance() == null || discordId == null) - return; + DiscordBot.withBot(bot -> { + Long discordId = player.user().getDiscordId(); + if(discordId == null) + return; - MessageBuilder builder = new MessageBuilder() - .setEmbeds(new EmbedBuilder() - .setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png") - .setColor(color) - .setTitle(player.parseToPlain(title)) - .setDescription(player.parseToPlain(description)) - .setTimestamp(Instant.now()) - .build()); - if(success) - builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")))); + User user = DiscordBot.getInstance().getJda().getUserById(discordId); + if(user == null) + return; - new DiscordChannel(player.user()).send(builder); + MessageBuilder builder = new MessageBuilder() + .setEmbeds(new EmbedBuilder() + .setAuthor("SteamWar", "https://steamwar.de", "https://cdn.discordapp.com/app-icons/869606970099904562/60c884000407c02671d91d8e7182b8a1.png") + .setColor(color) + .setTitle(player.parseToPlain(title)) + .setDescription(player.parseToPlain(description)) + .setTimestamp(Instant.now()) + .build()); + if(success) + builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")))); + + new DiscordChannel(user).send(builder); + }); } }