Trying to use my config in differnt classes

Discussion in 'BungeeCord Plugin Development' started by ImLiam2110, Jul 25, 2018.

  1. Hi when i try to call my config in a differnt class i am getting an error code:

    Code (Text):
    private BlackList plugin = BlackList.getInstance();
        private Configuration config = plugin.config;
       
        @Override
        public void execute(CommandSender sender, String[] args) {
            if(!(sender instanceof ProxiedPlayer)) {
                return;
            }

           
           
            ProxiedPlayer p = (ProxiedPlayer) sender;
           
            if(!config.contains("Permission.note")) {
                p.sendMessage("hihihi");
                return;
            }
           
           
            if(!p.hasPermission(config.getString("Permission.note"))) {
                p.sendMessage(c.format("&cNo Permissions"));
                return;
            }
           
            if(args.length == 1) {
           
                return;
            }
           
            p.sendMessage(c.format(plugin.config.getString("Message.Format")));
           
            String test = p.getUniqueId().toString();
            p.sendMessage("Test: " + test);
           
        }

    Main class:

    Code (Text):
        @Override
        public void onEnable() {
            getProxy().getPluginManager().registerCommand(this, new BlacklistCMD());
            //String host, String port, String username, String password, String database  
            try {
                loadConfiguration();      
            } catch (IOException e) {
                e.printStackTrace();
            }
           
       
            getLogger().info("[BlackList] Blacklist has been enabled");
       
        }


      private Configuration loadConfiguration() throws IOException {
            File file = new File(getDataFolder(), "config.yml");

            if (file.exists()) {
                return ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
            }

            // Create the file to save
            if (!file.getParentFile().exists()) {
                file.getParentFile().mkdirs();
            }
            file.createNewFile();

            // Load the default provided configuration and save it to the file
            Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class)
                    .load(getResourceAsStream("config.yml"));
            ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, file);
            return config;
        }
       
     
  2. public static Configuration config;
    and in onEnable:
    config = loadConfiguration();