Get all Commands

Discussion in 'Plugin Development' started by ToastHelmi, Jan 5, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    ToastHelmi

    hi guy's hope you can help me
    do you know how how i cann get all the commands from all enabled plugins and check if a player have permissons for it
     
  2. Offline

    CorrieKay

    This is a little tricky, with how plugins can issue commands without them being registered.

    But basically, you could iterate over all of the plugins, grab their plugin.yml files, load them as configurations, and then get the command object from that (or check command.name.permission).

    But theres no surefire way to grab all of the commands, because, like i said, some plugins catch unregistered commands in the command event. I think world edit does this)
     
  3. Offline

    MinecraftSped I steal plugins as my own

    Or you could go in game, open chat, type forward slash and then hold TAB. That lists every command your server has to offer.
     
  4. Offline

    CorrieKay

    um...

    *cough* Thats not how.... plugins work..

    even still, if a plugin uses a non-registration method, they wouldnt show up in the list of commands.
     
  5. Offline

    fireblast709

    get plugin -> get PluginDescriptionFile -> getCommands() -> keySet() -> Set<String> with all commands
     
  6. Offline

    Sagacious_Zed Bukkit Docs

    As CorrieKey has been mentioning that would return only the declared commands and declared permissions for those commands.
     
  7. Offline

    fireblast709

    Yes, my method was just a 'shortened' version of her suggestion to load in the plugin.yml
     
  8. Offline

    CorrieKay

    My mistake. Didnt know you could get the commands that way.

    the more you know!
     
  9. Offline

    ToastHelmi

    ok this should work for most of the plugins but how do i get the discription of the commands
     
  10. Offline

    fireblast709

    for each command, get the Map<String, Object>, and get the "description"
    Code:java
    1. // Assume command
    2. String description = (String) thePluginDescriptionFile.get(command).get("description");
    Don't forget to check for null values between the chained methods
     
  11. Offline

    ToastHelmi

    isn't there a way to get the commands all commands by hooking into essentails or some think elese otherwhise its a little bit triky to check if the players have permissons for the command because not every plugin has the permissons in the plugin.yml

    currendly i to it like
    Code:java
    1.  
    2. private String[] getCommandPage(Player pl)
    3. {
    4. List<String> commands = new ArrayList<String>();
    5. List<String> usage = new ArrayList<String>();
    6. List<String> discription = new ArrayList<String>();
    7. List<String> permissions = new ArrayList<String>();
    8. Plugin[] plugins = plugin.getServer().getPluginManager().getPlugins();
    9. PluginDescriptionFile file = null;
    10. try
    11. {
    12. for(Plugin p : plugins)
    13. {
    14. file = p.getDescription();
    15.  
    16. for(String command : file.getCommands().keySet())
    17. {
    18. commands.add(command);
    19. }
    20.  
    21. for(String s : commands)
    22. {
    23. if(file.getCommands().get(s).get("permission") != null)
    24. {
    25. permissions.add((String)file.getCommands().get(s).get("permission"));
    26. }
    27. else
    28. {
    29. discription.add("");
    30. }
    31.  
    32. if(file.getCommands().get(s).get("description") != null)
    33. {
    34. discription.add((String)file.getCommands().get(s).get("description"));
    35. }
    36. else
    37. {
    38. discription.add("");
    39. }
    40. if(file.getCommands().get(s).get("usage") != null)
    41. {
    42. usage.add((String)file.getCommands().get(s).get("usage"));
    43. }
    44. else
    45. {
    46. usage.add("");
    47. }
    48. }
    49. }
    50. }
    51. catch (Exception e)
    52. {
    53. }
    54.  
    55.  
    56. String page= "";
    57. List<String> res = new ArrayList<String>();
    58. for(int i = 0; i < commands.size(); i++)
    59. {
    60. if(pl.hasPermission(permissions.get(i)))
    61. page = usage.get(i) + " \n \n " + discription.get(i);
    62. res.add(page);
    63. }
    64.  
    65. return (String[])res.toArray() ;
    66. }

    but ther must be a better way to do that
     
  12. Offline

    fireblast709

    If they do not have the permissions in the plugin.yml page... you are kinda <insert statement here>. Unless you want to hook into every plugin on BukkitDev...
     
  13. Offline

    ToastHelmi

    well how fireblast709 describe it:
    <insert statement here>
     
Thread Status:
Not open for further replies.

Share This Page