Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	bukkit/src/main/java/revxrsal/commands/bukkit/brigadier/PaperCommodore.java
  • Loading branch information
Revxrsal committed Jan 1, 2024
2 parents 4b39a6b + 460ed5e commit 0fd6615
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ subprojects {
apply plugin: "maven-publish"

group = "io.github.revxrsal"
version = "3.1.7"
version = "3.1.8"

if (name != "velocity") {
sourceCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@
* Note that this selector ONLY works on 1.13+. Unfortunately, Bukkit provides no other
* ways for parsing selectors on older versions.
*/
public interface EntitySelector<E extends Entity> extends List<E> {}
public interface EntitySelector<E extends Entity> extends List<E> {

/**
* Checks if the selector results consists of specific entities
*/
boolean consistsOf(Entity... entities);

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,12 @@ public void action(Command<?> command) {

public Node canBeExecuted(BukkitBrigadier brigadier) {
action(a -> {
String input = stripNamespace(a.getInput());
String input = a.getInput();
ArgumentStack args = ArgumentStack.parse(
input.startsWith("/") ? input.substring(1) : input
input.indexOf('/') == 0 ? input.substring(1) : input
);
args.set(0, stripNamespace(args.getFirst()));

CommandActor actor = brigadier.wrapSource(a.getSource());
try {
brigadier.getCommandHandler().dispatch(actor, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import revxrsal.commands.bukkit.BukkitCommandHandler;
import revxrsal.commands.bukkit.core.BukkitCommandExecutor;
import revxrsal.commands.command.ArgumentStack;
import revxrsal.commands.exception.ArgumentParseException;

import java.util.Collection;
import java.util.HashMap;
Expand Down Expand Up @@ -72,14 +71,9 @@ public final class UnknownCommandListener implements Listener {

@EventHandler
public void onUnknownCommand(UnknownCommandEvent event) {
ArgumentStack args;
try {
args = ArgumentStack.parse(
stripNamespace(fallbackPrefix, event.getCommandLine())
);
} catch (ArgumentParseException e) {
return;
}
ArgumentStack args = ArgumentStack.parse(
stripNamespace(fallbackPrefix, event.getCommandLine())
);
if (commands.containsKey(args.getFirst())) {
event.message(null);
BukkitCommandActor actor = BukkitCommandActor.wrap(event.getSender(), handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public BukkitHandler(@NotNull Plugin plugin) {
getAutoCompleter().registerSuggestion("worlds", SuggestionProvider.map(Bukkit::getWorlds, World::getName));

getAutoCompleter().registerParameterSuggestions(Player.class, "players");
getAutoCompleter().registerParameterSuggestions(OfflinePlayer.class, "players");
getAutoCompleter().registerParameterSuggestions(World.class, "worlds");

getAutoCompleter().registerSuggestionFactory(SelectorSuggestionFactory.INSTANCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -136,6 +137,16 @@ public EntitySelectorImpl(List<E> entities) {
return entities;
}

@Override
public boolean consistsOf(final Entity... entities) {
if (entities.length != this.entities.size()) {
return false;
}
HashSet<Entity> set = new HashSet<>(entities.length);
Collections.addAll(set, entities);
return set.containsAll(this.entities);
}

}

public enum SelectorSuggestionFactory implements SuggestionProviderFactory {
Expand Down

0 comments on commit 0fd6615

Please sign in to comment.