Solved [Noob Question] Adding permissions to a command

Discussion in 'Plugin Development' started by ImJack, Mar 29, 2013.

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

    ImJack

    How can I make this command only executable by players with a certain permission?

    Code:
    public class CommandWoodClick {
        public boolean onCommand (CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(commandLabel.equalsIgnoreCase("woodclick") && args.length >= 1) {
            if(Bukkit.getPlayer(args[0]) == null) {
            sender.sendMessage("Player input is not online!");
            return true;
            }else{
            Player player = Bukkit.getPlayer(args[0]);
            player.getWorld().playSound(player.getLocation(), Sound.WOOD_CLICK, 1, 1);
            player.sendMessage(ChatColor.AQUA + "[UnusedSounds] Played sound 'wood_click' for" + player);
            return true;
            }
            }
            return false;
            }
         
    }
    Noob Level: OVER NINE THOUUUSAAANNDDD
     
  2. if(sender.hasPermissions("yourplugin.yoiurpermissions")
    {
    // your command code here
    }
     
    TheUpdater likes this.
  3. Offline

    TheUpdater

    if(player.hasPermission("FirstName.permissionName")) {
    your command / Event here
    }
     
  4. Offline

    ImJack

    So it'd be like this?
    Code:
    public class CommandWoodClick {
        public boolean onCommand (CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(sender.hasPermission("yourplugin.yoiurpermissions"))
                    {
                if(commandLabel.equalsIgnoreCase("woodclick") && args.length >= 1) {
                    if(Bukkit.getPlayer(args[0]) == null) {
                    sender.sendMessage("Player input is not online!");
                    return true;
                    }else{
                    Player player = Bukkit.getPlayer(args[0]);
                    player.getWorld().playSound(player.getLocation(), Sound.WOOD_CLICK, 1, 1);
                    player.sendMessage(ChatColor.AQUA + "[UnusedSounds] Played sound 'wood_click' for" + player);
                    return true;
                    }
                    }
                    return false;
                    }
                    }
           
    }
    
    When I tried this, Eclipse underlined this in red:
    Code:
    onCommand (CommandSender sender, Command cmd, String commandLabel, String[] args)
    and it says that "This method must return a result type of boolean"
     
  5. Offline

    Devil0s

  6. Offline

    TheUpdater

    public class CommandWoodClick {
    public boolean onCommand (CommandSender sender, Command cmd, String commandLabel, String[] args) {
    if(sender.hasPermission("yourplugin.yoiurpermissions")) {
    if(commandLabel.equalsIgnoreCase("woodclick") && args.length >= 1) {
    if(Bukkit.getPlayer(args[0]) == null) {
    sender.sendMessage("Player input is not online!");
    return true;
    }else{
    Player player = Bukkit.getPlayer(args[0]);
    player.getWorld().playSound(player.getLocation(), Sound.WOOD_CLICK, 1, 1);
    player.sendMessage(ChatColor.AQUA + "[UnusedSounds] Played sound 'wood_click' for" + player);
    return true;
    }
    }
    return false;
    }
    }

    }

    }
     
  7. Offline

    ImJack

    Can you please type that with the code tool? I can't see the spacing before each line there.
     
  8. Offline

    TheUpdater

    Code:
    public class CommandWoodClick {
        public boolean onCommand (CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(sender.hasPermission("yourplugin.yoiurpermissions")){
                if(commandLabel.equalsIgnoreCase("woodclick") ) {
                    if(Bukkit.getPlayer(args[0]) == null) {
                    sender.sendMessage("Player input is not online!");
                    return true;
                    }else{
                    Player player = Bukkit.getPlayer(args[0]);
                    player.getWorld().playSound(player.getLocation(), Sound.WOOD_CLICK, 1, 1);
                    player.sendMessage(ChatColor.AQUA + "[UnusedSounds] Played sound 'wood_click' for" + player);
                    return true;
                    }
                    }
                    return false;
                    }
                    }
    }
         
    }
     
  9. Offline

    ImJack

    Thanks
     
  10. Offline

    TheUpdater

    np i hate when i dont get respond =D so i like to help
     
  11. Offline

    ImJack

    Just one more thing XD Can you tell me how to fix this?
    [​IMG]
     
  12. Offline

    TheUpdater

    delete the red marked one

    delete the red marked one

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  13. Offline

    ImJack

    Then this happens :/
    [​IMG]
     
  14. Offline

    TheUpdater

    post code and
    i will fix it

    is this main file?
     
  15. Offline

    ImJack

    Code:
    package me.miniusb.unusedSounds;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class CommandWoodClick {
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(sender.hasPermission("yourplugin.yoiurpermissions")){
                if(commandLabel.equalsIgnoreCase("woodclick") ) {
                    if(Bukkit.getPlayer(args[0]) == null) {
                    sender.sendMessage("Player input is not online!");
                    return true;
                    }else{
                    Player player = Bukkit.getPlayer(args[0]);
                    player.getWorld().playSound(player.getLocation(), Sound.WOOD_CLICK, 1, 1);
                    player.sendMessage(ChatColor.AQUA + "[UnusedSounds] Played sound 'wood_click' for" + player);
                    return true;
                    }
                    }
                    return false;
                    }
                    }
     
       
        }
     
  16. Offline

    TheUpdater

    is this main class?

    you forgot to add
    Extends javaPlugin and Return false;

    Code:
    package me.miniusb.unusedSounds;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class CommandWoodClick extends JavaPlugin{
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if(sender.hasPermission("yourplugin.yoiurpermissions")){
                if(commandLabel.equalsIgnoreCase("woodclick") ) {
                    if(Bukkit.getPlayer(args[0]) == null) {
                    sender.sendMessage("Player input is not online!");
                    return true;
                    }else{
                    Player player = Bukkit.getPlayer(args[0]);
                    player.getWorld().playSound(player.getLocation(), Sound.WOOD_CLICK, 1, 1);
                    player.sendMessage(ChatColor.AQUA + "[UnusedSounds] Played sound 'wood_click' for" + player);
                    }
                  }
                  }
            return false;
                }
              }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  17. Offline

    ImJack

    Thank you so much!
     
  18. Offline

    TheUpdater

    no problem =D how long have you coded?
     
  19. Offline

    ImJack

    I've been doing Java for a pretty long time, but I've only been doing Bukkit for only a few months. I took a long break between now and the last time I've made a plugin, so I've forgot most of the basics XD
     
  20. Offline

    TheUpdater

    we need some coders for my big project
    this project, we thing we will earn at least 20 / 30$ a week when its done
    we also need texture pack maker beta will be relesed in 1 week =D
     
  21. Offline

    ImJack

    I might be able to help with the code a bit, but I'm pretty good with textures. PM me?
     
Thread Status:
Not open for further replies.

Share This Page