10000 Made NullCommandSender not throw an exception on Paper by SB2DD · Pull Request #580 · CommandAPI/CommandAPI · GitHub
[go: up one dir, main page]

Skip to content

Made NullCommandSender not throw an exception on Paper #580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,13 @@ public BukkitCommandSender<? extends CommandSender> wrapCommandSender(CommandSen
// We literally cannot type this at compile-time, so let's use a placeholder CommandSender instance
return new BukkitFeedbackForwardingCommandSender<CommandSender>(FeedbackForwardingSender.cast(sender));
}

final Class<? extends CommandSender> NullCommandSender = paper.getNullCommandSender();
if (NullCommandSender != null && NullCommandSender.isInstance(sender)) {
// Since this should only be during a function load, this is just a placeholder to evade the exception.
return null;
}

}
throw new RuntimeException("Failed to wrap CommandSender " + sender + " to a CommandAPI-compatible BukkitCommandSender");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class PaperImplementations {
private final boolean isFoliaPresent;
private final NMS<?> nmsInstance;
private final Class<? extends CommandSender> feedbackForwardingCommandSender;
private final Class<? extends CommandSender> nullCommandSender;

/**
* Constructs a PaperImplementations object
Expand All @@ -44,6 +45,15 @@ public PaperImplementations(boolean isPaperPresent, boolean isFoliaPresent, NMS<
}

this.feedbackForwardingCommandSender = tempFeedbackForwardingCommandSender;

Class<? extends CommandSender> tempNullCommandSender = null;
try {
tempNullCommandSender = (Class<? extends CommandSender>) Class.forName("io.papermc.paper.brigadier.NullCommandSender");
} catch (ClassNotFoundException e) {
// uhh...
}

this.nullCommandSender = tempNullCommandSender;
}

/**
Expand Down 6A93 Expand Up @@ -115,6 +125,13 @@ public Class<? extends CommandSender> getFeedbackForwardingCommandSender() {
return this.feedbackForwardingCommandSender;
}

/**
* @return a class reference pointing to {@code io.papermc.paper.brigadier.NullCommandSender}
*/
public Class<? extends CommandSender> getNullCommandSender() {
return this.nullCommandSender;
}

/**
* Builds a {@link WrapperCommandSyntaxException} from a message with colour codes like {@link ChatColor} or using the § symbol.
*
Expand Down
Loading
0