Solved Remove playerdata file on death

Discussion in 'Spigot Plugin Help' started by TheRaulXP, Apr 16, 2017.

  1. Hi, i'm currently running a Hardcore server and i want that when a player dies, his playerdata file (the one named uuid.dat) gets deleted. The code that i've been trying is that one:

    Code (Text):
      @EventHandler
      public void onDeath(PlayerDeathEvent event)
      {
        File BaseFolder = new File(Bukkit.getServer().getWorld("world").getWorldFolder(), "playerdata");
        Player player = event.getEntity().getPlayer();
        File playerData = new File(BaseFolder, player.getUniqueId()+".dat");
                playerData.delete();
      }
    But it doesnt seem to work with UUID (it worked with player.getName() in prior versions), could you suggest me what to do?
     
  2. Code (Text):
    @EventHandler
      public void onDeath(PlayerDeathEvent event)
      {
        File BaseFolder = new File(Bukkit.getServer().getWorld("world").getWorldFolder(), "playerdata");
        Player player = event.getEntity().getPlayer();
        File playerData = new File(BaseFolder, player.getUniqueId().toString()+".dat");
                playerData.delete();
      }
    Try that.
     
  3. Didn't work :( the thing is that if i use player.getName() instead of player.getUniqueId() and I create a file called TheRaulXP.dat it deletes it with no problem, so I don't really know which is the problem xD
     
  4. Hmm. Not to sure then, let me have a play around with some code and I'll get back to you.
     
  5. Thank you, really appreciate it! I'll check this post later.
     
  6. Code (Text):
    @EventHandler(priority = EventPriority.MONITOR)
        public void onDeath(PlayerDeathEvent event) {
            File BaseFolder = new File(Bukkit.getServer().getWorld("world").getWorldFolder(), "playerdata");
            Player player = event.getEntity().getPlayer();
            player.kickPlayer("You were killed!");
            String uuid = player.getUniqueId().toString();
            File playerData = new File(BaseFolder, uuid + ".dat");
            playerData.delete();
        }
    That works for me. Try it out
     
    #6 MrFishCakes, Apr 16, 2017
    Last edited: Apr 16, 2017
    • Useful Useful x 1
  7. Tried it, working now, i think the problem was the delay on the ban plugin (now i kick the player and then ban it) and the event priority. Thanks for all :D
     
  8. No problem! :) Be sure to mark this as solved.
     
    • Friendly Friendly x 1