mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-08-05 12:08:47 +00:00
Only show nested commands in the Bukkit help if the player has permission to use at least one of the children
This commit is contained in:
@@ -27,7 +27,9 @@ import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author zml2008
|
||||
@@ -52,13 +54,22 @@ public class CommandsManagerRegistration extends CommandRegistration {
|
||||
public boolean registerAll(List<Command> registered) {
|
||||
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
|
||||
for (Command command : registered) {
|
||||
String[] permissions = null;
|
||||
List<String> permissions = null;
|
||||
Method cmdMethod = commands.getMethods().get(null).get(command.aliases()[0]);
|
||||
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
|
||||
permissions = cmdMethod.getAnnotation(CommandPermissions.class).value();
|
||||
}
|
||||
Map<String, Method> childMethods = commands.getMethods().get(cmdMethod);
|
||||
|
||||
toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions));
|
||||
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
|
||||
permissions = Arrays.asList(cmdMethod.getAnnotation(CommandPermissions.class).value());
|
||||
} else if (cmdMethod != null && childMethods != null && childMethods.size() > 0) {
|
||||
permissions = new ArrayList<String>();
|
||||
for (Method m : childMethods.values()) {
|
||||
if (m.isAnnotationPresent(CommandPermissions.class)) {
|
||||
permissions.addAll(Arrays.asList(m.getAnnotation(CommandPermissions.class).value()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), commands, permissions == null ? null : permissions.toArray(new String[permissions.size()])));
|
||||
}
|
||||
|
||||
return register(toRegister);
|
||||
|
@@ -31,7 +31,7 @@ import org.bukkit.plugin.Plugin;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author zml2008
|
||||
* An implementation of a dynamically registered {@link org.bukkit.command.Command} attached to a plugin
|
||||
*/
|
||||
public class DynamicPluginCommand extends org.bukkit.command.Command implements PluginIdentifiableCommand {
|
||||
|
||||
|
Reference in New Issue
Block a user