HELP

Discussion in 'Spigot Plugin Help' started by ProIEZRush, Dec 3, 2019.

  1. Hello, my error is this.

    Code (Text):
    Could not load 'plugins\FFA.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:135) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugins(CraftServer.java:292) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:198) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_221]
    Caused by: java.lang.NullPointerException
            at me.proiezrush.ffa.utility.Config.getConfig(Config.java:17) ~[?:?]
            at me.proiezrush.ffa.utility.Chat.<init>(Chat.java:8) ~[?:?]
            at me.proiezrush.ffa.Main.<init>(Main.java:21) ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_221]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_221]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_221]
            at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_221]
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_221]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[spigot-1.8.8-R0.1-SNAPSHOT-latest.jar:git-Spigot-db6de12-18fbb24]
            ... 6 more
    My Main class

    Code (Java):
    package me.proiezrush.ffa;

    import me.proiezrush.ffa.command.FFACommand;
    import me.proiezrush.ffa.utility.Chat;
    import org.bukkit.Bukkit;
    import org.bukkit.command.ConsoleCommandSender;
    import org.bukkit.configuration.InvalidConfigurationException;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    import java.io.File;
    import java.io.IOException;

    public class Main extends JavaPlugin {

        private PluginDescriptionFile plugin = this.getDescription();
        private File arenas = null;
        private YamlConfiguration a = new YamlConfiguration();
        private Chat ch = new Chat();
        private String prefix = ch.prefix;

        private static Main instance;

        @Override
        public void onEnable() {
            instance = this;
            registerListeners();
            registerCommands();
            saveDefaultConfig();
            files();
            messages(true);
        }

        @Override
        public void onDisable() {
            messages(false);
        }

        private void messages(boolean a) {
            ConsoleCommandSender c = Bukkit.getConsoleSender();
            if (a) {
                c.sendMessage(ch.c(prefix + "&aPlugin activado por &e" + plugin.getAuthors()));
            }
            else {
                c.sendMessage(ch.c(prefix + "&aPlugin desactivado por &e" + plugin.getAuthors()));
            }
            c.sendMessage(ch.c(prefix + "&aVersion &E" + plugin.getVersion()));
        }

        private void registerListeners() {
            PluginManager pm = Bukkit.getPluginManager();
        }

        private void registerCommands() {
            this.getCommand("ffa").setExecutor(new FFACommand());
        }

        private void files() {
            arenas = new File(getDataFolder(), "arenas.yml");
            mkDir();
            load();
        }

        private void mkDir() {
            if (!arenas.exists()) {
                saveResource("arenas.yml", false);
            }
        }

        private void load() {
            try {
                a.load(arenas);
            } catch (IOException | InvalidConfigurationException e) {
                e.printStackTrace();
            }
        }

        public YamlConfiguration getArenas() {
            return a;
        }

        public void saveArenas() {
            try {
                a.save(arenas);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public void reloadArenas() {
            a = YamlConfiguration.loadConfiguration(arenas);
        }

        public static Main getInstance() {
            return instance;
        }
    }
     
    And my Config class

    Code (Java):
    package me.proiezrush.ffa.utility;

    import me.proiezrush.ffa.Main;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;

    public class Config {

        private Main instance = Main.getInstance();

        public static Config getInstance() {
            return new Config();
        }

        public FileConfiguration getConfig() {
            return instance.getConfig();
        }

        public void reloadConfig() {
            instance.reloadConfig();
        }

        public YamlConfiguration getArenas() {
            return instance.getArenas();
        }

        public void saveArenas() {
            instance.saveArenas();
        }

        public void reloadArenas() {
            instance.reloadArenas();
        }
    }
     
     
  2. Please, send your Chat.java, there might be a thing here
    Also, try to check if your var ch isn't null, also for instance
     
    • Agree Agree x 1
  3. It is probably because you initialize your Chat object in your Main class directly within it's declaration which is then trying to access your static Main instance from your Main class.
    The problem is that 'instance' it is not initialized at this point because the onEnable() method has not been called yet. You should rather initialize your Chat object in the onEnable() method _after_ setting your Main instance:
    Code (Text):
        @Override
        public void onEnable() {
            instance = this;
            ch = new Chat();
            registerListeners();
            registerCommands();
            saveDefaultConfig();
            files();
            messages(true);
        }
     
    • Agree Agree x 2
  4. I've already done that in my early plugins, it worked fine (now I don't if you were wondering)
     
    • Agree Agree x 1
  5. Sorry, not getting your point. Pretty sure that the problem is, that the Chat constructor is called before the onEnable() in the Main class is called. Another way to prevent this error would be to replace the initialization of "instance" in the Config class.
    Instead of
    Code (Text):
    private Main instance = Main.getInstance();
    it should be done like this
    Code (Text):
    private Main instance = Main.getPlugin(Main.class);
    as it is not required to set the JavaPlugin instance manually there so it should work before onEnable() is called.
     
    • Agree Agree x 1
  6. From what I see you speak Spanish

    Check that there is no accent in config.yml

    Most of the time, at least to me, it happens to me through incorrect config.yml
     
    • Like Like x 1
  7. If you use Eclipse, you can configure an YML file so it uses an UTF-8 encoding (for accents)