Skip to content

Commit

Permalink
Fixed CCE in TabComplete
Browse files Browse the repository at this point in the history
Added sender instanceof Player checks with the permission checks to ensure that the console wouldn't cause a class cast exception when trying to tab complete
Closes #86
  • Loading branch information
Dart2112 committed Feb 2, 2025
1 parent 0454c07 commit be00772
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Benjamin Martin
* Copyright 2025 Benjamin Martin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,9 +30,11 @@ public class OtherAFKPlusOptions implements LapisTabOption {
@Override
public List<String> getOptions(CommandSender sender) {
List<String> options = new ArrayList<>();
if (AFKPlus.getInstance().perms.isPermitted(((Player) sender).getUniqueId(), Permission.CanUpdate.getPermission()))
if (!(sender instanceof Player) ||
AFKPlus.getInstance().perms.isPermitted(((Player) sender).getUniqueId(), Permission.CanUpdate.getPermission()))
options.add("update");
if (AFKPlus.getInstance().perms.isPermitted(((Player) sender).getUniqueId(), Permission.CanReload.getPermission()))
if (!(sender instanceof Player) ||
AFKPlus.getInstance().perms.isPermitted(((Player) sender).getUniqueId(), Permission.CanReload.getPermission()))
options.add("reload");
options.add("help");
return options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Benjamin Martin
* Copyright 2025 Benjamin Martin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,7 +45,8 @@ public List<String> getOptions(CommandSender sender) {
}
} else {
//This is used by /afk and so needs a permission check before recommending players other than yourself
if (AFKPlus.getInstance().perms.isPermitted(((Player) sender).getUniqueId(), Permission.AFKOthers.getPermission()))
if (!(sender instanceof Player) ||
AFKPlus.getInstance().perms.isPermitted(((Player) sender).getUniqueId(), Permission.AFKOthers.getPermission()))
Bukkit.getServer().getOnlinePlayers().forEach(player -> names.add(player.getName()));
else
names.add(sender.getName());
Expand Down

0 comments on commit be00772

Please sign in to comment.