Search in sources :

Example 1 with Command

use of com.plotsquared.core.command.Command in project PlotSquared by IntellectualSites.

the class PaperListener method onAsyncTabCompletion.

@EventHandler
public void onAsyncTabCompletion(final AsyncTabCompleteEvent event) {
    if (!Settings.Paper_Components.ASYNC_TAB_COMPLETION) {
        return;
    }
    String buffer = event.getBuffer();
    if (!(event.getSender() instanceof Player)) {
        return;
    }
    if ((!event.isCommand() && !buffer.startsWith("/")) || buffer.indexOf(' ') == -1) {
        return;
    }
    if (buffer.startsWith("/")) {
        buffer = buffer.substring(1);
    }
    final String[] unprocessedArgs = buffer.split(Pattern.quote(" "));
    if (unprocessedArgs.length == 1) {
        // We don't do anything in this case
        return;
    } else if (!Settings.Enabled_Components.TAB_COMPLETED_ALIASES.contains(unprocessedArgs[0].toLowerCase(Locale.ENGLISH))) {
        return;
    }
    final String[] args = new String[unprocessedArgs.length - 1];
    System.arraycopy(unprocessedArgs, 1, args, 0, args.length);
    try {
        final PlotPlayer<?> player = BukkitUtil.adapt((Player) event.getSender());
        final Collection<Command> objects = MainCommand.getInstance().tab(player, args, buffer.endsWith(" "));
        if (objects == null) {
            return;
        }
        final List<String> result = new ArrayList<>();
        for (final com.plotsquared.core.command.Command o : objects) {
            result.add(o.toString());
        }
        event.setCompletions(result);
        event.setHandled(true);
    } catch (final Exception ignored) {
    }
}
Also used : Player(org.bukkit.entity.Player) PlotPlayer(com.plotsquared.core.player.PlotPlayer) Command(com.plotsquared.core.command.Command) MainCommand(com.plotsquared.core.command.MainCommand) ArrayList(java.util.ArrayList) Command(com.plotsquared.core.command.Command) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Command

use of com.plotsquared.core.command.Command in project PlotSquared by IntellectualSites.

the class TabCompletions method completeAreas.

/**
 * Get a list of plot areas matching the given input.
 * The list is unmodifiable.
 *
 * @param input Input to filter with
 * @return Unmodifiable list of area completions
 */
@NonNull
public static List<Command> completeAreas(@NonNull final String input) {
    final List<Command> completions = new ArrayList<>();
    for (final PlotArea area : PlotSquared.get().getPlotAreaManager().getAllPlotAreas()) {
        String areaName = area.getWorldName();
        if (area.getId() != null) {
            areaName += ";" + area.getId();
        }
        if (!areaName.toLowerCase().startsWith(input.toLowerCase())) {
            continue;
        }
        completions.add(new Command(null, false, areaName, "", RequiredType.NONE, null) {
        });
    }
    return Collections.unmodifiableList(completions);
}
Also used : PlotArea(com.plotsquared.core.plot.PlotArea) Command(com.plotsquared.core.command.Command) ArrayList(java.util.ArrayList) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Aggregations

Command (com.plotsquared.core.command.Command)2 ArrayList (java.util.ArrayList)2 MainCommand (com.plotsquared.core.command.MainCommand)1 PlotPlayer (com.plotsquared.core.player.PlotPlayer)1 PlotArea (com.plotsquared.core.plot.PlotArea)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 NonNull (org.checkerframework.checker.nullness.qual.NonNull)1