/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.techcavern.wavetact.ircCommands.chanhalfop;

import com.techcavern.wavetact.annot.IRCCMD;
import com.techcavern.wavetact.objects.IRCCommand;
import com.techcavern.wavetact.utils.*;
import org.apache.commons.lang3.StringUtils;
import org.jooq.Record;
import org.pircbotx.Channel;
import org.pircbotx.PircBotX;
import org.pircbotx.User;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

import static com.techcavern.wavetactdb.Tables.NETWORKS;

/**
 * @author jztech101
 */
@IRCCMD

public class Part extends IRCCommand {

    public Part() {
        super(GeneralUtils.toArray("part pa"), 7, "part (+)[channel]", "Parts a channel", true);
    }

    @Override
    public void onCommand(String command, User user, PircBotX network, String prefix, Channel channel, boolean isPrivate, int userPermLevel, String... args) throws Exception {
        if (args.length < 1 || (args.length == 1 && args[0].equalsIgnoreCase(channel.getName()))) {
            channel.send().part();
            Registry.lastLeftChannel = channel.getName();
        } else {
            if (userPermLevel >= 20) {
                boolean permanent = false;
                if (args[0].startsWith("+")) {
                    args[0] = args[0].replace("+", "");
                    Registry.lastLeftChannel = args[0];
                    permanent = true;
                }
                Registry.messageQueue.get(network).add("PART " + args[0]);
                if (permanent) {
                    Record netRecord = DatabaseUtils.getNetwork(IRCUtils.getNetworkNameByNetwork(network));
                    List<String> channels = new LinkedList<>(Arrays.asList(StringUtils.split(netRecord.getValue(NETWORKS.CHANNELS), ", ")));
                    channels.stream().filter(chan -> chan.equals(args[0])).forEach(channels::remove);
                    netRecord.setValue(NETWORKS.CHANNELS, StringUtils.join(channels, ", "));
                    DatabaseUtils.updateNetwork(netRecord);
                }
            } else {
                ErrorUtils.sendError(user, "Permission denied");
            }
        }
    }
}

@@ -548,17 +548,20 @@
 il.Array
-s
+List
 ;%0Aimport
@@ -571,26 +571,22 @@
 va.util.
-LinkedList
+Arrays
 ;%0Aimport
@@ -1828,14 +1828,13 @@
 new 
-Linked
+Array
 List
@@ -1949,78 +1949,22 @@
 els.
-stream().filter(chan -%3E chan.equals(args%5B0%5D)).forEach(channels::remove
+remove(args%5B0%5D
 );%0A 

Fix exceptions in perm-part