Custom config player data saving

Discussion in 'Plugin Development' started by Greeniousity, Mar 31, 2024.

  1. Offline

    Greeniousity

    Code:
    java: cannot find symbol
      symbol:   variable plugin
    build error here
     
  2. Online

    timtower Administrator Administrator Moderator

    So you don't blindly copy paste my code?
    You fill in the values?
     
  3. Offline

    Greeniousity

    no i did this first:
    Bukkit.getPluginManager().registerEvents(this, this);
    but remembered that it wasnt the same thing
    im new to both bukkit and java
     
  4. Online

    timtower Administrator Administrator Moderator

    Too bad it is the same thing.
    That is the right thing.
     
  5. Offline

    Greeniousity

    lol im testing it right now
    edit: The saving part worked but i cant update the values in the config and I tried to edit the value of the boost and restarted the server but my boost stayed 0
     
    Last edited: Apr 1, 2024
  6. Online

    timtower Administrator Administrator Moderator

    When did you try to edit the value? As it saves it on quit.
    Edit when the server is turned off.
     
    Greeniousity likes this.
  7. Offline

    Greeniousity

    I can't see why, it retrieves the data from the players.yml when joined. And all values are set to 0, but in the code it sets them to other numbers as default values.
     
    Last edited: Apr 1, 2024
  8. Online

    timtower Administrator Administrator Moderator

    Did you debug? Let the code print the values?
     
  9. Offline

    Greeniousity

    Alright Im adding prints for all the config section related parts
    Debug Found something:
    [22:30:19 INFO]: (Created Data for)CraftPlayer{name=Greeniousity}
    [22:30:19 INFO]: Level0
    [22:30:19 INFO]: Required0
    [22:30:19 INFO]: Experience0
    [22:30:19 INFO]: Boost0

    they are all set to 0
    And I will keep these debug messages, they look cool in the console
     
    Last edited: Apr 2, 2024
  10. Online

    timtower Administrator Administrator Moderator

    Nobody looks at the console and it only fills everything up.

    What is the data in the actual config?
     
  11. Offline

    Greeniousity

    I do look at my console:)
    and the actual config is empy, I dont get the data form there, its set in here:
    Code:
                data.setLevel(1);
                data.setReq(50);
                data.setExp(0);
                data.setBoost(1);
     
  12. Online

    timtower Administrator Administrator Moderator

    Then please post the entire function and the one that does the printing
     
  13. Offline

    Greeniousity

    Code:
        private void onJoinEvent(PlayerJoinEvent event)
        {
            playerData data = new playerData();
            File dat = new File(getDataFolder().getAbsolutePath() + "/players.yml");
            FileConfiguration conf = YamlConfiguration.loadConfiguration(dat);
            if(conf.contains("players." + event.getPlayer().getUniqueId().toString()))
            {
                data.setLevel(conf.getInt("players." + event.getPlayer().getUniqueId().toString() + ".main.level"));
                data.setReq(conf.getInt("players." + event.getPlayer().getUniqueId().toString() + ".main.required"));
                data.setExp(conf.getInt("players." + event.getPlayer().getUniqueId().toString() + ".main.exp"));
                data.setBoost(conf.getInt("players." + event.getPlayer().getUniqueId().toString() + ".main.boost"));
                System.out.println("§d(Created Data for) §e" + event.getPlayer());
                System.out.println("§dLevel " + data.getLevel());
                System.out.println("§dRequired " + data.getReq());
                System.out.println("§dExperience " + data.getExp());
                System.out.println("§dBoost " + data.getBoost());
            } else {
                data.setLevel(1);
                data.setReq(50);
                data.setExp(0);
                data.setBoost(1);
                System.out.println("§d(Loaded Data for) §e" + event.getPlayer());
                System.out.println("§dLevel " + data.getLevel());
                System.out.println("§dRequired " + data.getReq());
                System.out.println("§dExperience " + data.getExp());
                System.out.println("§dBoost " + data.getBoost());
    
            }
     
  14. Online

    timtower Administrator Administrator Moderator

    @Greeniousity Take a close look at your playerData object
    public void setLevel(int amount) {
    this.playerLevel = playerLevel;
    }
    Where does amount get used?
    Or here
    public void setReq(int amount) {
    this.playerRequired = playerExperience;
    }
     
  15. Offline

    Greeniousity

    im setting all the values of setters to the amount integer
     
  16. Online

    timtower Administrator Administrator Moderator

    Can you post the fixed class then?
     
  17. Offline

    Greeniousity

    WELL TIM IT WORKED!
    I will post the class just in case people from the future visit:
    Code:
    package me.altug.levelingsystem.data;
    
    public class playerData {
        private int playerLevel;
        private int playerExperience;
        private int playerRequired;
        private int playerBooster;
    
    
        public int getLevel() {
            return playerLevel;
        }
        public void setLevel(int amount) {
            playerLevel = amount;
        }
    
        public int getExp() {
            return playerExperience;
        }
        public void setExp(int amount) {
            playerExperience = amount;
        }
        public int getReq() {
            return playerRequired;
        }
        public void setReq(int amount) {
            playerRequired = amount;
        }
        public int getBoost() {
            return playerBooster;
        }
        public void setBoost(int amount) {
            playerBooster = amount;
        }
    }
    I really appreciate the help
     
    timtower likes this.

Share This Page