Java 类org.bukkit.event.server.TabCompleteEvent 实例源码

项目:Kineticraft    文件:Commands.java   
@EventHandler // Handles command-specific tab-completes.
public void onArgsComplete(TabCompleteEvent evt) {
    String input = evt.getBuffer();
    String label = input.split(" ")[0];
    boolean console = evt.getSender() instanceof ConsoleCommandSender;

    Command cmd = getUsable(evt.getSender()).stream()
            .filter(c -> !c.getCommandPrefix().contains(" ") && label.length() >= c.getCommandPrefix().length()) // Don't count /trigger
            .filter(c -> c.getAlias().contains(console ? label : label.substring(c.getCommandPrefix().length())))
            .findAny().orElse(null); // Get the command for the input supplied.

    if (!input.contains(" ") || cmd == null)
        return; // No command was found.

    String[] args = Utils.shift(input.split(" "));
    String lastArg = (args.length > 0 ? args[args.length - 1] : "").toLowerCase();
    boolean space = input.endsWith(" ");

    List<String> possible = cmd.getCompletions(evt.getSender(), args, args.length + (space ? 1 : 0) - 1);
    evt.setCompletions(possible.stream().filter(ac -> ac.toLowerCase().startsWith(lastArg) || space).collect(Collectors.toList()));
}
项目:McLink    文件:Chat.java   
@EventHandler
public void onTabList(TabCompleteEvent event) {
    if (!(event.getSender() instanceof Player))
        return;
    for (String s : event.getCompletions()) {
        Player ap = PlayerUtil.getPlayer(s);
        if (ap == null)
            continue;
        if (!((Player) event.getSender()).canSee(ap))
            event.getCompletions().remove(s);
    }
    if (event.getBuffer().startsWith("/")) {
        String[] a = event.getBuffer().substring(1).split(Pattern.quote(" "));
        Command c = Commands.getCommandMap().getCommand(a[0]);
        for (Tabby t : Tabby.tabbys) {
            String[] args = Arrays.copyOfRange(a, 1, a.length);
            List<String> cs = t.onTabComplete(event.getSender(), c, a[0], args);
            if (cs != null && !cs.isEmpty())
                event.setCompletions(cs);
        }
    }
}
项目:MundoSK    文件:ExprCompletions.java   
@Override
public void set(Event event, String[] value) {
    if (event instanceof PlayerChatTabCompleteEvent) {
        Collection<String> completions = ((PlayerChatTabCompleteEvent) event).getTabCompletions();
        ArrayList<String> newcompletions = new ArrayList<String>(Arrays.asList(value));
        String[] completionsarray = completions.toArray(new String[0]);
        for (int i = 0; i < completionsarray.length; i++) {
            if (newcompletions.contains(completionsarray[i])) {
                newcompletions.remove(completionsarray[i]);
            } else {
                completions.remove(completionsarray[i]);
            }
        }
        for (int i = 0; i < newcompletions.size(); i++) {
            completions.add(newcompletions.get(i));
        }
    } else if (event instanceof TabCompleteEvent) {
        ((TabCompleteEvent) event).setCompletions(Arrays.asList(value));
    }
}
项目:SpigotSource    文件:CraftServer.java   
public List<String> tabComplete(net.minecraft.server.ICommandListener sender, String message) {
    if (!(sender instanceof EntityPlayer)) {
        return ImmutableList.of();
    }

    List<String> offers;
    Player player = ((EntityPlayer) sender).getBukkitEntity();
    if (message.startsWith("/")) {
        offers = tabCompleteCommand(player, message);
    } else {
        offers = tabCompleteChat(player, message);
    }

    TabCompleteEvent tabEvent = new TabCompleteEvent(player, message, offers);
    getPluginManager().callEvent(tabEvent);

    return tabEvent.isCancelled() ? Collections.EMPTY_LIST : tabEvent.getCompletions();
}
项目:Kineticraft    文件:Commands.java   
@EventHandler // Handles populating the command list for all commands.
public void onTabComplete(TabCompleteEvent evt) {
    boolean console = evt.getSender() instanceof ConsoleCommandSender;
    for (Command c : getUsable(evt.getSender()))
        c.getAlias().stream().map(a -> (console ? "" : c.getCommandPrefix()) + a).filter(l -> l.startsWith(evt.getBuffer()))
                .filter(l -> Utils.getCount(l, " ") == Utils.getCount(evt.getBuffer(), " "))
                .map(l -> l.substring(l.lastIndexOf(" ") + 1)).forEach(evt.getCompletions()::add);
}
项目:Kineticraft    文件:Vanish.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onSendTabCompletes(TabCompleteEvent evt) {
    if (Utils.getRank(evt.getSender()).isStaff()) // Remove vanished players from non-staff view.
        return;

    List<String> completes = new ArrayList<>(evt.getCompletions());
    Core.getHiddenPlayers().stream().map(Player::getName).forEach(completes::remove);
    evt.setCompletions(completes);
}
项目:MundoSK    文件:MiscMundo.java   
private static void loadTabCompletion() {
    Registration.registerEvent("Chat Tab Complete Event", SimpleEvent.class, PlayerChatTabCompleteEvent.class, "chat tab complete")
            .document("Chat Tab Complete", "1.8", "Called when a player uses tab to auto complete a message (not a command). "
                    + "Also see the Completions and Last Token expressions.")
            .eventValue(String.class, "1.8", "The full message so far typed by the player.");
    Registration.registerEventValue(PlayerChatTabCompleteEvent.class, String.class, PlayerChatTabCompleteEvent::getChatMessage);
    if (Reflection.classExists("org.bukkit.event.server.TabCompleteEvent")) {
        Registration.registerEvent("Tab Complete Event", SimpleEvent.class, TabCompleteEvent.class, "tab complete")
                .document("Tab Complete", "1.8", "Called when a player uses tab to auto complete a message or a command. "
                        + "Only available in recent Bukkit versions. Also see the Completions and Last Token expressions.")
                .eventValue(String.class, "1.8", "The full message so far typed by the player.");
        Registration.registerEventValue(TabCompleteEvent.class, String.class, TabCompleteEvent::getBuffer);
        Registration.registerExpression(ExprCompletions.class,String.class,ExpressionType.SIMPLE,"completions")
                .document("Completions", "1.6.8", "An editable expression, used in the Tab Complete and Chat Tab Complete events, "
                        + "for a list of all completions available for this tab complete.");
        Registration.registerExpression(ExprLastToken.class, String.class, ExpressionType.SIMPLE, "last token")
                .document("Last Token", "1.6.8", "An expression, used in the Tab Complete and Chat Tab Complete events, "
                        + "for the last token typed by the player before tab completing.");
    } else {
        Registration.registerExpression(ExprCompletionsOld.class,String.class,ExpressionType.SIMPLE,"completions")
                .document("Completions", "1.6.8", "An editable expression, used in the Chat Tab Complete event, "
                        + "for a list of all completions available for this tab complete.");
        Registration.registerExpression(ExprLastTokenOld.class, String.class, ExpressionType.SIMPLE, "last token")
                .document("Last Token", "1.6.8", "An expression, used in the Chat Tab Complete event, "
                        + "for the last token typed by the player before tab completing.");
    }
}
项目:MundoSK    文件:ExprLastToken.java   
@Override
protected String[] get(Event event) {
    if (event instanceof PlayerChatTabCompleteEvent) {
        return new String[]{((PlayerChatTabCompleteEvent) event).getLastToken()};
    } else if (event instanceof TabCompleteEvent) {
        String buffer = ((TabCompleteEvent) event).getBuffer();
        if (buffer.endsWith(" ")) {
            return new String[]{""};
        }
        String[] tokens = buffer.split(" ");
        return new String[]{tokens[tokens.length - 1]};
    }
    return null;
}
项目:MundoSK    文件:ExprLastToken.java   
@Override
public boolean init(Expression<?>[] expressions, int i, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
    if (!ScriptLoader.isCurrentEvent(PlayerChatTabCompleteEvent.class) && !ScriptLoader.isCurrentEvent(TabCompleteEvent.class)) {
        Skript.error("The 'last token' expression can only be used in the 'on chat tab complete' event and the 'on tab complete' event!");
        return false;
    }
    return true;
}
项目:MundoSK    文件:ExprCompletions.java   
@Override
protected String[] get(Event event) {
    if (event instanceof PlayerChatTabCompleteEvent) {
        return ((PlayerChatTabCompleteEvent) event).getTabCompletions().toArray(new String[0]);
    } else if (event instanceof TabCompleteEvent) {
        return ((TabCompleteEvent) event).getCompletions().toArray(new String[0]);
    }
    return new String[0];
}
项目:MundoSK    文件:ExprCompletions.java   
@Override
public boolean subInit(Expression<?>[] expression, int matchedPattern, Kleenean kleenean, SkriptParser.ParseResult parseResult) {
    if (!ScriptLoader.isCurrentEvent(PlayerChatTabCompleteEvent.class) && !ScriptLoader.isCurrentEvent(TabCompleteEvent.class)) {
        Skript.error("The 'completions' expression can only be used in the 'on chat tab complete' event or the 'on tab complete' event!");
        return false;
    }
    return true;
}
项目:Kineticraft    文件:Commands.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onSendTabCompletes(TabCompleteEvent evt) {
    Utils.removeDuplicates(evt.getCompletions()); // Remove duplicate entries, if any.
}