Skip to content

Commit ef987e7

Browse files
committed
Address more code review
1 parent ca5600a commit ef987e7

File tree

8 files changed

+23
-17
lines changed

8 files changed

+23
-17
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
package dev.jorel.commandapi;
22

33
public record LoadContext(CommandAPIPlatform<?, ?, ?> platform, Runnable context) {
4+
5+
public LoadContext(CommandAPIPlatform<?, ?, ?> platform) {
6+
this(platform, () -> {});
7+
}
8+
49
}

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin-mojang-mapped/src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use-latest-nms-version: false
4646
# For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing
4747
# but will not allow an update from 1.21.2 to 1.22.
4848
# Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary.
49-
lenient-for-minor-versions: false
49+
be-lenient-for-minor-versions: false
5050

5151
# Hook into Paper's ServerResourcesReloadedEvent (default: true)
5252
# If "true", and the CommandAPI detects it is running on a Paper server, it will

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-plugin/src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use-latest-nms-version: false
4646
# For example, this setting may allow updating from 1.21.1 to 1.21.2 as only the minor version is changing
4747
# but will not allow an update from 1.21.2 to 1.22.
4848
# Keep in mind that implementations may vary and actually updating the CommandAPI might be necessary.
49-
lenient-for-minor-versions: false
49+
be-lenient-for-minor-versions: false
5050

5151
# Hook into Paper's ServerResourcesReloadedEvent (default: true)
5252
# If "true", and the CommandAPI detects it is running on a Paper server, it will

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-kotlin-test/src/test/kotlin/dev/jorel/commandapi/CommandAPIVersionHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface CommandAPIVersionHandler {
1414

1515
@JvmStatic
1616
fun getPlatform() : LoadContext {
17-
return LoadContext(MockNMS(NMS_1_19_1_R1())) {}
17+
return LoadContext(MockNMS(NMS_1_19_1_R1()))
1818
}
1919

2020
}

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/CommandAPIVersionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ static LoadContext getPlatform() {
5959
case "Minecraft_1_17" -> new NMS_1_17();
6060
case "Minecraft_1_16_5" -> new NMS_1_16_R3();
6161
default -> throw new IllegalArgumentException("Unexpected value: " + System.getProperty("profileId"));
62-
}), () -> {});
62+
}));
6363
}
6464
}
6565

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-vh/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import dev.jorel.commandapi.nms.*;
2525
import org.bukkit.Bukkit;
2626

27+
import java.util.function.Supplier;
28+
2729
/**
2830
* This file handles the NMS version to be loaded. The CommandAPIVersionHandler
2931
* file within the commandapi-core module is NOT used at compile time. Instead,
@@ -49,10 +51,11 @@ public interface CommandAPIVersionHandler {
4951
* @return an instance of NMS which can run on the specified Minecraft version
5052
*/
5153
static LoadContext getPlatform() {
52-
int latestMajorVersion = 21; // Change this for Minecraft's major update
54+
String latestMajorVersion = "21"; // Change this for Minecraft's major update
55+
Supplier<CommandAPIPlatform<?, ?, ?>> latestNMS = NMS_1_21_R1::new;
5356
if (CommandAPI.getConfiguration().shouldUseLatestNMSVersion()) {
54-
return new LoadContext(new NMS_1_21_R1(), () -> {
55-
CommandAPI.logWarning("Loading the CommandAPI with a potentially incompatible NMS implementation.");
57+
return new LoadContext(latestNMS.get(), () -> {
58+
CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation.");
5659
CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using.");
5760
});
5861
} else {
@@ -75,17 +78,15 @@ static LoadContext getPlatform() {
7578
default -> null;
7679
};
7780
if (platform != null) {
78-
return new LoadContext(platform, () -> {});
81+
return new LoadContext(platform);
7982
}
8083
if (CommandAPI.getConfiguration().shouldBeLenientForMinorVersions()) {
81-
int currentMajorVersion = Integer.parseInt(version.split("\\.")[1]);
82-
if (latestMajorVersion == currentMajorVersion) {
83-
return new LoadContext(new NMS_1_21_R1(), () -> {
84+
String currentMajorVersion = version.split("\\.")[1];
85+
if (latestMajorVersion.equals(currentMajorVersion)) {
86+
return new LoadContext(latestNMS.get(), () -> {
8487
CommandAPI.logWarning("Loading the CommandAPI with a potentially incompatible NMS implementation.");
8588
CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using.");
8689
});
87-
} else {
88-
throw new UnsupportedVersionException(version);
8990
}
9091
}
9192
throw new UnsupportedVersionException(version);

commandapi-platforms/commandapi-velocity/commandapi-velocity-core/src/main/java/dev/jorel/commandapi/CommandAPIVersionHandler.java

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

33
public interface CommandAPIVersionHandler {
44
static LoadContext getPlatform() {
5-
return new LoadContext(new CommandAPIVelocity(), () -> {});
5+
return new LoadContext(new CommandAPIVelocity());
66
}
77
}

docssrc/src/config.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ use-latest-nms-version: true
120120

121121
-----
122122

123-
### `lenient-for-minor-versions`
123+
### `be-lenient-for-minor-versions`
124124

125125
Controls whether the CommandAPI should be more lenient when updating to a new Minecraft version.
126126

@@ -135,13 +135,13 @@ Take the warning from the [`use-latest-nms-version`](#use-latest-nms-version) an
135135
**Default value**
136136

137137
```yml
138-
lenient-for-minor-versions: false
138+
be-lenient-for-minor-versions: false
139139
```
140140

141141
**Example value**
142142

143143
```yml
144-
lenient-for-minor-versions: true
144+
be-lenient-for-minor-versions: true
145145
```
146146

147147
-----

0 commit comments

Comments
 (0)