mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-04 00:46:40 +00:00
Add documentation to dev.plex.admin, dev.plex.banning, dev.plex.cache, and dev.plex.command (annotations and PlexCommand.java only)
Convert Date in punishments to LocalDateTime
This commit is contained in:
32
src/main/java/dev/plex/cache/DataUtils.java
vendored
32
src/main/java/dev/plex/cache/DataUtils.java
vendored
@ -6,10 +6,16 @@ import dev.plex.storage.StorageType;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
/**
|
||||
* Parent cache class
|
||||
*/
|
||||
public class DataUtils
|
||||
{
|
||||
/* PLEX PLAYER METHODS */
|
||||
|
||||
/**
|
||||
* Checks if the player has been on the server before
|
||||
* @param uuid The unique ID of the player
|
||||
* @return true if the player is registered in the database
|
||||
*/
|
||||
public static boolean hasPlayedBefore(UUID uuid)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
@ -22,6 +28,12 @@ public class DataUtils
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player from cache or from the database
|
||||
* @param uuid The unique ID of the player
|
||||
* @return a PlexPlayer object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public static PlexPlayer getPlayer(UUID uuid)
|
||||
{
|
||||
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
||||
@ -39,11 +51,22 @@ public class DataUtils
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a player from cache or from the database
|
||||
* @param name Username of the player
|
||||
* @return a PlexPlayer object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public static PlexPlayer getPlayer(String name)
|
||||
{
|
||||
return getPlayer(Bukkit.getPlayer(name).getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a player's information in the database
|
||||
* @param plexPlayer The PlexPlayer to update
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public static void update(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
@ -56,6 +79,11 @@ public class DataUtils
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts a player's information in the database
|
||||
* @param plexPlayer The PlexPlayer to insert
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public static void insert(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
|
@ -9,15 +9,29 @@ import dev.plex.Plex;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Mongo fetching utilities for players
|
||||
*/
|
||||
public class MongoPlayerData
|
||||
{
|
||||
/**
|
||||
* The datastore object / database
|
||||
*/
|
||||
private final Datastore datastore;
|
||||
|
||||
/**
|
||||
* Creates an instance of the player data
|
||||
*/
|
||||
public MongoPlayerData()
|
||||
{
|
||||
this.datastore = Plex.get().getMongoConnection().getDatastore();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the player exists in mongo's database
|
||||
* @param uuid The unique ID of the player
|
||||
* @return true if the player was found
|
||||
*/
|
||||
public boolean exists(UUID uuid)
|
||||
{
|
||||
Query<PlexPlayer> query = datastore.find(PlexPlayer.class)
|
||||
@ -26,6 +40,12 @@ public class MongoPlayerData
|
||||
return query.first() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player from cache or from mongo's database
|
||||
* @param uuid The unique ID of the player
|
||||
* @return a PlexPlayer object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public PlexPlayer getByUUID(UUID uuid)
|
||||
{
|
||||
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
||||
@ -37,6 +57,11 @@ public class MongoPlayerData
|
||||
return query2.first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a player's information in the mongo database
|
||||
* @param player The PlexPlayer object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public void update(PlexPlayer player)
|
||||
{
|
||||
Query<PlexPlayer> filter = datastore.find(PlexPlayer.class)
|
||||
@ -56,6 +81,11 @@ public class MongoPlayerData
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Saves the player's information in the database
|
||||
* @param plexPlayer The PlexPlayer object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public void save(PlexPlayer plexPlayer)
|
||||
{
|
||||
datastore.save(plexPlayer);
|
||||
|
11
src/main/java/dev/plex/cache/PlayerCache.java
vendored
11
src/main/java/dev/plex/cache/PlayerCache.java
vendored
@ -6,9 +6,20 @@ import dev.plex.player.PunishedPlayer;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Cache storage
|
||||
*/
|
||||
|
||||
public class PlayerCache
|
||||
{
|
||||
/**
|
||||
* A key/value pair where the key is the unique ID of the Plex Player
|
||||
*/
|
||||
private static final Map<UUID, PlexPlayer> plexPlayerMap = Maps.newHashMap();
|
||||
|
||||
/**
|
||||
* A key/value pair where the key is the unique ID of the Punished Player
|
||||
*/
|
||||
private static final Map<UUID, PunishedPlayer> punishedPlayerMap = Maps.newHashMap();
|
||||
|
||||
public static Map<UUID, PunishedPlayer> getPunishedPlayerMap()
|
||||
|
24
src/main/java/dev/plex/cache/SQLPlayerData.java
vendored
24
src/main/java/dev/plex/cache/SQLPlayerData.java
vendored
@ -11,12 +11,20 @@ import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* SQL fetching utilities for players
|
||||
*/
|
||||
public class SQLPlayerData
|
||||
{
|
||||
private final String SELECT = "SELECT * FROM `players` WHERE uuid=?";
|
||||
private final String UPDATE = "UPDATE `players` SET name=?, login_msg=?, prefix=?, rank=?, ips=?, coins=?, vanished=? WHERE uuid=?";
|
||||
private final String INSERT = "INSERT INTO `players` (`uuid`, `name`, `login_msg`, `prefix`, `rank`, `ips`, `coins`, `vanished`) VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
|
||||
|
||||
/**
|
||||
* Checks if a player exists in the SQL database
|
||||
* @param uuid The unique ID of the player
|
||||
* @return true if the player was found in the database
|
||||
*/
|
||||
public boolean exists(UUID uuid)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
@ -33,6 +41,12 @@ public class SQLPlayerData
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player from cache or from the SQL database
|
||||
* @param uuid The unique ID of the player
|
||||
* @return a PlexPlayer object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public PlexPlayer getByUUID(UUID uuid)
|
||||
{
|
||||
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
||||
@ -74,6 +88,11 @@ public class SQLPlayerData
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a player's information in the SQL database
|
||||
* @param player The PlexPlayer object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public void update(PlexPlayer player)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
@ -95,6 +114,11 @@ public class SQLPlayerData
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts the player's information in the database
|
||||
* @param player The PlexPlayer object
|
||||
* @see PlexPlayer
|
||||
*/
|
||||
public void insert(PlexPlayer player)
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
|
Reference in New Issue
Block a user