當前位置: 首頁>>代碼示例>>Java>>正文


Java StringUtil類代碼示例

本文整理匯總了Java中org.bukkit.util.StringUtil的典型用法代碼示例。如果您正苦於以下問題:Java StringUtil類的具體用法?Java StringUtil怎麽用?Java StringUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StringUtil類屬於org.bukkit.util包,在下文中一共展示了StringUtil類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: tabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@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();
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:19,代碼來源:TileEntityCommand.java

示例2: suggest

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@Override
public List<String> suggest(CommandSender sender, List<String> args) {
    if (args.isEmpty()) {
        return commands.stream()
                .filter(c -> c.canExecute(sender))
                .map(Command::getName)
                .collect(Collectors.toList());
    } else if (args.size() > 1) {
        Command sub = getCommand(args.get(0));
        if (sub != null)
            return sub.tabComplete(sender, args.subList(1, args.size()));
        else
            return emptyList();
    } else {
        String arg = args.get(0);

        return commands.stream()
                .filter(c -> c.canExecute(sender))
                .map(Command::getName)
                .filter(s -> StringUtil.startsWithIgnoreCase(s, arg))
                .collect(Collectors.toList());
    }
}
 
開發者ID:upperlevel,項目名稱:uppercore,代碼行數:24,代碼來源:NodeCommand.java

示例3: onTabCompletion

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@Override
public List<String> onTabCompletion(CommandSender sender, Class<?> type, List<String> args) {
    Stream<? extends Player> players = Bukkit.getOnlinePlayers().stream();
    if(sender instanceof Player) {
        Player player = (Player) sender;
        players = players.filter(player::canSee);
    }
    Stream<String> strStream = players.map(Player::getName);
    if(args.isEmpty())
        return strStream.collect(Collectors.toList());
    String partial = args.get(0);
    return strStream
            .filter(s -> StringUtil.startsWithIgnoreCase(s, partial))
            .sorted(String.CASE_INSENSITIVE_ORDER)
            .collect(Collectors.toList());
}
 
開發者ID:upperlevel,項目名稱:uppercore,代碼行數:17,代碼來源:PlayerArgumentParser.java

示例4: tabCompleteChat

import org.bukkit.util.StringUtil; //導入依賴的package包/類
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;
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:23,代碼來源:CraftServer.java

示例5: tabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@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])){
        MinecraftServer.getServer();
        MinecraftServer.getServer();
        return StringUtil.copyPartialMatches(args[1],MinecraftServer.entityConfig.getSettings().keySet(),new ArrayList<String>(MinecraftServer.tileEntityConfig.getSettings().size()));
    }

    return ImmutableList.of();
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:18,代碼來源:EntityCommand.java

示例6: tabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@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();
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:23,代碼來源:CauldronCommand.java

示例7: onTabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
    List<String> list = Lists.newArrayList();

    if (args.length != 1) {
        return Lists.newArrayList();
    }

    list.add("info");

    if (sender.hasPermission(PERMISSION)) {
        list.add("enable");
        list.add("disable");
    }

    return StringUtil.copyPartialMatches(args[args.length - 1], list, Lists.newArrayList());
}
 
開發者ID:LeonTG,項目名稱:NineSlots,代碼行數:18,代碼來源:NineSlotsCommand.java

示例8: onTabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
	List<String> list;
	if (args.length <= 1) {
		list = new ArrayList<>(subCommandMap.keySet());
	} else {
		AbstractSubCommand subCommand = subCommandMap.get(args[0].toLowerCase());
		if (subCommand == null) {
			return null;
		}
		list = subCommand.onTabComplete(sender, Arrays.copyOfRange(args, 1, args.length));
	}

	if (list == null || list.isEmpty()) {
		return null;
	}
	List<String> result = new ArrayList<>();
	StringUtil.copyPartialMatches(args[args.length - 1], list, result);
	return result;
}
 
開發者ID:jiongjionger,項目名稱:NeverLag,代碼行數:21,代碼來源:CommandDispatcher.java

示例9: tabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) 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 == 1) {
        List<String> completions = new ArrayList<String>();
        for (OfflinePlayer player : Bukkit.getOfflinePlayers()) {
            String playerName = player.getName();
            if (player.isOp() && StringUtil.startsWithIgnoreCase(playerName, args[0])) {
                completions.add(playerName);
            }
        }
        return completions;
    }
    return ImmutableList.of();
}
 
開發者ID:CyberdyneCC,項目名稱:Thermos-Bukkit,代碼行數:19,代碼來源:DeopCommand.java

示例10: tabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) 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 == 1) {
        return StringUtil.copyPartialMatches(args[0], Arrays.asList(getGameWorld(sender).getGameRules()), new ArrayList<String>());
    }

    if (args.length == 2) {
        return StringUtil.copyPartialMatches(args[1], GAMERULE_STATES, new ArrayList<String>(GAMERULE_STATES.size()));
    }

    return ImmutableList.of();
}
 
開發者ID:CyberdyneCC,項目名稱:Thermos-Bukkit,代碼行數:17,代碼來源:GameRuleCommand.java

示例11: tabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) 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 == 1) {
        return super.tabComplete(sender, alias, args);
    }

    if (args.length == 2) {
        return StringUtil.copyPartialMatches(args[1], ENCHANTMENT_NAMES, new ArrayList<String>(ENCHANTMENT_NAMES.size()));
    }

    if (args.length == 3 || args.length == 4) {
        if (!args[args.length - 2].equalsIgnoreCase("force")) {
            return ImmutableList.of("force");
        }
    }

    return ImmutableList.of();
 }
 
開發者ID:CyberdyneCC,項目名稱:Thermos-Bukkit,代碼行數:23,代碼來源:EnchantCommand.java

示例12: tabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@Override
public List<String> tabComplete(CommandSender sender, String alias, String[] args) 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 == 1) {
        List<String> completions = new ArrayList<String>();
        for (OfflinePlayer player : Bukkit.getBannedPlayers()) {
            String name = player.getName();
            if (StringUtil.startsWithIgnoreCase(name, args[0])) {
                completions.add(name);
            }
        }
        return completions;
    }
    return ImmutableList.of();
}
 
開發者ID:CyberdyneCC,項目名稱:Thermos-Bukkit,代碼行數:19,代碼來源:PardonCommand.java

示例13: tabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@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>();
        String toComplete = args[0].toLowerCase();
        for (Plugin plugin : Bukkit.getPluginManager().getPlugins()) {
            if (StringUtil.startsWithIgnoreCase(plugin.getName(), toComplete)) {
                completions.add(plugin.getName());
            }
        }
        return completions;
    }
    return ImmutableList.of();
}
 
開發者ID:CyberdyneCC,項目名稱:Thermos-Bukkit,代碼行數:19,代碼來源:VersionCommand.java

示例14: tabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
/**
 * Executed on tab completion for this command, returning a list of
 * options the player can tab through.
 *
 * @param sender Source object which is executing this command
 * @param alias the alias being used
 * @param args All arguments passed to the command, split via ' '
 * @return a list of tab-completions for the specified arguments. This
 *     will never be null. List may be immutable.
 * @throws IllegalArgumentException if sender, alias, or args is null
 */
public List<String> tabComplete(CommandSender sender, String alias, String[] args) 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;
}
 
開發者ID:CyberdyneCC,項目名稱:Thermos-Bukkit,代碼行數:36,代碼來源:Command.java

示例15: onTabComplete

import org.bukkit.util.StringUtil; //導入依賴的package包/類
@Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player)) {
        return null;
    }

    List<String> list = new ArrayList<>();

    if (args.length == 1) {
        List<String> ench = new ArrayList<>();
        for (Enchantment enchantment : Enchantment.values()) {
            ench.add(enchantment.getName());
        }
        StringUtil.copyPartialMatches(args[0], ench, list);
    }

    Collections.sort(list);

    return list;
}
 
開發者ID:tckz916,項目名稱:Mapper_2,代碼行數:21,代碼來源:EnchantmentTabComplete.java


注:本文中的org.bukkit.util.StringUtil類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。