Reload doen't load folder

Discussion in 'Spigot Plugin Development' started by to175, Jul 14, 2015.

  1. Hi, help me please :)
    When I do my /tk reload command it sais "Plugin reloaded :)" config reloaded but... If I delete the folder before, it will not create a new folder with config then :(

    Code (Text):
    public void reloadConfiguration(){
            config = YamlConfiguration.loadConfiguration(cFile);
            this.reloadConfig();
        }
    else if (args[0].equalsIgnoreCase("reload")&&player.hasPermission("tk.admin.reload")) {
           reloadConfiguration();
           player.sendMessage(ChatColor.GREEN + "Plugin reloaded :)");
           return true;
    }
     
     
    • Funny Funny x 1
  2. In theory, just using this.reloadConfig() (providing this is in the main class) it should work without the method... This.reloadConfig() checks if the config exists, if it doesn't it creates a new one otherwise it just saves the config from the memory to the file
     
  3. Thanks,
    I don't got it, what's wrong with my code ? :/
     
  4. You will want saveDefaultConfig(); before you do reloadConfig();

    From the javadoc:
     
  5. Thanks, but if I don't want the config to be modified when I /mypl reload is it okay ?
     
  6. Access the data folder and check if it's null, if it is call getDataFolder().mkdir();
     
  7. Read the last line... "This should fail silently if the config.yml already exists."
    So it won't change anything if the config already exists.
     
  8. ho ok thanks :)
    AND : how can I refresh the .jar ? I need to do a command instead of reloading my entire server...
     
  9. You can disable the plugin and then enable it.
     
  10. Ho yep thanks, I never managed to do this :/
    For the moment I have :
    Code (Text):
    public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            cFile = new File(getDataFolder(), "config.yml");
            config = YamlConfiguration.loadConfiguration(cFile);
            saveConfig();
            getCommand("tk").setExecutor(this);
            getLogger().info("Plugin started √ Please visit http://mecraft.fr");
        }
     
        public class Plugin extends JavaPlugin {
            @Override
            public void onDisable(){
                saveConfig();
                getLogger().info("Config saved √ Please visit http://mecraft.fr");
            }
        }
     
        public void reloadConfiguration(){
            config = YamlConfiguration.loadConfiguration(cFile);
            this.reloadConfig();
        }
     
  11. Why do you have an inner class extending JavaPlugin?
     
  12. Because Eclipse asked me, else : error. That's all. This is not the issue, the plugin is working. But I will search how to disable/enable it....
     
  13. Help please :
    [13:37:01] [Server thread/INFO]: to175 issued server command: /tk reload
    [13:37:01] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'tk' in plugin TeamKingdom v0.5
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:740) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:957) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:818) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    Caused by: java.lang.NullPointerException
    at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:421) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at fr.mecraft.teamkingdom.teamkingdom.reloadConfiguration(teamkingdom.java:95) ~[?:?]
    at fr.mecraft.teamkingdom.teamkingdom.onCommand(teamkingdom.java:865) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    ... 13 more
    And code :
    Code (Text):
    public class teamkingdom extends org.bukkit.plugin.java.JavaPlugin implements Listener{
          FileConfiguration config;
          File cFile;
          String PrefixMessage = "[TeamKingdom]";
          String worldName = "";
          teamkingdom tkpl = (teamkingdom) Bukkit.getPluginManager().getPlugin("teamkingdom");
         
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            cFile = new File(getDataFolder(), "config.yml");
            config = YamlConfiguration.loadConfiguration(cFile);
            saveConfig();
            getCommand("tk").setExecutor(this);
            getLogger().info("Plugin started √ Please visit http://mecraft.fr");
        }
       
        public class Plugin extends JavaPlugin {
            @Override
            public void onDisable(){
                saveConfig();
                getLogger().info("Config saved √ Please visit http://mecraft.fr");
            }
        }
       
        public void reloadConfiguration(){
            config = YamlConfiguration.loadConfiguration(cFile);
            this.reloadConfig();
        }
    //...........
    if (args[0].equalsIgnoreCase("reload")&&player.hasPermission("tk.admin.reload")) {
                        Bukkit.getPluginManager().disablePlugin(tkpl);
                        Bukkit.getPluginManager().enablePlugin(tkpl);
                        saveDefaultConfig();
                        reloadConfiguration();
                        player.sendMessage(ChatColor.GOLD + PrefixMessage + " " + ChatColor.GREEN + "Plugin reloaded :)");
                        return true;
                    }
     
  14. please show us which lines are

    at fr.mecraft.teamkingdom.teamkingdom.reloadConfiguration(teamkingdom.java:95) ~[?:?]
    at fr.mecraft.teamkingdom.teamkingdom.onCommand(teamkingdom.java:865) ~[?:?]

    and any methods or variables that link to those lines whether they be in the class or in a different class, we cannot see which line is which just by pasting half the code (the imports count as lines too) and by the looks of the error... you haven't supplied the whole class... otherwise your code you pasted would be atleast 865 lines long........

    P.S its a null pointer which means your either trying to access a variable that doesn't exist or your using a variable you haven't initiated yet, or your trying to create a variable in a config (as an example) path that doesn't exist
     
  15. Yep thanks, sorry,
    I change the code a bit. 1 line error only :
    Code (Text):
    public class team kingdom extends org.bukkit.plugin.java.JavaPlugin implements Listener{
          FileConfiguration config;
          File cFile;
          String PrefixMessage = "[TeamKingdom]";
          String worldName = "";
          teamkingdom tkpl = (teamkingdom) Bukkit.getPluginManager().getPlugin("teamkingdom");
         
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            cFile = new File(getDataFolder(), "config.yml");
            config = YamlConfiguration.loadConfiguration(cFile);
            saveConfig();
            getCommand("tk").setExecutor(this);
            getLogger().info("Plugin started √ Please visit http://mecraft.fr");
            worldName = getConfig().getString("WorldName");
        }
       
        public class Plugin extends JavaPlugin {
            @Override
            public void onDisable(){
                saveConfig();
                getLogger().info("Config saved √ Please visit http://mecraft.fr");
            }
        }
       
        public void reloadConfiguration(){
            config = YamlConfiguration.loadConfiguration(cFile);
            this.reloadConfig();
        }
    //.........
    if (args[0].equalsIgnoreCase("reload")&&player.hasPermission("tk.admin.reload")) {
                        Bukkit.getPluginManager().disablePlugin(tkpl);
                        Bukkit.getPluginManager().enablePlugin(tkpl);
                        saveDefaultConfig();
                        reloadConfiguration();
                        player.sendMessage(ChatColor.GOLD + PrefixMessage + " " + ChatColor.GREEN + "Plugin reloaded :)");
                        return true;
                    }

    at fr.mecraft.teamkingdom.teamkingdom.onCommand(teamkingdom.java:860) ~[?:?]
    =>
    Code (Text):
    Bukkit.getPluginManager().disablePlugin(tkpl);



    [14:05:30] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'tk' in plugin TeamKingdom v0.5
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:740) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerConnection.java:957) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java:818) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:258) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    Caused by: java.lang.NullPointerException
    at org.bukkit.plugin.SimplePluginManager.disablePlugin(SimplePluginManager.java:421) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    at fr.mecraft.teamkingdom.teamkingdom.onCommand(teamkingdom.java:860) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-20-g0b2ed13-b3108jnks]
    ... 13 more
     
  16. i
    if your disabling your own plugin, its not the best idea to get your plugin... just instead of that use

    mainClass.Bukkit.getPluginManager().disablePlugin(mainClass);

    that should disable your plugin without having to first cast your plugin to getting a plugin.

    if that doesn't work try removing the cast to your main class... but ONLY if the above doesn't work
     
  17. Thanks :)
    Code (Text):
    mainClass.Bukkit.getPluginManager().disablePlugin(mainClass);
    "mainClass cannot be resolved"
    Code (Text):
    teamkingdom.Bukkit.getPluginManager().disablePlugin("teamkingdom");
    "Bukkit cannot be resolved or is not a field"
     
  18. Why do you have an inner class in your main class? And why does it extend JavaPlugin?
     
  19. Please answer me too ! I have errors with what LeePMC gave me :p

    If I remove the Extend :
    ... Ho you're right I've removed it !

    "inner class in your main class", where do I have that ?
     
  20. You have a class inside your class