Kits from config errors.

Discussion in 'Plugin Development' started by LeonTG77, Feb 24, 2015.

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

    LeonTG77

    I've tried a bunch of things, but I give up, I've been trying to make a way to make a kit from a config, but it doesn't want to work. Please help me

    Kits.java: http://pastebin.com/2xbTyNPd
    Kits config: http://pastebin.com/1j4KYcGa
    Errors on enable: http://pastebin.com/z7BEyCE7
    Errors when doing /kit [name]:
    Code:
    [17:47:21] [Server thread/INFO]: LeonTG77 issued server command: /kit
    [17:47:21] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'kit' in plugin VexOP v2.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-b1e6da1-1092acb]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-b1e6da1-1092acb]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.dispatchCommand(CraftServer.java:645) ~[spigot.jar:git-Spigot-b1e6da1-1092acb]
        at net.minecraft.server.v1_8_R1.PlayerConnection.handleCommand(PlayerConnection.java:1115) [spigot.jar:git-Spigot-b1e6da1-1092acb]
        at net.minecraft.server.v1_8_R1.PlayerConnection.a(PlayerConnection.java:950) [spigot.jar:git-Spigot-b1e6da1-1092acb]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:26) [spigot.jar:git-Spigot-b1e6da1-1092acb]
        at net.minecraft.server.v1_8_R1.PacketPlayInChat.a(PacketPlayInChat.java:53) [spigot.jar:git-Spigot-b1e6da1-1092acb]
        at net.minecraft.server.v1_8_R1.PacketHandleTask.run(SourceFile:13) [spigot.jar:git-Spigot-b1e6da1-1092acb]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_20]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_20]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:683) [spigot.jar:git-Spigot-b1e6da1-1092acb]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot.jar:git-Spigot-b1e6da1-1092acb]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:623) [spigot.jar:git-Spigot-b1e6da1-1092acb]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:526) [spigot.jar:git-Spigot-b1e6da1-1092acb]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_20]
    Caused by: java.lang.NullPointerException
        at com.vexillarypvp.op.Kits.listKits(Kits.java:113) ~[?:?]
        at com.vexillarypvp.op.cmds.KitCommand.onCommand(KitCommand.java:24) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-b1e6da1-1092acb]
        ... 14 more
    
     
  2. It gives you a NullPointerException (try to access things, which arent there) on line 113 in Kits.java

    And you have a tab in a yml file in OP.java:124
     
  3. Offline

    LeonTG77

    @FisheyLP There is a nullpointer at the first line in the kits.yml file and I removed all tabs in the config
     
  4. Offline

    Bluesocks

    @LeonTG77 Either: Settings.getInstance() returns null, settings.getKits() returns null, or the configuration section "kits" doesn't exist.
     
  5. Offline

    LeonTG77

    the configuation section kits is there in the kits.yml file

    settings code:
    Code:
    package com.vexillarypvp.op;
    import java.io.File;
    import java.io.IOException;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.Plugin;
    
    /**
    * A settings class for managing data and stats files.
    * @author LeonTG77
    */
    public class Settings {
        private Settings() {}   
        private static Settings instance = new Settings(); 
        public static Settings getInstance() {
            return instance;
        }
    
        private FileConfiguration data;
        private File dfile;
       
        private FileConfiguration stats;
        private File sfile;
       
        private FileConfiguration kits;
        private File kfile;
          
        /**
         * Sets up the settings class, creates files that isn't created and makes sure everything is working.
         * @param p the plugin or main class
         */
        public void setup(Plugin p) {
            if (!p.getDataFolder().exists()) {
                p.getDataFolder().mkdir();
            }
                  
            dfile = new File(p.getDataFolder(), "data.yml");
           
            if (!dfile.exists()) {
                try {
                    dfile.createNewFile();
                } catch (IOException ex) {
                    Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create data.yml!");
                }
            }    
           
            data = YamlConfiguration.loadConfiguration(dfile);
           
            sfile = new File(p.getDataFolder(), "stats.yml");
           
            if (!sfile.exists()) {
                try {
                    sfile.createNewFile();
                } catch (IOException ex) {
                    Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create stats.yml!");
                }
            }
           
            stats = YamlConfiguration.loadConfiguration(sfile);
           
            kfile = new File(p.getDataFolder(), "kits.yml");
           
            if (!kfile.exists()) {
                try {
                    kfile.createNewFile();
                } catch (IOException ex) {
                    Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create kits.yml!");
                }
            }
           
            kits = YamlConfiguration.loadConfiguration(kfile);
        }
       
        /**
         * Gets the stats file.
         * @return the stats file.
         */
        public FileConfiguration getStats() {
            return stats;
        }
          
        /**
         * Saves the stats file.
         */
        public void saveStats() {
            try {
                stats.save(sfile);
            } catch (IOException ex) {
                Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save stats.yml!");
            }
        }
       
        /**
         * Reloads the stats file.
         */
        public void reloadStats() {
            stats = YamlConfiguration.loadConfiguration(sfile);
        }
       
        /**
         * Gets the data file.
         * @return the data file.
         */
        public FileConfiguration getData() {
            return data;
        }
       
        /**
         * Saves the data file.
         */
        public void saveData() {
            try {
                data.save(dfile);
            } catch (IOException ex) {
                Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save data.yml!");
            }
        }
       
        /**
         * Reloads the data file.
         */
        public void reloadData() {
            data = YamlConfiguration.loadConfiguration(dfile);
        }
          
        /**
         * Gets the kits file.
         * @return the kits file.
         */
        public FileConfiguration getKits() {
            return kits;
        }
          
        /**
         * Saves the kits file.
         */
        public void saveKits() {
            try {
                kits.save(kfile);
            } catch (IOException ex) {
                Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save kits.yml!");
            }
        }
       
        /**
         * Reloads the kits file.
         */
        public void reloaKits() {
            kits = YamlConfiguration.loadConfiguration(kfile);
        }
    }
     
  6. Offline

    LeonTG77

Thread Status:
Not open for further replies.

Share This Page