Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ yarn install
yarn docs:build
```

### View website changes locally

```bash
yarn docs:dev
```

### Verify reference code

```bash
Expand Down
79 changes: 44 additions & 35 deletions docs/.vitepress/theme/preference/PreferenceSwitch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
import {VTIconChevronDown, VTSwitch} from '@vue/theme'
import {useData, useRoute} from 'vitepress'
import {onMounted, ref, Ref, watch} from 'vue'
import {openPreference, openPreferenceKey, preferGroovyInGradle, preferGroovyInGradleKey, preferMaven, preferMavenKey, preferReobf, preferReobfKey,} from "./preference";
import {
openPreference, openPreferenceKey,
preferPaper, preferPaperKey,
preferGroovyInGradle, preferGroovyInGradleKey,
preferMaven, preferMavenKey
} from "./preference";

const {frontmatter} = useData();
let preferencesToDisplay: Ref<string[]> = ref();
Expand Down Expand Up @@ -36,6 +41,12 @@ const restoreOutline = (e: Event) => {
(e.target as HTMLElement).classList.remove('no-outline');
};

const togglePaper = useToggleFn(
preferPaperKey,
preferPaper,
'prefer-paper'
)

const toggleMaven = useToggleFn(
preferMavenKey,
preferMaven,
Expand All @@ -48,12 +59,6 @@ const toggleGradleDsl = useToggleFn(
'prefer-groovy'
);

const toggleMapping = useToggleFn(
preferReobfKey,
preferReobf,
'prefer-reobf'
)

function useToggleFn(
storageKey: string,
state: Ref<boolean>,
Expand All @@ -77,9 +82,9 @@ function useToggleFn(
refresh()

onMounted(() => {
togglePaper(preferPaper.value);
toggleMaven(preferMaven.value);
toggleGradleDsl(preferGroovyInGradle.value);
toggleMapping(preferReobf.value);
});
</script>

Expand All @@ -102,6 +107,16 @@ onMounted(() => {
:aria-hidden="!openPreference"
>
<div class="mobile-wrapper switches">
<div v-if="preferencesToDisplay.includes('paper-spigot')" class="switch-container">
<label class="paper-label prefer-label-left" @click="togglePaper(true)">Paper</label>
<VTSwitch
class="platform-switch"
aria-label="prefer paper"
:aria-checked="preferPaper"
@click="togglePaper()"
/>
<label class="spigot-label prefer-label-right" @click="togglePaper(false)">Spigot</label>
</div>
<div v-if="preferencesToDisplay.includes('build-system')" class="switch-container">
<label class="gradle-label prefer-label-left" @click="toggleMaven(false)">Gradle</label>
<VTSwitch
Expand All @@ -122,16 +137,6 @@ onMounted(() => {
/>
<label class="groovy-label prefer-label-right" @click="toggleGradleDsl(true)">.gradle</label>
</div>
<div v-if="preferencesToDisplay.includes('paper-spigot')" class="switch-container">
<label class="mojmap-label prefer-label-left" @click="toggleMapping(false)">Paper</label>
<VTSwitch
class="mapping-switch"
aria-label="prefer reobf"
:aria-checked="preferReobf"
@click="toggleMapping()"
/>
<label class="reobf-label prefer-label-right" @click="toggleMapping(true)">Spigot</label>
</div>
</div>
</div>
<br class="hide-on-mobile" :hidden="openPreference"/>
Expand Down Expand Up @@ -270,57 +275,61 @@ onMounted(() => {
</style>

<style>
.paper,
.maven,
.groovy,
.spigot {
.groovy {
display: none;
}

.prefer-paper .spigot,
.prefer-maven .gradle,
.prefer-groovy .kts,
.prefer-reobf .paper {
.prefer-groovy .kts {
display: none;
}

.prefer-paper .paper,
.prefer-maven .maven,
.prefer-groovy .groovy,
.prefer-reobf .spigot {
.prefer-groovy .groovy {
display: initial;
}

.paper-label,
.maven-label,
.groovy-label,
.reobf-label,
.prefer-paper .spigot-label,
.prefer-maven .gradle-label,
.prefer-groovy .kts-label,
.prefer-reobf .mojmap-label {
.prefer-groovy .kts-label {
color: var(--vt-c-text-3);
}

.prefer-paper .paper-label,
.prefer-maven .maven-label,
.prefer-groovy .groovy-label,
.prefer-reobf .reobf-label {
.prefer-groovy .groovy-label {
color: var(--vt-c-text-1);
}

.prefer-maven .api-switch .vt-switch-check {
.platform-switch .vt-switch-check {
transform: translateX(18px);
}

.prefer-groovy .dsl-switch .vt-switch-check {
.prefer-paper .platform-switch .vt-switch-check {
transform: translateX(0px);
}

.prefer-maven .api-switch .vt-switch-check {
transform: translateX(18px);
}

.prefer-reobf .mapping-switch .vt-switch-check {
.prefer-groovy .dsl-switch .vt-switch-check {
transform: translateX(18px);
}

.tip .paper,
.tip .spigot,
.tip .gradle,
.tip .groovy,
.tip .kts,
.tip .maven,
.tip .paper,
.tip .spigot {
.tip .maven {
//color: var(--vt-c-text-code);
/* transition: color 0.5s; */
//font-weight: 600;
Expand Down
8 changes: 4 additions & 4 deletions docs/.vitepress/theme/preference/preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ function getBoolean(key: string, defaultValue: boolean) {
export const openPreferenceKey = 'command-api-docs-prefer-open-preference'
export const openPreference = ref(getBoolean(openPreferenceKey, true))

export const preferPaperKey = 'command-api-docs-prefer-paper'
export const preferPaper = ref(getBoolean(preferPaperKey, true))

export const preferMavenKey = 'command-api-docs-prefer-maven'
export const preferMaven = ref(getBoolean(preferMavenKey, false))

export const preferGroovyInGradleKey = 'command-api-docs-prefer-groovy-dsl-in-gradle'
export const preferGroovyInGradle = ref(getBoolean(preferGroovyInGradleKey, false))

export const preferReobfKey = 'command-api-docs-prefer-mojmap'
export const preferReobf = ref(getBoolean(preferReobfKey, false))
export const preferGroovyInGradle = ref(getBoolean(preferGroovyInGradleKey, false))
2 changes: 1 addition & 1 deletion docs/en/dev-setup/shading.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class CommandAPIPaperConfig {
}
```

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.
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.

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

Expand Down
2 changes: 1 addition & 1 deletion docs/en/test/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors:

# Testing Commands

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.
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.

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).

Expand Down
50 changes: 43 additions & 7 deletions docs/en/test/load-mock-commandapi.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
order: 3
preferences: ["paper-spigot"]
authors:
- willkroboth
---
Expand All @@ -16,28 +17,63 @@ MockCommandAPIPlugin load()

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

<div class="paper">

```java
MockCommandAPIPlugin load(Consumer<CommandAPIPaperConfig> configureSettings)
```

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).

:::tip Example - Loading test CommandAPI with settings

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:

<<< @/../reference-code/paper/src/test/java/test/LoadMockCommandAPI.java#loadMockCommandAPIExample

:::

</div>
<div class="spigot">

```java
MockCommandAPIPlugin load(Consumer<CommandAPIBukkitConfig> configureSettings)
MockCommandAPIPlugin load(Consumer<CommandAPISpigotConfig> configureSettings)
```

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).
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).

:::tip Example - Loading test CommandAPI with settings

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:
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:

<<< @/../reference-code/bukkit/src/test/java/test/LoadMockCommandAPI.java#loadMockCommandAPIExample
<<< @/../reference-code/spigot/src/test/java/test/LoadMockCommandAPI.java#loadMockCommandAPIExample

:::

</div>

## Shaded Dependency

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.

## Loading a custom CommandAPI platform implementation

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.

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.
<div class="paper">

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.

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.

<<< @/../reference-code/paper/src/test/java/test/LoadMockCommandAPI.java#loadCustomCommandAPIPlatformImplementationExample

</div>
<div class="spigot">

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.

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.

<<< @/../reference-code/spigot/src/test/java/test/LoadMockCommandAPI.java#loadCustomCommandAPIPlatformImplementationExample

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