2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.cache;
|
2020-11-05 21:17:14 +00:00
|
|
|
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.Plex;
|
|
|
|
import dev.plex.player.PlexPlayer;
|
|
|
|
import dev.plex.storage.StorageType;
|
2022-01-04 03:04:39 +00:00
|
|
|
import java.util.UUID;
|
2022-01-27 21:23:01 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2022-01-04 03:04:39 +00:00
|
|
|
|
2020-11-05 21:17:14 +00:00
|
|
|
public class DataUtils
|
|
|
|
{
|
2020-11-06 18:51:47 +00:00
|
|
|
/* PLEX PLAYER METHODS */
|
|
|
|
|
2020-11-05 21:17:14 +00:00
|
|
|
public static boolean hasPlayedBefore(UUID uuid)
|
|
|
|
{
|
2021-01-03 07:21:15 +00:00
|
|
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
2020-11-05 21:17:14 +00:00
|
|
|
{
|
|
|
|
return Plex.get().getMongoPlayerData().exists(uuid);
|
2020-11-06 01:29:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-05 21:17:14 +00:00
|
|
|
return Plex.get().getSqlPlayerData().exists(uuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static PlexPlayer getPlayer(UUID uuid)
|
|
|
|
{
|
|
|
|
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
|
|
|
{
|
|
|
|
return PlayerCache.getPlexPlayerMap().get(uuid);
|
|
|
|
}
|
|
|
|
|
2021-01-03 07:21:15 +00:00
|
|
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
2020-11-05 21:17:14 +00:00
|
|
|
{
|
|
|
|
return Plex.get().getMongoPlayerData().getByUUID(uuid);
|
2020-11-06 01:29:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-05 21:17:14 +00:00
|
|
|
return Plex.get().getSqlPlayerData().getByUUID(uuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-06 03:50:16 +00:00
|
|
|
public static PlexPlayer getPlayer(String name)
|
|
|
|
{
|
|
|
|
return getPlayer(Bukkit.getPlayer(name).getUniqueId());
|
|
|
|
}
|
|
|
|
|
2020-11-05 21:17:14 +00:00
|
|
|
public static void update(PlexPlayer plexPlayer)
|
|
|
|
{
|
2021-01-03 07:21:15 +00:00
|
|
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
2020-11-05 21:17:14 +00:00
|
|
|
{
|
|
|
|
Plex.get().getMongoPlayerData().update(plexPlayer);
|
2020-11-06 01:29:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-11-05 21:17:14 +00:00
|
|
|
Plex.get().getSqlPlayerData().update(plexPlayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-06 18:19:38 +00:00
|
|
|
public static void insert(PlexPlayer plexPlayer)
|
|
|
|
{
|
2021-01-03 07:21:15 +00:00
|
|
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
2020-11-06 18:19:38 +00:00
|
|
|
{
|
|
|
|
Plex.get().getMongoPlayerData().save(plexPlayer);
|
|
|
|
} else {
|
|
|
|
Plex.get().getSqlPlayerData().insert(plexPlayer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-06 18:51:47 +00:00
|
|
|
/* REDIS METHODS AT ONE POINT FOR BANS, AND JSON METHODS FOR PUNISHMENTS */
|
|
|
|
|
2020-11-05 21:17:14 +00:00
|
|
|
}
|