Skip to content

Commit

Permalink
Fix CommandAPI loading on old versions (tested 1.19)
Browse files Browse the repository at this point in the history
This was a similar issue to what was brought up here: #594 (comment). It seems that having `NMS_1_21_R1::new` as a method reference still loads the `NMS_1_21_R1` class enough that Java gets mad. On 1.19, trying to load the CommandAPI gives `java.lang.VerifyError: Bad type on operand stack - Type 'net/minecraft/commands/CommandBuildContext' (current frame, stack[1]) is not assignable to 'net/minecraft/core/HolderLookup$a'` with the stacktrace going through that line.

Moving all references to the `NMS_1_21_R1` class into the if statements allowed loading on 1.19 as expected. That does mean the slight inconvenience of having to specify and update the latest NMS object in two place.
  • Loading branch information
willkroboth committed Sep 1, 2024
1 parent 4edb542 commit 7479cb8
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import dev.jorel.commandapi.nms.*;
import org.bukkit.Bukkit;

import java.util.function.Supplier;

/**
* This file handles the NMS version to be loaded. The CommandAPIVersionHandler
* file within the commandapi-core module is NOT used at compile time. Instead,
Expand All @@ -52,9 +50,8 @@ public interface CommandAPIVersionHandler {
*/
static LoadContext getPlatform() {
String latestMajorVersion = "21"; // Change this for Minecraft's major update
Supplier<CommandAPIPlatform<?, ?, ?>> latestNMS = NMS_1_21_R1::new;
if (CommandAPI.getConfiguration().shouldUseLatestNMSVersion()) {
return new LoadContext(latestNMS.get(), () -> {
return new LoadContext(new NMS_1_21_R1(), () -> {
CommandAPI.logWarning("Loading the CommandAPI with the latest and potentially incompatible NMS implementation.");
CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using.");
});
Expand Down Expand Up @@ -83,7 +80,7 @@ static LoadContext getPlatform() {
if (CommandAPI.getConfiguration().shouldBeLenientForMinorVersions()) {
String currentMajorVersion = version.split("\\.")[1];
if (latestMajorVersion.equals(currentMajorVersion)) {
return new LoadContext(latestNMS.get(), () -> {
return new LoadContext(new NMS_1_21_R1(), () -> {
CommandAPI.logWarning("Loading the CommandAPI with a potentially incompatible NMS implementation.");
CommandAPI.logWarning("While you may find success with this, further updates might be necessary to fully support the version you are using.");
});
Expand Down

0 comments on commit 7479cb8

Please sign in to comment.