mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 09:07:37 +00:00
make bans and kicks not take too long
This commit is contained in:
parent
bb019abd89
commit
cc9967f9c2
@ -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));
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user