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

The following examples show how to use org.bukkit.util.StringUtil#startsWithIgnoreCase() . 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: VersionCommand.java    From Kettle 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) {
        List<String> completions = new ArrayList<>();
        String toComplete = args[0].toLowerCase(java.util.Locale.ENGLISH);
        for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
            if (StringUtil.startsWithIgnoreCase(plugin.getName(), toComplete)) {
                completions.add(plugin.getName());
            }
        }
        return completions;
    }
    return ImmutableList.of();
}
 
Example 2
Source File: Command.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
private List<String> tabComplete0(CommandSender sender, String alias, String[] args, Location location) throws IllegalArgumentException {
    Validate.notNull(sender, "Sender cannot be null");
    Validate.notNull(args, "Arguments cannot be null");
    Validate.notNull(alias, "Alias cannot be null");

    if (args.length == 0) {
        return ImmutableList.of();
    }

    String lastWord = args[args.length - 1];

    Player senderPlayer = sender instanceof Player ? (Player) sender : null;

    ArrayList<String> matchedPlayers = new ArrayList<String>();
    for (Player player : sender.getServer().getOnlinePlayers()) {
        String name = player.getName();
        if ((senderPlayer == null || senderPlayer.canSee(player)) && StringUtil.startsWithIgnoreCase(name, lastWord)) {
            matchedPlayers.add(name);
        }
    }

    Collections.sort(matchedPlayers, String.CASE_INSENSITIVE_ORDER);
    return matchedPlayers;
}
 
Example 3
Source File: CraftServer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public List<String> tabCompleteChat(Player player, String message) {
    List<String> completions = new ArrayList<String>();
    PlayerChatTabCompleteEvent event = new PlayerChatTabCompleteEvent(player, message, completions);
    String token = event.getLastToken();
    for (Player p : getOnlinePlayers()) {
        if (player.canSee(p) && StringUtil.startsWithIgnoreCase(p.getName(), token)) {
            completions.add(p.getName());
        }
    }
    pluginManager.callEvent(event);

    Iterator<?> it = completions.iterator();
    while (it.hasNext()) {
        Object current = it.next();
        if (!(current instanceof String)) {
            // Sanity
            it.remove();
        }
    }
    Collections.sort(completions, String.CASE_INSENSITIVE_ORDER);
    return completions;
}
 
Example 4
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 5
Source File: Utils.java    From NBTEditor with GNU General Public License v3.0 6 votes vote down vote up
public static List<String> getElementsWithPrefix(Collection<String> values, String prefix, String ignorePrefix, boolean sort) {
	List<String> result;
	if (prefix == null || prefix.isEmpty()) {
		result = new ArrayList<String>(values);
	} else {
		result = new ArrayList<String>();
		for (String string : values) {
			if (StringUtil.startsWithIgnoreCase(string, prefix)) {
				result.add(string);
			} else if (ignorePrefix != null && !ignorePrefix.isEmpty() && StringUtil.startsWithIgnoreCase(string, ignorePrefix)) {
				if (string.regionMatches(ignorePrefix.length(), prefix, 0, prefix.length())) {
					result.add(string);
				}
			}
		}
	}
	if (sort) {
		Collections.sort(result, String.CASE_INSENSITIVE_ORDER);
	}
	return Collections.unmodifiableList(result);
}
 
Example 6
Source File: CraftServer.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public List<String> tabCompleteChat(Player player, String message) {
    List<String> completions = new ArrayList<String>();
    PlayerChatTabCompleteEvent event = new PlayerChatTabCompleteEvent(player, message, completions);
    String token = event.getLastToken();
    for (Player p : getOnlinePlayers()) {
        if (player.canSee(p) && StringUtil.startsWithIgnoreCase(p.getName(), token)) {
        	if (event.isPinging())
        	{
        		StringBuilder sb = new StringBuilder(1 + p.getName().length());
        		sb.append('@'); sb.append(p.getName());
        		completions.add(sb.toString());
        	}
        	else
        		completions.add(p.getName());
        }
    }
    pluginManager.callEvent(event);

    Iterator<?> it = completions.iterator();
    while (it.hasNext()) {
        Object current = it.next();
        if (!(current instanceof String)) {
            // Sanity
            it.remove();
        }
    }
    Collections.sort(completions, String.CASE_INSENSITIVE_ORDER);
    return completions;
}
 
Example 7
Source File: AbstractNBTCommand.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
private static List<String> getVariableNames(BaseNBT base, String prefix) {
	List<String> names = new ArrayList<String>();
	for (NBTVariableContainer container : base.getAllVariables()) {
		for (String name : container.getVariableNames()) {
			if (StringUtil.startsWithIgnoreCase(name, prefix)) {
				names.add(name);
			}
		}
	}
	Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
	return names;
}
 
Example 8
Source File: CommandCustomItems.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
private List<String> getCustomItemNamesList(String prefix) {
	ArrayList<String> names = new ArrayList<String>();
	for (CustomItem citem : CustomItemManager.getCustomItems()) {
		String slug = citem.getSlug();
		if (citem.isEnabled() && StringUtil.startsWithIgnoreCase(slug, prefix)) {
			names.add(slug);
		}
	}
	Collections.sort(names, String.CASE_INSENSITIVE_ORDER);
	return names;
}