예제 #1
0
 private Noun<?> getNounFor(String arg) {
   Noun<?> n = null;
   for (Noun<?> noun : nouns) {
     if (RandomUtils.contains(noun.getNames(), arg)) n = noun;
   }
   return n;
 }
예제 #2
0
 @Override
 protected List<String> handleTabComplete(
     CommandSender sender, Command command, String alias, String[] args) {
   if (!sender.hasPermission(PERMISSION)) return Collections.emptyList();
   // 0 - noun
   // 1 - noun autocomplete
   // 2 - verb
   // 3+ - not supported
   switch (args.length) {
     case 1:
       List<String> nounNames = new ArrayList<>();
       for (Noun<?> noun : nouns) {
         String s1 = args[0].toLowerCase();
         for (String s : noun.getNames()) {
           if (s.toLowerCase().startsWith(s1)) nounNames.add(s);
         }
       }
       return nounNames;
     case 2:
       Noun<?> nounFor = getNounFor(args[0]);
       if (nounFor == null) return Collections.emptyList();
       return nounFor.getTabCompleteFor(args[1]);
     case 3:
       Noun<?> nounFor1 = getNounFor(args[0]);
       if (nounFor1 == null) return Collections.emptyList();
       List<String> strings = new ArrayList<>();
       for (Verb<? extends CPermissible> verb : nounFor1.getVerbs()) {
         String s1 = args[2].toLowerCase();
         for (String s : verb.getNames()) {
           if (s.toLowerCase().startsWith(s1)
               && sender.hasPermission(getPermission(nounFor1, verb))) strings.add(s);
         }
       }
       return strings;
     default:
       return Collections.emptyList();
   }
 }