@@ -7,7 +7,7 @@ use flecs_ecs::{
7
7
} ;
8
8
use hyperion:: {
9
9
net:: { Compose , DataBundle , NetworkStreamRef , agnostic} ,
10
- simulation:: { command:: get_root_command_entity, handlers:: PacketSwitchQuery } ,
10
+ simulation:: { IgnMap , command:: get_root_command_entity, handlers:: PacketSwitchQuery } ,
11
11
storage:: { CommandCompletionRequest , EventFn } ,
12
12
system_registry:: SystemId ,
13
13
} ;
@@ -268,8 +268,97 @@ pub enum GameMode {
268
268
#[ derive( Component ) ]
269
269
pub struct ClapCommandModule ;
270
270
271
+ #[ derive( clap:: Parser , Debug ) ]
272
+ pub struct SetCommand {
273
+ player : String ,
274
+ group : Group ,
275
+ }
276
+
277
+ #[ derive( clap:: Parser , Debug ) ]
278
+ pub struct GetCommand {
279
+ player : String ,
280
+ }
281
+
282
+ #[ derive( Parser , CommandPermission , Debug ) ]
283
+ #[ command( name = "perms" ) ]
284
+ #[ command_permission( group = "Normal" ) ]
285
+ pub enum PermissionCommand {
286
+ Set ( SetCommand ) ,
287
+ Get ( GetCommand ) ,
288
+ }
289
+
290
+ impl MinecraftCommand for PermissionCommand {
291
+ fn execute ( self , world : & World , caller : Entity ) {
292
+ world. get :: < & IgnMap > ( |ign_map| {
293
+ match self {
294
+ Self :: Set ( cmd) => {
295
+ // Handle setting permissions
296
+ let Some ( entity) = ign_map. get ( cmd. player . as_str ( ) ) else {
297
+ caller
298
+ . entity_view ( world)
299
+ . get :: < & NetworkStreamRef > ( |stream| {
300
+ let msg = format ! ( "§c{} not found" , cmd. player) ;
301
+ let chat = hyperion:: net:: agnostic:: chat ( msg) ;
302
+ world. get :: < & Compose > ( |compose| {
303
+ compose. unicast ( & chat, * stream, SystemId ( 8 ) , world) . unwrap ( ) ;
304
+ } ) ;
305
+ } ) ;
306
+ return ;
307
+ } ;
308
+
309
+ entity. entity_view ( world) . get :: < & mut Group > ( |group| {
310
+ * group = cmd. group ;
311
+ caller
312
+ . entity_view ( world)
313
+ . get :: < & NetworkStreamRef > ( |stream| {
314
+ let msg = format ! (
315
+ "§b{}§r's group has been set to §e{:?}" ,
316
+ cmd. player, cmd. group
317
+ ) ;
318
+ let chat = hyperion:: net:: agnostic:: chat ( msg) ;
319
+ world. get :: < & Compose > ( |compose| {
320
+ compose. unicast ( & chat, * stream, SystemId ( 8 ) , world) . unwrap ( ) ;
321
+ } ) ;
322
+ } ) ;
323
+ } ) ;
324
+ }
325
+ Self :: Get ( cmd) => {
326
+ let Some ( entity) = ign_map. get ( cmd. player . as_str ( ) ) else {
327
+ caller
328
+ . entity_view ( world)
329
+ . get :: < & NetworkStreamRef > ( |stream| {
330
+ let msg = format ! ( "§c{} not found" , cmd. player) ;
331
+ let chat = hyperion:: net:: agnostic:: chat ( msg) ;
332
+ world. get :: < & Compose > ( |compose| {
333
+ compose. unicast ( & chat, * stream, SystemId ( 8 ) , world) . unwrap ( ) ;
334
+ } ) ;
335
+ } ) ;
336
+ return ;
337
+ } ;
338
+
339
+ entity. entity_view ( world) . get :: < & Group > ( |group| {
340
+ caller
341
+ . entity_view ( world)
342
+ . get :: < & NetworkStreamRef > ( |stream| {
343
+ let msg = format ! ( "§b{}§r's group is §e{:?}" , cmd. player, group) ;
344
+ let chat = hyperion:: net:: agnostic:: chat ( msg) ;
345
+ world. get :: < & Compose > ( |compose| {
346
+ compose. unicast ( & chat, * stream, SystemId ( 8 ) , world) . unwrap ( ) ;
347
+ } ) ;
348
+ } ) ;
349
+ } ) ;
350
+ }
351
+ }
352
+ } ) ;
353
+ }
354
+ }
355
+
271
356
impl Module for ClapCommandModule {
272
357
fn module ( world : & World ) {
273
358
world. import :: < hyperion_command:: CommandModule > ( ) ;
359
+
360
+ world. get :: < & mut CommandRegistry > ( |registry| {
361
+ PermissionCommand :: register ( registry, world) ;
362
+ } ) ;
274
363
}
275
364
}
0 commit comments