Changing the Default Bukkit "No Permission" Messages

Discussion in 'Plugin Development' started by Bionicrm, Dec 9, 2013.

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

    Bionicrm

    So we're all probably familiar with the "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error." message. I looked for plugins that changed this (looked at the source code to see what they did), and all of them required you to type in the command, permission, and custom message for each command in a config.yml file. I'd be okay with doing this, however it's just a waste of time and is inefficient.

    I have this example code (obviously doesn't work and I purposely omitted certain needed things) of what I'm trying to do:
    Code:java
    1. // Override "no permission" message.
    2.  
    3. @EventHandler
    4.  
    5. public void onPlayerCommandProcess(PlayerCommandPreprocessEvent event) {
    6.  
    7. if ((!player.hasPermission("bukkit.command.cmdTypedIn")) {
    8.  
    9. player.sendMessage(ChatColor.RED + "Denied access.");
    10.  
    11. event.setCancelled(true);
    12.  
    13. }
    14.  
    15. }
     
  2. Offline

    Chinwe

    I haven't tried this, but a possiblility could be getting the commandmap (with reflection like so), looping through knownCommands, and for every command in .values(), use command.setPermissionMessage("your message") ?
    I don't think you could do a check on PlayerCommandPreProcess, as the plugin authors may not have necessarily set the permission in their plugin.yml (and used an if statement instead) :)
     
    Minecrell likes this.
  3. Offline

    Bionicrm


    How would you go about looping through knownCommands, Chinwe? I'm pretty beginner with the Bukkit API and Java. Thanks :)
     
  4. Offline

    Chinwe

    Bionicrm
    It is a Map<String, Command>, so you would loop through it like so: :)
    for (Command command : knownCommands.values()) {...}
     
Thread Status:
Not open for further replies.

Share This Page