Configs set to null?!

Discussion in 'Plugin Development' started by XxZHALO13Xx, Dec 23, 2014.

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

    XxZHALO13Xx

    Ok i found a api that makes configs understandable.. im testing it and raging rn.. i got it to save.. for some reason when i kill a zombie i get "1 config: you have 1" im like yay! then i kill another. "2 config: you have null" WTF why is it null now?! i can't figure it out.. can someone help me fix it

    the configapi im using is

    http://bukkit.org/threads/simple-configuration-class-easily-create-edit-and-save-yml-files.293154/

    edit forgot code...

    Code:
    public class Main extends JavaPlugin implements Listener {
    
        private Config test = new Config(this, "Kills.");
    
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
    
    
            }
    
    
        public void onDisable() {
    
        }
    
        @EventHandler
        public void join(EntityDeathEvent event) {
            if (event.getEntity().getKiller() != null) {
                if (event.getEntity().getKiller() instanceof Player) {
                    if (event.getEntity() instanceof Zombie) {
                        Player p = (Player) event.getEntity().getKiller();
                        Zombie z = (Zombie) event.getEntity();
                        if(test.contains(p.getName())){
                            test.set(p.getName(), test.get(p.getName() + 1));
                            test.save();
                            p.sendMessage(ChatColor.RED + "2 config: You have: " + test.get(p.getName()));
                        }
                        else{
                            if(!test.contains(p.getName())) {
                                test.set(p.getName(), 1);
                                test.save();
                                p.sendMessage(ChatColor.RED + "1 config: You have: " + test.get(p.getName()));
                            }
    
                        }
    
                    }
    
                }
    
            }
        }
    }
     
  2. @XxZHALO13Xx
    Take a closer look at this line
    Code:
    test.set(p.getName(), test.get(p.getName() + 1));
     
  3. Offline

    XxZHALO13Xx

    @Assist i know its there but im confused whats making it null.. im adding 1 to their current kills
     
  4. Nope. That's why I asked you to take a closer look. You're trying to get an object from the config with key "<their name>1", (p.getName() +1), rather than adding + 1 to the int you get from the file.
     
  5. Offline

    XxZHALO13Xx

    @Assist how would i add it? test.set(p.getName(), 1); ?

    EDIT: Well that would set one constantly.

    @Assist

    Updated
    Code:
      Zombie z = (Zombie) event.getEntity();
                        if(test.contains(p.getName())){
                            test.set(p.getName(), + 1);
                            test.save();
                            p.sendMessage(ChatColor.RED + "2 config: You have: " + test.get(p.getName()));
                        }
                        else{
                            if(!test.contains(p.getName())) {
                                test.set(p.getName(), 1);
                                test.save();
                                p.sendMessage(ChatColor.RED + "1 config: You have: " + test.get(p.getName()));
                            }
    i keep getting you have 1

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
  6. @XxZHALO13Xx
    First get the int from the file. Then add 1 to it. Then save the new int to the file. I don't see what the problem is.
     
  7. Offline

    SuperOriginal

    Think about what you're doing. You are setting the value to "+ 1." Does that make any sense? It's simple logic.
     
  8. Offline

    XxZHALO13Xx

    @SuperOriginal right. im setting the value to whatever it was plus another 1
     
  9. @XxZHALO13Xx That's not how it works. When you say "+1" it doesn't magically think to get the value again and add one to it.
     
  10. Offline

    XxZHALO13Xx

    @AdamQpzm i've tried test.set(p.getName(), test.get(p.getName() +1)); and still doesnt work
     
  11. @XxZHALO13Xx
    That's exactly what you had in the original post.
     
    Skionz likes this.
  12. Offline

    Skionz

    teej107 likes this.
  13. @XxZHALO13Xx You need to pay attention to what you're doing. As @Assist already pointed out, you're adding one to their name, not to their score.
     
  14. Offline

    SuperOriginal

    @Skionz he already has all the parenthesis, he just needs to move it like 3 spaces.
     
  15. Offline

    Skionz

    I meant he had to move his +1 over 1 parenthesis
     
    SuperOriginal likes this.
Thread Status:
Not open for further replies.

Share This Page