Skip to content

Commit eaa5268

Browse files
committed
Fix Proxy args.
1 parent c8c27d9 commit eaa5268

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

src/minecraft/java_edition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub trait JavaEdition: Minecraft {
2929
where
3030
Self: Sized,
3131
{
32-
advancement::Proxy::new(self, target)
32+
advancement::Proxy::new(self, vec!["advancement".into(), target.serialize().into()])
3333
}
3434

3535
/// Manage a target's attribute.
Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
//! Gives, removes, or checks player advancements.
22
3+
use std::borrow::Cow;
4+
35
pub use grant::Grant;
46

5-
use super::TargetSelector;
6-
use crate::minecraft::{parse_response, Entity, Serialize};
7+
use crate::minecraft::{parse_response, Serialize};
78
use crate::{minecraft, RCon};
89

910
mod grant;
@@ -12,12 +13,12 @@ mod grant;
1213
#[derive(Debug)]
1314
pub struct Proxy<'client, T> {
1415
client: &'client mut T,
15-
target: Entity<TargetSelector>,
16+
args: Vec<Cow<'client, str>>,
1617
}
1718

1819
impl<'client, T> Proxy<'client, T> {
19-
pub(crate) const fn new(client: &'client mut T, target: Entity<TargetSelector>) -> Self {
20-
Proxy { client, target }
20+
pub(crate) const fn new(client: &'client mut T, args: Vec<Cow<'client, str>>) -> Self {
21+
Proxy { client, args }
2122
}
2223
}
2324

@@ -30,32 +31,19 @@ where
3031
/// # Errors
3132
///
3233
/// Returns an [`std::io::Error`] if granting the advancement fails.
33-
pub async fn grant(self, grant: Grant) -> Result<String, minecraft::Error> {
34-
parse_response(
35-
self.client
36-
.run_utf8(format!(
37-
"grant {} {}",
38-
self.target.serialize(),
39-
grant.serialize()
40-
))
41-
.await?,
42-
)
34+
pub async fn grant(mut self, grant: Grant) -> Result<String, minecraft::Error> {
35+
self.args.extend(["grant".into(), grant.serialize().into()]);
36+
parse_response(self.client.run_utf8(self.args.join(" ")).await?)
4337
}
4438

4539
/// Revoke some advancement.
4640
///
4741
/// # Errors
4842
///
4943
/// Returns an [`std::io::Error`] if revoking the advancement fails.
50-
pub async fn revoke(self, grant: Grant) -> Result<String, minecraft::Error> {
51-
parse_response(
52-
self.client
53-
.run_utf8(format!(
54-
"revoke {} {}",
55-
self.target.serialize(),
56-
grant.serialize()
57-
))
58-
.await?,
59-
)
44+
pub async fn revoke(mut self, grant: Grant) -> Result<String, minecraft::Error> {
45+
self.args
46+
.extend(["revoke".into(), grant.serialize().into()]);
47+
parse_response(self.client.run_utf8(self.args.join(" ")).await?)
6048
}
6149
}

0 commit comments

Comments
 (0)