Help I'm stuck with a config problem ..

Discussion in 'Plugin Development' started by kindak, Dec 13, 2016.

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

    kindak

    Introduction:
    Hey everyone! My ing is Kindak and I'm training to become a plugin dev.
    I am pretty good on making plugins etc but i just started with making configs to my plugins but got stuck in a problem hopefully some of you can help me with :)!

    So here's my problem:

    I am trying to make a loop that would go through each indiviual name of an Array, Get each name that is in the array and later on adding it to an argument so i can disable autosave on start. But i do know how to get the name of each world but i dont know how to make so each world would go through another loop which would disable autosave on start can someone please help me?

    I've tried a lot of things as converting the array to string but i really dont know how to continue...

    This is just my main ->

    Here's my code:

    Code:
    package pro.darkdungeon.www.worldreset.main;
    
    import java.io.File;
    import java.io.IOException;
    
    import org.bukkit.ChatColor;
    import org.bukkit.World;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.onarandombox.MultiverseCore.MultiverseCore;
    
    public class main extends JavaPlugin {
        String prefix = ChatColor.DARK_AQUA + "DarkDungeon ";
        public static File ConfigFolder;
        public static File config;
        public static FileConfiguration WorldConfig;
        main plugin;
        MultiverseCore mV = (MultiverseCore) plugin.getServer().getPluginManager().getPlugin("Multiverse-Core");
    
        Boolean serverstart;
        public void onEnable() {
            this.getCommand("dreset").setExecutor(new CommandHandler(this));
            this.getCommand("Ddas").setExecutor(new CommandHandler(this));
            this.getCommand("Dmapadd").setExecutor(new CommandHandler(this));
            serverstart = true;
            configloadup();
        }// enable
    
        public void onDisable() {
            try {
                WorldConfig.save(config);
            } catch (IOException e) {
                // TODO Auto-generated catch block
            }
        } // disable
    
        public void disableatuosave(){
        if(WorldConfig.contains(mV.getMVWorldManager().getMVWorlds().toString())){
        World world = mV.getMVWorldManager().getMVWorlds(WorldConfig.getKeys(true).toArray());
          
        }
    As you might see i tried converting thearray to string but dont know how to continue..
     
    Last edited: Dec 13, 2016
  2. Stop the static abuse
     
  3. Offline

    Zombie_Striker

    @kindak
    You don't need the www in your package name.

    Capitalize the first letter for all classes. Also, the main class should not be called "Main". Try something more descriptive.

    This is useless. You should remove it.

    This is getting the plugin before your plugin is even enabled. Most likely, this will return null as multiverse most likely has not been enabled yet. Move this to the onEnable.

    You want the lowercase b version.

    Instead of creating three new command handlers, create one and register the other commands as aliases.

    What do you mean by autosave? Also, why do you need another loop?
     
  4. Offline

    kindak

    I explained my self really bad.

    What i want is to get all the worlds that is stored in the config and set autosave to disable on serverstart.. but i dont know how to do it since the worlds would be an array and i cant make it so i would get each one of the name out indiviualy and disable autosave on them..
     
  5. Offline

    timtower Administrator Administrator Moderator

    @kindak Start your plugin before the worlds get loaded, then listen to the worldloadevent?
     
  6. Offline

    kindak

    Wow i did not think about that ..

    Let me see if i can figure this out ! :D

    I did as you said:
    Code:
    public class Disableautosaveevent implements Listener {
        @EventHandler
        public void WorldLoadEvent(World w){
            String name = w.getName();
            String prefix = ChatColor.DARK_AQUA + "DarkDungeon: ";
            if(main.WorldConfig.contains(name)){
                w.setAutoSave(false);
                Bukkit.broadcastMessage(prefix + ChatColor.DARK_GREEN + "Autosave has been disabled!");
            }else if(main.WorldConfig.getKeys(true).isEmpty()){
                Bukkit.broadcastMessage(prefix + ChatColor.YELLOW + "Config is empty!");
            }else{
                Bukkit.broadcastMessage(prefix + ChatColor.DARK_RED + "Could not load world!");
            }
         
         
        }
    }
    But now i am getting this error:
    Code:
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:133) ~[craftbukkit.jar:git-Bukkit-21e3b05]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[craftbukkit.jar:git-Bukkit-21e3b05]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [craftbukkit.jar:git-Bukkit-21e3b05]
            at org.bukkit.craftbukkit.v1_10_R1.CraftServer.loadPlugins(CraftServer.java:294) [craftbukkit.jar:git-Bukkit-21e3b05]
            at org.bukkit.craftbukkit.v1_10_R1.CraftServer.reload(CraftServer.java:723) [craftbukkit.jar:git-Bukkit-21e3b05]
            at org.bukkit.Bukkit.reload(Bukkit.java:548) [craftbukkit.jar:git-Bukkit-21e3b05]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [craftbukkit.jar:git-Bukkit-21e3b05]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) [craftbukkit.jar:git-Bukkit-21e3b05]
            at org.bukkit.craftbukkit.v1_10_R1.CraftServer.dispatchCommand(CraftServer.java:625) [craftbukkit.jar:git-Bukkit-21e3b05]
            at org.bukkit.craftbukkit.v1_10_R1.CraftServer.dispatchServerCommand(CraftServer.java:611) [craftbukkit.jar:git-Bukkit-21e3b05]
            at net.minecraft.server.v1_10_R1.DedicatedServer.aL(DedicatedServer.java:398) [craftbukkit.jar:git-Bukkit-21e3b05]
            at net.minecraft.server.v1_10_R1.DedicatedServer.D(DedicatedServer.java:362) [craftbukkit.jar:git-Bukkit-21e3b05]
            at net.minecraft.server.v1_10_R1.MinecraftServer.C(MinecraftServer.java:643) [craftbukkit.jar:git-Bukkit-21e3b05]
            at net.minecraft.server.v1_10_R1.MinecraftServer.run(MinecraftServer.java:547) [craftbukkit.jar:git-Bukkit-21e3b05]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_111]
    Caused by: java.lang.NullPointerException
            at pro.darkdungeon.www.worldreset.main.main.<init>(main.java:19) ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_111]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_111]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_111]
            at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_111]
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_111]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[craftbukkit.jar:git-Bukkit-21e3b05]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[craftbukkit.jar:git-Bukkit-21e3b05]
            ... 14 more
    My main now:
    Code:
    package pro.darkdungeon.www.worldreset.main;
    
    import java.io.File;
    import java.io.IOException;
    
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.onarandombox.MultiverseCore.MultiverseCore;
    
    public class main extends JavaPlugin {
        String prefix = ChatColor.DARK_AQUA + "DarkDungeon ";
    
    
        main plugin;
        boolean serverstart;
        MultiverseCore mV = (MultiverseCore) plugin.getServer().getPluginManager().getPlugin("Multiverse-Core");
        public File ConfigFolder;
        public static File config;
        public static FileConfiguration WorldConfig;
        public void onEnable() {
            registercommands();
            serverstart = true;
            configloadup();
            registerEvents();
        }// enable
    
        public void onDisable() {
            try {
                WorldConfig.save(config);
            } catch (IOException e) {
                // TODO Auto-generated catch block
            }
        } // disable
        public void configloadup() {
    
            ConfigFolder = getDataFolder();
            config = new File(ConfigFolder, "config.yml");
    
            WorldConfig = new YamlConfiguration();
    
            if (!ConfigFolder.exists()) {
                try {
                    ConfigFolder.mkdir();
                    // created configfolder!
                } catch (Exception ex) {
                    // Could not create configfolder!
                }
            }
            if (!config.exists()) {
                try {
                    config.createNewFile();
                    // Config File Loaded
                } catch (Exception ex) {
                    // Could not create Config
                }
            }
            try {
                WorldConfig.load(config);
                // Config File Loaded
            } catch (Exception ex) {
                // could not Load WorlddConfig file!
            }
        }
        public void registerEvents(){
            getServer().getPluginManager().registerEvents(new Disableautosaveevent(), this);
           
        }
        public void registercommands(){
            this.getCommand("dreset").setExecutor(new CommandHandler(this));
            this.getCommand("Ddas").setExecutor(new CommandHandler(this));
            this.getCommand("Dmapadd").setExecutor(new CommandHandler(this));
        }
    } // End
    
    If someone has a video tutorial of how to debugg a bukkit plugin please send !
     
    Last edited: Dec 13, 2016
  7. Offline

    mythbusterma

    @kindak

    A plugin is pretty much like any other Java program, it will have the same errors and reasons for failing. Also, get out of the habit of watching videos. There are no good videos on Bukkit that I've seen, so actually start reading things. In addition, you should have a firm grasp of Java before beginning plugin development.

    Your issue is relatively self-explanatory, given an understanding of Java. Something on the specified line is null, and you're trying to use its value. Find out what it is and make it not null.
     
  8. Offline

    kindak

    It is not the same thing since in java the debugger tells you what line the error is in.. which it dosent here ..
     
  9. Offline

    kindak

    is it line 19 ?
     
  10. Offline

    kindak

    I fixed it like 2 hourse ago but i am asking you though :p
     
  11. Offline

    mythbusterma

    @kindak

    This is Java, and you can use the Java debugger (jdb) with Bukkit. What are you talking about?
     
Thread Status:
Not open for further replies.

Share This Page