refactor(commands): from async to sync Part 3
This commit is contained in:
1 parent
5d841d6d3b
commit
66a5f53408
222 files changed
+11699
-12920
No files matched your search
@@ -27,23 +27,15 @@ impl GetClientSideArgParser for DamageTypeArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for DamageTypeArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let name_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = name_opt.map_or_else(
|
||||
|| None,
|
||||
|name| {
|
||||
let name = name.strip_prefix("minecraft:").unwrap_or(name);
|
||||
DamageType::from_name(name).map(Arg::DamageType)
|
||||
},
|
||||
);
|
||||
|
||||
Box::pin(async move { result })
|
||||
let name = args.pop().map(|arg| arg.value)?;
|
||||
let name = name.strip_prefix("minecraft:").unwrap_or(name);
|
||||
DamageType::from_name(name).map(Arg::DamageType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,22 +27,16 @@ impl GetClientSideArgParser for EffectTypeArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for EffectTypeArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let status_effect: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
match status_effect {
|
||||
Some(name) => Box::pin(async move {
|
||||
let status_effect =
|
||||
StatusEffect::from_name(name.strip_prefix("minecraft:").unwrap_or(name))?;
|
||||
Some(Arg::Effect(status_effect))
|
||||
}),
|
||||
None => Box::pin(async move { None }),
|
||||
}
|
||||
let name = args.pop().map(|arg| arg.value)?;
|
||||
let status_effect =
|
||||
StatusEffect::from_name(name.strip_prefix("minecraft:").unwrap_or(name))?;
|
||||
Some(Arg::Effect(status_effect))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,19 +27,14 @@ impl GetClientSideArgParser for EnchantmentArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for EnchantmentArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let name_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = name_opt.map_or_else(
|
||||
|| None,
|
||||
|name| Enchantment::from_name(name).map(Arg::Enchantment),
|
||||
);
|
||||
Box::pin(async move { result })
|
||||
let name = args.pop().map(|arg| arg.value)?;
|
||||
Enchantment::from_name(name).map(Arg::Enchantment)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,12 +37,7 @@ impl ArgumentConsumer for ItemArgumentConsumer {
|
||||
_server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let item = args.pop().map(|arg| arg.value);
|
||||
// TODO: When supporting data components in this argument, do it for ItemPredicateArgumentConsumer as well (both tags and items)
|
||||
match item {
|
||||
Some(s) => Box::pin(async move { Some(Arg::Item(s)) }),
|
||||
None => Box::pin(async move { None }),
|
||||
}
|
||||
args.pop().map(|arg| Arg::Item(arg.value))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,11 +177,7 @@ impl ArgumentConsumer for ItemPredicateArgumentConsumer {
|
||||
_server: &'a Server,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let item = args.pop().map(|arg| arg.value);
|
||||
match item {
|
||||
Some(s) => Box::pin(async move { Some(Arg::Item(s)) }),
|
||||
None => Box::pin(async move { None }),
|
||||
}
|
||||
args.pop().map(|arg| Arg::Item(arg.value))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,23 +27,14 @@ impl GetClientSideArgParser for ParticleArgumentConsumer {
|
||||
}
|
||||
|
||||
impl ArgumentConsumer for ParticleArgumentConsumer {
|
||||
fn consume<'a, 'b>(
|
||||
fn consume<'a>(
|
||||
&'a self,
|
||||
_sender: &'a CommandSender,
|
||||
_server: &'a Server,
|
||||
args: &'b mut RawArgs<'a>,
|
||||
args: &mut RawArgs<'a>,
|
||||
) -> ConsumeResult<'a> {
|
||||
let name_opt: Option<&'a str> = args.pop().map(|arg| arg.value);
|
||||
|
||||
let result: Option<Arg<'a>> = name_opt.map_or_else(
|
||||
|| None,
|
||||
|name| {
|
||||
Particle::from_name(name.strip_prefix("minecraft:").unwrap_or(name))
|
||||
.map(Arg::Particle)
|
||||
},
|
||||
);
|
||||
|
||||
Box::pin(async move { result })
|
||||
let name = args.pop().map(|arg| arg.value)?;
|
||||
Particle::from_name(name.strip_prefix("minecraft:").unwrap_or(name)).map(Arg::Particle)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user