Solved How Do I Properly Add Permission Nodes To My Bukkit Plugin?

Discussion in 'Plugin Development' started by imyussy, Oct 11, 2014.

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

    WesJD

    AdamQpzm
    It doesn't need to be that sophisticated. Just check if the message in a whole is /pl or /plugins. Pardon me if I misunderstood you.

    imyussy
    Anyways, the code in the OP wont work at all, the command isn't even inside the constructor. You can check for permissions with p.hasPermission("perm.node"). Before continuing with the Bukkit API I suggest learning Java.
     
  2. Offline

    imyussy

    mythbusterma Ok. I implemented the listener and there were no errors on console or in Eclipse. The only problem is that when I added the permission node noplugins.bypass to the default group and made myself default, it just said I didn't have permission to use that command. I posted my java code below to see if there are any problems that could be changed to solve this issue. Its probably not a problem with the plugin.yml, but I also pasted what that looks like too below.

    Java Code:
    Code:java
    1. package com.imyussy.customplugincommand;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.player.PlayerCommandPreprocessEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class CustomPluginCommand extends JavaPlugin implements Listener
    11. {
    12. public void onEnable() {
    13. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    14. //No log needed, it auto does it.
    15. }
    16.  
    17. public void onDisable() {
    18.  
    19. }
    20. @EventHandler
    21.  
    22. public void onCmd(PlayerCommandPreprocessEvent e) {
    23.  
    24. if(!e.getPlayer().hasPermission("noplugins.bypass")) {
    25. if(e.getMessage().equalsIgnoreCase("/pl") || e.getMessage().equalsIgnoreCase("/pl ") || e.getMessage().equalsIgnoreCase("/plugins") || e.getMessage().equalsIgnoreCase("/plugins ")) {
    26. e.setCancelled(true);
    27. e.getPlayer().sendMessage( "" + ChatColor.WHITE + "Plugins (3): " + ChatColor.GREEN + "You" + ChatColor.WHITE + ", " + ChatColor.GREEN + "Mad" + ChatColor.WHITE + ", "+ ChatColor.GREEN + "Bro?!?");
    28. }
    29. } else {
    30. }
    31. }
    32. }


    Plugin.yml:
    Code:
    name: PluginCommand
    main: com.imyussy.customplugincommand.CustomPluginCommand
    version: 1.0
    author: imyussy
    
     
  3. WesJD imyussy It does need to be more sophisticated than that - blocking /pl and /plugins as the whole message wouldn't block /pl 4, so the best way is to check for that is by splitting by space and checking whether the first argument is something you want to block... and the above approach still doesn't block /bukkit:plugins...

    Honestly, at this point, you're better off just negating the permission node. Why do you think it exists?
     
  4. Offline

    imyussy

    AdamQpzm Well I need the permission node because I don't want everyone to see that message when they type /pl or /plugins. I only want de-opped players to see that message. So I added a permission node so I can add it to the default group in GroupManager
     
  5. imyussy No, I mean take away the bukkit.command.plugins permission from people you don't want to see the plugin list, it's much more reliable.
     
  6. Offline

    imyussy

    @AdamQpzm Thank you so much! It works perfectly now! :)
     
Thread Status:
Not open for further replies.

Share This Page