Reading Player data files Need help!

Discussion in 'Plugin Development' started by donosoboso, Feb 9, 2013.

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

    donosoboso

    Hi guys,
    I need help with making my plugin so that when you do /history [playername] it accesses the player file i have made and sends the contents to the sender of the command in chat.
    This is what i have so far for the command part in my main class:
    Code:
        public boolean onCommand(CommandSender sender, Command cmd,
            String commandLabel, String[] args){
            if(commandLabel.equalsIgnoreCase("history"))
            if (args.length == 1){
                if(args.length <3){
                    Player player = getServer().getPlayer(args[0]);
                    String name = player.getName();     
                }
            }
    And this is the Listener class where i have the onPlayerJoin file creation:
    Code:
        @EventHandler(priority = EventPriority.HIGH)
        public void onPlayerJoin(PlayerLoginEvent event) throws IOException {
            Player player = event.getPlayer();
        final String name = player.getName();
        File playerFile = new File("plugins/PunishControl/UserData" ,name+ ".yml");
            if(!playerFile.exists()){
            playerFile.createNewFile();}
        FileConfiguration playerConfig = YamlConfiguration.loadConfiguration(playerFile);
        playerConfig.getString("plugins/PunishControl/Userdata");
        playerConfig.set("History", name);
        playerConfig.set("Language" , 0);
        playerConfig.set("Staff Abuse" , 0);
        playerConfig.set("Advertising" , 0);
        playerConfig.set("Spamming" , 0);
        playerConfig.set("Promotion" , 0);
        playerConfig.set("Items" , 0);
        playerConfig.set("disobeying" , 0);
        playerConfig.set("Hacking", 0);
        playerConfig.save(playerFile);
        }
    How do i go about doing this?
    Thanks!

    How do i make the command /history [playername] find the [playername].yml and then how can i spit out either the numbers or the whole thing into chat?

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

    chasechocolate

    playerConfig.getInt("spam")?
     
  3. Offline

    donosoboso

    How do i use that? (i'm relavtivly new to Plugin creation)
     
  4. Offline

    chasechocolate

  5. Offline

    donosoboso

    Last edited by a moderator: May 31, 2016
  6. Offline

    FTWin01Gurl

    Code:
    Int ex = config.getInt("test");
    if ( ex == 1 ) {
    // Do something
    }
    
     
    donosoboso likes this.
  7. Offline

    donosoboso

    How do i get that to look at my [playername].yml though?
     
  8. Offline

    FTWin01Gurl

    Use YamlConfiguration to load that file then use the variable and .getInt().
     
    donosoboso likes this.
  9. Offline

    donosoboso

    How do i specifify the path?

    Dont worry i have just got my head around it thankyou for all your help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page