add option to enable extra data such as punishments (default is yes)

This commit is contained in:
Taah 2022-05-05 18:41:11 -07:00
parent b23b7c0c1b
commit c9da0177ad
4 changed files with 48 additions and 15 deletions

View File

@ -64,6 +64,23 @@ public class DataUtils
}
}
public static PlexPlayer getPlayer(UUID uuid, boolean loadExtraData)
{
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
{
return PlayerCache.getPlexPlayerMap().get(uuid);
}
if (Plex.get().getStorageType() == StorageType.MONGODB)
{
return Plex.get().getMongoPlayerData().getByUUID(uuid);
}
else
{
return Plex.get().getSqlPlayerData().getByUUID(uuid, loadExtraData);
}
}
public static PlexPlayer getPlayer(String username)
{
if (Plex.get().getStorageType() == StorageType.MONGODB)

View File

@ -88,6 +88,11 @@ public class PlayerListener<T> extends PlexListener
plexPlayer.loadNotes();
}
if (plugin.getStorageType() == StorageType.MONGODB)
{
plexPlayer.loadPunishments();
}
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
{
String plural = notes.size() == 1 ? "note." : "notes.";

View File

@ -13,11 +13,6 @@ import dev.plex.punishment.Punishment;
import dev.plex.punishment.extra.Note;
import dev.plex.rank.enums.Rank;
import dev.plex.storage.StorageType;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import dev.plex.util.adapter.ZonedDateTimeSerializer;
import lombok.AccessLevel;
import lombok.Getter;
@ -28,6 +23,11 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.permissions.PermissionAttachment;
import java.time.ZonedDateTime;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Getter
@Setter
@Entity(value = "players", useDiscriminator = false)
@ -73,7 +73,7 @@ public class PlexPlayer implements IPlexPlayer
{
}
public PlexPlayer(UUID playerUUID)
public PlexPlayer(UUID playerUUID, boolean loadExtraData)
{
this.uuid = playerUUID;
@ -91,13 +91,21 @@ public class PlexPlayer implements IPlexPlayer
this.coins = 0;
this.rank = "";
this.loadPunishments();
if (Plex.get().getStorageType() != StorageType.MONGODB)
if (loadExtraData)
{
this.permissions.addAll(Plex.get().getSqlPermissions().getPermissions(this.uuid));
this.loadPunishments();
if (Plex.get().getStorageType() != StorageType.MONGODB)
{
this.permissions.addAll(Plex.get().getSqlPermissions().getPermissions(this.uuid));
}
}
}
public PlexPlayer(UUID playerUUID)
{
this(playerUUID, true);
}
public String displayName()
{
return PlainTextComponentSerializer.plainText().serialize(player.displayName());
@ -111,13 +119,11 @@ public class PlexPlayer implements IPlexPlayer
if (player.isOp())
{
return Rank.OP;
}
else
} else
{
return Rank.NONOP;
}
}
else
} else
{
return Rank.valueOf(rank.toUpperCase());
}

View File

@ -67,7 +67,7 @@ public class SQLPlayerData
* @return a PlexPlayer object
* @see PlexPlayer
*/
public PlexPlayer getByUUID(UUID uuid)
public PlexPlayer getByUUID(UUID uuid, boolean loadExtraData)
{
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
{
@ -79,7 +79,7 @@ public class SQLPlayerData
PreparedStatement statement = con.prepareStatement(SELECT);
statement.setString(1, uuid.toString());
ResultSet set = statement.executeQuery();
PlexPlayer plexPlayer = new PlexPlayer(uuid);
PlexPlayer plexPlayer = new PlexPlayer(uuid, loadExtraData);
while (set.next())
{
String name = set.getString("name");
@ -111,6 +111,11 @@ public class SQLPlayerData
return null;
}
public PlexPlayer getByUUID(UUID uuid)
{
return this.getByUUID(uuid, true);
}
public PlexPlayer getByName(String username)
{
PlexPlayer player = PlayerCache.getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getName().equalsIgnoreCase(username)).findFirst().orElse(null);