本文整理匯總了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();
}
示例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());
}
}
示例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());
}
示例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;
}
示例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();
}
示例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();
}
示例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());
}
示例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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}