Help me

Discussion in 'Spigot Plugin Development' started by BloodChain, Apr 12, 2018.

  1. Someone tells me why he does not send me the message of "No Permission"?

    Code (Text):
        public boolean onCommand(CommandSender sender, Command cmd, String laber, String[] args) {
            if(sender instanceof ConsoleCommandSender) {
                     ConsoleCommandSender c = (ConsoleCommandSender) sender;
                        FileConfiguration config = plugin.getConfig();
                        String path = "Config.CustomMessages";{
                             if (args.length == 0) {
                        if (cmd.getName().equalsIgnoreCase("cprl")) {
                            if(config.getString(path).equals("true")) {
                                String line1 = "Config.Reload-Line1";
                                String line2 = "Config.Reload-Line2";
                                String line3 = "Config.Reload-Line3";
                                String prefix = "Config.Prefix";
                                plugin.reloadConfig();
                                c.sendMessage(ChatColor.translateAlternateColorCodes('&',""+config.getString(line1)));
                                c.sendMessage(ChatColor.translateAlternateColorCodes('&',""+config.getString(line2).replace("{prefix}", config.getString(prefix))));
                                c.sendMessage(ChatColor.translateAlternateColorCodes('&',""+config.getString(line3)));
                                }else if(config.getString(path).equals("false")){
                                    plugin.reloadConfig();
                                    c.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7&m----------------------------------"));
                                    c.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bThe config has been reloaded"));
                                    c.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7&m----------------------------------"));
                        }
                 }else {
                     Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&c/cpreload"));
                 }
                        }
                        }
            }else {
                Player p = (Player)sender;
                FileConfiguration config = plugin.getConfig();
                String path = "Config.CustomMessages";{
                if(p.hasPermission("cp.reload"))
                if (args.length == 0) {
                        if(config.getString(path).equals("true")) {
                        String line1 = "Config.Reload-Line1";
                        String line2 = "Config.Reload-Line2";
                        String line3 = "Config.Reload-Line3";
                        String prefix = "Config.Prefix";
                        plugin.reloadConfig();
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&',""+config.getString(line1)));
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&',""+config.getString(line2).replace("{prefix}", config.getString(prefix))));
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&',""+config.getString(line3)));
                        }else if(config.getString(path).equals("false")){
                            plugin.reloadConfig();
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7&m----------------------------------"));
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7[&b&lCORE&7] &bThe config has been reloaded"));
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7&m----------------------------------"));
                    }else if(!p.hasPermission("cp.reload")) {
                        if(config.getString(path).equals("true")); {
                        String text = "Config.NoPermission";
                        p.sendMessage(ChatColor.translateAlternateColorCodes('&',""+config.getString(text)));
                        }
                    }else if(config.getString(path).equals("false")) {
                            p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cNo Permission."));
    }
    }
    }
    }
            return true;
    }
    }
     
  2. The else if with !hasPerm... is connected to the if(args.length==0) {...} else if(config.getstr...) {...}
    Else if(!p.hasPerm...)
    Instead it should be connected to if(p.hasPerm...)
    Just put { } around the first if else if statement

     
  3. Just remove the "else" from the permission check, and move it above all the standard code.
     
  4. How does this even compile?

    Learn java!
     
  5. Unrelated but:

    Code (Text):
    if(config.getBoolean(path)){

    }else{

    }

    //instead of
    if(config.getString(path).equals("true")){

    }else if(config.getString(path).equals("false")){

    }
    EDIT:
    Your code is broken as well. There are many unnecessary brackets. Not sure why compiler is not throwing errors. You should fix that
     
    #5 MTM123, Apr 12, 2018
    Last edited: Apr 12, 2018
  6. You are able to have bracket blocks. This code does compile if all blocks are closed correctly.
     
  7. Still, it's so wrong to use it in an instance like this, because he probably just put it there, then noticed the "expected }" error the IDE gives, then just put in another one to make it compile.

    So I stand by my point: learn java!
     
  8. Yes indeed, he should learn java. Looks like a bunch of copy and paste
     
    • Agree Agree x 1
  9. Yes, this compiles perfectly

    Well yes, I'm trying to learn by myself

    how did you learn? Do you know any course?
     
  10. But what's the point of having those brackets?
     
  11. I read a book for university with 11 and understood literally nothing. Than I read it again and again and... than (6-8 years later I understood the structures and the essence of java (I still don't know everything, but that is what makes development fun, right?)
     
  12. Yes, I'm just starting, but having no support material, I just try to understand the codes for myself, I do not know if you understand me :ROFLMAO:
     
  13. I do although I recommend looking at code for plain java and not smth complicated like plugins
     
  14. see some tutorials on yt or visit this
     
  15. Use codecademy.com for some basics
     

Share This Page