Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.tofa.discordwl.bot;
- import com.tofa.discordwl.Main;
- import net.dv8tion.jda.api.entities.ChannelType;
- import net.dv8tion.jda.api.entities.Guild;
- import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
- import net.dv8tion.jda.api.hooks.ListenerAdapter;
- import org.bukkit.Bukkit;
- import org.bukkit.OfflinePlayer;
- import org.jetbrains.annotations.NotNull;
- import net.dv8tion.jda.api.JDA;
- import java.util.Arrays;
- import java.util.Objects;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.lang.String;
- import static javax.swing.UIManager.getString;
- public class DiscordMessageListener extends ListenerAdapter {
- private final Main plugin;
- private final JDA jda;
- public DiscordMessageListener(@NotNull Main plugin) {
- this.plugin = plugin;
- this.jda = plugin.getBot().getJDA();
- }
- @Override
- public void onMessageReceived(@NotNull MessageReceivedEvent e) {
- if (!(e.getMessage().getAuthor().isBot() || e.isWebhookMessage()) && (plugin.getConfig().getString("ChannelID").equals(e.getChannel().getId()) && e.isFromType(ChannelType.TEXT))) {
- String argument = e.getMessage().getContentDisplay();
- if (plugin.getConfig().getBoolean("Blacklist") && plugin.getConfig().getStringList("Blacklist-nick").contains(argument)) {
- e.getChannel().sendMessage(Objects.requireNonNull(plugin.getConfig().getString("Blacklist-message"))).queue();
- } else if (argument.matches("^\\w{3,16}$")){
- OfflinePlayer p = Bukkit.getOfflinePlayer(argument);
- Guild guild = e.getGuild();
- if (p.isWhitelisted()) {
- e.getChannel().sendMessage((plugin.getConfig().getString("AlreadyIn"))).queue();
- } else {
- p.setWhitelisted(true);
- e.getChannel().sendMessage((plugin.getConfig().getString("AddedIn"))).queue();
- if (plugin.getConfig().getBoolean("Change-Name")) {
- guild.modifyNickname(e.getMessage().getMember(), argument).queue();
- }
- if (plugin.getConfig().getBoolean("Send-DM")) {
- e.getAuthor().openPrivateChannel().flatMap(channel -> channel.sendMessage(Objects.requireNonNull(plugin.getConfig().getString("DM-Message")))).queue();
- }
- if (plugin.getConfig().getBoolean("AddRole-enabled")) {
- }
- e.getGuild().addRoleToMember(e.getMember().getId(), Objects.requireNonNull(jda.getRoleById(Objects.requireNonNull(plugin.getConfig().getString("RoleID"))))).queue();
- }
- } else {
- if((argument.length < 3) || (argument.length > 16)) e.getChannel().sendMessage(Objects.requireNonNull(plugin.getConfig().getString("LengthError"))).queue();
- else e.getChannel().sendMessage(Objects.requireNonNull(plugin.getConfig().getString("SymbolsError"))).queue();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment