nullpointer

Discussion in 'Plugin Development' started by aquastt, May 6, 2021.

  1. Offline

    aquastt

    Code:
    public class configAllowed {
    
    private static Plugin plugin; private configAllowed(Plugin plugin) {
    this.plugin = plugin;}
    private static File allow; private static FileConfiguration allows; public static void setup() {
    allow = new File(Bukkit.getServer().getPluginManager().getPlugin("Plugin").getDataFolder(), "allowed_items.yml"); if (!allow.exists()) {
    plugin.saveResource("allowed_items",false);}
    allows = YamlConfiguration.loadConfiguration(allow); try {
    allows.save(allow);} catch (IOException e) {
    e.printStackTrace();}
    }
    
    public static void save() {
    try {
    allows.save(allow);} catch (IOException e) {
    System.out.println("&cerror");}
    }
    
    public static void reload() {
    allows = YamlConfiguration.loadConfiguration(allow);}
    
    public static FileConfiguration get() {
    return allows;}
    }
    
    public void onEnable() {
    getServer().getConsoleSender().sendMessage("was enabled");  config() }
    
    public void onDisable() {
    getServer().getConsoleSender().sendMessage("was disabled");}
    
    public void config() {
    configAllowed.setup();configAllowed.get().options().copyDefaults(true);configAllowed.save();}
    
    error: https://pastebin.com/LrYCHGxY


    if i write Plugin plugin = new Plugin() instead this.plugin=plugin i get a another error
     
    Last edited by a moderator: May 6, 2021
  2. Offline

    timtower Administrator Administrator Moderator

    @aquastt Why are you using a static config like that?
     
  3. Offline

    Kars

    Your error is not coming from the file you provided but from wherever you are trying to re-initialize plugin.
    Plugin (the main class, extends JavaPlugin, contains onEnable) cannot be instantiated as it is already instantiated by Bukkit.
     
  4. Offline

    Xp10d3

    Side note: Please format your code lol. It's painful to look at.
    Ex.
    Code:java
    1.  
    2. return allows;} // wat
    3.  
    4. // also no indentation??
    5. public class configAllowed {
    6.  
    7. private static Plugin plugin; private configAllowed(Plugin plugin) {
    8. this.plugin = plugin;}
    9. private static File allow; private static FileConfiguration allows; public static void setup() {
    10. allow = new File(Bukkit.getServer().getPluginManager().getPlugin("Plugin").getDataFolder(), "allowed_items.yml"); if (!allow.exists()) {
    11. plugin.saveResource("allowed_items",false);}
    12. allows = YamlConfiguration.loadConfiguration(allow); try {
    13. allows.save(allow);} catch (IOException e) {
    14. e.printStackTrace();}
    15. }
    16.  
     

Share This Page