feat(command): add team command
This commit is contained in:
1 parent
02c8c84789
commit
5e01d67579
5 files changed
+1146
No files matched your search
@@ -232,6 +232,7 @@ pub mod objective;
|
|||||||
pub mod range;
|
pub mod range;
|
||||||
pub mod resource_key;
|
pub mod resource_key;
|
||||||
pub mod slot;
|
pub mod slot;
|
||||||
|
pub mod team;
|
||||||
pub mod team_color;
|
pub mod team_color;
|
||||||
pub mod time;
|
pub mod time;
|
||||||
pub mod uuid;
|
pub mod uuid;
|
||||||
@@ -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())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,6 +59,7 @@ mod stop;
|
|||||||
mod stopsound;
|
mod stopsound;
|
||||||
mod summon;
|
mod summon;
|
||||||
mod tag;
|
mod tag;
|
||||||
|
mod team;
|
||||||
mod teleport;
|
mod teleport;
|
||||||
mod tellraw;
|
mod tellraw;
|
||||||
mod tick;
|
mod tick;
|
||||||
@@ -71,6 +72,7 @@ mod weather;
|
|||||||
mod whitelist;
|
mod whitelist;
|
||||||
mod worldborder;
|
mod worldborder;
|
||||||
|
|
||||||
|
#[allow(clippy::too_many_lines)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub async fn default_dispatcher(
|
pub async fn default_dispatcher(
|
||||||
registry: &RwLock<PermissionRegistry>,
|
registry: &RwLock<PermissionRegistry>,
|
||||||
@@ -179,6 +181,7 @@ pub async fn default_dispatcher(
|
|||||||
advancement::register(&mut dispatcher, registry);
|
advancement::register(&mut dispatcher, registry);
|
||||||
trigger::register(&mut dispatcher, registry);
|
trigger::register(&mut dispatcher, registry);
|
||||||
scoreboard::register(&mut dispatcher, registry);
|
scoreboard::register(&mut dispatcher, registry);
|
||||||
|
team::register(&mut dispatcher, registry);
|
||||||
clone::register(&mut dispatcher, registry);
|
clone::register(&mut dispatcher, registry);
|
||||||
attribute::register(&mut dispatcher, registry);
|
attribute::register(&mut dispatcher, registry);
|
||||||
dispatcher
|
dispatcher
|
||||||
|
|||||||
File diff suppressed because it is too large.
Load diff
@@ -36,6 +36,11 @@ impl Scoreboard {
|
|||||||
&self.scores
|
&self.scores
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
pub const fn get_teams(&self) -> &HashMap<String, Team> {
|
||||||
|
&self.teams
|
||||||
|
}
|
||||||
|
|
||||||
async fn broadcast_editioned<J: ClientPacket, B: BClientPacket>(
|
async fn broadcast_editioned<J: ClientPacket, B: BClientPacket>(
|
||||||
world: &World,
|
world: &World,
|
||||||
je_packet: &J,
|
je_packet: &J,
|
||||||
@@ -342,6 +347,7 @@ impl<'a> ScoreboardScore<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum NameTagVisibility {
|
pub enum NameTagVisibility {
|
||||||
Always,
|
Always,
|
||||||
Never,
|
Never,
|
||||||
@@ -361,6 +367,7 @@ impl NameTagVisibility {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
pub enum CollisionRule {
|
pub enum CollisionRule {
|
||||||
Always,
|
Always,
|
||||||
Never,
|
Never,
|
||||||
@@ -380,6 +387,7 @@ impl CollisionRule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Team {
|
pub struct Team {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub display_name: TextComponent,
|
pub display_name: TextComponent,
|
||||||
|
|||||||
Reference in new issue
Block a user