I don't know how the <StringUtil.copyPartialMatches()> Works

Discussion in 'Plugin Development' started by jhplayer, Jan 27, 2020.

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

    jhplayer

    I are try making a auto complete for my commando of plugin, but I stuck in this comand:

    Code:
    StringUtil.copyPartialMatches ()
    This fuction have a red underscore, thats means I dont know how work and how use it.

    How i can solve this? And have a alternative form to make auto compleate for my command with out API or external classes.

    My full code:

    @main CLASS FILE
    Code:Java
    1. //Import Class
    2. import net.makenoise.*;
    3.  
    4. //Inside of public Class....
    5. getCommand("makenoiseCompleter").setTabCompleter(new makenoiseCompleter());
    6.  


    @Compleater Class
    Code:Java
    1. package net.makenoise;
    2.  
    3. //Syntax=Java Utils
    4. import Syntax=Java.util.ArrayList;
    5. import Syntax=Java.util.Collections;
    6. import Syntax=Java.util.List;
    7.  
    8. //Bukkit
    9. import org.bukkit.command.Command;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.command.TabCompleater;
    12. import org.bukkit.util.StringUtil;
    13.  
    14. public class makenoiseCompleter implements TabCompleter{
    15.  
    16. private static final String[] COMMANDS = {"enderman","creeper","zombie","spider"};
    17.  
    18. @Override
    19. public List<String> onTabComplete(COmmandSender sender, Command command, String label, String[] args){
    20.  
    21. final List<String> completions = new ArrayList<>();
    22.  
    23. StringUtil.copyPartialMatches(args[0], COMMANDS, completions);
    24.  
    25. Collection.sort(completions);
    26.  
    27. return completions;
    28.  
    29.  
    30. }
    31.  
    32.  
    33. }
     
    Last edited: Jan 27, 2020
  2. Offline

    KarimAKL

    @jhplayer
    1. There's no need for you to sort the list, it's already done before the player sees it.
    2. Just do something like this:
    Code:Java
    1. String[] yourFirstArguments = new String[] {"test", "123", "lol"};
    2. String[] yourSecondArguments = new String[] {"still", "a", "test"};
    3.  
    4. List<String> list = new ArrayList<>();
    5.  
    6. if (args.length == 1) {
    7. for (String string : yourFirstArguments) if (string.toLowerCase().startsWith(args[0].toLowerCase())) list.add(string);
    8. } else if (args.length == 2) {
    9. if (args[0].equalsIgnoreCase("yourFirstArgument")) {
    10. for (String string : yourSecondArguments) if (string.toLowerCase().startsWith(args[1].toLowerCase())) list.add(string);
    11. }
    12. }
    13. return list;

    You should be able to guess the rest yourself.
     
    jhplayer likes this.
  3. Offline

    jhplayer

    Now thats make a lot more sense to me ... Thanks to help me to finde how to solve this case...

    [​IMG]
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page