Skip to content

Commit 08f1fe1

Browse files
authored
Merge pull request #13 from CommandAPI/dev/spigot-paper-test-toolkit
Modify documentation for CommandAPI/CommandAPI#667
2 parents cf47a18 + 66e8879 commit 08f1fe1

File tree

21 files changed

+339
-102
lines changed

21 files changed

+339
-102
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ yarn install
1414
yarn docs:build
1515
```
1616

17+
### View website changes locally
18+
19+
```bash
20+
yarn docs:dev
21+
```
22+
1723
### Verify reference code
1824

1925
```bash

docs/.vitepress/theme/preference/PreferenceSwitch.vue

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import {VTIconChevronDown, VTSwitch} from '@vue/theme'
55
import {useData, useRoute} from 'vitepress'
66
import {onMounted, ref, Ref, watch} from 'vue'
7-
import {openPreference, openPreferenceKey, preferGroovyInGradle, preferGroovyInGradleKey, preferMaven, preferMavenKey, preferReobf, preferReobfKey,} from "./preference";
7+
import {
8+
openPreference, openPreferenceKey,
9+
preferPaper, preferPaperKey,
10+
preferGroovyInGradle, preferGroovyInGradleKey,
11+
preferMaven, preferMavenKey
12+
} from "./preference";
813
914
const {frontmatter} = useData();
1015
let preferencesToDisplay: Ref<string[]> = ref();
@@ -36,6 +41,12 @@ const restoreOutline = (e: Event) => {
3641
(e.target as HTMLElement).classList.remove('no-outline');
3742
};
3843
44+
const togglePaper = useToggleFn(
45+
preferPaperKey,
46+
preferPaper,
47+
'prefer-paper'
48+
)
49+
3950
const toggleMaven = useToggleFn(
4051
preferMavenKey,
4152
preferMaven,
@@ -48,12 +59,6 @@ const toggleGradleDsl = useToggleFn(
4859
'prefer-groovy'
4960
);
5061
51-
const toggleMapping = useToggleFn(
52-
preferReobfKey,
53-
preferReobf,
54-
'prefer-reobf'
55-
)
56-
5762
function useToggleFn(
5863
storageKey: string,
5964
state: Ref<boolean>,
@@ -77,9 +82,9 @@ function useToggleFn(
7782
refresh()
7883
7984
onMounted(() => {
85+
togglePaper(preferPaper.value);
8086
toggleMaven(preferMaven.value);
8187
toggleGradleDsl(preferGroovyInGradle.value);
82-
toggleMapping(preferReobf.value);
8388
});
8489
</script>
8590

@@ -102,6 +107,16 @@ onMounted(() => {
102107
:aria-hidden="!openPreference"
103108
>
104109
<div class="mobile-wrapper switches">
110+
<div v-if="preferencesToDisplay.includes('paper-spigot')" class="switch-container">
111+
<label class="paper-label prefer-label-left" @click="togglePaper(true)">Paper</label>
112+
<VTSwitch
113+
class="platform-switch"
114+
aria-label="prefer paper"
115+
:aria-checked="preferPaper"
116+
@click="togglePaper()"
117+
/>
118+
<label class="spigot-label prefer-label-right" @click="togglePaper(false)">Spigot</label>
119+
</div>
105120
<div v-if="preferencesToDisplay.includes('build-system')" class="switch-container">
106121
<label class="gradle-label prefer-label-left" @click="toggleMaven(false)">Gradle</label>
107122
<VTSwitch
@@ -122,16 +137,6 @@ onMounted(() => {
122137
/>
123138
<label class="groovy-label prefer-label-right" @click="toggleGradleDsl(true)">.gradle</label>
124139
</div>
125-
<div v-if="preferencesToDisplay.includes('paper-spigot')" class="switch-container">
126-
<label class="mojmap-label prefer-label-left" @click="toggleMapping(false)">Paper</label>
127-
<VTSwitch
128-
class="mapping-switch"
129-
aria-label="prefer reobf"
130-
:aria-checked="preferReobf"
131-
@click="toggleMapping()"
132-
/>
133-
<label class="reobf-label prefer-label-right" @click="toggleMapping(true)">Spigot</label>
134-
</div>
135140
</div>
136141
</div>
137142
<br class="hide-on-mobile" :hidden="openPreference"/>
@@ -270,57 +275,61 @@ onMounted(() => {
270275
</style>
271276

272277
<style>
278+
.paper,
273279
.maven,
274-
.groovy,
275-
.spigot {
280+
.groovy {
276281
display: none;
277282
}
278283
284+
.prefer-paper .spigot,
279285
.prefer-maven .gradle,
280-
.prefer-groovy .kts,
281-
.prefer-reobf .paper {
286+
.prefer-groovy .kts {
282287
display: none;
283288
}
284289
290+
.prefer-paper .paper,
285291
.prefer-maven .maven,
286-
.prefer-groovy .groovy,
287-
.prefer-reobf .spigot {
292+
.prefer-groovy .groovy {
288293
display: initial;
289294
}
290295
296+
.paper-label,
291297
.maven-label,
292298
.groovy-label,
293-
.reobf-label,
299+
.prefer-paper .spigot-label,
294300
.prefer-maven .gradle-label,
295-
.prefer-groovy .kts-label,
296-
.prefer-reobf .mojmap-label {
301+
.prefer-groovy .kts-label {
297302
color: var(--vt-c-text-3);
298303
}
299304
305+
.prefer-paper .paper-label,
300306
.prefer-maven .maven-label,
301-
.prefer-groovy .groovy-label,
302-
.prefer-reobf .reobf-label {
307+
.prefer-groovy .groovy-label {
303308
color: var(--vt-c-text-1);
304309
}
305310
306-
.prefer-maven .api-switch .vt-switch-check {
311+
.platform-switch .vt-switch-check {
307312
transform: translateX(18px);
308313
}
309314
310-
.prefer-groovy .dsl-switch .vt-switch-check {
315+
.prefer-paper .platform-switch .vt-switch-check {
316+
transform: translateX(0px);
317+
}
318+
319+
.prefer-maven .api-switch .vt-switch-check {
311320
transform: translateX(18px);
312321
}
313322
314-
.prefer-reobf .mapping-switch .vt-switch-check {
323+
.prefer-groovy .dsl-switch .vt-switch-check {
315324
transform: translateX(18px);
316325
}
317326
327+
.tip .paper,
328+
.tip .spigot,
318329
.tip .gradle,
319330
.tip .groovy,
320331
.tip .kts,
321-
.tip .maven,
322-
.tip .paper,
323-
.tip .spigot {
332+
.tip .maven {
324333
//color: var(--vt-c-text-code);
325334
/* transition: color 0.5s; */
326335
//font-weight: 600;

docs/.vitepress/theme/preference/preference.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ function getBoolean(key: string, defaultValue: boolean) {
1212
export const openPreferenceKey = 'command-api-docs-prefer-open-preference'
1313
export const openPreference = ref(getBoolean(openPreferenceKey, true))
1414

15+
export const preferPaperKey = 'command-api-docs-prefer-paper'
16+
export const preferPaper = ref(getBoolean(preferPaperKey, true))
17+
1518
export const preferMavenKey = 'command-api-docs-prefer-maven'
1619
export const preferMaven = ref(getBoolean(preferMavenKey, false))
1720

1821
export const preferGroovyInGradleKey = 'command-api-docs-prefer-groovy-dsl-in-gradle'
19-
export const preferGroovyInGradle = ref(getBoolean(preferGroovyInGradleKey, false))
20-
21-
export const preferReobfKey = 'command-api-docs-prefer-mojmap'
22-
export const preferReobf = ref(getBoolean(preferReobfKey, false))
22+
export const preferGroovyInGradle = ref(getBoolean(preferGroovyInGradleKey, false))

docs/en/dev-setup/shading.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class CommandAPIPaperConfig {
5555
}
5656
```
5757

58-
In order to create a `CommandAPIPaperConfig` object, you must give it a reference to your `PluginMeta` and a `LifecycleEventOwner` instance, meaning either a `JavaPlugin` or `BootstrapContext` instance. The CommandAPI always uses this to register events, so it is required when loading the CommandAPI on Paper.
58+
In order to create a `CommandAPIPaperConfig` object, you must give it a reference to a `LifecycleEventOwner` instance, meaning either a `JavaPlugin` or `BootstrapContext` instance. The CommandAPI always uses this to register commands and events, so it is required when loading the CommandAPI on Paper.
5959

6060
For example, to load the CommandAPI on Paper with all logging disabled, you can use the following:
6161

docs/en/test/intro.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors:
66

77
# Testing Commands
88

9-
When developing large projects, it is good practice to add automated tests for your code. This section of the documentation describes how to use the `commandapi-bukkit-test-toolkit` dependency along with [MockBukkit](https://github.com/MockBukkit/MockBukkit) and [JUnit](https://junit.org/junit5/) to test the usage of commands registered with the CommandAPI.
9+
When developing large projects, it is good practice to add automated tests for your code. This section of the documentation describes how to use the `commandapi-spigot-test-toolkit`/`commandapi-paper-test-toolkit` dependency along with [MockBukkit](https://github.com/MockBukkit/MockBukkit) and [JUnit](https://junit.org/junit5/) to test the usage of commands registered with the CommandAPI.
1010

1111
For a big-picture view, you can find example projects that include automated tests in the [CommandAPI GitHub repository](https://github.com/CommandAPI/CommandAPI/tree/master/examples).
1212

docs/en/test/load-mock-commandapi.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
order: 3
3+
preferences: ["paper-spigot"]
34
authors:
45
- willkroboth
56
---
@@ -16,28 +17,63 @@ MockCommandAPIPlugin load()
1617

1718
Loads the CommandAPI Plugin in the test environment. Works exactly the same as `MockBukkit.load(MockCommandAPIPlugin.class)`.
1819

20+
<div class="paper">
21+
22+
```java
23+
MockCommandAPIPlugin load(Consumer<CommandAPIPaperConfig> configureSettings)
24+
```
25+
26+
Loads the CommandAPI Plugin after applying the given consumer. This allows configuring any setting from the [config.yml](../user-setup/config#configuration-settings) using the methods provided by [CommandAPIPaperConfig](../dev-setup/shading#loading).
27+
28+
:::tip Example - Loading test CommandAPI with settings
29+
30+
To change, for example, the `missing-executor-implementation` message while running tests, you can use the method `CommandAPIPaperConfig#missingExecutorImplementationMessage` when the `configureSettings` callback is run:
31+
32+
<<< @/../reference-code/paper/src/test/java/test/LoadMockCommandAPI.java#loadMockCommandAPIExample
33+
34+
:::
35+
36+
</div>
37+
<div class="spigot">
38+
1939
```java
20-
MockCommandAPIPlugin load(Consumer<CommandAPIBukkitConfig> configureSettings)
40+
MockCommandAPIPlugin load(Consumer<CommandAPISpigotConfig> configureSettings)
2141
```
2242

23-
Loads the CommandAPI Plugin after applying the given consumer. This allows configuring any setting from the [config.yml](../user-setup/config#configuration-settings) using the methods provided by [CommandAPIBukkitConfig](../dev-setup/shading#loading).
43+
Loads the CommandAPI Plugin after applying the given consumer. This allows configuring any setting from the [config.yml](../user-setup/config#configuration-settings) using the methods provided by [CommandAPISpigotConfig](../dev-setup/shading#loading).
2444

2545
:::tip Example - Loading test CommandAPI with settings
2646

27-
To change, for example, the `missing-executor-implementation` message while running tests, you can use the method `CommandAPIBukkitConfig#missingExecutorImplementationMessage` when the `configureSettings` callback is run:
47+
To change, for example, the `missing-executor-implementation` message while running tests, you can use the method `CommandAPISpigotConfig#missingExecutorImplementationMessage` when the `configureSettings` callback is run:
2848

29-
<<< @/../reference-code/bukkit/src/test/java/test/LoadMockCommandAPI.java#loadMockCommandAPIExample
49+
<<< @/../reference-code/spigot/src/test/java/test/LoadMockCommandAPI.java#loadMockCommandAPIExample
3050

3151
:::
3252

53+
</div>
54+
3355
## Shaded Dependency
3456

3557
If your plugin shades the CommandAPI, the CommandAPI will automatically load as usual when you use MockBukkit to load your plugin. Just note that you **must** call `CommandAPI.onDisable()` in your plugin's `onDisable` method in order for the test environment to reset properly after each test.
3658

3759
## Loading a custom CommandAPI platform implementation
3860

39-
By default, the testing environment will load `MockCommandAPIBukkit` as the CommandAPI platform object. This works for basic tests, but many methods in `MockCommandAPIBukkit` are not yet implemented and just throw an `UnimplementedMethodException`. This may cause your tests to fail if your code relies on any of these methods. If you see an `UnimplementedMethodException`, please tell us about it with a [GitHub Issue](https://github.com/CommandAPI/CommandAPI/issues) or a message in the CommandAPI Discord so we can get it solved for everyone.
4061

41-
In the short term, you can also try to avoid an `UnimplementedMethodException` by implementing the required method yourself. Simply create a class that extends `MockCommandAPIBukkit` and override the required method with an appropriate implementation. Before each test where you want to use your custom implementation, make sure to call `CommandAPIVersionHandler#usePlatformImplementation` to let the CommandAPI know what it should load.
62+
<div class="paper">
63+
64+
By default, the testing environment will load `MockCommandAPIPaper` and `MockPaperNMS` as the CommandAPI platform object. This works for basic tests, but many methods in `MockPaperNMS` are not yet implemented and just throw an `UnimplementedMethodException`. This may cause your tests to fail if your code relies on any of these methods. If you see an `UnimplementedMethodException`, please tell us about it with a [GitHub Issue](https://github.com/CommandAPI/CommandAPI/issues) or a message in the CommandAPI Discord so we can get it solved for everyone.
65+
66+
In the short term, you can also try to avoid an `UnimplementedMethodException` by implementing the required method yourself. Simply create a class that extends `MockCommandAPIPaper` or `MockPaperNMS` and override the required method with an appropriate implementation. Before each test where you want to use your custom implementation, make sure to call `CommandAPIVersionHandler#usePlatformImplementation` to let the CommandAPI know what it should load.
67+
68+
<<< @/../reference-code/paper/src/test/java/test/LoadMockCommandAPI.java#loadCustomCommandAPIPlatformImplementationExample
69+
70+
</div>
71+
<div class="spigot">
72+
73+
By default, the testing environment will load `MockCommandAPISpigot` as the CommandAPI platform object. This works for basic tests, but many methods in `MockCommandAPISpigot` are not yet implemented and just throw an `UnimplementedMethodException`. This may cause your tests to fail if your code relies on any of these methods. If you see an `UnimplementedMethodException`, please tell us about it with a [GitHub Issue](https://github.com/CommandAPI/CommandAPI/issues) or a message in the CommandAPI Discord so we can get it solved for everyone.
74+
75+
In the short term, you can also try to avoid an `UnimplementedMethodException` by implementing the required method yourself. Simply create a class that extends `MockCommandAPISpigot` and override the required method with an appropriate implementation. Before each test where you want to use your custom implementation, make sure to call `CommandAPIVersionHandler#usePlatformImplementation` to let the CommandAPI know what it should load.
76+
77+
<<< @/../reference-code/spigot/src/test/java/test/LoadMockCommandAPI.java#loadCustomCommandAPIPlatformImplementationExample
4278

43-
<<< @/../reference-code/bukkit/src/test/java/test/LoadMockCommandAPI.java#loadCustomCommandAPIPlatformImplementationExample
79+
</div>

0 commit comments

Comments
 (0)