11//! Gives, removes, or checks player advancements.
22
3+ use std:: borrow:: Cow ;
4+
35pub use grant:: Grant ;
46
5- use super :: TargetSelector ;
6- use crate :: minecraft:: { parse_response, Entity , Serialize } ;
7+ use crate :: minecraft:: { parse_response, Serialize } ;
78use crate :: { minecraft, RCon } ;
89
910mod grant;
@@ -12,12 +13,12 @@ mod grant;
1213#[ derive( Debug ) ]
1314pub struct Proxy < ' client , T > {
1415 client : & ' client mut T ,
15- target : Entity < TargetSelector > ,
16+ args : Vec < Cow < ' client , str > > ,
1617}
1718
1819impl < ' 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