[SOLVED]Send to onEnable();

Discussion in 'Spigot Plugin Development' started by ChikenGamer, Jun 13, 2015.

  1. Hi, my question is, how i can put some lines in the onEnable(), but from another class, it can by static method but how do I use this?

    HTML:
    public class Hats implements Listener{
     
        AdvancedHubPlusMain plugin;
        public Hats(AdvancedHubPlusMain plugin) {
            this.plugin = plugin;
        }
     
        public SimpleConfigManager manager;
        public SimpleConfig HGui;
     
        public static void Enable() { //to onEnable
            String[] comments = {"Multiple lines", "Of nice comments", "Are supported !"};
            String[] header = {"This is super simple", "And highly customizable", "new and fresh SimpleConfig !"};
            manager = new SimpleConfigManager(plugin);
            HGui = manager.getNewConfig("Hgui.yml", header);
            HGui.set("path1", "value1", comments);
            HGui.set("path2", "value2", "This is second comment !");
            HGui.saveConfig();
        }
    Main Class:
    HTML:
    public void onEnable(){
        PluginManager pm = Bukkit.getServer().getPluginManager();
     
            pm.registerEvents(this, this);
         
            pm.registerEvents(new Hats(this), this);
         
            l.log(Level.INFO, "=========[ID]=========");
            l.log(Level.INFO, " > Status: Enabled");
            l.log(Level.INFO, " > Version: " + getDescription().getVersion());
            l.log(Level.INFO, " > Author: " + getDescription().getAuthors());
            l.log(Level.INFO, " > Name: " + getDescription().getName());
            l.log(Level.INFO, "=======================");

            Hats.Enable();
         
    }
     
  2. Get rid of static, and de-capitalise the method name.
    To access, create a new instance of Hats in your main class somewhere
    Code (Java):
    Hats hats = new Hats(this);
    and access the method you want with hats.enable(); (put that in the onEnable method.)

    (You could also pass 'hats' to the register events method, for the sake of efficiency.)

    Also, why don't you just put the method directly in the onEnable?
     

  3. I get a error:
    PHP:
    [18:00:42 ERROR]: Error occurred while enabling AdvancedHubPlus v1.0.0 (Is it up
    to date?)
    java.lang.NullPointerException
            at com.jimdo.choscar.Principal.SimpleConfigManager.prepareFile(SimpleCon
    figManager.java:107) ~[?:?]
            at com.jimdo.choscar.Principal.SimpleConfigManager.prepareFile(SimpleCon
    figManager.java:122) ~[?:?]
            at com.jimdo.choscar.Principal.SimpleConfigManager.getNewConfig(SimpleCo
    nfigManager.java:39) ~[?:?]
            at com.jimdo.choscar.Principal.GADGETS.Hats.Enable(Hats.java:36) ~[?:?]
            at com.jimdo.choscar.Principal.AdvancedHubPlusMain.onEnable(AdvancedHubP
    lusMain.java:43) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[s
    pigot1_8.jar:git-Spigot-044d928-e8c6403]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:340) [spigot1_8.jar:git-Spigot-044d928-e8c6403]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:405) [spigot1_8.jar:git-Spigot-044d928-e8c6403]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.jav
    a:356) [spigot1_8.jar:git-Spigot-044d928-e8c6403]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.
    java:316) [spigot1_8.jar:git-Spigot-044d928-e8c6403]
            at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:4
    18) [spigot1_8.jar:git-Spigot-044d928-e8c6403]
            at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:3
    82) [spigot1_8.jar:git-Spigot-044d928-e8c6403]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:3
    37) [spigot1_8.jar:git-Spigot-044d928-e8c6403]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.jav
    a:256) [spigot1_8.jar:git-Spigot-044d928-e8c6403]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
    :528) [spigot1_8.jar:git-Spigot-044d928-e8c6403]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_31]
    Code on main:
    PHP:
    Hats Hats = new Hats(this);
     
        public void onEnable(){
        PluginManager pm = Bukkit.getServer().getPluginManager();
     
            pm.registerEvents(this, this);
         
            pm.registerEvents(new Hats(this), this);
         
            l.log(Level.INFO, "=========[AdvancedHubPlus]=========");
            l.log(Level.INFO, " > Status: Enabled");
            l.log(Level.INFO, " > Version: " + getDescription().getVersion());
            l.log(Level.INFO, " > Author: " + getDescription().getAuthors());
            l.log(Level.INFO, " > Name: " + getDescription().getName());
            l.log(Level.INFO, "=======================");

            Hats.Enable();
         
    }
    Code of Hats:
    HTML:
    public class Hats implements Listener{
     
        AdvancedHubPlusMain plugin;
        public Hats(AdvancedHubPlusMain plugin) {
            this.plugin = plugin;
        }
     
        public SimpleConfigManager manager;
        public SimpleConfig HGui;
     
        public void Enable() { //to onEnable
            String[] comments = {"Multiple lines", "Of nice comments", "Are supported !"};
            String[] header = {"This is super simple", "And highly customizable", "new and fresh SimpleConfig !"};
            manager = new SimpleConfigManager(plugin);
            HGui = manager.getNewConfig("Hgui.yml", header); //line 36
            HGui.set("path1", "value1", comments);
            HGui.set("path2", "value2", "This is second comment !");
            HGui.saveConfig();
        }
    I do not put in the main class, because it will be a big plug and do not want to stir, but thanks
     
  4. Try creating the new instance of Hats in the onEnable.
     
  5. Nope
     
  6. From the looks of it, your simpleConfig thingy is not creating a new file correctly/the file doesn't exist.
     
  7. I don't want to discourage you, but it may be best if you learned the difference between a method prefixed with static and a method without it. Static belongs to the class and those without static belong to instances of the class (objects).
     
  8. Yeah it's, i solved the problem, thanks!