Fix pre-1.13 compat

This commit is contained in:
Jason Penilla 2022-10-26 11:44:01 -07:00 committed by Jason
parent 3a0768500b
commit 82894ccdff
3 changed files with 17 additions and 6 deletions

View file

@ -27,7 +27,6 @@ import cloud.commandframework.ArgumentDescription;
import cloud.commandframework.arguments.CommandArgument;
import cloud.commandframework.bukkit.arguments.selector.MultipleEntitySelector;
import cloud.commandframework.context.CommandContext;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import java.util.List;
import java.util.function.BiFunction;
import org.apiguardian.api.API;
@ -191,10 +190,10 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
public MultipleEntitySelector mapResult(
final @NonNull String input,
final SelectorUtils.@NonNull EntitySelectorWrapper wrapper
) throws Exception {
) {
final List<Entity> entities = wrapper.entities();
if (entities.isEmpty() && !this.allowEmpty) {
throw ((SimpleCommandExceptionType) NO_ENTITIES_EXCEPTION_TYPE.get()).create();
new Thrower(NO_ENTITIES_EXCEPTION_TYPE.get()).throwIt();
}
return new MultipleEntitySelector(input, entities);
}

View file

@ -30,7 +30,6 @@ import cloud.commandframework.bukkit.arguments.selector.MultiplePlayerSelector;
import cloud.commandframework.bukkit.parsers.PlayerArgument;
import cloud.commandframework.context.CommandContext;
import com.google.common.collect.ImmutableList;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
@ -197,10 +196,10 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
public MultiplePlayerSelector mapResult(
final @NonNull String input,
final SelectorUtils.@NonNull EntitySelectorWrapper wrapper
) throws Exception {
) {
final List<Player> players = wrapper.players();
if (players.isEmpty() && !this.allowEmpty) {
throw ((SimpleCommandExceptionType) NO_PLAYERS_EXCEPTION_TYPE.get()).create();
new Thrower(NO_PLAYERS_EXCEPTION_TYPE.get()).throwIt();
}
return new MultiplePlayerSelector(input, new ArrayList<>(players));
}

View file

@ -139,6 +139,19 @@ final class SelectorUtils {
private final @Nullable ArgumentParser<C, T> modernParser;
// Hide brigadier references in inner class
protected static final class Thrower {
private final Object type;
Thrower(final Object simpleCommandExceptionType) {
this.type = simpleCommandExceptionType;
}
void throwIt() {
throw rethrow(((SimpleCommandExceptionType) this.type).create());
}
}
protected SelectorParser(
final boolean single,
final boolean playersOnly