Individual Player Config Help

Discussion in 'Plugin Development' started by hubeb, Jun 22, 2013.

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

    hubeb

    Ok so im having a problem I honestly dont know whats going on because its working in another plugin im working on.
    Here is the code:
    Code:
    public void onLogin(PlayerLoginEvent event) throws IOException{
            Player player = event.getPlayer();
            createNewplayerFile(player);
            if(hasFile == true){
            updateLogin(player);
            }
        }
        public void updateLogin(Player player) throws IOException{
            File playerFile = new File(plugin.getDataFolder() + File.separator + "players" + File.separator + player.getName() + ".yml");
            if(playerFile.exists()){
                FileConfiguration fc = YamlConfiguration.loadConfiguration(playerFile);
                int TimesLogedIn = fc.getInt("Player.TimesLoggedIn");
                fc.set("Player.TimesLoggedIn", TimesLogedIn + 1);
                fc.save(playerFile);
            }
        }
        public static void createNewplayerFile(Player player) throws IOException{
            DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
            Date date = new Date();
            File playersDir = new File(plugin.getDataFolder() + File.separator + "players");
            if(!playersDir.exists()){
                playersDir.mkdir();
            }
            File playerFile = new File(plugin.getDataFolder() + File.separator + "players" + File.separator + player.getName() + ".yml");
            if(!playerFile.exists()){
                playerFile.createNewFile();
                FileConfiguration fc = YamlConfiguration.loadConfiguration(playerFile);
                fc.set("Player.PlayerName", player.getName());//Players Name
                fc.set("Player.JoinDate", dateFormat.format(date));//Join date
                fc.set("Player.PlayerIP", player.getAddress().getHostName());//Player first join IP
                fc.set("Player.Class", "Undecided");//Player class
                fc.save(playerFile);
            }
        }
    The this class's events are registered.
    Any help would be appreciated.

    Thanks,
    Hubeb

    Bump

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

    chasechocolate

    @EventHandler?
     
  3. Offline

    Minnymin3

    Also listeners shouldn't throw exceptions as AFAIK I do not believe that the Bukkit API handles exceptions with listeners
     
  4. Offline

    hubeb

    chasechocolate & Minnymin3 Ill try the event handler i think its already in. I make it trow errors instead of try/catch.
     
  5. Offline

    Minnymin3

    Yeah don't throw errors. Try and catch for events.
     
  6. Offline

    hubeb

    ok, and chase was right it was the @EventHandler i had it spelled wrong, and for some reason eclispe wasnt pointing it out.
     
Thread Status:
Not open for further replies.

Share This Page