Solved Deleting a player data file with a plugin?

Discussion in 'Plugin Development' started by GlacialCreeper, May 29, 2014.

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

    GlacialCreeper

    Hey, sorry if I'm in the wrong section, but I need to make a plugin that will delete someone's playerdata file. My friend's server is hosted online, and the admins cant do it. Secondly, my friend is glitched on the server, and if he tries to join it says he has an invalid stance (something along those lines). He says deleting the playerdata file could fix it, and I think so too. So what code would you use to delete a player data file with a command, say, /pldatadelete <player>?
    Code:java
    1. public class plugin extends JavaPlugin {
    2. public void onEnable(){
    3. ...
    4. }
    5.  
    6. public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args){
    7.  
    8. if (cmdLabel.equalsIgnoreCase("pldatadelete"){
    9. ..
    10. }
    11.  
    12. return true;
    13. }
    14. }


    PS: I am op on the server, and they do let me make plugins. Any help is greatly appreciated!
     
  2. try this method:
    Code:
    public void removeFile(String player) {
    File f = new File("world/players", player+".dat");
    if (f.exists()) {
    f.delete();
    }
    }
    
    :D
     
  3. Offline

    GlacialCreeper

    Ok thanks, I'll see if that works..
     
  4. Offline

    GlacialCreeper

    It worked the first time actually! (I have my own private testing server).
    I'll try that again with the new one

    They both work fine, thank you so much!

    FisheyLP

    If it's alright with you, I'm making a public plugin out of this; but am giving credit to you for helping me :). Thanks again!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 1, 2016
  5. Offline

    RebzO1

    FisheyLP
    how would you do this and delete all players?
     
  6. maybe delete the players folder and make a new one? :D

    Code:java
    1.  
    2. File folder = new File("world/players");
    3. folder.delete();
    4. folder.mkdir();
    5.  


    Can you say me the server ip with a pn? :) i dont have many servers in my severlist and im bored xD
     
Thread Status:
Not open for further replies.

Share This Page