Need help with config EconomyPlugin

Discussion in 'Plugin Development' started by Banjer_HD, Jan 9, 2016.

Thread Status:
Not open for further replies.
  1. Hello,

    I am trying to put every new join in the config, but the config gives a error at line 25:
    Code:
    at me.banjer_hd.survival.factions.Events.PlayerEvents.playerJoinEvent(PlayerEvents.java:25) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_66]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_66]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_66]
    
    My class:
    Code:
    public class PlayerEvents implements Listener {
    
        public static Main plugin;
    
        @EventHandler
        public void playerJoinEvent(PlayerJoinEvent e) {
            Player p = e.getPlayer();
        
            if(existConfig(p.getUniqueId().toString()) == false) {
                p.sendMessage(ChatColor.WHITE + "Welcome!");
    >>>>>plugin.getConfig().addDefault("money.players." + p.getUniqueId(), 1000); 
    //^ is line 25
                plugin.getConfig().options().copyDefaults(true);
                plugin.saveConfig();
            }
        
        }
        public boolean existConfig(String UUID) {
            try{
                String s = plugin.getConfig().getString("money.players." + UUID);
                if(s.length() == 1) { // this is for the yellow error on s
                
                }
                return true;
                } catch(NullPointerException e){
                return false;
                }
        }
    
    }
    
    
    Thank you in advance!!
     
    Last edited: Jan 9, 2016
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    timtower Administrator Administrator Moderator

    @Banjer_HD
    public static Main plugin;
    That line, do you ever set it? And why is it static?
     
    Areoace likes this.
  4. @timtower I am not in the main class... with that line i can use "plugin.getConfig()"
     
  5. Offline

    timtower Administrator Administrator Moderator

    @Banjer_HD I know that you are not in the main class.
    And you can do that with a constructor.
     
  6. Offline

    Areoace

  7. @Areoace Why do you ask that? xD
    Its called SurvivalFactions :p
     
  8. Offline

    Areoace

    Ok I don't think you're getting what I'm saying. You should really get rid of static methods as much as possible and use instances or getters.

    You also need to set main, so try make an instance of it. No need for static btw, remove it.
     
  9. Offline

    metincasper

    You have to set
    to be something, it's like a string you can't just do this
    and if you print that string it will "Im a string" you have to do it like this
     
  10. @Areoace I have tested this and it works.. So thats not the problem..
     
  11. Offline

    Areoace

    Static abusing is a very bad habit. @Banjer_HD
     
  12. Offline

    mythbusterma

    @Banjer_HD

    It most certainly is the problem. It causes a very demonstrable lack of understanding of your own code that results in making mistakes like this.
     
  13. @mythbusterma @Areoace Okay... But what code do i need to do this?

    yes it works now :) Thanks to every1 who helped!
    Solution:
    Code:
    Main plugin;
         
        public PlayerEvents(Main instance) {
        plugin = instance;
        }
    
    Sorry for my bad english i am Dutch ;)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 11, 2016
    Areoace likes this.
  14. @Banjer_HD
    add 'System.println(plugin);' before the error.
     
Thread Status:
Not open for further replies.

Share This Page