Skip to content

Commit

Permalink
Fix HelpCommand searching
Browse files Browse the repository at this point in the history
Prevent index out of bounds exception when finding possible matches in
the help topics.
A general empty string is caught and directed to the defaultTopic by
getHelpTopic(). #findPossibleMatches hence should not concern itself
with possible empty strings anymore.
  • Loading branch information
notTamion committed Jul 13, 2024
1 parent cb33966 commit 7507d0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ protected HelpTopic findPossibleMatches(@NotNull String searchString) {
searchString = searchString.substring(1);
}

if (searchString.isEmpty()) return null; // Paper - prevent index out of bounds - nothing matches an empty search string, should have been special cased to defaultTopic earlier, just return null.
for (HelpTopic topic : Bukkit.getServer().getHelpMap().getHelpTopics()) {
String trimmedTopic = topic.getName().startsWith("/") ? topic.getName().substring(1) : topic.getName();

Expand Down
11 changes: 8 additions & 3 deletions paper-api/src/main/java/org/bukkit/help/IndexHelpTopic.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ public boolean canSee(@NotNull CommandSender sender) {
if (sender instanceof ConsoleCommandSender) {
return true;
}
if (permission == null) {
return true;
// Paper start - Fix HelpCommand searching - do not show index if no topic is visible to the sender
if (permission != null && !sender.hasPermission(permission)) return false; // old spigot permission check

for (HelpTopic topic : allTopics) {
if (topic.canSee(sender)) return true;
}
return sender.hasPermission(permission);

return false;
// Paper end - Fix HelpCommand searching - do not show index if no topic is visible to the sender
}

@Override
Expand Down

0 comments on commit 7507d0f

Please sign in to comment.