Solved For loop issue

Discussion in 'Plugin Development' started by gban, Oct 7, 2018.

Thread Status:
Not open for further replies.
  1. Offline

    gban

    Sorry for all the threads

    In my for loop

    Code:
    List<String> bad = survive.getConfig().getStringList("messages.alert");
                        for (int x = 0; x < bad.size(); x++){
                            if (message.toString().toUpperCase().contains(bad.get(x).toUpperCase())){
                                for (Player staff : Bukkit.getOnlinePlayers()){
                                   if( staff.hasPermission("survive.messages")){
                                        staff.sendMessage(ChatColor.RED + "[Filtered] (" +ChatColor.GREEN + player.getDisplayName() + ChatColor.RED + " -> " +ChatColor.GREEN +target.getDisplayName() + ChatColor.RED + ") " + message.toString());
                                    }
    
                                }
                                player.sendMessage(ChatColor.LIGHT_PURPLE + "(To "+ ChatColor.RESET+target.getDisplayName() + ChatColor.LIGHT_PURPLE+ ") "+ message.toString());
                                target.sendMessage(ChatColor.LIGHT_PURPLE + "(From "+ ChatColor.RESET+player.getDisplayName() + ChatColor.LIGHT_PURPLE+ ") "+ message.toString());
                                survive.getManager().recentlyMessaged.put(target, player);
                            }else{
                                player.sendMessage(ChatColor.LIGHT_PURPLE + "(To "+ ChatColor.RESET+target.getDisplayName() + ChatColor.LIGHT_PURPLE+ ") "+ message.toString());
                                target.sendMessage(ChatColor.LIGHT_PURPLE + "(From "+ ChatColor.RESET+player.getDisplayName() + ChatColor.LIGHT_PURPLE+ ") "+ message.toString());
                                survive.getManager().recentlyMessaged.put(target, player);
                               
                            }
                        }
    Whenever I type a word that isnt allowed it sends repeats the for loop for every message
    I just want one message and 1 filtered message not 4 messages

    [​IMG]
     
  2. Offline

    Reflxction

    I probably can't seem to understand the scene correctly, but did you try to break the loop? Also, use Java 8 streams, they look cleaner and nicer (also use for each loops rather fori loops)

    Sent from my TRT-L21A using Tapatalk
     
Thread Status:
Not open for further replies.

Share This Page