Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. package events;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.configuration.file.FileConfiguration;
  6. import org.bukkit.configuration.file.YamlConfiguration;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.event.EventHandler;
  9. import org.bukkit.event.EventPriority;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.event.player.AsyncPlayerChatEvent;
  12. import org.bukkit.event.player.PlayerJoinEvent;
  13.  
  14. import java.io.*;
  15. import java.nio.file.Files;
  16.  
  17. public class PlayerData implements Listener {
  18.  
  19. private static FileConfiguration customFile;
  20. private static File file;
  21. @EventHandler(priority = EventPriority.HIGHEST)
  22. public static void setup(PlayerJoinEvent event) throws IOException {
  23. Player player = event.getPlayer();
  24. File folder = new File("plugins/Carstergames", "PlayerData");
  25. Bukkit.broadcastMessage("Welcome to Carster" + ":D");
  26. if (!folder.exists()) {
  27. folder.mkdirs();
  28.  
  29. }
  30. File file = new File("plugins/Carstergames/PlayerData/", player.getUniqueId() + ".yml");
  31. PlayerData.get().options().copyDefaults(true);
  32. PlayerData.get().addDefault("Name", player.getDisplayName());
  33. PlayerData.get().addDefault("Gamemode", player.getGameMode());
  34. PlayerData.get().addDefault("Location", player.getLocation());
  35. if (!file.exists()) {
  36. file.createNewFile();
  37.  
  38. }
  39.  
  40.  
  41. customFile = YamlConfiguration.loadConfiguration(file);
  42.  
  43. }
  44.  
  45. public static FileConfiguration get(){
  46. return customFile;
  47. }
  48.  
  49. public static void save(){
  50. try {
  51. customFile.save(file);
  52. }catch (IOException e){
  53. System.out.println("Could't save the file");
  54. }
  55. }
  56.  
  57. public static void reload() {
  58. customFile = YamlConfiguration.loadConfiguration(file);
  59. }
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement