Not adding a player to the config

Discussion in 'Plugin Development' started by Fhbgsdhkfbl, Nov 24, 2015.

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

    Fhbgsdhkfbl

    I'm creating a punishment system, and I need to save a player to a player.yml file, and if they're offline, check that file, and set them banned in the bans.yml file, if there's an easier to do this, let me know.

    but it's not adding the player when they log in

    Code:
    public FileConfiguration playerConfig;
        public File playerConfigFile;
       
        public FileConfiguration banConfig;
        public File banConfigFile;
    
        private static Main instance;
    
        public static Main getInstance() {
            return instance;
        }
    
        public void onEnable() {
            registerCommands();
           
            playerConfigFile = new File(getDataFolder(), "players.yml");
            try {
                firstrun();
            }
            catch (Exception ex)
            {
           
            }
            playerConfig = new YamlConfiguration();
            try {
                playerConfig.load(playerConfigFile);
            }
            catch (IOException | InvalidConfigurationException ex)
            {
            }
    
            banConfigFile = new File(getDataFolder(), "bans.yml");
            try
            {
                firstrun();
            }
            catch (Exception ex)
            {
    
            }
    
            banConfig = new YamlConfiguration();
            try
            {
    
                banConfig.load(banConfigFile);
            }
            catch (IOException  | InvalidConfigurationException ex)
            {
    
            }
        }
         public void copy(InputStream in, File file)
            {
                try
                {
                    OutputStream out = new FileOutputStream(file);
                    byte[] buf = new byte[1024];
                    int len;
                
                    while((len = in.read(buf)) > 0)
                    {
                        out.write(buf, 0 ,len);
                    }
                
                    out.close();
                    in.close();
                }
                catch (Exception e)
                {
                }
            }
        private void firstrun() throws Exception
        {
            if(!banConfigFile.exists())
            {
                banConfigFile.getParentFile().mkdirs();
                copy(getResource("bans.yml"), banConfigFile);
            }
            if(!playerConfigFile.exists())
            {
                playerConfigFile.getParentFile().mkdirs();
                copy(getResource("players.yml"), playerConfigFile);
            }
        }
        @EventHandler
        public void onNewPlayer(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            playerConfig.set("Player." + p.getName(), p.getUniqueId());
        }
     
  2. Offline

    teej107

    @Fhbgsdhkfbl What's wrong with using Bukkit's ban system?
     
  3. Offline

    Fhbgsdhkfbl

    I want to save reasons, and the date and who banned them in a config.
     
  4. Offline

    teej107

  5. Offline

    Fhbgsdhkfbl

  6. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page