Solved Delete files of another plugin using command?

Discussion in 'Plugin Development' started by matcracker, Sep 10, 2015.

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

    matcracker

    Hi! I need your help :) I write a plugin that reset file of another plugin by command, but when I run a command don't delete the files.

    Code:
    }else if(args[0].equalsIgnoreCase("reset")){
                            if(sender.hasPermission("cm.command.reset")){
                                if(args[1] != null){
                                    String name = args[1];
                                    Player target = this.getServer().getPlayer(name);
                               
                                    if(target != null && target.isOnline()){
                                       File playerDat = new File(<PluginName>.plugin.getDataFolder() + File.separator + "players" + File.separator + target.getUniqueId() + ".dat");
                                       File playerYml = new File(<PluginName>.plugin.getDataFolder() + File.separator + "players" + File.separator + target.getUniqueId() + ".yml");
                                        playerDat.delete();
                                        playerYml.delete();
                       
                                        target.kickPlayer("§c§lClass and levels resetted!");
                                        sender.sendMessage("Class e livels of player " + target.getName() + " resette with success");
                                        return true;
                                    }else{
                                        sender.sendMessage(ChatColor.RED + "The player is OFFLINE");
                                        return true;
                                    }
                                }
                            }
    Thank for your help!! :)
     
    Last edited: Sep 10, 2015
  2. Offline

    RoboticPlayer

    Do you get any errors in the console when you run the command?
     
  3. Offline

    matcracker

    No errors in console, it run all the fuctions and send me the messages. I add the check if the files exist but it works good.
     
    Last edited: Sep 10, 2015
  4. Offline

    Geekxboy

    You should check to make sure the file exists first or else it will throw exceptions
    or use java's "deleteIfExists" method
    Code:
    Files.deleteIfExists(path);
     
  5. Offline

    matcracker

    Now the code is this:
    Code:
    File playerDat = new File(<PluginName>.plugin.getDataFolder() + File.separator + "players" + File.separator + target.getUniqueId() + ".dat");
    File playerYml = new File((<PluginName>.plugin.getDataFolder() + File.separator + "players" + File.separator + target.getUniqueId() + ".yml");
    if(playerDat.exists() && playerYml.exists()){
        playerDat.delete();
        playerYml.delete();
        target.kickPlayer("§c§lClass e levels reset");
        sender.sendMessage("Class and levels of player " + target.getName() + " reset with success");
    }else{
         sender.sendMessage(ChatColor.RED + "Can't find player file's " + target.getName());
    }
    return true;
     
    Last edited: Sep 10, 2015
  6. Offline

    RoboticPlayer

    You never closed the paraenthesis after "Class e levels resetted"
    (Also, a grammar change: resetted should be reset)
     
  7. Offline

    matcracker

    Oh sorry, it's my mistake when I paste the code xD But the problem persist :(
     
  8. Offline

    RoboticPlayer

    What part of it isn't working? Is it not working at all, any of it? Is it just not deleting the files, etc.
     
  9. Offline

    matcracker

    Just not delete the files
     
  10. Offline

    mythbusterma

    @matcracker

    Keep in mind the plugin probably resaves the file.
     
  11. Offline

    matcracker

    I tried to check this as well, but the internal data are not cleared and remain the last saved instead of having the default ones .
     
  12. Offline

    mythbusterma

    @matcracker

    Probably because you're not clearing the data that is loaded into memory. You'd have to get that plugin's configuration and clear it.
     
  13. Offline

    matcracker

    Ok, I resolved the problem.
    It isn't my plugin that doesn't work, but the plugin that I use. I resolve in another way, anyway, thanks to all :)
     
  14. Offline

    RoboticPlayer

    How did you go about doing so?
     
Thread Status:
Not open for further replies.

Share This Page