11/* *
2-  * ! This command implementation by Mojang Game  Studios! 
2+  * ! This command implementation by Mojang Studios! 
33 * 
44 * Decompiled with idea source code was converted to kotlin code. 
55 * But with additions such as permissions checking and etc. 
99 */  
1010package  com.mairwunnx.projectessentials.core.impl.vanilla.commands 
1111
12- import  com.mairwunnx.projectessentials.core.api.v1.SETTING_LOC_ENABLED 
1312import  com.mairwunnx.projectessentials.core.api.v1.commands.CommandAPI.getDispatcher 
1413import  com.mairwunnx.projectessentials.core.api.v1.commands.CommandAliases 
15- import  com.mairwunnx.projectessentials.core.api.v1.extensions.hoverEventFrom 
16- import  com.mairwunnx.projectessentials.core.api.v1.extensions.textComponentFrom 
17- import  com.mairwunnx.projectessentials.core.api.v1.permissions.hasPermission 
18- import  com.mairwunnx.projectessentials.core.impl.generalConfiguration 
1914import  com.mairwunnx.projectessentials.core.impl.nativeMappingsConfiguration 
2015import  com.mojang.brigadier.CommandDispatcher 
2116import  com.mojang.brigadier.arguments.IntegerArgumentType 
22- import  net.minecraft.command.CommandException 
2317import  net.minecraft.command.CommandSource 
2418import  net.minecraft.command.Commands 
2519import  net.minecraft.command.Commands.literal 
2620import  net.minecraft.command.arguments.TimeArgument 
2721import  net.minecraft.command.impl.TimeCommand 
28- import  net.minecraft.entity.player.ServerPlayerEntity 
29- import  net.minecraft.util.text.Style 
3022
3123internal  object  TimeCommand : VanillaCommandBase(" time" 
3224 override  fun  register (dispatcher :  CommandDispatcher <CommandSource >) {
@@ -42,53 +34,65 @@ internal object TimeCommand : VanillaCommandBase("time") {
4234 dispatcher.register(
4335 literal(" time" 
4436 literal(" set" 
45-  literal(" day" TimeCommand .setTime(it.source, 1000 ) }
37+  literal(" day" " set" 
38+  TimeCommand .setTime(it.source, 1000 )
39+  }
4640 ).then(
47-  literal(" noon" TimeCommand .setTime(it.source, 6000 ) }
41+  literal(" noon" " set" 
42+  TimeCommand .setTime(it.source, 6000 )
43+  }
4844 ).then(
49-  literal(" sunset" TimeCommand .setTime(it.source, 12000 ) }
45+  literal(" sunset" " set" 
46+  TimeCommand .setTime(it.source, 12000 )
47+  }
5048 ).then(
51-  literal(" night" TimeCommand .setTime(it.source, 13000 ) }
49+  literal(" night" " set" 
50+  TimeCommand .setTime(it.source, 13000 )
51+  }
5252 ).then(
53-  literal(" midnight" TimeCommand .setTime(it.source, 18000 ) }
53+  literal(" midnight" " set" 
54+  TimeCommand .setTime(it.source, 18000 )
55+  }
5456 ).then(
55-  literal(" sunrise" TimeCommand .setTime(it.source, 23000 ) }
57+  literal(" sunrise" " set" 
58+  TimeCommand .setTime(it.source, 23000 )
59+  }
5660 ).then(
5761 Commands .argument(
5862 " time" TimeArgument .func_218091_a()
59-  ).executes {
60-  permission(it.source, " set" 
63+  ).requires { permission(it, " set" 
6164 TimeCommand .setTime(it.source, IntegerArgumentType .getInteger(it, " time" 
6265 }
6366 )
6467 ).then(
6568 literal(" add" 
6669 Commands .argument(
6770 " time" TimeArgument .func_218091_a()
68-  ).executes {
69-  permission(it.source, " add" 
71+  ).requires { permission(it, " add" 
7072 TimeCommand .addTime(it.source, IntegerArgumentType .getInteger(it, " time" 
7173 }
7274 )
7375 ).then(
7476 literal(" query" 
75-  literal(" daytime" 
76-  permission(it.source, " query" 
77+  literal(" daytime" 
78+  permission(it, " query" 
79+  }.executes {
7780 TimeCommand .sendQueryResults(
78-  it.source,
79-  TimeCommand .getDayTime(it.source.world)
81+  it.source, TimeCommand .getDayTime(it.source.world)
8082 )
8183 }
8284 ).then(
83-  literal(" gametime" 
84-  permission(it.source, " query" 
85+  literal(" gametime" 
86+  permission(it, " query" 
87+  }.executes {
8588 TimeCommand .sendQueryResults(
8689 it.source, (it.source.world.gameTime %  2147483647L ).toInt()
8790 )
8891 }
8992 ).then(
90-  literal(" day" 
91-  permission(it.source, " query" 
93+  literal(" day" 
94+  permission(it, " query" 
95+  }.executes {
9296 TimeCommand .sendQueryResults(
9397 it.source, (it.source.world.dayTime /  24000L  %  2147483647L ).toInt()
9498 )
@@ -98,35 +102,17 @@ internal object TimeCommand : VanillaCommandBase("time") {
98102 )
99103 }
100104
101-  private  fun  permission (source :  CommandSource , type :  String ) {
102-  val  node = 
103-  if  (type ==  " add" ||  type ==  " set" " native.time.change.$type " else  " native.time.query" 
104-  if  (source.entity is  ServerPlayerEntity  &&  ! hasPermission(source.asPlayer(), node, 2 )) {
105-  throw  CommandException (
106-  textComponentFrom(
107-  source.asPlayer(),
108-  generalConfiguration.getBool(SETTING_LOC_ENABLED ),
109-  " native.command.restricted" 
110-  ).setStyle(
111-  Style ().setHoverEvent(
112-  hoverEventFrom(
113-  source.asPlayer(),
114-  generalConfiguration.getBool(SETTING_LOC_ENABLED ),
115-  " native.command.restricted_hover" 
116-  node, " 2" 
117-  )
118-  )
119-  )
120-  )
121-  }
105+  private  fun  permission (source :  CommandSource , type :  String ): Boolean  {
106+  val  node =  if  (type ==  " add" ||  type ==  " set" 
107+  " time.change.$type " 
108+  } else  " time.query" 
109+  return  isAllowed(source, node, 2 )
122110 }
123111
124112 fun  short (name :  String , time :  Int ) {
125113 aliasesOf(name).forEach { command -> 
126114 getDispatcher().register(literal(command).requires {
127-  if  (it.entity is  ServerPlayerEntity ) {
128-  hasPermission(it.entity as  ServerPlayerEntity , " native.time.change.set" 2 )
129-  } else  true 
115+  permission(it, " set" 
130116 }.executes { TimeCommand .setTime(it.source, time) })
131117 }
132118 }
0 commit comments