mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
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>
This commit is contained in:
51
pumpkin/src/command/argument_types/gamemode.rs
Normal file
51
pumpkin/src/command/argument_types/gamemode.rs
Normal file
@@ -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<Self::Item, CommandSyntaxError> {
|
||||
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<Box<dyn Future<Output = Suggestions> + 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<String> {
|
||||
examples!("survival", "creative")
|
||||
}
|
||||
}
|
||||
|
||||
impl_copy_get!(GameModeArgumentType, GameMode);
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user