Solved Config file not generating/copying defaults (Repost b/c the Admin didn't read the post b4 closing)

Discussion in 'Plugin Development' started by reesercollins, Aug 21, 2017.

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

    reesercollins

    Hello all,

    I've been working on a plugin which needs to have to the ability to configure some stuff. I keep running into the same problem:

    Console:

    Code:
    [16:19:12 INFO]: [BungeeCompass] Disabling BungeeCompass v1.0
    [16:19:12 INFO]: [BungeeCompass] BungeeCompass has been disabled! :(
    [16:19:12 INFO]: [BungeeCompass] Loading BungeeCompass v1.0
    [16:19:12 INFO]: [BungeeCompass] Enabling BungeeCompass v1.0
    [16:19:12 ERROR]: Error occurred while enabling BungeeCompass v1.0 (Is it up to date?)
    java.lang.IllegalArgumentException: The embedded resource 'config.yml' cannot be found in plugins\BungeeCompass.jar
    at org.bukkit.plugin.java.JavaPlugin.saveResource(JavaPlugin.java:195) ~[spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at org.bukkit.plugin.java.JavaPlugin.saveDefaultConfig(JavaPlugin.java:182) ~[spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at com.mifexnetwork.bungeecompass.BungeeCompass.loadConfiguration(BungeeCompass.java:40) ~[?:?]
    at com.mifexnetwork.bungeecompass.BungeeCompass.onEnable(BungeeCompass.java:15) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:402) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:380) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:329) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.reload(CraftServer.java:751) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at org.bukkit.Bukkit.reload(Bukkit.java:525) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:647) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchServerCommand(CraftServer.java:633) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at net.minecraft.server.v1_12_R1.DedicatedServer.aP(DedicatedServer.java:444) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:407) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [spigot-1.12.1.jar:git-Spigot-65e8124-357b573]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_144]
    [16:19:12 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [16:19:12 INFO]: CONSOLE: Reload complete.
    Jar layout:
    [​IMG]

    BungeeCompass.jar (Main file)

    Code:
    package com.mifexnetwork.bungeecompass;
    
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import net.md_5.bungee.api.ChatColor;
    
    public class BungeeCompass extends JavaPlugin {
       
        @Override
        public void onEnable() {
            loadConfiguration();
            // Register EventListener class with bukkit
            Bukkit.getServer().getPluginManager().registerEvents(new EventListener(this), this);
            getLogger().info("BungeeCompass has been enabled!");
        }
       
        @Override
        public void onDisable() {
            getLogger().info("BungeeCompass has been disabled! :( ");
        }
       
        // Commands
        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (command.getName().equalsIgnoreCase("menu")) {
                if (sender instanceof Player) {
                    Player player = (Player) sender;
                    Menu menu = new Menu(player, /*this.getConfig().getInt("inventory-size")*/ 27, /*this.getConfig().getString("inventory-name")*/ "Navigation");
                } else {
                    sender.sendMessage(ChatColor.RED + "Only players can use that command!");
                }
            }
            return false;
        }
       
        public void loadConfiguration() {
            this.saveDefaultConfig();
        }
    }
    
    Config.yml:

    Code:
    # Hah...jokes. Config doesn't work at the moment
    
    # Inventory Size (number of rows, max. 6)
    inventory-size: 3
    
    # Inventory Name (What will be seen at the top of the window)
    inventory-name: Navigation
    
    # Items
    row1:
      -
      -
      -
      -
      - IRON_FENCE
    

    I realize that the plugin isn't taking values from the config, but that's on purpose for the moment

    NOTICE: DESPITE WHAT THE PLUGIN FILE NAME IS, IT IS NOT A BUNGEECORD PLUGIN. I'VE READ THE TERMS
     
    Last edited: Aug 21, 2017
  2. Offline

    Zombie_Striker

    @reesercollins
    The issue is that the plugin could not find the config.yml in the jar. Are you sure the files are being exported correctly? Are you sure the the file is in the exported jar?

    Also, what is the purpose of your plugin? Why would you specifically include the term "Bungee" if it does not have anything to do with bungeecord?
     
  3. Offline

    ASHninja1997

    Code:
    File file = new File("plugins" + File.separator + "[Folder Name]" + File.separator + "config" + File.separator  + ".yml");
            FileConfiguration conf = YamlConfiguration.loadConfiguration(file);
    
    if(!file.exists()){
                try {
                    file.createNewFile();
                } catch (IOException e1) {
                    Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "creating file ");
                }  
    conf.set("[Variable]", variable);
    try {
             conf.save(file);
           } catch (IOException e) {
             Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Error");
           }
    
    This is how I save my data files. You use the same "file" to grab info from it as well
    You're error is occurring because it can't find your config.yml in your jar
     
  4. Online

    timtower Administrator Administrator Moderator

    Then why did you call it BungeeCompass ?
    And it looks like you are posting on 2 websites (image url), is this correct?
     
Thread Status:
Not open for further replies.

Share This Page