Reload my plugin ?

Discussion in 'Plugin Development' started by To175, Dec 29, 2014.

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

    To175

    Hi, when I write "reload" in the search box I can find anything interesting :( (forum development)
    So I post !
    Someone can help me please ?
    It does NOT load/save when I :
    - Drag a new Mecraft.jar in "plugins" folder to replace the old one.
    - Drag a modified config.yml in "Mecraft" folder to replace the old one.

    That means the modifications of the new .jar are not here + the modifications of the new config.yml are not saved (can't use it on the server). I have to /stop

    However here is my log :
    LOG (open)
    [03:14:46] [Server thread/INFO]: to175 issued server command: /mpl reload
    [03:14:46] [Server thread/INFO]: [Mecraft] Disabling Mecraft v1
    [03:14:46] [Server thread/INFO]: [Mecraft] Enabling Mecraft v1
    [03:14:46] [Server thread/INFO]: [Mecraft] Plugin démarré √


    Code:
    public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            getLogger().info("Plugin démarré √");
        }
    //...
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("mecraft")){
              if(sender instanceof Player){
                    Player player = (Player) sender;
                    if(args.length == 1){
                        if (args[0].equalsIgnoreCase("reload")&&player.getName().equals("to175")) {
                        saveConfig();
                        this.reloadConfig();
                        saveConfig();
                        getServer().getPluginManager().disablePlugin(this);
                        getServer().getPluginManager().enablePlugin(this);
                        player.sendMessage(prefixMecraft + ChatColor.GREEN + "Plugin reloaded :)");
                        return true;
                        }
              }
    }
     
    Last edited: Dec 29, 2014
  2. Offline

    Experminator

    Sorry, but this is a wrong section. This should be in Plugin Development.
    Ontopic:
    Code:
    FileConfiguration config;
    File cFile;
    
    public void onEnable(){
         cFile = new File(getDataFolder(), "config.yml");
        config = YamlConfiguration.loadConfiguration(cfile);
        saveConfig();
    }
    
    public void reloadConfiguration(){
        config = YamlConfiguration.loadConfiguration(cfile);
        this.reloadConfig();
    }
     
  3. Offline

    xXSniperzzXx_SD

    @To175 You can't enable your plugin after you disable it, therefor you can't restart your own plugin, and this is the wrong section.
     
  4. Offline

    To175

    @Experminator @xXSniperzzXx_SD
    ??
    HomeForums>Bukkit>Plugin Development
    ??
    I am in Plugin development !

    Thanks,
    Why did you remove those lines ?
    getServer().getPluginManager().registerEvents(this, this); and saveDefaultConfig(); ?

    What is reloadConfiguration() ?
    How does it know that I do /reload ?
     
    Last edited: Dec 29, 2014
  5. Offline

    Samthelord1

    If I recall, go into the search bar and search something along the lines of Dropbox api world reloading, not sure how this would go with plugins, but I think people managed to get it working with world reloads
     
  6. Offline

    To175

    @Samthelord1
    I don't understand what you say.

    Thanks @Experminator BUT
    Please, why ?
    Why did you remove those lines ?
    getServer().getPluginManager().registerEvents(this, this); and saveDefaultConfig(); ?

    What is reloadConfiguration() ?
    How does it know that I do /reload ?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
  7. Offline

    Samthelord1

    Last edited by a moderator: Oct 31, 2016
    To175 likes this.
  8. Offline

    To175

    @Samthelord1 @xXSniperzzXx_SD @Experminator
    doesn't work :
    [16:15:34] [Server thread/INFO]: to175 issued server command: /mecraft reload

    nothing else in log !

    Code:
          FileConfiguration config;
          File cFile;
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            cFile = new File(getDataFolder(), "config.yml");
            config = YamlConfiguration.loadConfiguration(cFile);
            saveConfig();
            getLogger().info("Plugin démarré √");
        }
        public void reloadConfiguration(){
            config = YamlConfiguration.loadConfiguration(cFile);
            this.reloadConfig();
        }
    
    //...
    
    if (args[0].equalsIgnoreCase("reload")&&player.getName().equals("to175")) {
                                reloadConfiguration();
                                player.sendMessage(prefixMecraft + ChatColor.GREEN + "Plugin reloaded :)");
                                return true;
                            }
    
     
  9. Offline

    1Rogue

    Just make a method that reinitializes all the parts of your plugin:

    Code:java
    1. public void reload() {
    2. //call onDisable
    3. //cancel any tasks / don't allow calls to your plugin (locking)
    4. //reset fields
    5. //call onEnable
    6. }
     
  10. Offline

    Experminator

    @1Rogue Right.
    And Hey Rogue! You rocks!
     
  11. Offline

    To175

    Thanks,
    I have not "onDisable" I don't know what to put in it :(

    I don't know how to do that :
    1. /cancel any tasks / don't allow calls to your plugin (locking)
    2. //reset fields
     
Thread Status:
Not open for further replies.

Share This Page