Not updating integers

Discussion in 'Plugin Development' started by iAmGuus, Sep 6, 2014.

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

    iAmGuus

    hey guys,
    So, i found a problem in my plugin, it doesn't update an integer in the config when it should,
    im a little tired, so that might be the problem of that i couldnt find the solution :D

    There are no problems in my console.

    Anyways, here is my code:
    Code:java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent e) {
    3. Player p = e.getEntity();
    4. if(data.getConfigurationSection("stats." + p.getUniqueId()) == null) {
    5. p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "There is no section available for you!");
    6. return;
    7. }
    8.  
    9. data.set("stats." + p.getKiller().getUniqueId() + ".kills", data.getInt("stats." + p.getKiller().getUniqueId() + ".kills" + (int) 1));
    10. data.set("stats." + p.getUniqueId() + ".deaths", data.getInt("stats." + p.getUniqueId() + ".deaths") + (int) 1);
    11. if(data.getInt("stats." + p.getKiller().getUniqueId() + ".kills") == (int) 0 || data.getInt("stats." + p.getKiller().getUniqueId() + ".deaths") == (int) 0) {
    12. return;
    13. }
    14. if(data.getInt("stats." + p.getUniqueId() + ".kills") == (int) 0 || data.getInt("stats." + p.getUniqueId() + ".deaths") == (int) 0) {
    15. return;
    16. }
    17. settings.saveData();
    18.  
    19. p.getKiller().sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Congratulations on killing " + p.getName() + "!");
    20. if (p.getKiller() == null) {
    21. data.set("stats." + p.getUniqueId() + ".deaths", data.getInt("stats." + p.getUniqueId() + ".deaths") + (int) 1);
    22. settings.saveData();
    23. }
    24. }
     
  2. Offline

    indyetoile

    iAmGuus
    Assuming 'data' isn't null and the rest of the code is correct, have you registered your events?
     
  3. Offline

    Unica

    iAmGuus
    If you did register, add debug messages with syso. (System.out.println),
    you probably return somewhere before the actual saving.
     
  4. Offline

    iAmGuus

    I did register my events in the Main class.
    Im gonna try the debug messages for the kills now, because death updates work.

    Ok, so what works: the death update and the kill message, but the kill update doesnt.
    Here is my new code:

    Code:java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent e) {
    3. Player p = e.getEntity();
    4. Player killer = p.getKiller();
    5. if (settings.getData().getConfigurationSection("stats." + p.getUniqueId()) == null) {
    6. p.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "There is no section available for you!");
    7. }
    8.  
    9. settings.getData().set("stats." + killer.getUniqueId() + ".kills", settings.getData().getInt("stats." + killer.getUniqueId() + ".kills" + (int) 1));
    10. settings.getData().set("stats." + p.getUniqueId() + ".deaths", settings.getData().getInt("stats." + p.getUniqueId() + ".deaths") + (int) 1);
    11. settings.saveData();
    12.  
    13. killer.sendMessage(ChatColor.BLUE + "ExperiencePvP> " + ChatColor.WHITE + "Congratulations on killing " + p.getName() + "!");
    14. if (p.getKiller() == null) {
    15. settings.getData().set("stats." + p.getUniqueId() + ".deaths", settings.getData().getInt("stats." + p.getUniqueId() + ".deaths") + (int) 1);
    16. settings.saveData();
    17. }
    18. }


    Bump

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

    firecombat4

    If your console has any errors, a stack trace would do wonders for us. I think part of your error is this
    Code:
    settings.getData().getInt("stats." + killer.getUniqueId() + ".kills" + (int) 1)
    This is essentially telling your getData() method to get a line from the config that says "stats.<players UUID>.kills1. Try this instead
    Code:
    settings.getData().set("stats." + killer.getUniqueId() + ".kills", settings.getData().getInt("stats." + killer.getUniqueId() + ".kills")+1);
     
  6. Offline

    iAmGuus

Thread Status:
Not open for further replies.

Share This Page