2025-11-24 22:52:51 +03:00

66 lines
2.6 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.brigadier.StringReader
* com.mojang.brigadier.arguments.ArgumentType
* com.mojang.brigadier.context.CommandContext
* com.mojang.brigadier.exceptions.CommandSyntaxException
* com.mojang.brigadier.exceptions.DynamicCommandExceptionType
* com.mojang.brigadier.suggestion.Suggestions
* com.mojang.brigadier.suggestion.SuggestionsBuilder
*/
package net.minecraft.commands.arguments;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import java.util.Arrays;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.network.chat.Component;
import net.minecraft.server.ServerScoreboard;
import net.minecraft.world.scores.PlayerTeam;
public class TeamArgument
implements ArgumentType<String> {
private static final Collection<String> EXAMPLES = Arrays.asList("foo", "123");
private static final DynamicCommandExceptionType ERROR_TEAM_NOT_FOUND = new DynamicCommandExceptionType(name -> Component.translatableEscape("team.notFound", name));
public static TeamArgument team() {
return new TeamArgument();
}
public static PlayerTeam getTeam(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
String id = (String)context.getArgument(name, String.class);
ServerScoreboard scoreboard = ((CommandSourceStack)context.getSource()).getServer().getScoreboard();
PlayerTeam team = scoreboard.getPlayerTeam(id);
if (team == null) {
throw ERROR_TEAM_NOT_FOUND.create((Object)id);
}
return team;
}
public String parse(StringReader reader) throws CommandSyntaxException {
return reader.readUnquotedString();
}
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> contextBuilder, SuggestionsBuilder builder) {
if (contextBuilder.getSource() instanceof SharedSuggestionProvider) {
return SharedSuggestionProvider.suggest(((SharedSuggestionProvider)contextBuilder.getSource()).getAllTeams(), builder);
}
return Suggestions.empty();
}
public Collection<String> getExamples() {
return EXAMPLES;
}
}