Skip to content
This repository was archived by the owner on Feb 3, 2024. It is now read-only.

Commit 2afec54

Browse files
committed
minecraft: Move commands over to cloud library
This brings brigadier compatibility and a nice help menu
1 parent 48435f2 commit 2afec54

File tree

45 files changed

+1280
-193
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1280
-193
lines changed

api/src/main/java/ca/stellardrift/permissionsex/exception/PermissionsException.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import net.kyori.adventure.text.Component;
2020
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
2121
import net.kyori.adventure.translation.GlobalTranslator;
22+
import net.kyori.adventure.util.ComponentMessageThrowable;
2223
import org.checkerframework.checker.nullness.qual.Nullable;
2324

2425
import java.util.Locale;
@@ -28,7 +29,7 @@
2829
*
2930
* @since 2.0.0
3031
*/
31-
public class PermissionsException extends Exception {
32+
public class PermissionsException extends Exception implements ComponentMessageThrowable {
3233
private static final long serialVersionUID = 138001301588644173L;
3334
private static final Component NULL = Component.text("null");
3435

@@ -53,11 +54,12 @@ public String getLocalizedMessage() {
5354
return getLocalizedMessage(Locale.getDefault());
5455
}
5556

56-
public Component getComponent() {
57+
@Override
58+
public Component componentMessage() {
5759
return this.message == null ? NULL : this.message;
5860
}
5961

6062
public String getLocalizedMessage(Locale locale) {
61-
return PlainComponentSerializer.plain().serialize(GlobalTranslator.renderer().render(getComponent(), locale));
63+
return PlainComponentSerializer.plain().serialize(GlobalTranslator.renderer().render(componentMessage(), locale));
6264
}
6365
}

buildSrc/src/main/kotlin/pex-platform.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ val shadowJar = tasks.named("shadowJar", ShadowJar::class) {
2121
// Caffeine reflectively accesses some of its cache implementations, so it can't be minimized
2222
minimize {
2323
exclude(dependency("com.github.ben-manes.caffeine:.*:.*"))
24+
exclude(project(":datastore:sql"))
2425
}
2526

2627
// Don't shade compile-only annotations, or other project's module info files

core/src/main/java/ca/stellardrift/permissionsex/impl/util/PCollections.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ public static <E> PSet<E> set(final E element) {
201201
return HashTreePSet.singleton(element);
202202
}
203203

204+
@SafeVarargs
204205
public static <E> PSet<E> set(final E... elements) {
205206
PSet<E> out = set();
206207
for (final E element : elements) {
@@ -217,6 +218,7 @@ public static <E> PVector<E> vector(final E element) {
217218
return TreePVector.singleton(element);
218219
}
219220

221+
@SafeVarargs
220222
public static <E> PVector<E> vector(final E... elements) {
221223
PVector<E> out = vector();
222224
for (final E element : elements) {
@@ -233,6 +235,7 @@ public static <E> PStack<E> stack(final E element) {
233235
return ConsPStack.singleton(element);
234236
}
235237

238+
@SafeVarargs
236239
public static <E> PStack<E> stack(final E... elements) {
237240
PStack<E> out = stack();
238241
for (final E element : elements) {

core/src/main/kotlin/ca/stellardrift/permissionsex/util/TextExtensions.kt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package ca.stellardrift.permissionsex.util
1818

19-
import ca.stellardrift.permissionsex.context.ContextValue
2019
import java.text.MessageFormat
2120
import java.util.Locale
2221
import java.util.ResourceBundle
@@ -27,7 +26,6 @@ import net.kyori.adventure.text.Component.space
2726
import net.kyori.adventure.text.ComponentBuilder
2827
import net.kyori.adventure.text.ComponentLike
2928
import net.kyori.adventure.text.TextComponent
30-
import net.kyori.adventure.text.format.NamedTextColor
3129
import net.kyori.adventure.text.format.Style
3230
import net.kyori.adventure.text.format.Style.style
3331
import net.kyori.adventure.text.format.TextColor
@@ -45,11 +43,12 @@ fun Any?.toComponent(): Component {
4543
}
4644

4745
fun Boolean.toComponent(): Component {
48-
return if (this) {
46+
return +this.toString()
47+
/*return if (this) {
4948
Messages.FORMATTER_BOOLEAN_TRUE.bTr().color(NamedTextColor.GREEN)
5049
} else {
5150
Messages.FORMATTER_BOOLEAN_FALSE.bTr().color(NamedTextColor.RED)
52-
}.build()
51+
}.build()*/
5352
}
5453
operator fun Boolean.unaryPlus() = this.toComponent()
5554

@@ -98,14 +97,6 @@ operator fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> B.plusAs
9897

9998
// -- PEX-Specific
10099

101-
fun Set<ContextValue<*>>.toComponent(): Component {
102-
return if (isEmpty()) {
103-
Messages.COMMON_ARGS_CONTEXT_GLOBAL.tr()
104-
} else {
105-
+toString()
106-
}
107-
}
108-
109100
object PEXComponentRenderer : TranslatableComponentRenderer<Locale>() {
110101
override fun translate(key: String, context: Locale): MessageFormat {
111102
val idx = key.indexOf("/")

core/src/main/messages/ca/stellardrift/permissionsex/impl/commands/messages.properties

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,6 @@ delete.error.does-not-exist=Subject {0} does not exist!
123123
delete.success=Successfully deleted data for subject {0}
124124

125125

126-
command.arg-type.callback-id=An ID of a registered callback
127-
128-
command.callback.description=Execute a callback. This command is usually not run manually.
129-
command.callback.arg.callback-id=id
130-
command.callback.error.unknown-id=Unknown callback identifier {0}
131-
command.callback.error.only-own-allowed=You can only activate your own callbacks!
132126

133127

134128

doc/2.0-home.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This section contains documentation about the new 2.0 release of PermissionsEx.
44

55
Just getting started? You'll want to work through the [tutorial](tutorial.md).
66

7-
Coming from PermissionsEx v1? Take a look at the list of [changes in v2](https://github.com/PEXPlugins/PermissionsEx/tree/b8c6b5a57be63ae79911cb56dc5cc0df510bbe06/doc/changes-in-2.0.md), and the [new commands](https://github.com/PEXPlugins/PermissionsEx/tree/b8c6b5a57be63ae79911cb56dc5cc0df510bbe06/doc/command-equivalency.md).
7+
Coming from PermissionsEx v1? Take a look at the list of [changes in v2](learning-v2-from-other-plugins-and-v1/changes-in-2.0.md), and the [new commands](components-in-detail/command.md).
88

99
Take a look at the contents in sidebar for more information!
1010

doc/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* [Home](2.0-home.md)
44
* [Getting Started](tutorial.md)
5+
* [Commands](components-in-detail/command.md)
56
* [Components in Detail](components-in-detail/README.md)
67
* [Subject](components-in-detail/subject.md)
78
* [Defaults and Fallbacks](components-in-detail/defaults-and-fallbacks.md)

doc/components-in-detail/command.md

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
# Commands
2+
3+
PermissionsEx can be configured in-game using its set of commands:
4+
5+
## Argument types
6+
7+
- *subject type*: a type of subject
8+
- *subject*: A compound argument of subject type and identifier
9+
- *context*: A `<context-type>=<context-value>`
10+
- *rank-ladder*: The name of a currently existing rank ladder
11+
- *permission*: A permission string
12+
- *option*: An option string
13+
- *permission value*: a number, boolean, or `none`, `null`, or `unset`
14+
15+
16+
## Common flags
17+
18+
These flags can be specified after any permissions modification command to control the specific areas permissions are updated in:
19+
20+
- `--transient`: If the data should be stored transiently (i.e. only for the current session)
21+
- `--context <context>`: A context to restrict a permission to, such as a world
22+
23+
## The actual commands
24+
25+
### `/pex|permissionsex`
26+
27+
**Description:** Provides simple information about PermissionsEx.
28+
29+
### `/pex|permissionsex help [command]`
30+
31+
**Description:** Provide help about PermissionsEx commands
32+
33+
**Permission:** `permissionsex.help`
34+
35+
Provides an in-game help viewer for information on PermissionsEx commands
36+
37+
### `/pex|permissionsex debug|d [filter]`
38+
39+
**Description:** Toggle whether all permissions checks are logged to console
40+
41+
**Permission:** `permissionsex.debug`
42+
43+
When enabled, any check executed through PermissionsEx will be logged to console. If the `filter`
44+
regular expression is provided, only permissions, objects, and parent names that match the pattern will be logged.
45+
46+
### `/pex|permissionsex import [source data store]`
47+
48+
**Description:** Import data from another data store
49+
50+
**Permission:** `permissionsex.import`
51+
52+
Import permissions data from a configured backend, or automatically configured conversion provider.
53+
If no data store is specified, a list of available sources will be provided.
54+
55+
This import will fully replace any subject in the active data store that is also present in the source data store
56+
57+
### `/pex|permissionsex ranking|rank [ladder]`
58+
59+
**Description:** Print the contents of a rank ladder
60+
61+
**Permission:** `permissionsex.rank.view.<ladder>`
62+
63+
Clickable buttons are added to ease working with rank ladders.
64+
65+
### `/pex|permissionsex ranking|rank <ladder> add|+ <subject> [position] [-r|--relative]`
66+
67+
**Description:** Add a subject to the rank ladder
68+
69+
**Permission:** `permissionsex.rank.add.<ladder>`
70+
71+
Adds a subject to the rank ladder, by default at the end of the ladder. If a position is specified,
72+
the rank will be inserted at that position. If the rank is already on the ladder and the `--relative`
73+
flag is provided, the rank will be moved by the specified number of positions.
74+
75+
### `/pex|permissionsex ranking|rank <ladder> remove|rem|- <subject>`
76+
77+
**Description:** Remove a subject from a rank ladder.
78+
79+
**Permission:** `permissionsex.rank.remove.<ladder>`
80+
81+
Remove a subject from a rank ladder.
82+
83+
### `/pex|permissionsex reload|rel`
84+
85+
**Description:** Reload all PermissionsEx configuration
86+
87+
**Permission:** `permissionsex.reload`
88+
89+
Reloads all permissions data. The reload is performed asynchronously, and new data will only be
90+
applied if the reload is successful.
91+
92+
### `/pex|permissionsex version [--verbose|-v]`
93+
94+
**Description**: Provide information on the current PermissionsEx version.
95+
96+
**Permission:** `permissionsex.version`
97+
98+
Print detailed information on the version of PermissionsEx that is currently running. If
99+
the `verbose` option is provided, more detailed information on base directories will be printed.
100+
101+
### `/pex|permissionsex <type> <subject> delete [--transient|-t]`
102+
103+
**Description:**: Delete all data for a subject
104+
105+
**Permission:** `permissionsex.delete.<type>.<subject>`
106+
107+
### `/pex|permissionsex <type> <subject> info`
108+
109+
**Description:**: Print all known information for a certain subject.
110+
111+
**Permission:** `permissionsex.info.<type>.<subject>`
112+
113+
All information will be printed for the subject
114+
115+
### `/pex|permissionsex <type> <subject> option|options|opt|o|meta <key> [value] [--transient|-t] [--context key=value]`
116+
117+
**Description:**: Sets or unsets an option for the subject
118+
119+
**Permission:** `permissionsex.option.set.<type>.<subject>`
120+
121+
Sets (if `value` is provided) or unset (if not provided) a certain option on the subject.
122+
123+
### `/pex|permissionsex <type> <subject> parents|parent|par|p add|a|+ <type> <subject> [--transient|t] [--context key=value]`
124+
125+
**Description:**: Adds a parent to the subject
126+
127+
**Permission:** `permissionsex.parent.add.<type>.<subject>`
128+
129+
The parent will be added at the first position to the subject, meaning it will take priority over other parents.
130+
131+
### `/pex|permissionsex <type> <subject> parents|parent|par|p remove|rem|delete|del|- <type> <subject> [--transient|t] [--context key=value]`
132+
133+
**Description:**: Adds a parent to the subject
134+
135+
**Permission:** `permissionsex.parent.remove.<type>.<subject>`
136+
137+
Remove the specified parent from the subject.
138+
139+
### `/pex|permissionsex <type> <subject> parents|parent|par|p remove|rem|delete|del|- <type> <subject> [--transient|t] [--context key=value...]`
140+
141+
**Description:**: Replace all parents of the subject with one parent.
142+
143+
**Permission:** `permissionsex.parent.set.<type>.<subject>`
144+
145+
Remove all parents from the subject and replace them with the one provided subject.
146+
147+
### `/pex|permissionsex <type> <subject> permission|permissions|perm|perms|p <permission> <value> [--transient|t] [--context key=value...]`
148+
149+
**Description:**: Set the permission for a subject
150+
151+
**Permission:** `permissionsex.permission.set.<type>.<subject>`
152+
153+
Set a permission on the subject.
154+
155+
Permission values can be a true or false value to explicitly set the permission, `none`, `null`, or `unset` to clear
156+
the permission, or a number to assign a weight to the permission.
157+
158+
- Prefixing a permission with `#` means that its value will only be applicable to a subject and its direct parents.
159+
- Glob syntax will be evaluated for permissions:
160+
- `permissionsex.{permission,parent}.set` will evaluate to both `permissionsex.permission.set` and `permissionsex.parent.set`
161+
- `some.permission[a-z]` will match `some.permissiona`, `some.permissionb`, and so on, all the way through until `some.permissionz`
162+
163+
### `/pex|permissionsex <type> <subject> permission-default|perms-def|permsdef|pdef|pd|default|def <value> [--transient|t] [--context key=value...]`
164+
165+
**Description:**: Set the fallback permission value for a subject
166+
167+
**Permission:** `permissionsex.permission.set-default.<type>.<subject>`
168+
169+
Set the default permissions value for a subject. This is the result that is returned for a subject
170+
when no more specific node matches.
171+
172+
This value is roughly equivalent to the `*` permission formerly used, but will not override
173+
permissions specifically set to `false`.

doc/contributing/commands-api.md

Lines changed: 0 additions & 33 deletions
This file was deleted.

doc/contributing/localization.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ An eventual goal is to allow overriding messages using files in the plugin data
1414

1515
While we eventually plan to put up a CrowdIn page to allow translations to be contributed more easily, the only way to contribute at the moment is to provide new versions of the files in the `src/main/messages` folder in each module.
1616

17-
Feel free to ask for help in the Discord -- we will be happy to assist in getting more localizations in
17+
Feel free to ask for help in the Discord -- we will be happy to assist in getting more localizations in.
1818

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ adventurePlatformVersion=4.0.0-SNAPSHOT
3030
antlrVersion=4.9
3131
autoServiceVersion=1.0-rc7
3232
checkerVersion=3.7.1
33+
cloudVersion=1.3.0
3334
configurateVersion=4.0.0
3435
errorproneVersion=2.4.0
3536
immutablesVersion=2.8.8

impl-blocks/minecraft/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,17 @@ plugins {
2424

2525
useImmutables()
2626
dependencies {
27+
val cloudVersion: String by project
2728
val immutablesVersion: String by project
2829

2930
api(project(":api"))
3031
api(project(":core"))
3132
implementation(adventure("text-serializer-plain"))
3233
compileOnlyApi("org.immutables:gson:$immutablesVersion")
3334
implementation("io.projectreactor:reactor-core:3.4.0")
34-
implementation(project(":datastore:sql")) // todo: once core deps are extracted, this module should be a dep of core
35+
runtimeOnly(project(":datastore:sql"))
36+
api("cloud.commandframework:cloud-core:$cloudVersion")
37+
implementation("cloud.commandframework:cloud-minecraft-extras:$cloudVersion")
3538

3639
// Fixed version to line up with MC
3740
implementation("com.google.code.gson:gson:2.8.0")

0 commit comments

Comments
 (0)