package xyz.rc24.bot.commands.botadm;

import com.google.gson.Gson;
import com.jagrosh.jdautilities.commandclient.Command;
import com.jagrosh.jdautilities.commandclient.CommandEvent;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.TextChannel;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import xyz.rc24.bot.commands.Categories;
import xyz.rc24.bot.mangers.LogManager;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MassMessage extends Command {
    private JedisPool pool;

    public MassMessage(JedisPool pool) {
        this.pool = pool;
        this.name = "super_secret_server_message";
        this.help = "Sends a message to _every_ log on the bot. USE WITH CAUTION!";
        this.category = Categories.ADMIN;
        this.botPermissions = new Permission[]{Permission.MESSAGE_WRITE};
        this.ownerCommand = true;
    }

    @Override
    protected void execute(CommandEvent event) {
        try (Jedis conn = pool.getResource()) {
            Map<String, String> logConfigs = conn.hgetAll("logs");
            List<TextChannel> serverList = new ArrayList<>();
            Gson gson = new Gson();

            // For every channel we have:
            // If we can speak, add it to the growing total.
            for (String serverJson : logConfigs.values()) {
                LogManager.StorageFormat format = gson.fromJson(serverJson, LogManager.StorageFormat.class);
                if (format.serverLog != null) {
                    TextChannel serverChannel = event.getJDA().getTextChannelById(format.serverLog);
                    if (serverChannel.canTalk()) {
                        serverList.add(serverChannel);
                    }
                }
                if (format.modLog != null) {
                    TextChannel serverChannel = event.getJDA().getTextChannelById(format.serverLog);
                    if (serverChannel.canTalk()) {
                        serverList.add(serverChannel);
                    }
                }
            }

            // Actually send
            for (TextChannel logChannel : serverList) {
                logChannel.sendMessage(event.getArgs()).complete();
            }
        }
    }
}

@@ -1615,32 +1615,62 @@
 mat.serverLog);%0A
+                    try %7B%0A    
                 
@@ -1696,32 +1696,36 @@
 el.canTalk()) %7B%0A
+    
                 
@@ -1755,32 +1755,120 @@
 serverChannel);%0A
+                        %7D%0A                    %7D catch (NullPointerException ignored) %7B%0A%0A
                 
@@ -2029,32 +2029,62 @@
 mat.serverLog);%0A
+                    try %7B%0A    
                 
@@ -2134,32 +2134,36 @@
                 
+    
 serverList.add(s
@@ -2169,32 +2169,144 @@
 serverChannel);%0A
+                        %7D%0A                    %7D catch (NullPointerException ignored) %7B%0A                        %0A
                 

Add null checks