config help

Discussion in 'Plugin Development' started by kamakarzy, May 9, 2013.

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

    kamakarzy

    hi all i have a problem i want to read the Day from my code but i would need to read player and day how would i do it

    Code:
    @EventHandler
                public void onPlayerLogin (PlayerLoginEvent event){
                    Player player = event.getPlayer();
                    int number = 0;
                    if(Main.plugin.getConfig().get(player.getName()) != null){
                                Main.plugin.getConfig().set(player.getName(), "Day"+1);
                       
                    Main.plugin.getConfig().set(player.getName() + "Day", number+1 );
    i have tried a few ways this is what i thought it was but i was wrong
    Code:
    if(Main.plugin.getConfig().get(player.getName() + "Day");
     
  2. Offline

    Nitnelave

    A few things : number is always 0, so it is useless. Instead of "number + 1", you can simply have 1, it's the same.

    "Day" is a String, not a number, and certainly not a day. So "Day" + 1 is "Day1" (Java does the number->string conversion for you).

    You have to think about how you want to store your data. Do you want the day of the week, the number of days he's played, the number of times he's connected?

    For the day of the week, you'll have to do some conversion : for example, keep a number from 0 to 6, and lookup the name of the corresponding day in a table.

    For the number of times connected, you should do something like that :
    Code:
    int days = getConfig().getInt(player.getName() + ".Day", 0); // with a default value in case the node doesn't exist
    getConfig().set(player.getName() + ".Day", days + 1);
    
     
Thread Status:
Not open for further replies.

Share This Page