Configuration Issue (I think...)

Discussion in 'Plugin Development' started by TehCoderHD, Feb 26, 2017.

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

    TehCoderHD

    Okay, so I have this bug and I have recoded this class so many times and it seems to keep reappearing.
    (The HCF Class is irrelevant even though its in the error, its only referred to to get the getDataFolder() method)

    Error:
    Error (open)

    Code:
    [21:59:59] [Server thread/ERROR]: Error occurred while enabling TheCore v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at me.subbotted.hcf.scoreboard.display.ScoreboardService.init(ScoreboardService.java:20) ~[?:?]
        at me.subbotted.hcf.HCF.onEnable(HCF.java:102) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[custom.jar:git-PaperSpigot-a925999]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:325) [custom.jar:git-PaperSpigot-a925999]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:416) [custom.jar:git-PaperSpigot-a925999]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:481) [custom.jar:git-PaperSpigot-a925999]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:399) [custom.jar:git-PaperSpigot-a925999]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.reload(CraftServer.java:875) [custom.jar:git-PaperSpigot-a925999]
        at org.bukkit.Bukkit.reload(Bukkit.java:308) [custom.jar:git-PaperSpigot-a925999]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [custom.jar:git-PaperSpigot-a925999]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) [custom.jar:git-PaperSpigot-a925999]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:773) [custom.jar:git-PaperSpigot-a925999]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchServerCommand(CraftServer.java:759) [custom.jar:git-PaperSpigot-a925999]
        at net.minecraft.server.v1_7_R4.DedicatedServer.aB(DedicatedServer.java:325) [custom.jar:git-PaperSpigot-a925999]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:287) [custom.jar:git-PaperSpigot-a925999]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:651) [custom.jar:git-PaperSpigot-a925999]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:557) [custom.jar:git-PaperSpigot-a925999]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [custom.jar:git-PaperSpigot-a925999]
    [21:59:59] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it

    ScoreboardService Class:
    Code:
    package me.subbotted.hcf.scoreboard.display;
    
    import java.util.HashMap;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    
    import me.subbotted.api.utils.Config;
    import me.subbotted.hcf.HCF;
    
    public class ScoreboardService{
    
        public static HashMap<String, String> entries;
        public static HashMap<String, Boolean> enabled;
       
        public void init(){
           
            Config c = new Config(HCF.getPlugin(), "scoreboard.yml");
       
            entries.put("title", C(c.getString("scoreboard_title")));
            entries.put("vanish", C(c.getString("staffBoard.vanish.entry")));
            entries.put("staffchat", C(c.getString("staffBoard.staffchat.entry")));
        }
       
        public boolean isEnabled(String entryName){
            return enabled.get(entryName);
        }
       
        public String C(String s){
            return ChatColor.translateAlternateColorCodes('&', s);
        }
    }
    Config Class (It works perfectly fine but why not give it to yall, you'd ask for it anyway xD):
    Code:
    package me.subbotted.api.utils;
    
    import org.bukkit.configuration.file.YamlConfiguration;
    
    import me.subbotted.hcf.HCF;
    
    import java.io.File;
    
    public class Config extends YamlConfiguration {
        private final String fileName;
        private final HCF plugin;
    
        public Config(final HCF plugin, final String fileName) {
            this(plugin, fileName, ".yml");
        }
    
        public Config(final HCF plugin, final String fileName, final String fileExtension) {
            this.plugin = plugin;
            this.fileName = fileName + (fileName.endsWith(fileExtension) ? "" : fileExtension);
            this.createFile();
        }
    
        public String getFileName() {
            return this.fileName;
        }
    
        public HCF getPlugin() {
            return this.plugin;
        }
    
        private void createFile() {
            final File folder = this.plugin.getDataFolder();
            try {
                final File file = new File(folder, this.fileName);
                if (!file.exists()) {
                    if (this.plugin.getResource(this.fileName) != null) {
                        this.plugin.saveResource(this.fileName, false);
                    } else {
                        this.save(file);
                    }
                    this.load(file);
                } else {
                    this.load(file);
                    this.save(file);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    
        public void save() {
            final File folder = this.plugin.getDataFolder();
            try {
                this.save(new File(folder, this.fileName));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    
        public boolean equals(final Object o) {
            if (this == o) {
                return true;
            }
            if (!(o instanceof Config)) {
                return false;
            }
            final Config config = (Config) o;
            Label_0054:
            {
                if (this.fileName != null) {
                    if (this.fileName.equals(config.fileName)) {
                        break Label_0054;
                    }
                } else if (config.fileName == null) {
                    break Label_0054;
                }
                return false;
            }
            if (this.plugin != null) {
                if (!this.plugin.equals((Object) config.plugin)) {
                    return false;
                }
            } else if (config.plugin != null) {
                return false;
            }
            return true;
        }
    
        public int hashCode() {
            int result = (this.fileName != null) ? this.fileName.hashCode() : 0;
            result = 31 * result + ((this.plugin != null) ? this.plugin.hashCode() : 0);
            return result;
        }
    }
    
    If anyone has any idea on why this is happening please tell me, probably a stupid mistake but oh well... they happen :(

    Oh also heres the config file:
    Code:
    scoreboard_title: '&6&lHCFCore &c[Map 1]'
    
    staffBoard:
      vanish:
        entry: '&aVanish: &r{0}'
        enabled: true
      staffchat:
        entry: '&aStaff Chat: &r{0}'
        enabled: true
      line:
        entry: '&7&m-------------------------'
        enabled: false
     
  2. Offline

    mine-care

    Encapsulate and also make sure that 'static' there is absolutely nessesary.
    the problem is that these static variables are not initialised therefore null which is what causes the exception ;)
     
Thread Status:
Not open for further replies.

Share This Page