Solved Multiple config files- IllegalArgumentException: File cannot be null

Discussion in 'Plugin Development' started by gamingmind99, May 30, 2017.

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

    gamingmind99

    I've been trying to educate myself on working with multiple config files. I want to save an array of all jails for my viewing to help administrate staff decisions. I wanted this to be on a new file, and now get an IllegalArgumentException. Here's the starting code where I make the file called jails:
    Code:
    public class Intergrat extends JavaPlugin{
        File jails;
        FileConfiguration config = this.getConfig();
       
        public Permission sSpawn = new Permission("Intergrat.sSpawn");
        public Permission spawn = new Permission("Intergrat.spawn");
        public Permission tSpawn = new Permission("Intergrat.tSpawn");
        public Permission home = new Permission("Intergrat.home");
        public Permission tHome = new Permission("Intergrat.tHome");
        public Permission freeze = new Permission("Intergrat.freeze");
        public Permission jail = new Permission("Intergrat.jail");
       
        public void onEnable(){
            config.addDefault("Spawn.Exists", false);
            config.addDefault("Jail.Exists", false);
            config.options().copyDefaults(true);
            this.saveConfig();
            jails = new File(this.getDataFolder(), "jails.yml");
            if(!jails.exists()){
                try{
                    jails.createNewFile();
                }catch(IOException e){
                    Bukkit.getServer().getLogger().severe("Unable to create jails.yml");
                }
            }
            Bukkit.getServer().getLogger().info("Intergrat by SeductiveWalrus has been enabled");
        }
       
        public void onDisable(){
            Bukkit.getServer().getLogger().info("Intergrat has been disabled");
        }
       
        FileConfiguration jfile = YamlConfiguration.loadConfiguration(jails);
       
        public void saveJails(){
            try{
                jfile.save(jails);
            }catch(IOException e){
                Bukkit.getServer().getLogger().severe("Unable to save jails.yml");
            }
        }
    Now here's the only command I use it in:
    Code:
    else if(cmd.getName().equalsIgnoreCase("jail")){
           if(s instanceof Player){
             Player p = (Player) s;
             if(p.hasPermission(jail)){
               if(args.length > 0){
                 Player t = Bukkit.getPlayerExact(args[0]);
                 if(t != null && !t.hasPermission(jail)){
                   if(config.getBoolean("Jail.Exists") == true){
                     if(config.getBoolean("Players." + t.getUniqueId() + ".Jailed") == true){
                       config.set("Players." + t.getUniqueId() + ".Jailed", false);
                       saveConfig();
                       p.sendMessage(ChatColor.GRAY + t.getName() + " has been unjailed");
                       t.sendMessage(ChatColor.GRAY + "You have been unjailed");
                       if(config.getBoolean("Players." + t.getUniqueId() + ".Home.Exists") == true){
                         World hw = Bukkit.getServer().getWorld(config.getString("Players." + t.getUniqueId() + ".Home.World"));
                         double hx = config.getDouble("Players." + t.getUniqueId() + ".Home.X");
                         double hy = config.getDouble("Players." + t.getUniqueId() + ".Home.Y");
                         double hz = config.getDouble("Players." + t.getUniqueId() + ".Home.Z");
                         t.teleport(new Location(hw, hx, hy, hz));
                       }else if(config.getBoolean("Spawn.Exists") == true){
                         World sw = Bukkit.getServer().getWorld(config.getString("Spawn.World"));
                         double sx = config.getDouble("Spawn.X");
                         double sy = config.getDouble("Spawn.Y");
                         double sz = config.getDouble("Spawn.Z");
                         t.teleport(new Location(sw, sx, sy, sz));
                       }else t.damage(t.getMaxHealth());
                     }else{
                       if(args.length > 1){
                         StringBuilder sb = new StringBuilder("");
                         for(int i=1; i<args.length; i++){
                          sb.append(args[i]).append(" ");
                         }
                         String jm = sb.toString();
                         List<String> list = new ArrayList<String>();
                         jfile.set("Jails", list);
                         saveJails();
                         List<String> jlist = jfile.getStringList("Jails");
                         jlist.add("Jailer:" + p.getName() + "Player:" + t.getName() + "Reason:" + jm);
                       World jw = Bukkit.getServer().getWorld(config.getString("Jail.World"));
                       double jx = config.getDouble("Jail.X");
                       double jy = config.getDouble("Jail.Y");
                       double jz = config.getDouble("Jail.Z");
                       t.teleport(new Location(jw, jx, jy, jz));
                       config.set("Players." + t.getUniqueId() + ".Jailed", true);
                       saveConfig();
                       p.sendMessage(ChatColor.GRAY + t.getName() + " has been jailed");
                       t.sendMessage(ChatColor.GRAY + p.getName() + " has jailed you");
                       Bukkit.broadcastMessage(ChatColor.GRAY + p.getName() + " has jailed " + t.getName() + " for " + jm);
                       }else p.sendMessage(bReason);
                     }
                   }else p.sendMessage(ChatColor.GRAY + "Unable to find jail");
                 }else p.sendMessage(bTarget);
               }else p.sendMessage(bTarget);
             }else p.sendMessage(denyCPerms);
           }else{
             if(args.length > 0){
               Player t = Bukkit.getPlayer(args[0]);
               if(t != null){
                 if(config.getBoolean("Players." + t.getUniqueId() + ".Jailed") == true){
                     config.set("Players." + t.getUniqueId() + ".Jailed", false);
                     saveConfig();
                    Bukkit.getServer().getLogger().info(t.getName() + " has been unjailed");
                     t.sendMessage(ChatColor.GRAY + "You have been unjailed");
                     if(config.getBoolean("Players." + t.getUniqueId() + ".Home.Exists") == true){
                       World hw = Bukkit.getServer().getWorld(config.getString("Players." + t.getUniqueId() + ".Home.World"));
                       double hx = config.getDouble("Players." + t.getUniqueId() + ".Home.X");
                       double hy = config.getDouble("Players." + t.getUniqueId() + ".Home.Y");
                       double hz = config.getDouble("Players." + t.getUniqueId() + ".Home.Z");
                       t.teleport(new Location(hw, hx, hy, hz));
                     }else if(config.getBoolean("Spawn.Exists") == true){
                       World sw = Bukkit.getServer().getWorld(config.getString("Spawn.World"));
                       double sx = config.getDouble("Spawn.X");
                       double sy = config.getDouble("Spawn.Y");
                       double sz = config.getDouble("Spawn.Z");
                       t.teleport(new Location(sw, sx, sy, sz));
                     }else t.damage(t.getMaxHealth());
                 }else{
                  if(config.getBoolean("Jail.Exists") == true){
                   if(args.length > 1){
                     StringBuilder sb = new StringBuilder("");
                     for(int i=1; i<args.length; i++){
                      sb.append(args[i]).append(" ");
                     }
                     String jm = sb.toString();
                     List<String> list = new ArrayList<String>();
                     jfile.set("Jails", list);
                     saveJails();
                     List<String> jlist = jfile.getStringList("Jails");
                     jlist.add("Jailer:Console" + "Player:" + t.getName() + "Reason:" + jm);
                   World jw = Bukkit.getServer().getWorld(config.getString("Jail.World"));
                   double jx = config.getDouble("Jail.X");
                   double jy = config.getDouble("Jail.Y");
                   double jz = config.getDouble("Jail.Z");
                   t.teleport(new Location(jw, jx, jy, jz));
                   config.set("Players." + t.getUniqueId() + ".Jailed", true);
                   saveConfig();
                   Bukkit.getServer().getLogger().info(t.getName() + " has been jailed");
                   t.sendMessage(ChatColor.GRAY + "You have been jailed");
                   Bukkit.broadcastMessage(ChatColor.GRAY  + t.getName() + " has been jailed for " + jm);
                   }else Bukkit.getServer().getLogger().info("Invalid reason");
                  }else Bukkit.getServer().getLogger().info("Unable to find jail");
                 }
               }else Bukkit.getServer().getLogger().info("Invalid player");
             }else Bukkit.getServer().getLogger().info("Invalid player");
           }
          }
    Last, the error:
    Code:
    [17:49:13] [Server thread/ERROR]: Could not load 'plugins\IntergratMain.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: File cannot be null
       at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:133) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot.jar:git-Spigot-d276ab1-d219213]
       at org.bukkit.craftbukkit.v1_11_R1.CraftServer.loadPlugins(CraftServer.java:301) [spigot.jar:git-Spigot-d276ab1-d219213]
       at net.minecraft.server.v1_11_R1.DedicatedServer.init(DedicatedServer.java:204) [spigot.jar:git-Spigot-d276ab1-d219213]
       at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:544) [spigot.jar:git-Spigot-d276ab1-d219213]
       at java.lang.Thread.run(Unknown Source) [?:1.8.0_77]
    Caused by: java.lang.IllegalArgumentException: File cannot be null
       at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:174) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       at me.SeductiveWalrus.Intergrat.<init>(Intergrat.java:54) ~[?:?]
       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_77]
       at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_77]
       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_77]
       at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_77]
       at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_77]
       at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       ... 6 more
    [17:49:13] [Server thread/ERROR]: Could not load 'plugins\PlugMan.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
       at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:78) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot.jar:git-Spigot-d276ab1-d219213]
       at org.bukkit.craftbukkit.v1_11_R1.CraftServer.loadPlugins(CraftServer.java:301) [spigot.jar:git-Spigot-d276ab1-d219213]
       at net.minecraft.server.v1_11_R1.DedicatedServer.init(DedicatedServer.java:204) [spigot.jar:git-Spigot-d276ab1-d219213]
       at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:544) [spigot.jar:git-Spigot-d276ab1-d219213]
       at java.lang.Thread.run(Unknown Source) [?:1.8.0_77]
    Caused by: org.bukkit.plugin.InvalidDescriptionException: Invalid plugin.yml
       at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:160) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:76) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       ... 6 more
    Caused by: java.util.zip.ZipException: error in opening zip file
       at java.util.zip.ZipFile.open(Native Method) ~[?:1.8.0_77]
       at java.util.zip.ZipFile.<init>(Unknown Source) ~[?:1.8.0_77]
       at java.util.zip.ZipFile.<init>(Unknown Source) ~[?:1.8.0_77]
       at java.util.jar.JarFile.<init>(Unknown Source) ~[?:1.8.0_77]
       at java.util.jar.JarFile.<init>(Unknown Source) ~[?:1.8.0_77]
       at org.bukkit.plugin.java.JavaPluginLoader.getPluginDescription(JavaPluginLoader.java:148) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:76) ~[spigot.jar:git-Spigot-d276ab1-d219213]
       ... 6 more
    I'd really appreciate any help on this, as I've had a hard time educating myself on this. I don't want to be spoonfed the fix for this, I just want to know where I went wrong so I can teach this to myself. I still consider myself a beginner, so any help would be strongly appreciated. Thanks guys.

    ~SeductiveWalrus
     
  2. Offline

    Horsey

    There's something wrong with your plugin.yml, can we see it?
     
  3. Offline

    CeramicTitan

    That's the wrong issue :eek:.

    @gamingmind99

    When does this error occur? Is jail.yml being created?

    EDIT: Can you show line 54 from Intregat.java
     
  4. Offline

    Caderape2

  5. Offline

    YoloSanta

    Are you using 1 class? I suggest using PasteBin as it helps everyone read your code instead of separating it in half
     
  6. Offline

    gamingmind99

    @CeramicTitan when I get home from school I'll label it and make pastebins for everything.
     
  7. Offline

    gamingmind99

  8. Offline

    CeramicTitan

  9. Offline

    gamingmind99

Thread Status:
Not open for further replies.

Share This Page