Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package events;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.configuration.file.YamlConfiguration;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.EventPriority;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.AsyncPlayerChatEvent;
- import org.bukkit.event.player.PlayerJoinEvent;
- import java.io.*;
- import java.nio.file.Files;
- public class PlayerData implements Listener {
- private static FileConfiguration customFile;
- private static File file;
- @EventHandler(priority = EventPriority.HIGHEST)
- public static void setup(PlayerJoinEvent event) throws IOException {
- Player player = event.getPlayer();
- File folder = new File("plugins/Carstergames", "PlayerData");
- Bukkit.broadcastMessage("Welcome to Carster" + ":D");
- if (!folder.exists()) {
- folder.mkdirs();
- }
- File file = new File("plugins/Carstergames/PlayerData/", player.getUniqueId() + ".yml");
- PlayerData.get().options().copyDefaults(true);
- PlayerData.get().addDefault("Name", player.getDisplayName());
- PlayerData.get().addDefault("Gamemode", player.getGameMode());
- PlayerData.get().addDefault("Location", player.getLocation());
- if (!file.exists()) {
- file.createNewFile();
- }
- customFile = YamlConfiguration.loadConfiguration(file);
- }
- public static FileConfiguration get(){
- return customFile;
- }
- public static void save(){
- try {
- customFile.save(file);
- }catch (IOException e){
- System.out.println("Could't save the file");
- }
- }
- public static void reload() {
- customFile = YamlConfiguration.loadConfiguration(file);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement