Default config

Discussion in 'Spigot Plugin Development' started by ItsChristian, May 4, 2017.

  1. I am creating a playerdata w/ the players data (Duh) but I don't want to say for every thing
    Code (Text):
    if (data.contains("Money"))
                this.Money = data.getInt("Money");
            else
                this.Money = 0;
    How can i do this automaticly?
     
  2. What are you talking about? You said "I don't want to say for every thing", but never said what you didn't want to do for everything?
     
  3. if (data.contains("Money"))
    this.Money = data.getInt("Money");
    else
    this.Money = 0;

    (Money can be anything)
     
  4. ...and you don't want to do this every time for what? Every player? On join event? More information please!

    Also, I hope that's not your actual code. It should look like this:
    Code (Text):
    if (data.contains("money")) {
            this.money = data.getInt("money");
    }else{
            this.money = 0;
    }
     
  5. every thing like money, power, health, deaths, items, name it.

    EDIT: You dont have to use {} if you only use one line
     
  6. for example :

    Code (Text):
    public <T> get(String key){
    if data.contains(key){
    return data.get(key);
    } else {
    return null;
    }
    }
    I don't know if you need to cast (T) to your return by the way.
     
  7. Easy
    Code (Java):
    this.Money = data.getInt("money", 0);
    In fact I'm pretty sure you don't even need the second 0 parameter 0 cause if it isn't found in data it'll return 0

    Also you shouldn't be storing a FileConfiguration object. If the config is reloaded after being changed your data object will still refer to the old contents of that file.

    That isn't even the right method that's the get method. OP uses getInt
     
    • Agree Agree x 1
  8. I suggest you read back in this thread. The OP clearly said that he might want to store items which clearly isn't an Integer.
     
  9. Okay, so you need to create a method for each value you want to retrieve, and make sure that you store/save that data correctly. Also, you don't need to store data that you can just get from in-game (like a player's health). One more thing: use UUIDs, not player names, for your data file(s).
    Code (Text):
    public static double getMoney(String uuid) {
            return Double.parseDouble(data.getDouble("money"));
    ^ This method would be used like this:
    Code (Text):
    Double money = Class.getMoney(player.getUniqueId().toString());
    Code (Text):
    public static double getHealth(Player player) {
            return player.getHealth();


    @_xXProDudeXx_ I'm sure I've seen you spoon-feeding before. Could you please explain those snippets to people and teach them how to create/use them, instead of just letting them copy/paste and learn nothing?

    Edit: After reading your previous reply, I want to point out that the OP specifically mentioned things like money. So don't go around arguing with people when you don't even understand the question yourself. Another clarification: "items" can be integers by the way.
     
    #9 _diam, May 4, 2017
    Last edited: May 4, 2017
    • Agree Agree x 1
  10. @_diam Yea thanks for your Tip, I will do later
     
    • Like Like x 1
  11. Thank you.
     
    • Like Like x 1
  12. How can Items be integers, Materials by ID?
     
  13. They could be (although that's deprecated), but also data values, amounts, inventory locations, etc.