Solved How to properly instance these classes

Discussion in 'Plugin Development' started by Lightcaster5, Feb 19, 2020.

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

    Lightcaster5

    Thanks but that wasn’t the issue... I kept instancing classes in my main class outside of my on enabled which was what kept making it return null. I already knew I needed to use that form of doing it I just tried something different because I was getting errors which have been solved by my original problem.
     
  2. Offline

    Xp10d3

    Just wondering, couldn't you do:
    Code:
        Main plugin = Main.getPlugin(Main.class);
       
        public SQLManager(Main plugin) {
            this.plugin = plugin;
        }
    
    Just a thought :p
     
  3. Offline

    bowlerguy66

    Yeah, I’ve seen that but have never really tried it. I just saw that he was already passing his plugin class through so he might was well use it
     
  4. Offline

    Xp10d3

    oh ok
     
  5. Offline

    timtower Administrator Administrator Moderator

    Why would you set it twice though?
     
  6. Offline

    Xp10d3

    Wdym?
     
  7. Offline

    timtower Administrator Administrator Moderator

    First you set it using the static method, then using the constructor.
    One of them is not needed.
     
  8. Offline

    Xp10d3

    Ohhhhh whoops xD
     
  9. Offline

    Lightcaster5

    Got everything working now, thanks for all the help!
    Answer:
    I was using a method of instancing my main class that would never work, use this over anything:
    Code:
    public YourClass {
           
            private MainClass plugin;
           
            public YourClass(MainClass plugin) {
                    this.plugin = plugin;
            }
    }
     
    Xp10d3 likes this.
Thread Status:
Not open for further replies.

Share This Page