refactor: fixup custom argument support on Fabric

dependabot/gradle/org.projectlombok-lombok-1.18.34 1.0.7
William 5 months ago
parent e23b39c6a5
commit aaa86932e7
No known key found for this signature in database

@ -21,6 +21,7 @@
package net.william278.uniform.fabric; package net.william278.uniform.fabric;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -31,8 +32,10 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.InvalidIdentifierException; import net.minecraft.util.InvalidIdentifierException;
import net.william278.uniform.BaseCommand; import net.william278.uniform.BaseCommand;
import net.william278.uniform.Command; import net.william278.uniform.Command;
import net.william278.uniform.CommandSyntax;
import net.william278.uniform.Uniform; import net.william278.uniform.Uniform;
import net.william278.uniform.element.ArgumentElement; import net.william278.uniform.element.ArgumentElement;
import net.william278.uniform.element.CommandElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
@ -48,7 +51,8 @@ public class FabricCommand extends BaseCommand<ServerCommandSource> {
super(name, aliases); super(name, aliases);
} }
public FabricCommand(@NotNull String name, @NotNull String description, @NotNull List<String> aliases) { public FabricCommand(@NotNull String name, @NotNull String description,
@NotNull List<String> aliases) {
super(name, description, aliases); super(name, description, aliases);
} }
@ -79,6 +83,28 @@ public class FabricCommand extends BaseCommand<ServerCommandSource> {
}); });
} }
@Override
@NotNull
@SuppressWarnings("unchecked")
public List<CommandSyntax<ServerCommandSource>> getSyntaxes() {
return super.getSyntaxes().stream().map(
syntax -> new CommandSyntax<>(
syntax.condition(),
syntax.executor(),
syntax.elements().stream()
.filter(e -> e instanceof ArgumentElement)
.map(e -> (ArgumentElement<?, ?>) e)
.map(e -> e.custom() ? new ArgumentElement<>(
e.name(),
StringArgumentType.string(),
e.suggestionProvider()
) : e)
.map(e -> (CommandElement<ServerCommandSource>) e)
.toList()
)
).toList();
}
@Override @Override
public void addSubCommand(@NotNull Command command) { public void addSubCommand(@NotNull Command command) {
addSubCommand(new FabricCommand(command)); addSubCommand(new FabricCommand(command));
@ -88,5 +114,4 @@ public class FabricCommand extends BaseCommand<ServerCommandSource> {
public Uniform getUniform() { public Uniform getUniform() {
return FabricUniform.INSTANCE; return FabricUniform.INSTANCE;
} }
} }

@ -21,6 +21,7 @@
package net.william278.uniform.fabric; package net.william278.uniform.fabric;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -31,8 +32,10 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.InvalidIdentifierException; import net.minecraft.util.InvalidIdentifierException;
import net.william278.uniform.BaseCommand; import net.william278.uniform.BaseCommand;
import net.william278.uniform.Command; import net.william278.uniform.Command;
import net.william278.uniform.CommandSyntax;
import net.william278.uniform.Uniform; import net.william278.uniform.Uniform;
import net.william278.uniform.element.ArgumentElement; import net.william278.uniform.element.ArgumentElement;
import net.william278.uniform.element.CommandElement;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List; import java.util.List;
@ -80,6 +83,28 @@ public class FabricCommand extends BaseCommand<ServerCommandSource> {
}); });
} }
@Override
@NotNull
@SuppressWarnings("unchecked")
public List<CommandSyntax<ServerCommandSource>> getSyntaxes() {
return super.getSyntaxes().stream().map(
syntax -> new CommandSyntax<>(
syntax.condition(),
syntax.executor(),
syntax.elements().stream()
.filter(e -> e instanceof ArgumentElement)
.map(e -> (ArgumentElement<?, ?>) e)
.map(e -> e.custom() ? new ArgumentElement<>(
e.name(),
StringArgumentType.string(),
e.suggestionProvider()
) : e)
.map(e -> (CommandElement<ServerCommandSource>) e)
.toList()
)
).toList();
}
@Override @Override
public void addSubCommand(@NotNull Command command) { public void addSubCommand(@NotNull Command command) {
addSubCommand(new FabricCommand(command)); addSubCommand(new FabricCommand(command));

@ -33,7 +33,8 @@ import java.util.UUID;
public record VelocityCommandUser(CommandSource source) implements CommandUser { public record VelocityCommandUser(CommandSource source) implements CommandUser {
@Override @Override
public @NotNull Audience getAudience() { @NotNull
public Audience getAudience() {
return source; return source;
} }

Loading…
Cancel
Save