mirror of
https://github.com/Crazy-Crew/CrazyAuctions.git
synced 2024-11-22 11:55:12 +01:00
Start working on per player data files
This commit is contained in:
parent
cf4cab91be
commit
65e390131f
@ -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);
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package us.crazycrew.crazyauctions.configs;
|
||||
|
||||
public class StorageManager {
|
||||
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user