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
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.mojang.brigadier.CommandDispatcher
20- import net.minecraft.command.CommandException
2115import net.minecraft.command.CommandSource
2216import net.minecraft.command.Commands
2317import net.minecraft.command.arguments.EntityArgument
2418import net.minecraft.command.impl.GameModeCommand
25- import net.minecraft.entity.player.ServerPlayerEntity
26- import net.minecraft.util.text.Style
2719import net.minecraft.world.GameType
2820
2921internal object GameModeCommand : VanillaCommandBase(" gamemode" ) {
@@ -36,12 +28,14 @@ internal object GameModeCommand : VanillaCommandBase("gamemode") {
3628 GameType .values().forEach { type ->
3729 if (type != GameType .NOT_SET ) {
3830 literal.then(
39- Commands .literal(type.getName()).executes {
40- checkPermissions(it.source, type, false )
31+ Commands .literal(type.getName()).requires {
32+ isAllowed(it, " gamemode.${type.getName()} " , 2 )
33+ }.executes {
4134 GameModeCommand .setGameMode(it, setOf (it.source.asPlayer()), type)
4235 }.then(
43- Commands .argument(" target" , EntityArgument .players()).executes {
44- checkPermissions(it.source, type, true )
36+ Commands .argument(" target" , EntityArgument .players()).requires {
37+ isAllowed(it, " gamemode.${type.getName()} .other" , 3 )
38+ }.executes {
4539 GameModeCommand .setGameMode(
4640 it, EntityArgument .getPlayers(it, " target" ), type
4741 )
@@ -59,43 +53,16 @@ internal object GameModeCommand : VanillaCommandBase("gamemode") {
5953 }
6054
6155 private fun short (short : String , mode : GameType ) {
62- Commands .literal(short).executes {
63- checkPermissions(it.source, mode, false )
56+ Commands .literal(short).requires {
57+ isAllowed(it, " gamemode.${mode.getName()} " , 2 )
58+ }.executes {
6459 GameModeCommand .setGameMode(it, setOf (it.source.asPlayer()), mode)
6560 }.then(
66- Commands .argument(" target" , EntityArgument .players()).executes {
67- checkPermissions(it.source, mode, true )
61+ Commands .argument(" target" , EntityArgument .players()).requires {
62+ isAllowed(it, " gamemode.${mode.getName()} .other" , 3 )
63+ }.executes {
6864 GameModeCommand .setGameMode(it, EntityArgument .getPlayers(it, " target" ), mode)
6965 }
7066 ).also { CommandAPI .getDispatcher().register(it) }
7167 }
72-
73- private fun checkPermissions (source : CommandSource , gameTypeIn : GameType , other : Boolean ) {
74- if (source !is ServerPlayerEntity ) return
75- if (! hasPermission(
76- source.asPlayer(),
77- " native.gamemode.${gameTypeIn.getName()}${if (other) " .other" else " " } " ,
78- if (other) 3 else 2
79- )
80- ) {
81- throw CommandException (
82- textComponentFrom(
83- source.asPlayer(),
84- generalConfiguration.getBool(SETTING_LOC_ENABLED ),
85- " native.command.restricted"
86- ).setStyle(
87- Style ().setHoverEvent(
88- hoverEventFrom(
89- source.asPlayer(),
90- generalConfiguration.getBool(SETTING_LOC_ENABLED ),
91- " native.command.restricted_hover" ,
92- " native.gamemode.${gameTypeIn.getName()}${if (other) " .other" else " " } " ,
93- if (other) " 3" else " 2"
94- )
95- )
96- )
97- )
98- }
99- }
10068}
101-
0 commit comments