11//! The implementations of various commands.
22
3- use crate :: arguments:: Coordinates ;
43use crate :: {
5- arguments:: { EntitySelector , ItemArgument , ParsedGamemode , PositiveI32Argument , TextArgument } ,
4+ arguments:: {
5+ Coordinates , EntitySelector , ItemArgument , ParsedGamemode , PositiveI32Argument ,
6+ TextArgument , TimeArgument , TimeQueryInformation , TimeSpec ,
7+ } ,
68 CommandCtx ,
79} ;
810use feather_core:: inventory:: { Inventory , SlotIndex } ;
@@ -11,7 +13,7 @@ use feather_core::util::{Gamemode, Position};
1113use feather_definitions:: Item ;
1214use feather_server_types:: {
1315 Ban , ChatEvent , ChatPosition , GamemodeUpdateEvent , InventoryUpdateEvent , MessageReceiver , Name ,
14- Player , ShutdownChannels , Teleported , WrappedBanInfo ,
16+ Player , ShutdownChannels , Teleported , TimeUpdateEvent , WrappedBanInfo ,
1517} ;
1618use feather_server_util:: { name_to_uuid_offline, name_to_uuid_online} ;
1719use fecs:: { Entity , IntoQuery , Read , ResourcesProvider , World } ;
@@ -816,3 +818,62 @@ pub fn pardonip(ctx: &mut CommandCtx, ip: String) -> anyhow::Result<()> {
816818
817819 Ok ( None )
818820}
821+
822+ #[ command( usage = "time query <info>" ) ]
823+ pub fn time_query ( ctx : & mut CommandCtx , info : TimeQueryInformation ) -> anyhow:: Result < ( ) > {
824+ let time = match info {
825+ TimeQueryInformation :: DayTime => ctx. game . time . time_of_day ( ) ,
826+ TimeQueryInformation :: GameTime => ctx. game . time . world_age ( ) ,
827+ TimeQueryInformation :: Day => ctx. game . time . days ( ) ,
828+ } ;
829+
830+ if let Some ( mut sender_message_receiver) = ctx. world . try_get_mut :: < MessageReceiver > ( ctx. sender )
831+ {
832+ let message = Text :: from ( TextValue :: translate_with (
833+ "commands.time.query" ,
834+ vec ! [ Text :: from( time. to_string( ) ) ] ,
835+ ) ) ;
836+ sender_message_receiver. send ( message) ;
837+ }
838+
839+ Ok ( None )
840+ }
841+
842+ #[ command( usage = "time add <time>" ) ]
843+ pub fn time_add ( ctx : & mut CommandCtx , time : TimeArgument ) -> anyhow:: Result < ( ) > {
844+ time_set ( ctx, ctx. game . time . time_of_day ( ) + time. 0 )
845+ }
846+
847+ #[ command( usage = "time set <time>" ) ]
848+ pub fn time_set_0 ( ctx : & mut CommandCtx , time : TimeArgument ) -> anyhow:: Result < ( ) > {
849+ time_set ( ctx, time. 0 )
850+ }
851+
852+ #[ command( usage = "time set <time_spec>" ) ]
853+ pub fn time_set_1 ( ctx : & mut CommandCtx , time_spec : TimeSpec ) -> anyhow:: Result < ( ) > {
854+ time_set (
855+ ctx,
856+ match time_spec {
857+ TimeSpec :: Day => 1_000 ,
858+ TimeSpec :: Noon => 6_000 ,
859+ TimeSpec :: Night => 13_000 ,
860+ TimeSpec :: Midnight => 18_000 ,
861+ } ,
862+ )
863+ }
864+
865+ pub fn time_set ( ctx : & mut CommandCtx , time : u64 ) -> anyhow:: Result < Option < String > > {
866+ ctx. game
867+ . handle ( & mut ctx. world , TimeUpdateEvent { new_time : time } ) ;
868+
869+ if let Some ( mut sender_message_receiver) = ctx. world . try_get_mut :: < MessageReceiver > ( ctx. sender )
870+ {
871+ let message = Text :: from ( TextValue :: translate_with (
872+ "commands.time.set" ,
873+ vec ! [ Text :: from( ctx. game. time. time_of_day( ) . to_string( ) ) ] ,
874+ ) ) ;
875+ sender_message_receiver. send ( message) ;
876+ }
877+
878+ Ok ( None )
879+ }
0 commit comments