Java Code Examples for org.bukkit.util.StringUtil#copyPartialMatches()

The following examples show how to use org.bukkit.util.StringUtil#copyPartialMatches() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BwCommandsExecutor.java    From BedWars with GNU Lesser General Public License v3.0 8 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
    List<String> completionList = new ArrayList<>();
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (args.length == 1) {
            for (BaseCommand c : Main.getCommands().values()) {
                if (c.hasPermission(player)) {
                    completionList.add(c.getName());
                }
            }
        } else if (args.length > 1) {
            ArrayList<String> arguments = new ArrayList<>(Arrays.asList(args));
            arguments.remove(0);
            BaseCommand bCommand = Main.getCommands().get(args[0]);
            if (bCommand != null) {
                if (bCommand.hasPermission(player)) {
                    bCommand.completeTab(completionList, sender, arguments);
                }
            }
        }
    }
    List<String> finalCompletionList = new ArrayList<>();
    StringUtil.copyPartialMatches(args[args.length - 1], completionList, finalCompletionList);
    return finalCompletionList;
}
 
Example 2
Source File: BwCommandsExecutor.java    From BedWars with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String alias, String[] args) {
    List<String> completionList = new ArrayList<>();
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (args.length == 1) {
            for (BaseCommand c : Main.getCommands().values()) {
                if (c.hasPermission(player)) {
                    completionList.add(c.getName());
                }
            }
        } else if (args.length > 1) {
            ArrayList<String> arguments = new ArrayList<>(Arrays.asList(args));
            arguments.remove(0);
            BaseCommand bCommand = Main.getCommands().get(args[0]);
            if (bCommand != null) {
                if (bCommand.hasPermission(player)) {
                    bCommand.completeTab(completionList, sender, arguments);
                }
            }
        }
    }
    List<String> finalCompletionList = new ArrayList<>();
    StringUtil.copyPartialMatches(args[args.length - 1], completionList, finalCompletionList);
    return finalCompletionList;
}
 
Example 3
Source File: CommandWesv.java    From WorldEditSelectionVisualizer with MIT License 6 votes vote down vote up
@Override
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String alias, @NotNull String[] args) {
    if (args.length > 2 || !sender.hasPermission("wesv.use")) {
        return Collections.emptyList();
    }

    if (args.length == 1) {
        List<String> completions = new ArrayList<>();

        if (sender instanceof Player) {
            completions.add("toggle");
        }

        if (sender.hasPermission("wesv.reload")) {
            completions.add("reload");
        }

        return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>());
    }

    if (args.length == 2 && args[0].equalsIgnoreCase("toggle") && StringUtil.startsWithIgnoreCase("clipboard", args[1])) {
        return Collections.singletonList("clipboard");
    }

    return Collections.emptyList();
}
 
Example 4
Source File: SushchestvoCommand.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
{
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    if (args.length == 1)
    {
        return StringUtil.copyPartialMatches(args[0], COMMANDS, new ArrayList<String>(COMMANDS.size()));
    }
    if (((args.length == 2) && "get".equalsIgnoreCase(args[0])) || "set".equalsIgnoreCase(args[0]))
    {
        return StringUtil.copyPartialMatches(args[1], MinecraftServer.getServer().sushchestvoConfig.getSettings().keySet(), new ArrayList<String>(MinecraftServer.getServer().sushchestvoConfig.getSettings().size()));
    }

    return ImmutableList.of();
}
 
Example 5
Source File: TileEntityCommand.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
{
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    if (args.length == 1)
    {
        return StringUtil.copyPartialMatches(args[0], COMMANDS, new ArrayList<String>(COMMANDS.size()));
    }
    if (((args.length == 2) && "get".equalsIgnoreCase(args[0])) || "set".equalsIgnoreCase(args[0]))
    {
        return StringUtil.copyPartialMatches(args[1], MinecraftServer.getServer().tileEntityConfig.getSettings().keySet(), new ArrayList<String>(MinecraftServer.getServer().tileEntityConfig.getSettings().size()));
    }

    return ImmutableList.of();
}
 
Example 6
Source File: CauldronCommand.java    From Thermos with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args)
{
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    if (args.length == 1)
    {
        return StringUtil.copyPartialMatches(args[0], COMMANDS, new ArrayList<String>(COMMANDS.size()));
    }
    if (((args.length == 2) && "get".equalsIgnoreCase(args[0])) || "set".equalsIgnoreCase(args[0]))
    {
        return StringUtil.copyPartialMatches(args[1], MinecraftServer.getServer().cauldronConfig.getSettings().keySet(), new ArrayList<String>(MinecraftServer.getServer().cauldronConfig.getSettings().size()));
    }
    else if ((args.length == 2) && "chunks".equalsIgnoreCase(args[0]))
    {
        return StringUtil.copyPartialMatches(args[1], CHUNK_COMMANDS, new ArrayList<String>(CHUNK_COMMANDS.size()));
    }

    return ImmutableList.of();
}
 
Example 7
Source File: TimingsCommand.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    if (args.length == 1) {
        return StringUtil.copyPartialMatches(args[0], TIMINGS_SUBCOMMANDS, new ArrayList<String>(TIMINGS_SUBCOMMANDS.size()));
    }
    return ImmutableList.of();
}
 
Example 8
Source File: CraftMagicNumbers.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public List<String> tabCompleteInternalMaterialName(String token, List<String> completions) {
    ArrayList<String> results = Lists.newArrayList();
    for (ResourceLocation key : Item.REGISTRY.getKeys()) {
        results.add(key.toString());
    }
    return StringUtil.copyPartialMatches(token, results, completions);
}
 
Example 9
Source File: KeyTab.java    From Crazy-Crates with MIT License 5 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String commandLable, String[] args) {
    List<String> completions = new ArrayList<>();
    if (args.length == 1) {// /key
        if (hasPermission(sender, "key")) {
            Bukkit.getOnlinePlayers().forEach(player -> completions.add(player.getName()));
        }
        return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>());
    }
    return new ArrayList<>();
}
 
Example 10
Source File: RequestResponseCommand.java    From UHC with MIT License 5 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
    return StringUtil.copyPartialMatches(
            args[args.length - 1],
            Iterables.transform(requestManager.getRequests(), GET_ID),
            Lists.<String>newArrayList()
    );
}
 
Example 11
Source File: CCTab.java    From Crazy-Crates with MIT License 4 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String commandLable, String[] args) {
    List<String> completions = new ArrayList<>();
    if (args.length == 1) {// /cc
        if (hasPermission(sender, "access")) completions.add("help");
        if (hasPermission(sender, "additem")) completions.add("additem");
        if (hasPermission(sender, "admin")) completions.add("admin");
        if (hasPermission(sender, "convert")) completions.add("convert");
        if (hasPermission(sender, "list")) completions.add("list");
        if (hasPermission(sender, "open")) completions.add("open");
        if (hasPermission(sender, "forceopen")) completions.add("forceopen");
        if (hasPermission(sender, "tp")) completions.add("tp");
        if (hasPermission(sender, "transfer")) completions.add("transfer");
        if (hasPermission(sender, "give")) completions.add("give");
        if (hasPermission(sender, "giveall")) completions.add("giveall");
        if (hasPermission(sender, "take")) completions.add("take");
        if (hasPermission(sender, "set")) completions.add("set");
        if (hasPermission(sender, "reload")) completions.add("reload");
        if (hasPermission(sender, "schematic")) completions.add("set1");
        if (hasPermission(sender, "schematic")) completions.add("set2");
        if (hasPermission(sender, "schematic")) completions.add("save");
        return StringUtil.copyPartialMatches(args[0], completions, new ArrayList<>());
    } else if (args.length == 2) {// /cc arg0
        switch (args[0].toLowerCase()) {
            case "additem":
            case "open":
            case "forceopen":
            case "transfer":
                cc.getCrates().forEach(crate -> completions.add(crate.getName()));
                completions.remove("Menu");//Takes out a crate that doesn't exist as a file.
                break;
            case "set":
                cc.getCrates().forEach(crate -> completions.add(crate.getName()));
                break;
            case "tp":
                cc.getCrateLocations().forEach(location -> completions.add(location.getID()));
                break;
            case "give":
            case "giveall":
            case "take":
                completions.add("physical");
                completions.add("p");
                completions.add("virtual");
                completions.add("v");
                break;
            case "save":
                completions.add("<Schematic Name>");
                break;
        }
        return StringUtil.copyPartialMatches(args[1], completions, new ArrayList<>());
    } else if (args.length == 3) {// /cc arg0 arg1
        switch (args[0].toLowerCase()) {
            case "additem":
                Crate crateFromName = cc.getCrateFromName(args[1]);
                if (crateFromName != null && crateFromName.getCrateType() != CrateType.MENU) {
                    cc.getCrateFromName(args[1]).getPrizes().forEach(prize -> completions.add(prize.getName()));
                }
                break;
            case "open":
            case "forceopen":
            case "transfer":
                Bukkit.getOnlinePlayers().forEach(player -> completions.add(player.getName()));
                break;
            case "give":
            case "giveall":
            case "take":
                cc.getCrates().forEach(crate -> completions.add(crate.getName()));
                completions.remove("Menu");//Takes out a crate that doesn't exist as a file.
                break;
        }
        return StringUtil.copyPartialMatches(args[2], completions, new ArrayList<>());
    } else if (args.length == 4) {// /cc arg0 arg1 arg2
        switch (args[0].toLowerCase()) {
            case "give":
            case "giveall":
            case "take":
            case "transfer":
                for (int i = 1; i <= 100; i++) completions.add(i + "");
                break;
        }
        return StringUtil.copyPartialMatches(args[3], completions, new ArrayList<>());
    } else if (args.length == 5) {// /cc arg0 arg1 arg2 arg3
        switch (args[0].toLowerCase()) {
            case "give":
            case "giveall":
            case "take":
                Bukkit.getOnlinePlayers().forEach(player -> completions.add(player.getName()));
                break;
        }
        return StringUtil.copyPartialMatches(args[4], completions, new ArrayList<>());
    }
    return new ArrayList<>();
}
 
Example 12
Source File: CraftMagicNumbers.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
@Override
public List<String> tabCompleteInternalMaterialName(String token, List<String> completions) {
    return StringUtil.copyPartialMatches(token, net.minecraft.item.Item.itemRegistry.getKeys(), completions);
}
 
Example 13
Source File: ModuleTabComplete.java    From UHC with MIT License 4 votes vote down vote up
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args,
                                  String complete, String[] others) {
    return StringUtil.copyPartialMatches(complete, registry.getIds(), Lists.<String>newArrayList());
}