Command block doesn't have permission for my Bukkit command

Discussion in 'Plugin Development' started by Roboi, Jan 23, 2020.

  1. Offline

    Roboi

    How do I allow command blocks to do this command?

    upload_2020-1-23_22-6-2.png

    Code:
    Code:
    package me.bukkit.Roboi;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    
    public class RSayCommand implements CommandExecutor {
      
        public static String color(String string) {
            return ChatColor.translateAlternateColorCodes('&', string);
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
      
        if (cmd.getName().equalsIgnoreCase("rsay")) {
            if (!sender.hasPermission("r.say")) {
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cNo permission!"));          
            }
            String myString = "";
            for(int i = 0; i < args.length; i++){
                String arg = args[i] + " ";
                myString = myString + arg;
            }
     

    Attached Files:

  2. Offline

    KarimAKL

    @Roboi Just check if the sender is a player, like this:
    Code:Java
    1. if (sender instanceof Player && !sender.hasPermission("r.say")) {
     

Share This Page