fabric: Remove unfinished argument types, add some javadoc, fix checkstyle issues
This commit is contained in:
parent
78e7146ba3
commit
d72558ee81
20 changed files with 145 additions and 416 deletions
|
|
@ -100,6 +100,7 @@
|
|||
<module name="LineLength">
|
||||
<property name="fileExtensions" value="java"/>
|
||||
<property name="max" value="140"/>
|
||||
<property name="ignorePattern" value="^ *\* "/> <!-- Ignore long JavaDoc lines (i.e. a link) -->
|
||||
</module>
|
||||
|
||||
<!-- Checks for whitespace -->
|
||||
|
|
|
|||
|
|
@ -206,7 +206,6 @@ public abstract class FabricCommandManager<C, S extends CommandSource> extends C
|
|||
|
||||
/* Wrapped brigadier requiring parameters */
|
||||
// score holder: single vs multiple
|
||||
// entity argument type: single or multiple, players or any entity -- returns EntitySelector, but do we want that?
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
|
|
|
|||
|
|
@ -73,17 +73,12 @@ public final class FabricArgumentParsers {
|
|||
.map((ctx, val) -> ArgumentParseResult.success(MinecraftTime.of(val)));
|
||||
}
|
||||
|
||||
/*
|
||||
public static <C> ArgumentParser<C, CommandFunction> commandFunction() {
|
||||
// TODO: Should probably write our own parser for this, it's either Identifier or tag.
|
||||
// Server parsers
|
||||
return new WrappedBrigadierParser<C, FunctionArgumentType.FunctionArgument>(FunctionArgumentType.function()).map((ctx, val) -> {
|
||||
final CommandSource source = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
|
||||
source.getCompletions()
|
||||
})
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* A parser for {@link SinglePlayerSelector}.
|
||||
*
|
||||
* @param <C> sender type
|
||||
* @return a parser instance
|
||||
*/
|
||||
public static <C> ArgumentParser<C, SinglePlayerSelector> singlePlayerSelector() {
|
||||
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.player())
|
||||
.map((ctx, entitySelector) -> {
|
||||
|
|
@ -103,6 +98,12 @@ public final class FabricArgumentParsers {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A parser for {@link MultiplePlayerSelector}.
|
||||
*
|
||||
* @param <C> sender type
|
||||
* @return a parser instance
|
||||
*/
|
||||
public static <C> ArgumentParser<C, MultiplePlayerSelector> multiplePlayerSelector() {
|
||||
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.players())
|
||||
.map((ctx, entitySelector) -> {
|
||||
|
|
@ -122,6 +123,12 @@ public final class FabricArgumentParsers {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A parser for {@link SingleEntitySelector}.
|
||||
*
|
||||
* @param <C> sender type
|
||||
* @return a parser instance
|
||||
*/
|
||||
public static <C> ArgumentParser<C, SingleEntitySelector> singleEntitySelector() {
|
||||
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entity())
|
||||
.map((ctx, entitySelector) -> {
|
||||
|
|
@ -141,6 +148,12 @@ public final class FabricArgumentParsers {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A parser for {@link MultipleEntitySelector}.
|
||||
*
|
||||
* @param <C> sender type
|
||||
* @return a parser instance
|
||||
*/
|
||||
public static <C> ArgumentParser<C, MultipleEntitySelector> multipleEntitySelector() {
|
||||
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgumentType.entities())
|
||||
.map((ctx, entitySelector) -> {
|
||||
|
|
@ -160,6 +173,12 @@ public final class FabricArgumentParsers {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* A parser for {@link Message}.
|
||||
*
|
||||
* @param <C> sender type
|
||||
* @return a parser instance
|
||||
*/
|
||||
public static <C> ArgumentParser<C, Message> message() {
|
||||
return new WrappedBrigadierParser<C, MessageArgumentType.MessageFormat>(MessageArgumentType.message())
|
||||
.map((ctx, format) -> {
|
||||
|
|
@ -214,12 +233,12 @@ public final class FabricArgumentParsers {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Collection<Entity> getMentionedEntities() {
|
||||
public @NonNull Collection<Entity> getMentionedEntities() {
|
||||
return this.mentionedEntities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Text getContents() {
|
||||
public @NonNull Text getContents() {
|
||||
return this.contents;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -94,21 +94,6 @@ public final class ScoreboardOperationArgument<C> extends CommandArgument<C, Ope
|
|||
return ScoreboardOperationArgument.<C>newBuilder(name).asOptional().build();
|
||||
}
|
||||
|
||||
/* (todo: there's no way to get a parseable form from an unknown Operation)
|
||||
* Create a new optional command argument with a default value
|
||||
*
|
||||
* @param name Argument name
|
||||
* @param defaultTag Default tag value
|
||||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
*
|
||||
public static <C> @NonNull ScoreboardOperationArgument<C> optional(
|
||||
final @NonNull String name,
|
||||
final Operation defaultTag
|
||||
) {
|
||||
return ScoreboardOperationArgument.<C>newBuilder(name).asOptionalWithDefault(defaultTag.toString()).build();
|
||||
}*/
|
||||
|
||||
public static final class Builder<C> extends TypedBuilder<C, Operation, Builder<C>> {
|
||||
|
||||
Builder(final @NonNull String name) {
|
||||
|
|
|
|||
|
|
@ -25,11 +25,8 @@
|
|||
package cloud.commandframework.fabric.argument;
|
||||
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.fabric.data.MinecraftTime;
|
||||
import net.minecraft.command.argument.TimeArgumentType;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
|
|
@ -87,7 +84,7 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
|
|||
*
|
||||
* @param name Component name
|
||||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull TimeArgument<C> optional(final @NonNull String name) {
|
||||
return TimeArgument.<C>newBuilder(name).asOptional().build();
|
||||
|
|
@ -97,7 +94,7 @@ public final class TimeArgument<C> extends CommandArgument<C, MinecraftTime> {
|
|||
* Create a new optional command argument with a default value
|
||||
*
|
||||
* @param name Argument name
|
||||
* @param defaultTime Default time, in ticks
|
||||
* @param defaultTime Default time, in ticks
|
||||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,313 +0,0 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2021 Alexander Söderberg & Contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
package cloud.commandframework.fabric.argument.server;
|
||||
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||
import cloud.commandframework.captions.CaptionVariable;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.ParserException;
|
||||
import cloud.commandframework.fabric.FabricCaptionKeys;
|
||||
import cloud.commandframework.fabric.FabricCommandContextKeys;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import io.leangen.geantyref.TypeToken;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.server.function.CommandFunction;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
/**
|
||||
* Get a value from a registry.
|
||||
*
|
||||
* <p>Both static and dynamic registries are supported.</p>
|
||||
*
|
||||
* @param <C> the command sender type
|
||||
* @since 1.4.0
|
||||
*/
|
||||
public class CommandFunctionArgument<C> extends CommandArgument<C, CommandFunction> {
|
||||
|
||||
CommandFunctionArgument(
|
||||
final boolean required,
|
||||
final @NonNull String name,
|
||||
final @NonNull RegistryKey<? extends Registry<V>> registry,
|
||||
final @NonNull String defaultValue,
|
||||
final @NonNull TypeToken<V> valueType,
|
||||
final @Nullable BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider
|
||||
) {
|
||||
super(required, name, new RegistryEntryParser<>(registry), defaultValue, valueType, suggestionsProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder.
|
||||
*
|
||||
* @param name Name of the argument
|
||||
* @param type The type of registry entry
|
||||
* @param registry A key for the registry to get values from
|
||||
* @param <C> Command sender type
|
||||
* @param <V> Registry entry type
|
||||
* @return Created builder
|
||||
*/
|
||||
public static <C, V> CommandFunctionArgument.@NonNull Builder<C, V> newBuilder(
|
||||
final @NonNull String name,
|
||||
final @NonNull Class<V> type,
|
||||
final @NonNull RegistryKey<? extends Registry<V>> registry) {
|
||||
return new CommandFunctionArgument.Builder<>(registry, type, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new builder.
|
||||
*
|
||||
* @param name Name of the argument
|
||||
* @param type The type of registry entry
|
||||
* @param registry A key for the registry to get values from
|
||||
* @param <C> Command sender type
|
||||
* @param <V> Registry entry type
|
||||
* @return Created builder
|
||||
*/
|
||||
public static <C, V> CommandFunctionArgument.@NonNull Builder<C, V> newBuilder(
|
||||
final @NonNull String name,
|
||||
final @NonNull TypeToken<V> type,
|
||||
final @NonNull RegistryKey<? extends Registry<V>> registry) {
|
||||
return new CommandFunctionArgument.Builder<>(registry, type, name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new required command argument.
|
||||
*
|
||||
* @param name Argument name
|
||||
* @param type The type of registry entry
|
||||
* @param registry A key for the registry to get values from
|
||||
* @param <C> Command sender type
|
||||
* @param <V> Registry entry type
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C, V> @NonNull CommandFunctionArgument<C, V> of(
|
||||
final @NonNull String name,
|
||||
final @NonNull Class<V> type,
|
||||
final @NonNull RegistryKey<? extends Registry<V>> registry
|
||||
) {
|
||||
return CommandFunctionArgument.<C, V>newBuilder(name, type, registry).asRequired().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new optional command argument
|
||||
*
|
||||
* @param name Argument name
|
||||
* @param type The type of registry entry
|
||||
* @param registry A key for the registry to get values from
|
||||
* @param <C> Command sender type
|
||||
* @param <V> Registry entry type
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C, V> @NonNull CommandFunctionArgument<C, V> optional(
|
||||
final @NonNull String name,
|
||||
final @NonNull Class<V> type,
|
||||
final @NonNull RegistryKey<? extends Registry<V>> registry
|
||||
) {
|
||||
return CommandFunctionArgument.<C, V>newBuilder(name, type, registry).asOptional().build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new optional command argument with a default value
|
||||
*
|
||||
* @param name Argument name
|
||||
* @param type The type of registry entry
|
||||
* @param registry A key for the registry to get values from
|
||||
* @param defaultValue Default value
|
||||
* @param <C> Command sender type
|
||||
* @param <V> Registry entry type
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C, V> @NonNull CommandFunctionArgument<C, V> optional(
|
||||
final @NonNull String name,
|
||||
final @NonNull Class<V> type,
|
||||
final @NonNull RegistryKey<? extends Registry<V>> registry,
|
||||
final @NonNull RegistryKey<V> defaultValue
|
||||
) {
|
||||
return CommandFunctionArgument.<C, V>newBuilder(name, type, registry)
|
||||
.asOptionalWithDefault(defaultValue.getValue().toString())
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* A parser for values stored in a {@link Registry}
|
||||
*
|
||||
* @param <C> Command sender type
|
||||
* @param <V> Registry entry type
|
||||
*/
|
||||
public static final class RegistryEntryParser<C, V> implements ArgumentParser<C, V> {
|
||||
private final RegistryKey<? extends Registry<V>> registryIdent;
|
||||
|
||||
/**
|
||||
* Create a new parser for registry entries.
|
||||
*
|
||||
* @param registryIdent the registry identifier
|
||||
*/
|
||||
public RegistryEntryParser(final RegistryKey<? extends Registry<V>> registryIdent) {
|
||||
this.registryIdent = requireNonNull(registryIdent, "registryIdent");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ArgumentParseResult<@NonNull V> parse(
|
||||
@NonNull final CommandContext<@NonNull C> commandContext,
|
||||
@NonNull final Queue<@NonNull String> inputQueue
|
||||
) {
|
||||
final String possibleIdentifier = inputQueue.peek();
|
||||
if (possibleIdentifier == null) {
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
CommandFunctionArgument.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
|
||||
final Identifier key;
|
||||
try {
|
||||
key = Identifier.fromCommandInput(new StringReader(possibleIdentifier));
|
||||
} catch (final CommandSyntaxException ex) {
|
||||
return ArgumentParseResult.failure(ex);
|
||||
}
|
||||
inputQueue.poll();
|
||||
|
||||
final Registry<V> registry = this.getRegistry(commandContext);
|
||||
if (registry == null) {
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException("Unknown registry " + this.registryIdent));
|
||||
}
|
||||
|
||||
final V entry = registry.get(key);
|
||||
if (entry == null) {
|
||||
return ArgumentParseResult.failure(new UnknownEntryException(commandContext, key, this.registryIdent));
|
||||
}
|
||||
|
||||
return ArgumentParseResult.success(entry);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Registry<V> getRegistry(final CommandContext<C> ctx) {
|
||||
final CommandSource reverseMapped = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
|
||||
// First try dynamic registries (for things loaded from data-packs)
|
||||
Registry<V> registry = reverseMapped.getRegistryManager().getOptional(this.registryIdent).orElse(null);
|
||||
if (registry == null) {
|
||||
// And then static registries
|
||||
registry = (Registry<V>) Registry.REGISTRIES.get(this.registryIdent.getValue());
|
||||
}
|
||||
return registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<@NonNull String> suggestions(
|
||||
final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input
|
||||
) {
|
||||
final Set<Identifier> ids = this.getRegistry(commandContext).getIds();
|
||||
final List<String> results = new ArrayList<>(ids.size());
|
||||
for (final Identifier entry : ids) {
|
||||
if (entry.getNamespace().equals(NAMESPACE_MINECRAFT)) {
|
||||
results.add(entry.getPath());
|
||||
}
|
||||
results.add(entry.toString());
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContextFree() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the registry associated with this parser
|
||||
* @return the registry
|
||||
*/
|
||||
public RegistryKey<? extends Registry<?>> getRegistry() {
|
||||
return this.registryIdent;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A builder for registry entry arguments.
|
||||
*
|
||||
* @param <C> The sender type
|
||||
* @param <V> The registry value type
|
||||
*/
|
||||
public static final class Builder<C, V> extends TypedBuilder<C, V, Builder<C, V>> {
|
||||
|
||||
Builder(
|
||||
final @NonNull String name
|
||||
) {
|
||||
super(valueType, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CommandFunctionArgument<@NonNull C, @NonNull V> build() {
|
||||
return new CommandFunctionArgument<>(
|
||||
this.isRequired(),
|
||||
this.getName(),
|
||||
this.getDefaultValue(),
|
||||
this.getValueType(),
|
||||
this.getSuggestionsProvider()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An exception thrown when an entry in a registry could not be found.
|
||||
*/
|
||||
private static final class UnknownEntryException extends ParserException {
|
||||
|
||||
private static final long serialVersionUID = 7694424294461849903L;
|
||||
|
||||
UnknownEntryException(
|
||||
final CommandContext<?> context,
|
||||
final Identifier key,
|
||||
final RegistryKey<? extends Registry<?>> registry
|
||||
) {
|
||||
super(
|
||||
CommandFunctionArgument.class,
|
||||
context,
|
||||
FabricCaptionKeys.ARGUMENT_PARSE_FAILURE_REGISTRY_ENTRY_UNKNOWN_ENTRY,
|
||||
CaptionVariable.of("id", key.toString()),
|
||||
CaptionVariable.of("registry", registry.toString())
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -25,26 +25,12 @@
|
|||
package cloud.commandframework.fabric.argument.server;
|
||||
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.fabric.FabricCommandContextKeys;
|
||||
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
||||
import cloud.commandframework.fabric.data.Message;
|
||||
import cloud.commandframework.fabric.mixin.MessageArgumentTypeMessageFormatAccess;
|
||||
import cloud.commandframework.fabric.mixin.MessageArgumentTypeMessageSelectorAccess;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.argument.MessageArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
|
|
@ -99,7 +85,7 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
|
|||
*
|
||||
* @param name Component name
|
||||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull MessageArgument<C> optional(final @NonNull String name) {
|
||||
return MessageArgument.<C>newBuilder(name).asOptional().build();
|
||||
|
|
@ -108,9 +94,9 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
|
|||
/**
|
||||
* Create a new optional command argument with a default value
|
||||
*
|
||||
* @param name Argument name
|
||||
* @param name Argument name
|
||||
* @param defaultValue Default value
|
||||
* @param <C> Command sender type
|
||||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull MessageArgument<C> optional(
|
||||
|
|
@ -134,7 +120,12 @@ public final class MessageArgument<C> extends CommandArgument<C, Message> {
|
|||
*/
|
||||
@Override
|
||||
public @NonNull MessageArgument<C> build() {
|
||||
return new MessageArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
|
||||
return new MessageArgument<>(
|
||||
this.isRequired(),
|
||||
this.getName(),
|
||||
this.getDefaultValue(),
|
||||
this.getSuggestionsProvider()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,11 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
package cloud.commandframework.fabric.argument;
|
||||
package cloud.commandframework.fabric.argument.server;
|
||||
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
||||
import cloud.commandframework.fabric.data.MultipleEntitySelector;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -83,7 +84,7 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
|
|||
*
|
||||
* @param name Component name
|
||||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull MultipleEntitySelectorArgument<C> optional(final @NonNull String name) {
|
||||
return MultipleEntitySelectorArgument.<C>newBuilder(name).asOptional().build();
|
||||
|
|
@ -102,7 +103,12 @@ public final class MultipleEntitySelectorArgument<C> extends CommandArgument<C,
|
|||
*/
|
||||
@Override
|
||||
public @NonNull MultipleEntitySelectorArgument<C> build() {
|
||||
return new MultipleEntitySelectorArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
|
||||
return new MultipleEntitySelectorArgument<>(
|
||||
this.isRequired(),
|
||||
this.getName(),
|
||||
this.getDefaultValue(),
|
||||
this.getSuggestionsProvider()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -21,10 +21,11 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
package cloud.commandframework.fabric.argument;
|
||||
package cloud.commandframework.fabric.argument.server;
|
||||
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
||||
import cloud.commandframework.fabric.data.MultiplePlayerSelector;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -83,7 +84,7 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
|
|||
*
|
||||
* @param name Component name
|
||||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull MultiplePlayerSelectorArgument<C> optional(final @NonNull String name) {
|
||||
return MultiplePlayerSelectorArgument.<C>newBuilder(name).asOptional().build();
|
||||
|
|
@ -102,7 +103,12 @@ public final class MultiplePlayerSelectorArgument<C> extends CommandArgument<C,
|
|||
*/
|
||||
@Override
|
||||
public @NonNull MultiplePlayerSelectorArgument<C> build() {
|
||||
return new MultiplePlayerSelectorArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
|
||||
return new MultiplePlayerSelectorArgument<>(
|
||||
this.isRequired(),
|
||||
this.getName(),
|
||||
this.getDefaultValue(),
|
||||
this.getSuggestionsProvider()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -21,10 +21,11 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
package cloud.commandframework.fabric.argument;
|
||||
package cloud.commandframework.fabric.argument.server;
|
||||
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
||||
import cloud.commandframework.fabric.data.SingleEntitySelector;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -83,7 +84,7 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
|
|||
*
|
||||
* @param name Component name
|
||||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull SingleEntitySelectorArgument<C> optional(final @NonNull String name) {
|
||||
return SingleEntitySelectorArgument.<C>newBuilder(name).asOptional().build();
|
||||
|
|
@ -102,7 +103,12 @@ public final class SingleEntitySelectorArgument<C> extends CommandArgument<C, Si
|
|||
*/
|
||||
@Override
|
||||
public @NonNull SingleEntitySelectorArgument<C> build() {
|
||||
return new SingleEntitySelectorArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
|
||||
return new SingleEntitySelectorArgument<>(
|
||||
this.isRequired(),
|
||||
this.getName(),
|
||||
this.getDefaultValue(),
|
||||
this.getSuggestionsProvider()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -21,10 +21,11 @@
|
|||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
package cloud.commandframework.fabric.argument;
|
||||
package cloud.commandframework.fabric.argument.server;
|
||||
|
||||
import cloud.commandframework.arguments.CommandArgument;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.fabric.argument.FabricArgumentParsers;
|
||||
import cloud.commandframework.fabric.data.SinglePlayerSelector;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -83,7 +84,7 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
|
|||
*
|
||||
* @param name Component name
|
||||
* @param <C> Command sender type
|
||||
* @return Created argument
|
||||
* @return Created argument
|
||||
*/
|
||||
public static <C> @NonNull SinglePlayerSelectorArgument<C> optional(final @NonNull String name) {
|
||||
return SinglePlayerSelectorArgument.<C>newBuilder(name).asOptional().build();
|
||||
|
|
@ -102,7 +103,12 @@ public final class SinglePlayerSelectorArgument<C> extends CommandArgument<C, Si
|
|||
*/
|
||||
@Override
|
||||
public @NonNull SinglePlayerSelectorArgument<C> build() {
|
||||
return new SinglePlayerSelectorArgument<>(this.isRequired(), this.getName(), this.getDefaultValue(), this.getSuggestionsProvider());
|
||||
return new SinglePlayerSelectorArgument<>(
|
||||
this.isRequired(),
|
||||
this.getName(),
|
||||
this.getDefaultValue(),
|
||||
this.getSuggestionsProvider()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@ package cloud.commandframework.fabric.data;
|
|||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.text.Text;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
|
@ -34,8 +35,18 @@ import java.util.Collection;
|
|||
*/
|
||||
public interface Message {
|
||||
|
||||
Collection<Entity> getMentionedEntities();
|
||||
/**
|
||||
* Get the collection of entities mentioned in this message.
|
||||
*
|
||||
* @return the mentioned entities
|
||||
*/
|
||||
@NonNull Collection<Entity> getMentionedEntities();
|
||||
|
||||
Text getContents();
|
||||
/**
|
||||
* Get the parsed text contents of this message.
|
||||
*
|
||||
* @return the parsed text
|
||||
*/
|
||||
@NonNull Text getContents();
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,12 +29,22 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A selector for multiple entities.
|
||||
*/
|
||||
public final class MultipleEntitySelector implements 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
|
||||
*/
|
||||
public MultipleEntitySelector(
|
||||
final @NonNull String inputString,
|
||||
final @NonNull EntitySelector entitySelector,
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2021 Alexander Söderberg & Contributors
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
package cloud.commandframework.fabric.data;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.command.EntitySelector;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface MultipleGameProfileSelector extends Selector<GameProfile> {
|
||||
|
||||
}
|
||||
|
|
@ -29,12 +29,22 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* A selector for multiple players.
|
||||
*/
|
||||
public final class MultiplePlayerSelector implements 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
|
||||
*/
|
||||
public MultiplePlayerSelector(
|
||||
final @NonNull String inputString,
|
||||
final @NonNull EntitySelector entitySelector,
|
||||
|
|
|
|||
|
|
@ -27,12 +27,22 @@ import net.minecraft.command.EntitySelector;
|
|||
import net.minecraft.entity.Entity;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* A selector for a single entity.
|
||||
*/
|
||||
public final class SingleEntitySelector implements 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
|
||||
*/
|
||||
public SingleEntitySelector(
|
||||
final @NonNull String inputString,
|
||||
final @NonNull EntitySelector entitySelector,
|
||||
|
|
|
|||
|
|
@ -27,12 +27,22 @@ import net.minecraft.command.EntitySelector;
|
|||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* A selector for a single player.
|
||||
*/
|
||||
public final class SinglePlayerSelector implements 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
|
||||
*/
|
||||
public SinglePlayerSelector(
|
||||
final @NonNull String inputString,
|
||||
final @NonNull EntitySelector entitySelector,
|
||||
|
|
|
|||
|
|
@ -27,8 +27,18 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||
|
||||
public interface EntitySelectorAccess {
|
||||
|
||||
/**
|
||||
* Get the last parsed input string
|
||||
*
|
||||
* @return input string
|
||||
*/
|
||||
@NonNull String inputString();
|
||||
|
||||
/**
|
||||
* Set the last parsed input string
|
||||
*
|
||||
* @param inputString input string
|
||||
*/
|
||||
void inputString(@NonNull String inputString);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import net.fabricmc.api.ClientModInitializer;
|
|||
import net.fabricmc.fabric.api.client.command.v1.FabricClientCommandSource;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
||||
public class FabricClientExample implements ClientModInitializer {
|
||||
public final class FabricClientExample implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
final FabricClientCommandManager<FabricClientCommandSource> commandManager =
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import cloud.commandframework.arguments.standard.IntegerArgument;
|
|||
import cloud.commandframework.arguments.standard.StringArgument;
|
||||
import cloud.commandframework.execution.CommandExecutionCoordinator;
|
||||
import cloud.commandframework.fabric.FabricServerCommandManager;
|
||||
import cloud.commandframework.fabric.argument.MultiplePlayerSelectorArgument;
|
||||
import cloud.commandframework.fabric.argument.server.MultiplePlayerSelectorArgument;
|
||||
import cloud.commandframework.fabric.data.MultiplePlayerSelector;
|
||||
import cloud.commandframework.meta.CommandMeta;
|
||||
import com.google.gson.JsonObject;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue