NullPointerException:null when using getConfigurationSection()

Discussion in 'Bukkit Help' started by Chubby_Unicorn, Aug 27, 2019.

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

    Chubby_Unicorn

    I am trying to make a plugin were you can make custom items in a config file called customitemsV2 but everytime I try to use getConfigurationSection it comes up with NPE in the console. Heres the code for my Config Class:
    Code:
    package me.blank.Tutorial;
    
    import java.io.File;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.event.EventHandler;
    
    
    public class ConfigManager {   
        //Files @ Files Configs Here
        static File customitemsV2file;
        static FileConfiguration customitemsV2cfg;
        //----------------------------
       
       
        //Find or generates the custom config file
        @EventHandler
        public void setup() {
            customitemsV2file = new File(Bukkit.getServer().getPluginManager().getPlugin("Tutorial").getDataFolder(),"customitemsV2.yml");
            customitemsV2cfg = YamlConfiguration.loadConfiguration(customitemsV2file);
        }
       
        //Gets the actual file
        @EventHandler
        public FileConfiguration getConfig() {
            if(customitemsV2cfg == null)
                reload();
            return customitemsV2cfg;
        }
       
        //Reloads the config file
        public void reload() {
            customitemsV2cfg = YamlConfiguration.loadConfiguration(customitemsV2file);
        }
       
        //Saves the config with changes
        public void saveNewConfig() {
            if (customitemsV2file == null) {
                customitemsV2file = new File(Bukkit.getServer().getPluginManager().getPlugin("Tutorial").getDataFolder(), "customitemsV2.yml");
                reload();
            }
            if (!customitemsV2file.exists()) {           
                 Bukkit.getServer().getPluginManager().getPlugin("Tutorial").saveResource("customitemsV2.yml", false);
                 reload();
             }
        }
    
        public void testItems() {
                  String itemname = getConfig().getConfigurationSection("items").toString();
                  System.out.println(ChatColor.YELLOW + "Item is... " + ChatColor.DARK_RED + itemname);
        }
       
    }
    Heres the main class:
    Code:
    package me.blank.Tutorial;
    
    
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    
    import me.rrojas.Tutorial.Events.EventsClass;
    import net.md_5.bungee.api.ChatColor;
    
    public class Tutorial extends JavaPlugin{
    
        private Commands commands = new Commands();
        private ConfigManager cfgm = new ConfigManager();
       
       
        public void onEnable() {
            //Commands
            getCommand(commands.cmd1).setExecutor(commands);
            //---------------------------------------------------
           
            getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "\n\nTutorial has been Enabled\n\n");
            getServer().getPluginManager().registerEvents(new EventsClass(), this);
            loadConfig();
            loadConfigManager();
        }
       
        public void onDisable() {
            getServer().getConsoleSender().sendMessage(ChatColor.RED + "\n\nTutorial has been Disabled\n\n");
        }
       
        //Load ConfigManager Class
        public void loadConfigManager() {
            cfgm.setup();
            cfgm.saveNewConfig();
            cfgm.testItems();
        }
       
        //Load Default Config
        public void loadConfig() {
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
    }
    Heres the CMD:

    Code:
    [01:33:48] [Server thread/ERROR]: Fatal error trying to convert Tutorial v1.0:me/rrojas/Tutorial/Events/EventsClass.class
    org.bukkit.plugin.AuthorNagException: No legacy enum constant for OAK_PLANKS. Did you forget to define api-version: 1.13 in your plugin.yml?
            at org.bukkit.craftbukkit.v1_14_R1.util.Commodore$1$1.visitFieldInsn(Commodore.java:176) ~[server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.libs.org.objectweb.asm.ClassReader.readCode(ClassReader.java:2210) ~[server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.libs.org.objectweb.asm.ClassReader.readMethod(ClassReader.java:1283) ~[server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.libs.org.objectweb.asm.ClassReader.accept(ClassReader.java:688) ~[server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.libs.org.objectweb.asm.ClassReader.accept(ClassReader.java:400) ~[server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.util.Commodore.convert(Commodore.java:130) ~[server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.util.CraftMagicNumbers.processClass(CraftMagicNumbers.java:283) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:108) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.plugin.java.JavaPluginLoader.getClassByName(JavaPluginLoader.java:202) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:92) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:81) [server.jar:git-Spigot-a596182-edd8fdf]
            at java.lang.ClassLoader.loadClass(Unknown Source) [?:1.8.0_221]
            at java.lang.ClassLoader.loadClass(Unknown Source) [?:1.8.0_221]
            at me.rrojas.Tutorial.Tutorial.onEnable(Tutorial.java:22) [Tutorial.jar:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:352) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:417) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugin(CraftServer.java:461) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugins(CraftServer.java:375) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.reload(CraftServer.java:810) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.Bukkit.reload(Bukkit.java:576) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:710) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchServerCommand(CraftServer.java:695) [server.jar:git-Spigot-a596182-edd8fdf]
            at net.minecraft.server.v1_14_R1.DedicatedServer.handleCommandQueue(DedicatedServer.java:430) [server.jar:git-Spigot-a596182-edd8fdf]
            at net.minecraft.server.v1_14_R1.DedicatedServer.b(DedicatedServer.java:394) [server.jar:git-Spigot-a596182-edd8fdf]
            at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:970) [server.jar:git-Spigot-a596182-edd8fdf]
            at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:815) [server.jar:git-Spigot-a596182-edd8fdf]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
    [01:33:48] [Server thread/ERROR]: Error occurred while enabling Tutorial v1.0 (Is it up to date?)
    java.lang.NullPointerException: null
            at me.rrojas.Tutorial.ConfigManager.testItems(ConfigManager.java:62) ~[?:?]
            at me.rrojas.Tutorial.Tutorial.loadConfigManager(Tutorial.java:36) ~[?:?]
            at me.rrojas.Tutorial.Tutorial.onEnable(Tutorial.java:24) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:352) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:417) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugin(CraftServer.java:461) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.enablePlugins(CraftServer.java:375) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.reload(CraftServer.java:810) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.Bukkit.reload(Bukkit.java:576) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:27) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchCommand(CraftServer.java:710) [server.jar:git-Spigot-a596182-edd8fdf]
            at org.bukkit.craftbukkit.v1_14_R1.CraftServer.dispatchServerCommand(CraftServer.java:695) [server.jar:git-Spigot-a596182-edd8fdf]
            at net.minecraft.server.v1_14_R1.DedicatedServer.handleCommandQueue(DedicatedServer.java:430) [server.jar:git-Spigot-a596182-edd8fdf]
            at net.minecraft.server.v1_14_R1.DedicatedServer.b(DedicatedServer.java:394) [server.jar:git-Spigot-a596182-edd8fdf]
            at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:970) [server.jar:git-Spigot-a596182-edd8fdf]
            at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:815) [server.jar:git-Spigot-a596182-edd8fdf]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
    [01:33:48] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [01:33:48] [Server thread/INFO]: CONSOLE: Reload complete.
    Finally heres the config file:

    Code:
    items:
      - name: "Workers Axe"
        item_id: "workers_axe"
        material: "STONE_AXE"
        enchantments:
          - eName: null
            level: 0
        lore:
          - "Used to cut wood"
        stack_Size: 1
    Any help would be greatly appreciated!
     
  2. Online

    timtower Moderator Moderator

  3. Offline

    Chubby_Unicorn

    Even if I change it so configurationsection searches "name". It still returns null. I checked the format of my yml and it's fine. If I wanted it to search through the item list what would I do instead of getConfigurationSection() ?
     
Thread Status:
Not open for further replies.

Share This Page