3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-09 21:10:05 +01:00

Only show nested commands in the Bukkit help if the player has permission to use at least one of the children

Dieser Commit ist enthalten in:
zml 2013-08-06 20:09:47 -07:00
Ursprung 63f2f96a8c
Commit bf2c8ebed4
3 geänderte Dateien mit 33 neuen und 11 gelöschten Zeilen

Datei anzeigen

@ -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);

Datei anzeigen

@ -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 {

Datei anzeigen

@ -21,7 +21,9 @@ package com.sk89q.worldedit.bukkit;
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 class BukkitServerInterface extends ServerInterface {
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);