1
1
package com.mairwunnx.projectessentials.permissions.impl.commands
2
2
3
+ import com.mairwunnx.projectessentials.core.api.v1.commands.CommandAPI
4
+ import com.mairwunnx.projectessentials.permissions.api.v1.PermissionsAPI
3
5
import com.mojang.brigadier.arguments.BoolArgumentType
4
6
import com.mojang.brigadier.arguments.IntegerArgumentType
5
7
import com.mojang.brigadier.arguments.StringArgumentType
6
8
import com.mojang.brigadier.builder.LiteralArgumentBuilder
7
9
import com.mojang.brigadier.builder.LiteralArgumentBuilder.literal
8
10
import net.minecraft.command.CommandSource
9
11
import net.minecraft.command.Commands
12
+ import net.minecraft.command.ISuggestionProvider
13
+ import net.minecraftforge.fml.server.ServerLifecycleHooks.getCurrentServer
10
14
11
15
fun takePermissionsLiteral (): LiteralArgumentBuilder <CommandSource > =
12
16
literal<CommandSource >(" permissions" ).then(
@@ -17,26 +21,47 @@ fun takePermissionsLiteral(): LiteralArgumentBuilder<CommandSource> =
17
21
Commands .literal(" user" ).then(
18
22
Commands .literal(" info" ).then(
19
23
Commands .argument(" user-name" , StringArgumentType .string())
24
+ .suggests { _, builder ->
25
+ ISuggestionProvider .suggest(
26
+ getCurrentServer().playerList.players.map { it.name.string }, builder
27
+ )
28
+ }
20
29
.executes { PermissionsCommand .userInfo(it) }
21
30
)
22
31
).then(
23
32
Commands .literal(" remove" ).then(
24
33
Commands .argument(" user-name" , StringArgumentType .string())
25
- .executes { PermissionsCommand .userRemove(it) }
34
+ .suggests { _, builder ->
35
+ ISuggestionProvider .suggest(
36
+ PermissionsAPI .getUsers().map { it.nickname }, builder
37
+ )
38
+ }.executes { PermissionsCommand .userRemove(it) }
26
39
)
27
40
).then(
28
41
Commands .literal(" permissions" ).then(
29
42
Commands .argument(
30
43
" user-name" , StringArgumentType .string()
31
- ).then(
44
+ ).suggests { _, builder ->
45
+ ISuggestionProvider .suggest(
46
+ getCurrentServer().playerList.players.map { it.name.string }, builder
47
+ )
48
+ }.then(
32
49
Commands .literal(" add" ).then(
33
50
Commands .argument(" node" , StringArgumentType .string())
34
51
.executes { PermissionsCommand .userPermissionsAdd(it) }
35
52
)
36
53
).then(
37
54
Commands .literal(" remove" ).then(
38
55
Commands .argument(" node" , StringArgumentType .string())
39
- ).executes { PermissionsCommand .userPermissionsRemove(it) }
56
+ .suggests { context, builder ->
57
+ ISuggestionProvider .suggest(
58
+ PermissionsAPI .getUserPermissions(
59
+ CommandAPI .getString(context, " user-name" ), false
60
+ ), builder
61
+ )
62
+ }
63
+ .executes { PermissionsCommand .userPermissionsRemove(it) }
64
+ )
40
65
).then(
41
66
Commands .literal(" list" ).then(
42
67
Commands .argument(" deep" , BoolArgumentType .bool())
@@ -56,9 +81,19 @@ fun takePermissionsLiteral(): LiteralArgumentBuilder<CommandSource> =
56
81
Commands .literal(" set" ).then(
57
82
Commands .argument(
58
83
" group-name" , StringArgumentType .string()
59
- ).then(
84
+ ).suggests { _, builder ->
85
+ ISuggestionProvider .suggest(
86
+ PermissionsAPI .getGroups().map { it.name }, builder
87
+ )
88
+ }.then(
60
89
Commands .literal(" for" ).then(
61
90
Commands .argument(" user-name" , StringArgumentType .string())
91
+ .suggests { _, builder ->
92
+ ISuggestionProvider .suggest(
93
+ getCurrentServer().playerList.players.map { it.name.string },
94
+ builder
95
+ )
96
+ }
62
97
.executes { PermissionsCommand .userSetGroup(it) }
63
98
)
64
99
)
@@ -75,7 +110,11 @@ fun takePermissionsLiteral(): LiteralArgumentBuilder<CommandSource> =
75
110
Commands .literal(" set-default" ).then(
76
111
Commands .argument(
77
112
" group-name" , StringArgumentType .string()
78
- ).executes { PermissionsCommand .groupDefaultSet(it) }
113
+ ).suggests { _, builder ->
114
+ ISuggestionProvider .suggest(
115
+ PermissionsAPI .getGroups().filter { ! it.isDefault }.map { it.name }, builder
116
+ )
117
+ }.executes { PermissionsCommand .groupDefaultSet(it) }
79
118
)
80
119
).then(
81
120
Commands .literal(" create" ).then(
@@ -86,20 +125,31 @@ fun takePermissionsLiteral(): LiteralArgumentBuilder<CommandSource> =
86
125
Commands .literal(" remove" ).then(
87
126
Commands .argument(
88
127
" group-name" , StringArgumentType .string()
89
- ).executes { PermissionsCommand .groupRemove(it) }
128
+ ).suggests { _, builder ->
129
+ ISuggestionProvider .suggest(PermissionsAPI .getGroups().map { it.name }, builder)
130
+ }.executes { PermissionsCommand .groupRemove(it) }
90
131
)
91
132
).then(
92
133
Commands .literal(" permissions" ).then(
93
134
Commands .argument(
94
135
" group-name" , StringArgumentType .string()
95
- ).then(
136
+ ).suggests { _, builder ->
137
+ ISuggestionProvider .suggest(PermissionsAPI .getGroups().map { it.name }, builder)
138
+ }.then(
96
139
Commands .literal(" add" ).then(
97
140
Commands .argument(" node" , StringArgumentType .string())
98
141
.executes { PermissionsCommand .groupPermissionsAdd(it) }
99
142
)
100
143
).then(
101
144
Commands .literal(" remove" ).then(
102
145
Commands .argument(" node" , StringArgumentType .string())
146
+ .suggests { context, builder ->
147
+ ISuggestionProvider .suggest(
148
+ PermissionsAPI .getGroupPermissions(
149
+ CommandAPI .getString(context, " group-name" )
150
+ ), builder
151
+ )
152
+ }
103
153
.executes { PermissionsCommand .groupPermissionsRemove(it) }
104
154
)
105
155
).then(
@@ -120,17 +170,33 @@ fun takePermissionsLiteral(): LiteralArgumentBuilder<CommandSource> =
120
170
Commands .literal(" inherit" ).then(
121
171
Commands .argument(
122
172
" group-name" , StringArgumentType .string()
123
- ).then(
173
+ ).suggests { _, builder ->
174
+ ISuggestionProvider .suggest(
175
+ PermissionsAPI .getGroups().map { it.name }, builder
176
+ )
177
+ }.then(
124
178
Commands .literal(" add" ).then(
125
179
Commands .argument(
126
180
" inherit-group" , StringArgumentType .string()
127
- ).executes { PermissionsCommand .groupInheritAdd(it) }
181
+ ).suggests { context, builder ->
182
+ ISuggestionProvider .suggest(
183
+ PermissionsAPI .getGroups().filter {
184
+ it.name != CommandAPI .getString(context, " group-name" )
185
+ }.map { it.name }, builder
186
+ )
187
+ }.executes { PermissionsCommand .groupInheritAdd(it) }
128
188
)
129
189
).then(
130
190
Commands .literal(" remove" ).then(
131
191
Commands .argument(
132
192
" inherit-group" , StringArgumentType .string()
133
- ).executes { PermissionsCommand .groupInheritRemove(it) }
193
+ ).suggests { context, builder ->
194
+ ISuggestionProvider .suggest(
195
+ PermissionsAPI .getGroupInherits(
196
+ CommandAPI .getString(context, " group-name" ), false
197
+ ), builder
198
+ )
199
+ }.executes { PermissionsCommand .groupInheritRemove(it) }
134
200
)
135
201
).then(
136
202
Commands .literal(" list" ).then(
@@ -143,7 +209,11 @@ fun takePermissionsLiteral(): LiteralArgumentBuilder<CommandSource> =
143
209
Commands .literal(" prefix" ).then(
144
210
Commands .argument(
145
211
" group-name" , StringArgumentType .string()
146
- ).then(
212
+ ).suggests { _, builder ->
213
+ ISuggestionProvider .suggest(
214
+ PermissionsAPI .getGroups().map { it.name }, builder
215
+ )
216
+ }.then(
147
217
Commands .argument(" prefix" , StringArgumentType .string())
148
218
.executes { PermissionsCommand .groupPrefixSet(it) }
149
219
).executes { PermissionsCommand .groupPrefixTake(it) }
0 commit comments