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) {
}
}
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);
}
Aggregations