Blocked-Commands

Discussion in 'Spigot Plugin Help' started by Instanity, May 1, 2017.

  1. I'm pretty new into plugin coding, and one of my issues is that I don't know how to make that if someone doesn't have a specific permission he wouldn't be able to do the command and it will send him a message "You don't seemed to have a permission to access this command"
    Here is what I have done so far:
    Code (Text):
    package mc.bukkit.instanity;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class DisallowedPermissions extends JavaPlugin {
       
        public Permission playerPermission = new Permission("hiddencommands.showm");
       
        @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            pm.addPermission(playerPermission);
        }
       

        public void onDisable() {
       
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("plugins") && sender instanceof Player) {
                Player player = (Player) sender;
               
                if(!player.hasPermission("hiddencommands.showm")) {[/B]
                    [What do I do from here!?}
    [B]              
                   
                  }
            }
           
            return false;
        }
       
       
    }
     
  2. So you've added an if statement which will follow into the block if they don't have the permission.

    Now all you have to do is 2 things
    1. Send the message
    2. return true

    Code (Text):
    sender.sendMessage(ChatColor.RED + "You don't have permission to perform this command")
    and return true.
     
  3. Would it cancel the command they did? Because I don't just want to print a message.
     
  4. That's why you return true. The whole method is returning the boolean value true. It will stop evaluating code below the return statement.
     
  5. One late question.
    I have done this and got a error:
    Code (Text):
    package mc.bukkit.instanity;

    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class DisallowedPermissions extends JavaPlugin {
       
        public Permission playerPermission = new Permission("hiddencommands.showm");
       
        @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            pm.addPermission(playerPermission);
        }
       

        public void onDisable() {
       
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("plugins") && sender instanceof Player) {
                Player player = (Player) sender;
               
                if(!player.hasPermission("hiddencommands.showm")) {
                    sender.sendMessage(ChatColor.RED + "You don't have permission to perform this command");
               
                    return true;  
            }
           
            return false;
        }
        }
    What is the problem now?
     
  6. What's the error?
     
  7. As the error says, you're missing a } somewhere. Your IDE should tell you where. At a first glance, I guess you need to add one more } at the end of your file.
     
  8. Code (Text):
    package mc.bukkit.instanity;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class DisallowedPermissions extends JavaPlugin {
     
        public Permission playerPermission = new Permission("hiddencommands.showm");
     
        @Override
        public void onEnable() {
         
        }
     
        @Override
        public void onDisable() {
     
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("plugins") && sender instanceof Player) {
                if(!sender.hasPermission("hiddencommands.showm"));
                sender.sendMessage(ChatColor.YELLOW + "LightMC" + ChatColor.GRAY + "ยป " + ChatColor.DARK_RED + "You're not premitted to do this!");
                   return true;
                  }
           return true;
        }
     
     
    }
    IDK why it doesn't work!
     
  9. You can block the command with a listener
     
  10. Can you write me the code so I can read it?
     
  11. It seems like you're just ignoring instruction people give and expecting the code to be written to you. You don't pay us to develop for you. This is free advice, not free development.

    You are using Eclipse IDE from the looks of it. Your error says, in plain English, that you are missing a curly brace ("}"). Each method and class must be opened and closed using curly braces. Your IDE will tell you exactly where you are missing one. Furthermore, someone actually told you exactly where to put the curly brace.
     
  12. I just don't understand why do they mean, as I said earlier, i'm new to Java so I have almost no idea how to code, but I saw earlier a video with a Listener but I didn't really understand,, that's the reason that I just want the code to be made so I can read it and understand it.
     
  13. I tried what he said, I still couldn't fix it.
     
  14. CommandPreProcessEvent or something I think it's called, you can block it there.
     
  15. Yeah yeah i explained it in private ^^
     
    • Like Like x 1