Skip to content

Commit 1f4ec1f

Browse files
committed
GameModeCommand.kt generic permission added.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent c3ac051 commit 1f4ec1f

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
lines changed

src/main/kotlin/com/mairwunnx/projectessentials/core/impl/vanilla/commands/GameModeCommand.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ internal object GameModeCommand : VanillaCommandBase("gamemode") {
3131
val literal = Commands.literal(name)
3232
GameType.values().forEach { type ->
3333
if (type != GameType.NOT_SET) {
34-
literal.then(
34+
literal.requires {
35+
isAllowedAny(it) {
36+
listOf(
37+
"native.gamemode.survival" to 2,
38+
"native.gamemode.creative" to 2,
39+
"native.gamemode.adventure" to 2,
40+
"native.gamemode.spectator" to 2
41+
)
42+
}
43+
}.then(
3544
Commands.literal(type.getName()).requires {
3645
isAllowed(it, "gamemode.${type.getName()}", 2)
3746
}.executes {

src/main/kotlin/com/mairwunnx/projectessentials/core/impl/vanilla/commands/TimeCommand.kt

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,67 +32,65 @@ internal object TimeCommand : VanillaCommandBase("time") {
3232
aliases()
3333

3434
dispatcher.register(
35-
literal("time").then(
36-
literal("set").then(
37-
literal("day").requires { permission(it, "set") }.executes {
35+
literal("time").requires {
36+
isAllowedAny(it) {
37+
listOf("time.change.set" to 2, "time.change.add" to 2, "time.query" to 2)
38+
}
39+
}.then(
40+
literal("set").requires { permission(it, "set") }.then(
41+
literal("day").executes {
3842
TimeCommand.setTime(it.source, 1000)
3943
}
4044
).then(
41-
literal("noon").requires { permission(it, "set") }.executes {
45+
literal("noon").executes {
4246
TimeCommand.setTime(it.source, 6000)
4347
}
4448
).then(
45-
literal("sunset").requires { permission(it, "set") }.executes {
49+
literal("sunset").executes {
4650
TimeCommand.setTime(it.source, 12000)
4751
}
4852
).then(
49-
literal("night").requires { permission(it, "set") }.executes {
53+
literal("night").executes {
5054
TimeCommand.setTime(it.source, 13000)
5155
}
5256
).then(
53-
literal("midnight").requires { permission(it, "set") }.executes {
57+
literal("midnight").executes {
5458
TimeCommand.setTime(it.source, 18000)
5559
}
5660
).then(
57-
literal("sunrise").requires { permission(it, "set") }.executes {
61+
literal("sunrise").executes {
5862
TimeCommand.setTime(it.source, 23000)
5963
}
6064
).then(
6165
Commands.argument(
6266
"time", TimeArgument.func_218091_a()
63-
).requires { permission(it, "set") }.executes {
67+
).executes {
6468
TimeCommand.setTime(it.source, IntegerArgumentType.getInteger(it, "time"))
6569
}
6670
)
6771
).then(
68-
literal("add").then(
72+
literal("add").requires { permission(it, "add") }.then(
6973
Commands.argument(
7074
"time", TimeArgument.func_218091_a()
71-
).requires { permission(it, "add") }.executes {
75+
).executes {
7276
TimeCommand.addTime(it.source, IntegerArgumentType.getInteger(it, "time"))
7377
}
7478
)
7579
).then(
76-
literal("query").then(
77-
literal("daytime").requires {
78-
permission(it, "query")
79-
}.executes {
80+
literal("query").requires { permission(it, "query") }.then(
81+
literal("daytime").executes {
8082
TimeCommand.sendQueryResults(
8183
it.source, TimeCommand.getDayTime(it.source.world)
8284
)
8385
}
8486
).then(
85-
literal("gametime").requires {
86-
permission(it, "query")
87-
}.executes {
87+
literal("gametime").executes {
8888
TimeCommand.sendQueryResults(
8989
it.source, (it.source.world.gameTime % 2147483647L).toInt()
9090
)
9191
}
9292
).then(
93-
literal("day").requires {
94-
permission(it, "query")
95-
}.executes {
93+
literal("day").executes {
9694
TimeCommand.sendQueryResults(
9795
it.source, (it.source.world.dayTime / 24000L % 2147483647L).toInt()
9896
)

src/main/kotlin/com/mairwunnx/projectessentials/core/impl/vanilla/commands/VanillaCommandBase.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,13 @@ abstract class VanillaCommandBase(val name: String) {
1919
if (source.entity is ServerPlayerEntity) {
2020
hasPermission(source.asPlayer(), "native.$node", opLevel)
2121
} else true
22+
23+
@JvmStatic
24+
fun isAllowedAny(source: CommandSource, notation: () -> List<Pair<String, Int>>) =
25+
if (source.entity is ServerPlayerEntity) {
26+
notation().forEach {
27+
if (hasPermission(source.asPlayer(), it.first, it.second)) return true
28+
}.let { false }
29+
} else true
2230
}
2331
}

src/main/kotlin/com/mairwunnx/projectessentials/core/impl/vanilla/commands/WeatherCommand.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ internal object WeatherCommand : VanillaCommandBase("weather") {
2828
super.register(dispatcher)
2929
short("sun").also { short("rain") }.also { short("thunder") }.also { aliases() }
3030
dispatcher.register(
31-
Commands.literal(name).then(
31+
Commands.literal(name).requires {
32+
isAllowedAny(it) {
33+
listOf("weather.sun" to 2, "weather.rain" to 2, "weather.thunder" to 2)
34+
}
35+
}.then(
3236
Commands.literal("clear").requires {
3337
isAllowed(it, "weather.sun", 2)
3438
}.executes {

0 commit comments

Comments
 (0)