All Downloads are FREE. Search and download functionalities are using the official Maven repository.

personthecat.catlib.command.arguments.ArgumentSuppliers Maven / Gradle / Ivy

Go to download

Utilities for serialization, commands, noise generation, IO, and some new data types.

The newest version!
package personthecat.catlib.command.arguments;

import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.DoubleArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import lombok.experimental.UtilityClass;
import personthecat.catlib.command.annotations.ModCommand;
import personthecat.catlib.command.CommandRegistrationContext;
import personthecat.catlib.command.CommandSuggestions;
import personthecat.catlib.data.ModDescriptor;

/**
 * A few convenience {@link ArgumentSupplier} classes to be used as descriptors
 * inside of {@link ModCommand}-annotated command builders.
 * 

* Most of the generic argument types provided by Brigadier and the base game can be used * in command builders by setting a type. Note that this setup is only valid * for {@link ArgumentType}s with no argument constructors. *

*/ @UtilityClass @SuppressWarnings("unused") public class ArgumentSuppliers { /** * Provides a {@link FileArgument} with the current mod's config folder as the root. */ public static class File implements ArgumentSupplier { public ArgumentDescriptor get() { final ModDescriptor descriptor = getModDescriptorOrThrow(); return new ArgumentDescriptor<>(new FileArgument(descriptor.getConfigFolder(), descriptor.getPreferredDirectory())); } } /** * Provides a {@link FileArgument} which does not search recursively. */ public static class SimpleFile implements ArgumentSupplier { public ArgumentDescriptor get() { final ModDescriptor mod = getModDescriptorOrThrow(); return new ArgumentDescriptor<>(new FileArgument(mod.getConfigFolder(), false)); } } /** * Provides an {@link JsonArgument} with the current mod's config folder as the root. */ public static class XjsFile implements ArgumentSupplier { public ArgumentDescriptor get() { final ModDescriptor mod = getModDescriptorOrThrow(); return new ArgumentDescriptor<>(new JsonArgument(mod.getConfigFolder(), mod.getPreferredDirectory(), true)); } } /** * Provides an {@link JsonArgument} which does not search recursively. */ public static class SimpleXjsFile implements ArgumentSupplier { public ArgumentDescriptor get() { final ModDescriptor mod = getModDescriptorOrThrow(); return new ArgumentDescriptor<>(new JsonArgument(mod.getConfigFolder(), false)); } } /** * Provides a generic string argument suggesting the text [<any_value>] */ public static class AnyValue implements ArgumentSupplier { public ArgumentDescriptor get() { return new ArgumentDescriptor<>(StringArgumentType.greedyString(), CommandSuggestions.ANY_VALUE); } } /** * Provides a generic integer argument suggesting a few random integer values. */ public static class AnyInt implements ArgumentSupplier { public ArgumentDescriptor get() { return new ArgumentDescriptor<>(IntegerArgumentType.integer(), CommandSuggestions.ANY_INT); } } /** * Provides a generic decimal argument suggesting a few random decimal values. */ public static class AnyDouble implements ArgumentSupplier { public ArgumentDescriptor get() { return new ArgumentDescriptor<>(DoubleArgumentType.doubleArg(), CommandSuggestions.ANY_DECIMAL); } } private static ModDescriptor getModDescriptorOrThrow() { return CommandRegistrationContext.getActiveModOrThrow(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy