Skip to content

Commit f1735ce

Browse files
committed
feat: more arguments page, fix target version in pom.xml
1 parent e05c3ba commit f1735ce

File tree

10 files changed

+666
-2
lines changed

10 files changed

+666
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ docs/.vitepress/cache
55

66
yarn.lock
77
reference-code.iml
8-
reference-code/reference-code.iml
8+
reference-code/reference-code.iml
9+
reference-code/target
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<script setup lang="ts">
2+
import {ref, Ref} from "vue";
3+
import {VTSwitch} from "@vue/theme";
4+
5+
const before1204 = ref(false);
6+
7+
function useToggleFn(
8+
state: Ref<boolean>,
9+
className: string
10+
) {
11+
const classList = document.documentElement.classList;
12+
return (value = !state.value) => {
13+
if ((state.value = value)) {
14+
classList.add(className);
15+
} else {
16+
classList.remove(className);
17+
}
18+
}
19+
}
20+
21+
const toggleBefore1204 = useToggleFn(before1204, "choose-before-1204")
22+
</script>
23+
24+
<template>
25+
<div class="switch-container" id="preference-switches">
26+
<label class="after-1205-label" style="width: fit-content" @click="toggleBefore1204(false)">1.20.5+</label>
27+
<VTSwitch
28+
class="mcver-switch"
29+
aria-label="before 1.20.4"
30+
:aria-checked="before1204"
31+
@click="toggleBefore1204()"
32+
/>
33+
<label class="before-1204-label" style="width: fit-content" @click="toggleBefore1204(true)">1.20.4-</label>
34+
</div>
35+
</template>
36+
37+
<style scoped>
38+
.no-outline {
39+
outline: 0;
40+
}
41+
42+
.vt-link-icon {
43+
position: relative;
44+
top: 1px;
45+
}
46+
47+
.vt-link-icon.open {
48+
transform: rotate(180deg);
49+
}
50+
51+
.switch-container {
52+
display: flex;
53+
align-items: center;
54+
}
55+
56+
@media (max-width: 959px) {
57+
.switch-container {
58+
padding: 0 1em;
59+
}
60+
}
61+
62+
.switch-container:not(:first-child) {
63+
margin-top: 10px;
64+
}
65+
66+
.vt-switch {
67+
margin-right: 5px;
68+
transform: scale(0.8);
69+
}
70+
71+
.switch-container label {
72+
transition: color 0.5s;
73+
cursor: pointer;
74+
}
75+
76+
.switch-container label:first-child {
77+
width: 50px;
78+
}
79+
80+
@media (max-width: 1439px) {
81+
.vt-switch {
82+
margin: auto;
83+
}
84+
85+
.switch-container label:first-child {
86+
width: 46px;
87+
}
88+
}
89+
90+
#preference-switches {
91+
width: fit-content;
92+
padding: 12px 16px;
93+
background-color: var(--vt-c-bg-soft);
94+
margin: 6px 0 12px;
95+
border-radius: 8px;
96+
font-weight: 600;
97+
}
98+
</style>
99+
100+
<style>
101+
.after-1205 {
102+
display: initial;
103+
}
104+
105+
.before-1204 {
106+
display: none;
107+
}
108+
109+
.choose-before-1204 .before-1204 {
110+
display: initial;
111+
}
112+
113+
.choose-before-1204 .after-1205 {
114+
display: none;
115+
}
116+
117+
.choose-before-1204 .after-1205-label,
118+
.before-1204-label {
119+
color: var(--vt-c-text-3);
120+
}
121+
122+
.choose-before-1204 .before-1204-label,
123+
.after-1205-label {
124+
color: var(--vt-c-text-1);
125+
}
126+
127+
.choose-before-1204 .mcver-switch .vt-switch-check {
128+
transform: translateX(18px);
129+
}
130+
131+
.tip .after-1205,
132+
.tip .before-1204 {
133+
color: var(--vt-c-text-code);
134+
/* transition: color 0.5s; */
135+
font-weight: 600;
136+
}
137+
</style>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
order: 8
3+
authors:
4+
- JorelAli
5+
- DerEchtePilz
6+
- willkroboth
7+
---
8+
9+
# MathOperation arguments
10+
11+
![An image of the math operation argument, with suggestions "%=", "*=", "+=", "-=", "/=", "<", "=", ">" and "><"](/images/arguments/mathop.png)
12+
13+
The CommandAPI's `MathOperationArgument` is used to represent the Minecraft scoreboard arithmetic operation to alter scoreboard scores. Since there is no default representation in the Bukkit API, the CommandAPI provides the `MathOperation` class to represent each operation:
14+
15+
| Symbol (in Minecraft) | MathOperation enum value |
16+
|:---------------------:|--------------------------|
17+
| `+=` | `MathOperation.ADD` |
18+
| `-=` | `MathOperation.SUBTRACT` |
19+
| `*=` | `MathOperation.MULTIPLY` |
20+
| `/=` | `MathOperation.DIVIDE` |
21+
| `%=` | `MathOperation.MOD` |
22+
| `=` | `MathOperation.ASSIGN` |
23+
| `<` | `MathOperation.MIN` |
24+
| `>` | `MathOperation.MAX` |
25+
| `><` | `MathOperation.SWAP` |
26+
27+
The `MathOperation` also has two methods:
28+
29+
```java
30+
public int apply(int val1, int val2);
31+
public float apply(float val1, float val2);
32+
```
33+
34+
These methods are used to provide a basic implementation of these math operations on a given input. Given the values `val1` and `val2`, these are the operation that the `apply(val1, val2)` method performs:
35+
36+
| MathOperation enum value | Result |
37+
|--------------------------|------------------------|
38+
| `MathOperation.ADD` | `val1 + val2` |
39+
| `MathOperation.SUBTRACT` | `val1 - val2` |
40+
| `MathOperation.MULTIPLY` | `val1 * val2` |
41+
| `MathOperation.DIVIDE` | `val1 / val2` |
42+
| `MathOperation.MOD` | `val1 % val2` |
43+
| `MathOperation.ASSIGN` | `val2` |
44+
| `MathOperation.MIN` | `Math.min(val1, val2)` |
45+
| `MathOperation.MAX` | `Math.max(val1, val2)` |
46+
| `MathOperation.SWAP` | `val2` |
47+
48+
::::tip Example - Changing a player's level
49+
50+
Say we wanted to create a player's level. Typically, this is implemented in the following manner:
51+
52+
```mccmd
53+
/xp set <player> <level>
54+
/xp add <player> <levels>
55+
```
56+
57+
Using the `MathOperationArgument`, we can extend the functionality of adding and setting a player's level by allowing the user to choose what operation they desire. To do this, we'll use the following syntax:
58+
59+
```mccmd
60+
/changelevel <player> <operation> <value>
61+
```
62+
63+
As with any command, we declare our arguments, cast them properly and then we write our main code. In this example, we use the `apply(int, int)` method from our `MathOperation` to calculate the player's new level.
64+
65+
:::tabs
66+
===Java
67+
<<< @/../reference-code/src/main/java/createcommands/arguments/types/misc/MathOperationArguments.java#mathOperationArgumentsExample
68+
===Kotlin
69+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt#mathOperationArgumentsExample
70+
===Kotlin DSL
71+
<<< @/../reference-code/src/main/kotlin/createcommands/arguments/types/misc/MathOperationArguments.kt#mathOperationArgumentsExampleDSL
72+
:::
73+
74+
There are various applications for the `changelevel` command based on what the user inputs. For example:
75+
76+
- To set the player _Notch_ to level 10:
77+
78+
```mccmd
79+
/changelevel Notch = 10
80+
```
81+
82+
- To double the player _Notch's_ level:
83+
84+
```mccmd
85+
/changelevel Notch *= 2
86+
```
87+
88+
- To set the player _Notch_'s level to 20, or keep it as their current level if it is higher than 20:
89+
90+
```mccmd
91+
/changelevel Notch > 20
92+
```
93+
94+
::::
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
order: 9
3+
authors:
4+
- JorelAli
5+
- misode
6+
---
7+
8+
# NamespacedKey arguments
9+
10+
NamespacedKey arguments represent Minecraft's [resource locations](https://minecraft.wiki/w/Resource_location), or namespaced keys. This argument is casted to Bukkit's `NamespacedKey` object.
11+
12+
Namespaced keys are typically of the form `namespace:key`. If no namespace is provided, the default namespace (`minecraft`) will be used.

0 commit comments

Comments
 (0)