From 2966a21fd66728c6f015dd7c98bbd41cd3a77b6a Mon Sep 17 00:00:00 2001 From: Laptop59 <90901102+Laptop59@users.noreply.github.com> Date: Thu, 4 Jun 2026 14:37:42 +0530 Subject: [PATCH] feat(command): implement gamemode argument type (#2186) * to be completed * removed block state parser for now * gamemode argument type * plugin wit submodules * fixed submodules --------- Co-authored-by: Missing_Love <42416195+Q2297045667@users.noreply.github.com> --- .../src/command/argument_types/gamemode.rs | 51 +++++++++++++++++++ pumpkin/src/command/argument_types/mod.rs | 1 + 2 files changed, 52 insertions(+) create mode 100644 pumpkin/src/command/argument_types/gamemode.rs diff --git a/pumpkin/src/command/argument_types/gamemode.rs b/pumpkin/src/command/argument_types/gamemode.rs new file mode 100644 index 000000000..9490fe11c --- /dev/null +++ b/pumpkin/src/command/argument_types/gamemode.rs @@ -0,0 +1,51 @@ +use crate::command::argument_types::argument_type::{ArgumentType, JavaClientArgumentType}; +use crate::command::context::command_context::CommandContext; +use crate::command::errors::command_syntax_error::CommandSyntaxError; +use crate::command::errors::error_types::CommandErrorType; +use crate::command::string_reader::StringReader; +use crate::command::suggestion::suggestions::{Suggestions, SuggestionsBuilder}; +use pumpkin_data::translation; +use pumpkin_util::GameMode; +use pumpkin_util::text::TextComponent; +use std::pin::Pin; +use std::str::FromStr; + +pub const INVALID_ERROR_TYPE: CommandErrorType<1> = CommandErrorType::new( + translation::java::ARGUMENT_GAMEMODE_INVALID, + translation::java::ARGUMENT_GAMEMODE_INVALID, +); + +pub struct GameModeArgumentType; + +impl ArgumentType for GameModeArgumentType { + type Item = GameMode; + + fn parse(&self, reader: &mut StringReader) -> Result { + let string = reader.read_unquoted_string(); + GameMode::from_str(&string) + .map_err(|_| INVALID_ERROR_TYPE.create(reader, TextComponent::text(string))) + } + + fn client_side_parser(&'_ self) -> JavaClientArgumentType<'_> { + JavaClientArgumentType::Gamemode + } + + fn list_suggestions<'a>( + &'a self, + _context: &'a CommandContext, + mut builder: SuggestionsBuilder, + ) -> Pin + Send + 'a>> { + Box::pin(async move { + for gamemode in GameMode::VALUES { + builder = builder.filter_and_suggest_one(gamemode.name()); + } + builder.build() + }) + } + + fn examples(&self) -> Vec { + examples!("survival", "creative") + } +} + +impl_copy_get!(GameModeArgumentType, GameMode); diff --git a/pumpkin/src/command/argument_types/mod.rs b/pumpkin/src/command/argument_types/mod.rs index 9cc3c9430..97f5632b3 100644 --- a/pumpkin/src/command/argument_types/mod.rs +++ b/pumpkin/src/command/argument_types/mod.rs @@ -223,6 +223,7 @@ pub mod entity; pub mod entity_anchor; pub mod entity_selector; pub mod game_profile; +pub mod gamemode; pub mod identifier; pub mod nbt; pub mod range;