@@ -6,13 +6,15 @@ use flecs_ecs::{
66 prelude:: { Component , Module } ,
77} ;
88use hyperion:: {
9- net:: { Compose , agnostic} ,
9+ net:: { Compose , DataBundle , NetworkStreamRef , agnostic} ,
1010 simulation:: { command:: get_root_command_entity, handlers:: PacketSwitchQuery } ,
1111 storage:: { CommandCompletionRequest , EventFn } ,
1212 system_registry:: SystemId ,
1313} ;
14+ pub use hyperion_clap_macros:: CommandPermission ;
1415pub use hyperion_command;
1516use hyperion_command:: { CommandHandler , CommandRegistry } ;
17+ use hyperion_permission:: Group ;
1618use valence_protocol:: {
1719 VarInt ,
1820 packets:: {
@@ -21,7 +23,7 @@ use valence_protocol::{
2123 } ,
2224} ;
2325
24- pub trait MinecraftCommand : Parser {
26+ pub trait MinecraftCommand : Parser + CommandPermission {
2527 fn execute ( self , world : & World , caller : Entity ) ;
2628
2729 fn register ( registry : & mut CommandRegistry , world : & World ) {
@@ -51,7 +53,29 @@ pub trait MinecraftCommand: Parser {
5153 let input = input. split_whitespace ( ) ;
5254
5355 match Self :: try_parse_from ( input) {
54- Ok ( elem) => elem. execute ( world, caller) ,
56+ Ok ( elem) => {
57+ if world. get :: < & Compose > ( |compose| {
58+ caller
59+ . entity_view ( world)
60+ . get :: < ( & NetworkStreamRef , & Group ) > ( |( stream, group) | {
61+ if elem. has_required_permission ( * group) {
62+ true
63+ } else {
64+ let chat = agnostic:: chat (
65+ "§cYou do not have permission to use this command!" ,
66+ ) ;
67+
68+ let mut bundle = DataBundle :: new ( compose) ;
69+ bundle. add_packet ( & chat, world) . unwrap ( ) ;
70+ bundle. send ( world, * stream, SystemId ( 8 ) ) . unwrap ( ) ;
71+
72+ false
73+ }
74+ } )
75+ } ) {
76+ elem. execute ( world, caller) ;
77+ }
78+ }
5579 Err ( e) => {
5680 // add red if not display help
5781 let prefix = match e. kind ( ) {
@@ -225,6 +249,10 @@ impl MinecraftArg for ClapArg {
225249 }
226250}
227251
252+ pub trait CommandPermission {
253+ fn has_required_permission ( & self , user_group : hyperion_permission:: Group ) -> bool ;
254+ }
255+
228256#[ derive( Clone , Debug , ValueEnum , PartialEq , Eq ) ]
229257pub enum GameMode {
230258 Survival ,
0 commit comments