mirror of
https://github.com/plexusorg/Plex.git
synced 2025-07-04 16:56: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:
@ -6,11 +6,15 @@ import dev.morphia.query.experimental.filters.Filters;
|
||||
import dev.morphia.query.experimental.updates.UpdateOperators;
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.storage.StorageType;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -19,6 +23,10 @@ public class BanManager
|
||||
private final String SELECT = "SELECT * FROM `bans` WHERE uuid=?";
|
||||
private final String INSERT = "INSERT INTO `bans` (`banID`, `uuid`, `banner`, `ip`, `reason`, `enddate`, `active`) VALUES (?, ?, ?, ?, ?, ?, ?);";
|
||||
|
||||
/**
|
||||
* Adds the ban to the database
|
||||
* @param ban The ban object
|
||||
*/
|
||||
public void executeBan(Ban ban)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
@ -35,7 +43,7 @@ public class BanManager
|
||||
statement.setString(3, ban.getBanner() == null ? "" : ban.getBanner().toString());
|
||||
statement.setString(4, ban.getIp());
|
||||
statement.setString(5, ban.getReason());
|
||||
statement.setLong(6, ban.getEndDate().toInstant().toEpochMilli());
|
||||
statement.setLong(6, ban.getEndDate().toInstant(ZoneOffset.of(ZoneId.systemDefault().getId())).toEpochMilli());
|
||||
statement.setBoolean(7, ban.isActive());
|
||||
statement.execute();
|
||||
|
||||
@ -47,6 +55,11 @@ public class BanManager
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the unique ID has an active ban in the database
|
||||
* @param uuid The unique ID of the player
|
||||
* @return true if the unique ID is banned
|
||||
*/
|
||||
public boolean isBanned(UUID uuid)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
@ -81,6 +94,10 @@ public class BanManager
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbans a player if they have an active ban on record
|
||||
* @param uuid The unique ID of the player
|
||||
*/
|
||||
public void unban(UUID uuid)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
@ -95,9 +112,10 @@ public class BanManager
|
||||
{
|
||||
try (Connection con = Plex.get().getSqlConnection().getCon())
|
||||
{
|
||||
PreparedStatement statement = con.prepareStatement("UPDATE `bans` SET active=? WHERE uuid=?");
|
||||
PreparedStatement statement = con.prepareStatement("UPDATE `bans` SET active=? WHERE uuid=? AND active=?");
|
||||
statement.setBoolean(1, false);
|
||||
statement.setString(2, uuid.toString());
|
||||
statement.setBoolean(3, true);
|
||||
statement.executeUpdate();
|
||||
}
|
||||
catch (SQLException throwables)
|
||||
@ -107,6 +125,10 @@ public class BanManager
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbans a player if they have an active ban on record
|
||||
* @param id Custom ID of the ban
|
||||
*/
|
||||
public void unban(String id)
|
||||
{
|
||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||
@ -133,6 +155,10 @@ public class BanManager
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a list of all the current bans active
|
||||
* @return An arraylist of bans
|
||||
*/
|
||||
public List<Ban> getActiveBans()
|
||||
{
|
||||
List<Ban> bans = Lists.newArrayList();
|
||||
@ -158,7 +184,7 @@ public class BanManager
|
||||
UUID banner = set.getString("banner").isEmpty() ? null : UUID.fromString(set.getString("banner"));
|
||||
String ip = set.getString("ip");
|
||||
String reason = set.getString("reason");
|
||||
Date endDate = set.getLong("enddate") != 0 ? new Date(set.getLong("enddate")) : null;
|
||||
LocalDateTime endDate = set.getLong("enddate") != 0 ? LocalDateTime.ofInstant(Instant.ofEpochMilli(set.getLong("enddate")), ZoneId.systemDefault()) : null;
|
||||
Ban ban = new Ban(id, uuid, banner, ip, reason, endDate);
|
||||
bans.add(ban);
|
||||
}
|
||||
|
Reference in New Issue
Block a user