Vaerys_Dawn

Spagett?

Mar 24th, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.90 KB | None | 0 0
  1. public static List<Command> getCommandsByType(List<Command> commands, CommandObject commandObject, SAILType type, boolean testPerms) {
  2.         List<Command> toReturn = new ArrayList<>();
  3.  
  4.         //return empty if not creator.
  5.         if (type == SAILType.CREATOR && !commandObject.user.checkIsCreator()) return toReturn;
  6.  
  7.         //get command list
  8.         switch (type) {
  9.             case DM:
  10.                 toReturn.addAll(commands.stream()
  11.                         .filter(c -> c.channel == ChannelSetting.FROM_DM)
  12.                         .filter(c -> {
  13.                             //only show creator commands if the user the creator.
  14.                             if (c.type == SAILType.CREATOR && commandObject.user.checkIsCreator())
  15.                                 return true;
  16.                             if (c.type != SAILType.CREATOR) {
  17.                                 return true;
  18.                             }
  19.                             return false;
  20.                         })
  21.                         .collect(Collectors.toList()));
  22.                 return toReturn;
  23.             default:
  24.                 toReturn.addAll(commands.stream()
  25.                         .filter(c -> c.type == type).collect(Collectors.toList()));
  26.                 break;
  27.         }
  28.  
  29.         toReturn.addAll(commands.stream().filter(c -> c.subCommands.size() != 0)
  30.                 .filter(c -> c.hasSubCommands(type))
  31.                 .collect(Collectors.toList()));
  32.  
  33.         if (testPerms) {
  34.             toReturn = toReturn.stream()
  35.                     .filter(c -> c.isVisibleInType(commandObject, type))
  36.                     .collect(Collectors.toList());
  37.         }
  38.         if (type != SAILType.DM) {
  39.             toReturn = toReturn.stream().filter(c -> c.channel != ChannelSetting.FROM_DM).collect(Collectors.toList());
  40.         }
  41.         toReturn.sort(Comparator.comparing(o -> o.names[0]));
  42.         return toReturn;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment