make bans and kicks not take too long

This commit is contained in:
Taah 2023-08-31 02:18:11 -07:00
parent bb019abd89
commit cc9967f9c2
3 changed files with 37 additions and 4 deletions

View File

@ -65,7 +65,7 @@ public class PlexPlayer
{
}
public PlexPlayer(UUID playerUUID, boolean loadExtraData)
public PlexPlayer(UUID playerUUID, boolean loadPunishments)
{
this.uuid = playerUUID;
this.name = "";
@ -78,7 +78,7 @@ public class PlexPlayer
this.coins = 0;
if (loadExtraData)
if (loadPunishments)
{
this.loadPunishments();
// this.permissions.addAll(Plex.get().getSqlPermissions().getPermissions(this.uuid));

View File

@ -3,6 +3,7 @@ package dev.plex.punishment;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import dev.plex.Plex;
import dev.plex.cache.DataUtils;
import dev.plex.storage.annotation.SQLTable;
import dev.plex.util.MojangUtils;
import dev.plex.util.PlexUtils;
@ -48,12 +49,12 @@ public class Punishment
public static Component generateBanMessage(Punishment punishment)
{
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(), TimeUtils.useTimezone(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : Plex.get().getSqlPlayerData().getNameByUUID(punishment.getPunisher()));
}
public static Component generateKickMessage(Punishment punishment)
{
return PlexUtils.messageComponent("kickMessage", punishment.getReason(), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
return PlexUtils.messageComponent("kickMessage", punishment.getReason(), punishment.getPunisher() == null ? "CONSOLE" : Plex.get().getSqlPlayerData().getNameByUUID(punishment.getPunisher()));
}
public static Component generateIndefBanMessageWithReason(String type, String reason)

View File

@ -111,6 +111,38 @@ public class SQLPlayerData
return null;
}
/**
* 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 String getNameByUUID(UUID uuid)
{
if (Plex.get().getPlayerCache().getPlexPlayerMap().containsKey(uuid))
{
return Plex.get().getPlayerCache().getPlexPlayerMap().get(uuid).getName();
}
try (Connection con = Plex.get().getSqlConnection().getCon())
{
PreparedStatement statement = con.prepareStatement("SELECT `name` FROM `players` WHERE uuid=?");
statement.setString(1, uuid.toString());
ResultSet set = statement.executeQuery();
if (set.next())
{
return set.getString("name");
}
}
catch (SQLException throwables)
{
throwables.printStackTrace();
}
return null;
}
public PlexPlayer getByUUID(UUID uuid)
{
return this.getByUUID(uuid, true);