fabric: Remove get prefixes from new methods

This commit is contained in:
Jason Penilla 2021-06-28 00:49:30 -07:00 committed by Jason
parent ab0a9299e4
commit 8460284ea0
11 changed files with 38 additions and 37 deletions

View file

@ -71,7 +71,7 @@ public final class FabricCaptionKeys {
* @return Immutable collection of keys * @return Immutable collection of keys
* @since 1.5.0 * @since 1.5.0
*/ */
public static @NonNull Collection<@NonNull Caption> getFabricCaptionKeys() { public static @NonNull Collection<@NonNull Caption> fabricCaptionKeys() {
return Collections.unmodifiableCollection(RECOGNIZED_CAPTIONS); return Collections.unmodifiableCollection(RECOGNIZED_CAPTIONS);
} }

View file

@ -211,7 +211,7 @@ public abstract class FabricCommandManager<C, S extends SharedSuggestionProvider
}, },
builder -> builder.to(argument -> { builder -> builder.to(argument -> {
/* several registries have specialized argument types, so let's use those where possible */ /* several registries have specialized argument types, so let's use those where possible */
final ResourceKey<? extends Registry<?>> registry = argument.getRegistry(); final ResourceKey<? extends Registry<?>> registry = argument.registryKey();
if (registry.equals(Registry.ENTITY_TYPE_REGISTRY)) { if (registry.equals(Registry.ENTITY_TYPE_REGISTRY)) {
return EntitySummonArgument.id(); return EntitySummonArgument.id();
} else if (registry.equals(Registry.ENCHANTMENT_REGISTRY)) { } else if (registry.equals(Registry.ENCHANTMENT_REGISTRY)) {
@ -226,7 +226,7 @@ public abstract class FabricCommandManager<C, S extends SharedSuggestionProvider
).suggestedBy((argument, useCloud) -> { ).suggestedBy((argument, useCloud) -> {
/* A few other registries have client-side suggestion providers but no argument type */ /* A few other registries have client-side suggestion providers but no argument type */
/* Type parameters are messed up here for some reason */ /* Type parameters are messed up here for some reason */
final ResourceKey<? extends Registry<?>> registry = argument.getRegistry(); final ResourceKey<? extends Registry<?>> registry = argument.registryKey();
if (registry.equals(Registry.SOUND_EVENT_REGISTRY)) { if (registry.equals(Registry.SOUND_EVENT_REGISTRY)) {
return (SuggestionProvider<S>) SuggestionProviders.AVAILABLE_SOUNDS; return (SuggestionProvider<S>) SuggestionProviders.AVAILABLE_SOUNDS;
} else if (registry.equals(Registry.BIOME_REGISTRY)) { } else if (registry.equals(Registry.BIOME_REGISTRY)) {
@ -331,7 +331,7 @@ public abstract class FabricCommandManager<C, S extends SharedSuggestionProvider
* @return Command source mapper * @return Command source mapper
* @since 1.5.0 * @since 1.5.0
*/ */
public final @NonNull Function<@NonNull S, @NonNull C> getCommandSourceMapper() { public final @NonNull Function<@NonNull S, @NonNull C> commandSourceMapper() {
return this.commandSourceMapper; return this.commandSourceMapper;
} }
@ -341,7 +341,7 @@ public abstract class FabricCommandManager<C, S extends SharedSuggestionProvider
* @return Command source mapper * @return Command source mapper
* @since 1.5.0 * @since 1.5.0
*/ */
public final @NonNull Function<@NonNull C, @NonNull S> getBackwardsCommandSourceMapper() { public final @NonNull Function<@NonNull C, @NonNull S> backwardsCommandSourceMapper() {
return this.backwardsCommandSourceMapper; return this.backwardsCommandSourceMapper;
} }
@ -363,7 +363,7 @@ public abstract class FabricCommandManager<C, S extends SharedSuggestionProvider
* @since 1.5.0 * @since 1.5.0
*/ */
public @NonNull PredicatePermission<C> permissionLevel(final int permissionLevel) { public @NonNull PredicatePermission<C> permissionLevel(final int permissionLevel) {
return sender -> this.getBackwardsCommandSourceMapper() return sender -> this.backwardsCommandSourceMapper()
.apply(sender) .apply(sender)
.hasPermission(permissionLevel); .hasPermission(permissionLevel);
} }

View file

@ -39,7 +39,7 @@ final class FabricCommandPreprocessor<C> implements CommandPreprocessor<C> {
public void accept(@NonNull final CommandPreprocessingContext<C> context) { public void accept(@NonNull final CommandPreprocessingContext<C> context) {
context.getCommandContext().store( context.getCommandContext().store(
FabricCommandContextKeys.NATIVE_COMMAND_SOURCE, FabricCommandContextKeys.NATIVE_COMMAND_SOURCE,
this.manager.getBackwardsCommandSourceMapper().apply(context.getCommandContext().getSender()) this.manager.backwardsCommandSourceMapper().apply(context.getCommandContext().getSender())
); );
} }

View file

@ -58,7 +58,7 @@ abstract class FabricCommandRegistrationHandler<C, S extends SharedSuggestionPro
this.commandManager = manager; this.commandManager = manager;
} }
FabricCommandManager<C, S> getCommandManager() { FabricCommandManager<C, S> commandManager() {
return this.commandManager; return this.commandManager;
} }
@ -110,18 +110,18 @@ abstract class FabricCommandRegistrationHandler<C, S extends SharedSuggestionPro
final RootCommandNode<FabricClientCommandSource> rootNode = ClientCommandManager.DISPATCHER.getRoot(); final RootCommandNode<FabricClientCommandSource> rootNode = ClientCommandManager.DISPATCHER.getRoot();
final StaticArgument<C> first = ((StaticArgument<C>) command.getArguments().get(0)); final StaticArgument<C> first = ((StaticArgument<C>) command.getArguments().get(0));
final CommandNode<FabricClientCommandSource> baseNode = this final CommandNode<FabricClientCommandSource> baseNode = this
.getCommandManager() .commandManager()
.brigadierManager() .brigadierManager()
.createLiteralCommandNode( .createLiteralCommandNode(
first.getName(), first.getName(),
command, command,
(src, perm) -> this.getCommandManager().hasPermission( (src, perm) -> this.commandManager().hasPermission(
this.getCommandManager().getCommandSourceMapper().apply(src), this.commandManager().commandSourceMapper().apply(src),
perm perm
), ),
true, true,
new FabricExecutor<>( new FabricExecutor<>(
this.getCommandManager(), this.commandManager(),
source -> source.getPlayer().getGameProfile().getName(), source -> source.getPlayer().getGameProfile().getName(),
FabricClientCommandSource::sendError FabricClientCommandSource::sendError
) )
@ -152,7 +152,7 @@ abstract class FabricCommandRegistrationHandler<C, S extends SharedSuggestionPro
} }
private void registerAllCommands(final CommandDispatcher<CommandSourceStack> dispatcher, final boolean isDedicated) { private void registerAllCommands(final CommandDispatcher<CommandSourceStack> dispatcher, final boolean isDedicated) {
this.getCommandManager().registrationCalled(); this.commandManager().registrationCalled();
for (final Command<C> command : this.registeredCommands) { for (final Command<C> command : this.registeredCommands) {
/* Only register commands in the declared environment */ /* Only register commands in the declared environment */
final CommandSelection env = command.getCommandMeta().getOrDefault( final CommandSelection env = command.getCommandMeta().getOrDefault(
@ -171,15 +171,15 @@ abstract class FabricCommandRegistrationHandler<C, S extends SharedSuggestionPro
private void registerCommand(final RootCommandNode<CommandSourceStack> dispatcher, final Command<C> command) { private void registerCommand(final RootCommandNode<CommandSourceStack> dispatcher, final Command<C> command) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
final StaticArgument<C> first = ((StaticArgument<C>) command.getArguments().get(0)); final StaticArgument<C> first = ((StaticArgument<C>) command.getArguments().get(0));
final CommandNode<CommandSourceStack> baseNode = this.getCommandManager().brigadierManager().createLiteralCommandNode( final CommandNode<CommandSourceStack> baseNode = this.commandManager().brigadierManager().createLiteralCommandNode(
first.getName(), first.getName(),
command, command,
(src, perm) -> this.getCommandManager().hasPermission( (src, perm) -> this.commandManager().hasPermission(
this.getCommandManager().getCommandSourceMapper().apply(src), this.commandManager().commandSourceMapper().apply(src),
perm perm
), ),
true, true,
new FabricExecutor<>(this.getCommandManager(), CommandSourceStack::getTextName, CommandSourceStack::sendFailure)); new FabricExecutor<>(this.commandManager(), CommandSourceStack::getTextName, CommandSourceStack::sendFailure));
dispatcher.addChild(baseNode); dispatcher.addChild(baseNode);

View file

@ -79,7 +79,7 @@ final class FabricExecutor<C, S extends SharedSuggestionProvider> implements Com
public int run(final @NonNull CommandContext<S> ctx) { public int run(final @NonNull CommandContext<S> ctx) {
final S source = ctx.getSource(); final S source = ctx.getSource();
final String input = ctx.getInput().substring(ctx.getLastChild().getNodes().get(0).getRange().getStart()); final String input = ctx.getInput().substring(ctx.getLastChild().getNodes().get(0).getRange().getStart());
final C sender = this.manager.getCommandSourceMapper().apply(source); final C sender = this.manager.commandSourceMapper().apply(source);
this.manager.executeCommand(sender, input).whenComplete((result, throwable) -> { this.manager.executeCommand(sender, input).whenComplete((result, throwable) -> {
if (throwable == null) { if (throwable == null) {
return; return;

View file

@ -199,7 +199,7 @@ public final class FabricServerCommandManager<C> extends FabricCommandManager<C,
*/ */
@Override @Override
public boolean hasPermission(final @NonNull C sender, final @NonNull String permission) { public boolean hasPermission(final @NonNull C sender, final @NonNull String permission) {
final CommandSourceStack source = this.getBackwardsCommandSourceMapper().apply(sender); final CommandSourceStack source = this.backwardsCommandSourceMapper().apply(sender);
return Permissions.check(source, permission, source.getServer().getOperatorUserPermissionLevel()); return Permissions.check(source, permission, source.getServer().getOperatorUserPermissionLevel());
} }

View file

@ -135,7 +135,7 @@ public final class FabricArgumentParsers {
final @NonNull CommandContext<C> ctx, final @NonNull CommandContext<C> ctx,
final net.minecraft.commands.arguments.coordinates.@NonNull Coordinates posArgument final net.minecraft.commands.arguments.coordinates.@NonNull Coordinates posArgument
) { ) {
return requireServerCommandSource( return requireCommandSourceStack(
ctx, ctx,
serverCommandSource -> ArgumentParseResult.success((O) new CoordinatesImpl( serverCommandSource -> ArgumentParseResult.success((O) new CoordinatesImpl(
serverCommandSource, serverCommandSource,
@ -153,7 +153,7 @@ public final class FabricArgumentParsers {
*/ */
public static <C> @NonNull ArgumentParser<C, SinglePlayerSelector> singlePlayerSelector() { public static <C> @NonNull ArgumentParser<C, SinglePlayerSelector> singlePlayerSelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.player()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.player())
.map((ctx, entitySelector) -> requireServerCommandSource( .map((ctx, entitySelector) -> requireCommandSourceStack(
ctx, ctx,
serverCommandSource -> handleCommandSyntaxExceptionAsFailure( serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
() -> ArgumentParseResult.success(new SinglePlayerSelectorImpl( () -> ArgumentParseResult.success(new SinglePlayerSelectorImpl(
@ -174,7 +174,7 @@ public final class FabricArgumentParsers {
*/ */
public static <C> @NonNull ArgumentParser<C, MultiplePlayerSelector> multiplePlayerSelector() { public static <C> @NonNull ArgumentParser<C, MultiplePlayerSelector> multiplePlayerSelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.players()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.players())
.map((ctx, entitySelector) -> requireServerCommandSource( .map((ctx, entitySelector) -> requireCommandSourceStack(
ctx, ctx,
serverCommandSource -> handleCommandSyntaxExceptionAsFailure( serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
() -> ArgumentParseResult.success(new MultiplePlayerSelectorImpl( () -> ArgumentParseResult.success(new MultiplePlayerSelectorImpl(
@ -195,7 +195,7 @@ public final class FabricArgumentParsers {
*/ */
public static <C> @NonNull ArgumentParser<C, SingleEntitySelector> singleEntitySelector() { public static <C> @NonNull ArgumentParser<C, SingleEntitySelector> singleEntitySelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.entity()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.entity())
.map((ctx, entitySelector) -> requireServerCommandSource( .map((ctx, entitySelector) -> requireCommandSourceStack(
ctx, ctx,
serverCommandSource -> handleCommandSyntaxExceptionAsFailure( serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
() -> ArgumentParseResult.success(new SingleEntitySelectorImpl( () -> ArgumentParseResult.success(new SingleEntitySelectorImpl(
@ -216,7 +216,7 @@ public final class FabricArgumentParsers {
*/ */
public static <C> @NonNull ArgumentParser<C, MultipleEntitySelector> multipleEntitySelector() { public static <C> @NonNull ArgumentParser<C, MultipleEntitySelector> multipleEntitySelector() {
return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.entities()) return new WrappedBrigadierParser<C, EntitySelector>(EntityArgument.entities())
.map((ctx, entitySelector) -> requireServerCommandSource( .map((ctx, entitySelector) -> requireCommandSourceStack(
ctx, ctx,
serverCommandSource -> handleCommandSyntaxExceptionAsFailure( serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
() -> ArgumentParseResult.success(new MultipleEntitySelectorImpl( () -> ArgumentParseResult.success(new MultipleEntitySelectorImpl(
@ -237,7 +237,7 @@ public final class FabricArgumentParsers {
*/ */
public static <C> @NonNull ArgumentParser<C, Message> message() { public static <C> @NonNull ArgumentParser<C, Message> message() {
return new WrappedBrigadierParser<C, MessageArgument.Message>(MessageArgument.message()) return new WrappedBrigadierParser<C, MessageArgument.Message>(MessageArgument.message())
.map((ctx, format) -> requireServerCommandSource( .map((ctx, format) -> requireCommandSourceStack(
ctx, ctx,
serverCommandSource -> handleCommandSyntaxExceptionAsFailure( serverCommandSource -> handleCommandSyntaxExceptionAsFailure(
() -> ArgumentParseResult.success(MessageImpl.from( () -> ArgumentParseResult.success(MessageImpl.from(
@ -270,7 +270,7 @@ public final class FabricArgumentParsers {
return new IllegalStateException("This command argument type is server-only."); return new IllegalStateException("This command argument type is server-only.");
} }
private static <C, O> @NonNull ArgumentParseResult<O> requireServerCommandSource( private static <C, O> @NonNull ArgumentParseResult<O> requireCommandSourceStack(
final @NonNull CommandContext<C> context, final @NonNull CommandContext<C> context,
final @NonNull Function<CommandSourceStack, ArgumentParseResult<O>> resultFunction final @NonNull Function<CommandSourceStack, ArgumentParseResult<O>> resultFunction
) { ) {
@ -315,12 +315,12 @@ public final class FabricArgumentParsers {
} }
@Override @Override
public @NonNull Collection<Entity> getMentionedEntities() { public @NonNull Collection<Entity> mentionedEntities() {
return this.mentionedEntities; return this.mentionedEntities;
} }
@Override @Override
public @NonNull Component getContents() { public @NonNull Component contents() {
return this.contents; return this.contents;
} }

View file

@ -117,6 +117,7 @@ public final class ItemInputArgument<C> extends CommandArgument<C, ItemInput> {
* Builder for {@link ItemInputArgument}. * Builder for {@link ItemInputArgument}.
* *
* @param <C> sender type * @param <C> sender type
* @since 1.5.0
*/ */
public static final class Builder<C> extends TypedBuilder<C, ItemInput, Builder<C>> { public static final class Builder<C> extends TypedBuilder<C, ItemInput, Builder<C>> {

View file

@ -222,7 +222,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
inputQueue.poll(); inputQueue.poll();
final Registry<V> registry = this.getRegistry(commandContext); final Registry<V> registry = this.resolveRegistry(commandContext);
if (registry == null) { if (registry == null) {
return ArgumentParseResult.failure(new IllegalArgumentException("Unknown registry " + this.registryIdent)); return ArgumentParseResult.failure(new IllegalArgumentException("Unknown registry " + this.registryIdent));
} }
@ -236,7 +236,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Registry<V> getRegistry(final CommandContext<C> ctx) { Registry<V> resolveRegistry(final CommandContext<C> ctx) {
final SharedSuggestionProvider reverseMapped = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE); final SharedSuggestionProvider reverseMapped = ctx.get(FabricCommandContextKeys.NATIVE_COMMAND_SOURCE);
// First try dynamic registries (for things loaded from data-packs) // First try dynamic registries (for things loaded from data-packs)
Registry<V> registry = reverseMapped.registryAccess().registry(this.registryIdent).orElse(null); Registry<V> registry = reverseMapped.registryAccess().registry(this.registryIdent).orElse(null);
@ -252,7 +252,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
final @NonNull CommandContext<C> commandContext, final @NonNull CommandContext<C> commandContext,
final @NonNull String input final @NonNull String input
) { ) {
final Set<ResourceLocation> ids = this.getRegistry(commandContext).keySet(); final Set<ResourceLocation> ids = this.resolveRegistry(commandContext).keySet();
final List<String> results = new ArrayList<>(ids.size()); final List<String> results = new ArrayList<>(ids.size());
for (final ResourceLocation entry : ids) { for (final ResourceLocation entry : ids) {
if (entry.getNamespace().equals(NAMESPACE_MINECRAFT)) { if (entry.getNamespace().equals(NAMESPACE_MINECRAFT)) {
@ -275,7 +275,7 @@ public class RegistryEntryArgument<C, V> extends CommandArgument<C, V> {
* @return the registry * @return the registry
* @since 1.5.0 * @since 1.5.0
*/ */
public ResourceKey<? extends Registry<?>> getRegistry() { public ResourceKey<? extends Registry<?>> registryKey() {
return this.registryIdent; return this.registryIdent;
} }

View file

@ -42,7 +42,7 @@ public interface Message {
* @return the mentioned entities * @return the mentioned entities
* @since 1.5.0 * @since 1.5.0
*/ */
@NonNull Collection<Entity> getMentionedEntities(); @NonNull Collection<Entity> mentionedEntities();
/** /**
* Get the parsed text contents of this message. * Get the parsed text contents of this message.
@ -50,6 +50,6 @@ public interface Message {
* @return the parsed text * @return the parsed text
* @since 1.5.0 * @since 1.5.0
*/ */
@NonNull Component getContents(); @NonNull Component contents();
} }

View file

@ -89,12 +89,12 @@ public final class MinecraftTime {
* Get the number of in-game ticks represented by this time. * Get the number of in-game ticks represented by this time.
* *
* <p>This time will be truncated to the maximum value of an integer. * <p>This time will be truncated to the maximum value of an integer.
* See {@link #getLongTicks()} for the full contents.</p> * See {@link #ticksLong()} for the full contents.</p>
* *
* @return the time in ticks * @return the time in ticks
* @since 1.5.0 * @since 1.5.0
*/ */
public int getTicks() { public int ticks() {
return (int) this.ticks; return (int) this.ticks;
} }
@ -104,7 +104,7 @@ public final class MinecraftTime {
* @return the time in ticks * @return the time in ticks
* @since 1.5.0 * @since 1.5.0
*/ */
public long getLongTicks() { public long ticksLong() {
return this.ticks; return this.ticks;
} }