mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2024-12-21 04:49:51 +08: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:
parent
63f2f96a8c
commit
bf2c8ebed4
@ -27,7 +27,9 @@
|
||||
|
||||
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 boolean register(Class<?> clazz) {
|
||||
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 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 {
|
||||
|
||||
|
@ -21,7 +21,9 @@
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sk89q.bukkit.util.CommandInfo;
|
||||
import com.sk89q.bukkit.util.CommandRegistration;
|
||||
@ -96,13 +98,22 @@ public List<LocalWorld> getWorlds() {
|
||||
public void onCommandRegistration(List<Command> commands, CommandsManager<LocalPlayer> manager) {
|
||||
List<CommandInfo> toRegister = new ArrayList<CommandInfo>();
|
||||
for (Command command : commands) {
|
||||
String[] permissions = null;
|
||||
List<String> permissions = null;
|
||||
Method cmdMethod = manager.getMethods().get(null).get(command.aliases()[0]);
|
||||
if (cmdMethod != null && cmdMethod.isAnnotationPresent(CommandPermissions.class)) {
|
||||
permissions = cmdMethod.getAnnotation(CommandPermissions.class).value();
|
||||
}
|
||||
Map<String, Method> childMethods = manager.getMethods().get(cmdMethod);
|
||||
|
||||
toRegister.add(new CommandInfo(command.usage(), command.desc(), command.aliases(), manager, 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()])));
|
||||
}
|
||||
|
||||
dynamicCommands.register(toRegister);
|
||||
|
Loading…
Reference in New Issue
Block a user