Start working on per player data files

This commit is contained in:
Ryder Belserion 2023-02-28 01:27:07 -05:00
parent cf4cab91be
commit 65e390131f
No known key found for this signature in database
GPG Key ID: 8FC2E6C54BBF05FE
4 changed files with 80 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package us.crazycrew.crazyauctions.data;
import java.util.UUID;
public interface ProfileCache {
void load();
void save();
void add(final UUID uuid);
String getName(final UUID uuid);
}

View File

@ -0,0 +1,5 @@
package us.crazycrew.crazyauctions.configs;
public class StorageManager {
}

View File

@ -0,0 +1,36 @@
package us.crazycrew.crazyauctions.configs.data;
import com.google.gson.annotations.Expose;
import us.crazycrew.crazyauctions.api.interfaces.Universal;
import us.crazycrew.crazycore.files.FileExtension;
import java.nio.file.Path;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class PlayerData extends FileExtension implements Universal {
@Expose
public static ConcurrentHashMap<UUID, String> auctions = new ConcurrentHashMap<>();
public PlayerData(UUID uuid) {
super(uuid + ".json", plugin.getUsers());
}
public static void load(UUID uuid) {
plugin.getCrazyCore().getFileHandler().addFile(new PlayerData(uuid));
}
public static void save(UUID uuid) {
plugin.getCrazyCore().getFileHandler().saveFile(new PlayerData(uuid));
}
/**
* Fetch the uuid file of the player.
*
* @param playerData the path i.e. 'CrazyAuctions/userdata/random-uuid.'
* @return the complete path
*/
public static Path getFile(Path playerData, UUID uuid) {
return playerData.resolve(uuid + ".json");
}
}

View File

@ -0,0 +1,24 @@
package us.crazycrew.crazyauctions.events;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import us.crazycrew.crazyauctions.api.interfaces.Universal;
import us.crazycrew.crazyauctions.configs.data.PlayerData;
import java.io.File;
public class TestListener implements Listener, Universal {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
PlayerData.load(event.getPlayer().getUniqueId());
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
File playerData = PlayerData.getFile(plugin.getUsers(), event.getPlayer().getUniqueId()).toFile();
PlayerData.save(event.getPlayer().getUniqueId());
}
}