feat(command): add team command

This commit is contained in:
Alexander Medvedev
2026-07-14 12:36:47 +02:00
parent 02c8c84789
commit 5e01d67579
5 changed files with 1146 additions and 0 deletions

View File

@@ -232,6 +232,7 @@ pub mod objective;
pub mod range;
pub mod resource_key;
pub mod slot;
pub mod team;
pub mod team_color;
pub mod time;
pub mod uuid;

View File

@@ -0,0 +1,50 @@
use crate::command::{
argument_types::argument_type::{ArgumentType, JavaClientArgumentType},
context::command_context::CommandContext,
errors::command_syntax_error::CommandSyntaxError,
string_reader::StringReader,
suggestion::suggestions::{Suggestions, SuggestionsBuilder},
};
use std::pin::Pin;
/// Represents an argument type parsing a team name.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct TeamArgumentType;
impl ArgumentType for TeamArgumentType {
type Item = String;
fn parse(&self, reader: &mut StringReader) -> Result<Self::Item, CommandSyntaxError> {
let name = reader.read_unquoted_string();
Ok(name)
}
fn client_side_parser(&'_ self) -> JavaClientArgumentType {
JavaClientArgumentType::Team
}
fn list_suggestions<'a>(
&'a self,
context: &'a CommandContext,
mut builder: SuggestionsBuilder,
) -> Pin<Box<dyn Future<Output = Suggestions> + Send + 'a>> {
Box::pin(async move {
let scoreboard = context.world().scoreboard.lock().await;
for team_name in scoreboard.get_teams().keys() {
builder = builder.filter_and_suggest_one(team_name.as_str());
}
builder.build()
})
}
fn examples(&self) -> Vec<String> {
vec!["foo".to_string(), "foo_bar".to_string()]
}
}
impl TeamArgumentType {
/// Returns a [`CommandContext`]'s parsed `String` argument as a string slice.
pub fn get<'a>(context: &'a CommandContext, name: &str) -> Result<&'a str, CommandSyntaxError> {
Ok(context.get_argument::<String>(name)?.as_str())
}
}

View File

@@ -59,6 +59,7 @@ mod stop;
mod stopsound;
mod summon;
mod tag;
mod team;
mod teleport;
mod tellraw;
mod tick;
@@ -71,6 +72,7 @@ mod weather;
mod whitelist;
mod worldborder;
#[allow(clippy::too_many_lines)]
#[must_use]
pub async fn default_dispatcher(
registry: &RwLock<PermissionRegistry>,
@@ -179,6 +181,7 @@ pub async fn default_dispatcher(
advancement::register(&mut dispatcher, registry);
trigger::register(&mut dispatcher, registry);
scoreboard::register(&mut dispatcher, registry);
team::register(&mut dispatcher, registry);
clone::register(&mut dispatcher, registry);
attribute::register(&mut dispatcher, registry);
dispatcher

File diff suppressed because it is too large Load Diff

View File

@@ -36,6 +36,11 @@ impl Scoreboard {
&self.scores
}
#[must_use]
pub const fn get_teams(&self) -> &HashMap<String, Team> {
&self.teams
}
async fn broadcast_editioned<J: ClientPacket, B: BClientPacket>(
world: &World,
je_packet: &J,
@@ -342,6 +347,7 @@ impl<'a> ScoreboardScore<'a> {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NameTagVisibility {
Always,
Never,
@@ -361,6 +367,7 @@ impl NameTagVisibility {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CollisionRule {
Always,
Never,
@@ -380,6 +387,7 @@ impl CollisionRule {
}
}
#[derive(Clone)]
pub struct Team {
pub name: String,
pub display_name: TextComponent,