fabric: use interfaces for entity selectors
This commit is contained in:
parent
69b2e52e49
commit
9e9a9d79d8
5 changed files with 142 additions and 169 deletions
|
|
@ -54,6 +54,7 @@ import net.minecraft.command.argument.Vec2ArgumentType;
|
||||||
import net.minecraft.command.argument.Vec3ArgumentType;
|
import net.minecraft.command.argument.Vec3ArgumentType;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
@ -159,7 +160,7 @@ public final class FabricArgumentParsers {
|
||||||
.map((ctx, entitySelector) -> requireServerCommandSource(
|
.map((ctx, entitySelector) -> requireServerCommandSource(
|
||||||
ctx,
|
ctx,
|
||||||
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
||||||
() -> ArgumentParseResult.success(new SinglePlayerSelector(
|
() -> ArgumentParseResult.success(new SinglePlayerSelectorImpl(
|
||||||
((EntitySelectorAccess) entitySelector).inputString(),
|
((EntitySelectorAccess) entitySelector).inputString(),
|
||||||
entitySelector,
|
entitySelector,
|
||||||
entitySelector.getPlayer(serverCommandSource)
|
entitySelector.getPlayer(serverCommandSource)
|
||||||
|
|
@ -180,7 +181,7 @@ public final class FabricArgumentParsers {
|
||||||
.map((ctx, entitySelector) -> requireServerCommandSource(
|
.map((ctx, entitySelector) -> requireServerCommandSource(
|
||||||
ctx,
|
ctx,
|
||||||
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
||||||
() -> ArgumentParseResult.success(new MultiplePlayerSelector(
|
() -> ArgumentParseResult.success(new MultiplePlayerSelectorImpl(
|
||||||
((EntitySelectorAccess) entitySelector).inputString(),
|
((EntitySelectorAccess) entitySelector).inputString(),
|
||||||
entitySelector,
|
entitySelector,
|
||||||
entitySelector.getPlayers(serverCommandSource)
|
entitySelector.getPlayers(serverCommandSource)
|
||||||
|
|
@ -201,7 +202,7 @@ public final class FabricArgumentParsers {
|
||||||
.map((ctx, entitySelector) -> requireServerCommandSource(
|
.map((ctx, entitySelector) -> requireServerCommandSource(
|
||||||
ctx,
|
ctx,
|
||||||
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
||||||
() -> ArgumentParseResult.success(new SingleEntitySelector(
|
() -> ArgumentParseResult.success(new SingleEntitySelectorImpl(
|
||||||
((EntitySelectorAccess) entitySelector).inputString(),
|
((EntitySelectorAccess) entitySelector).inputString(),
|
||||||
entitySelector,
|
entitySelector,
|
||||||
entitySelector.getEntity(serverCommandSource)
|
entitySelector.getEntity(serverCommandSource)
|
||||||
|
|
@ -222,7 +223,7 @@ public final class FabricArgumentParsers {
|
||||||
.map((ctx, entitySelector) -> requireServerCommandSource(
|
.map((ctx, entitySelector) -> requireServerCommandSource(
|
||||||
ctx,
|
ctx,
|
||||||
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
|
||||||
() -> ArgumentParseResult.success(new MultipleEntitySelector(
|
() -> ArgumentParseResult.success(new MultipleEntitySelectorImpl(
|
||||||
((EntitySelectorAccess) entitySelector).inputString(),
|
((EntitySelectorAccess) entitySelector).inputString(),
|
||||||
entitySelector,
|
entitySelector,
|
||||||
Collections.unmodifiableCollection(entitySelector.getEntities(serverCommandSource))
|
Collections.unmodifiableCollection(entitySelector.getEntities(serverCommandSource))
|
||||||
|
|
@ -360,7 +361,7 @@ public final class FabricArgumentParsers {
|
||||||
private final ServerCommandSource source;
|
private final ServerCommandSource source;
|
||||||
private final PosArgument posArgument;
|
private final PosArgument posArgument;
|
||||||
|
|
||||||
private CoordinatesImpl(final @NonNull ServerCommandSource source, final @NonNull PosArgument posArgument) {
|
CoordinatesImpl(final @NonNull ServerCommandSource source, final @NonNull PosArgument posArgument) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
this.posArgument = posArgument;
|
this.posArgument = posArgument;
|
||||||
}
|
}
|
||||||
|
|
@ -397,4 +398,136 @@ public final class FabricArgumentParsers {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static final class SingleEntitySelectorImpl implements SingleEntitySelector {
|
||||||
|
|
||||||
|
private final String inputString;
|
||||||
|
private final EntitySelector entitySelector;
|
||||||
|
private final Entity selectedEntity;
|
||||||
|
|
||||||
|
SingleEntitySelectorImpl(
|
||||||
|
final @NonNull String inputString,
|
||||||
|
final @NonNull EntitySelector entitySelector,
|
||||||
|
final @NonNull Entity selectedEntity
|
||||||
|
) {
|
||||||
|
this.inputString = inputString;
|
||||||
|
this.entitySelector = entitySelector;
|
||||||
|
this.selectedEntity = selectedEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull String getInput() {
|
||||||
|
return this.inputString;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull EntitySelector getSelector() {
|
||||||
|
return this.entitySelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Entity getSingle() {
|
||||||
|
return this.selectedEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class MultipleEntitySelectorImpl implements MultipleEntitySelector {
|
||||||
|
|
||||||
|
private final String inputString;
|
||||||
|
private final EntitySelector entitySelector;
|
||||||
|
private final Collection<Entity> selectedEntities;
|
||||||
|
|
||||||
|
MultipleEntitySelectorImpl(
|
||||||
|
final @NonNull String inputString,
|
||||||
|
final @NonNull EntitySelector entitySelector,
|
||||||
|
final @NonNull Collection<Entity> selectedEntities
|
||||||
|
) {
|
||||||
|
this.inputString = inputString;
|
||||||
|
this.entitySelector = entitySelector;
|
||||||
|
this.selectedEntities = selectedEntities;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull String getInput() {
|
||||||
|
return this.inputString;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull EntitySelector getSelector() {
|
||||||
|
return this.entitySelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Collection<Entity> get() {
|
||||||
|
return this.selectedEntities;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class SinglePlayerSelectorImpl implements SinglePlayerSelector {
|
||||||
|
|
||||||
|
private final String inputString;
|
||||||
|
private final EntitySelector entitySelector;
|
||||||
|
private final ServerPlayerEntity selectedPlayer;
|
||||||
|
|
||||||
|
SinglePlayerSelectorImpl(
|
||||||
|
final @NonNull String inputString,
|
||||||
|
final @NonNull EntitySelector entitySelector,
|
||||||
|
final @NonNull ServerPlayerEntity selectedPlayer
|
||||||
|
) {
|
||||||
|
this.inputString = inputString;
|
||||||
|
this.entitySelector = entitySelector;
|
||||||
|
this.selectedPlayer = selectedPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull String getInput() {
|
||||||
|
return this.inputString;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull EntitySelector getSelector() {
|
||||||
|
return this.entitySelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull ServerPlayerEntity getSingle() {
|
||||||
|
return this.selectedPlayer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class MultiplePlayerSelectorImpl implements MultiplePlayerSelector {
|
||||||
|
|
||||||
|
private final String inputString;
|
||||||
|
private final EntitySelector entitySelector;
|
||||||
|
private final Collection<ServerPlayerEntity> selectedPlayers;
|
||||||
|
|
||||||
|
MultiplePlayerSelectorImpl(
|
||||||
|
final @NonNull String inputString,
|
||||||
|
final @NonNull EntitySelector entitySelector,
|
||||||
|
final @NonNull Collection<ServerPlayerEntity> selectedPlayers
|
||||||
|
) {
|
||||||
|
this.inputString = inputString;
|
||||||
|
this.entitySelector = entitySelector;
|
||||||
|
this.selectedPlayers = selectedPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull String getInput() {
|
||||||
|
return this.inputString;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull EntitySelector getSelector() {
|
||||||
|
return this.entitySelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NonNull Collection<ServerPlayerEntity> get() {
|
||||||
|
return this.selectedPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,54 +23,13 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.data;
|
package cloud.commandframework.fabric.data;
|
||||||
|
|
||||||
import net.minecraft.command.EntitySelector;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A selector for multiple entities.
|
* A selector for multiple entities.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class MultipleEntitySelector implements Selector<Entity> {
|
public interface MultipleEntitySelector extends Selector<Entity> {
|
||||||
|
|
||||||
private final String inputString;
|
|
||||||
private final net.minecraft.command.EntitySelector entitySelector;
|
|
||||||
private final Collection<Entity> selectedEntities;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new MultipleEntitySelector.
|
|
||||||
*
|
|
||||||
* @param inputString input string
|
|
||||||
* @param entitySelector entity selector
|
|
||||||
* @param selectedEntities selected entities
|
|
||||||
* @since 1.5.0
|
|
||||||
*/
|
|
||||||
public MultipleEntitySelector(
|
|
||||||
final @NonNull String inputString,
|
|
||||||
final @NonNull EntitySelector entitySelector,
|
|
||||||
final @NonNull Collection<Entity> selectedEntities
|
|
||||||
) {
|
|
||||||
this.inputString = inputString;
|
|
||||||
this.entitySelector = entitySelector;
|
|
||||||
this.selectedEntities = selectedEntities;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull String getInput() {
|
|
||||||
return this.inputString;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull EntitySelector getSelector() {
|
|
||||||
return this.entitySelector;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull Collection<Entity> get() {
|
|
||||||
return this.selectedEntities;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,54 +23,13 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.data;
|
package cloud.commandframework.fabric.data;
|
||||||
|
|
||||||
import net.minecraft.command.EntitySelector;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A selector for multiple players.
|
* A selector for multiple players.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class MultiplePlayerSelector implements Selector<ServerPlayerEntity> {
|
public interface MultiplePlayerSelector extends Selector<ServerPlayerEntity> {
|
||||||
|
|
||||||
private final String inputString;
|
|
||||||
private final EntitySelector entitySelector;
|
|
||||||
private final Collection<ServerPlayerEntity> selectedPlayers;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new MultiplePlayerSelector.
|
|
||||||
*
|
|
||||||
* @param inputString input string
|
|
||||||
* @param entitySelector entity selector
|
|
||||||
* @param selectedPlayers selected players
|
|
||||||
* @since 1.5.0
|
|
||||||
*/
|
|
||||||
public MultiplePlayerSelector(
|
|
||||||
final @NonNull String inputString,
|
|
||||||
final @NonNull EntitySelector entitySelector,
|
|
||||||
final @NonNull Collection<ServerPlayerEntity> selectedPlayers
|
|
||||||
) {
|
|
||||||
this.inputString = inputString;
|
|
||||||
this.entitySelector = entitySelector;
|
|
||||||
this.selectedPlayers = selectedPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull String getInput() {
|
|
||||||
return this.inputString;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull EntitySelector getSelector() {
|
|
||||||
return this.entitySelector;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull Collection<ServerPlayerEntity> get() {
|
|
||||||
return this.selectedPlayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,52 +23,13 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.data;
|
package cloud.commandframework.fabric.data;
|
||||||
|
|
||||||
import net.minecraft.command.EntitySelector;
|
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A selector for a single entity.
|
* A selector for a single entity.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class SingleEntitySelector implements Selector.Single<Entity> {
|
public interface SingleEntitySelector extends Selector.Single<Entity> {
|
||||||
|
|
||||||
private final String inputString;
|
|
||||||
private final EntitySelector entitySelector;
|
|
||||||
private final Entity selectedEntity;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new SingleEntitySelector.
|
|
||||||
*
|
|
||||||
* @param inputString input string
|
|
||||||
* @param entitySelector entity selector
|
|
||||||
* @param selectedEntity selected entity
|
|
||||||
* @since 1.5.0
|
|
||||||
*/
|
|
||||||
public SingleEntitySelector(
|
|
||||||
final @NonNull String inputString,
|
|
||||||
final @NonNull EntitySelector entitySelector,
|
|
||||||
final @NonNull Entity selectedEntity
|
|
||||||
) {
|
|
||||||
this.inputString = inputString;
|
|
||||||
this.entitySelector = entitySelector;
|
|
||||||
this.selectedEntity = selectedEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull String getInput() {
|
|
||||||
return this.inputString;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull EntitySelector getSelector() {
|
|
||||||
return this.entitySelector;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull Entity getSingle() {
|
|
||||||
return this.selectedEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,52 +23,13 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.fabric.data;
|
package cloud.commandframework.fabric.data;
|
||||||
|
|
||||||
import net.minecraft.command.EntitySelector;
|
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A selector for a single player.
|
* A selector for a single player.
|
||||||
*
|
*
|
||||||
* @since 1.5.0
|
* @since 1.5.0
|
||||||
*/
|
*/
|
||||||
public final class SinglePlayerSelector implements Selector.Single<ServerPlayerEntity> {
|
public interface SinglePlayerSelector extends Selector.Single<ServerPlayerEntity> {
|
||||||
|
|
||||||
private final String inputString;
|
|
||||||
private final EntitySelector entitySelector;
|
|
||||||
private final ServerPlayerEntity selectedPlayer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new SinglePlayerSelector.
|
|
||||||
*
|
|
||||||
* @param inputString input string
|
|
||||||
* @param entitySelector entity selector
|
|
||||||
* @param selectedPlayer selected player
|
|
||||||
* @since 1.5.0
|
|
||||||
*/
|
|
||||||
public SinglePlayerSelector(
|
|
||||||
final @NonNull String inputString,
|
|
||||||
final @NonNull EntitySelector entitySelector,
|
|
||||||
final @NonNull ServerPlayerEntity selectedPlayer
|
|
||||||
) {
|
|
||||||
this.inputString = inputString;
|
|
||||||
this.entitySelector = entitySelector;
|
|
||||||
this.selectedPlayer = selectedPlayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull String getInput() {
|
|
||||||
return this.inputString;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull EntitySelector getSelector() {
|
|
||||||
return this.entitySelector;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull ServerPlayerEntity getSingle() {
|
|
||||||
return this.selectedPlayer;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue