mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
add option to enable extra data such as punishments (default is yes)
This commit is contained in:
parent
b23b7c0c1b
commit
c9da0177ad
@ -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)
|
public static PlexPlayer getPlayer(String username)
|
||||||
{
|
{
|
||||||
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
if (Plex.get().getStorageType() == StorageType.MONGODB)
|
||||||
|
@ -88,6 +88,11 @@ public class PlayerListener<T> extends PlexListener
|
|||||||
plexPlayer.loadNotes();
|
plexPlayer.loadNotes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (plugin.getStorageType() == StorageType.MONGODB)
|
||||||
|
{
|
||||||
|
plexPlayer.loadPunishments();
|
||||||
|
}
|
||||||
|
|
||||||
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
plugin.getSqlNotes().getNotes(plexPlayer.getUuid()).whenComplete((notes, ex) ->
|
||||||
{
|
{
|
||||||
String plural = notes.size() == 1 ? "note." : "notes.";
|
String plural = notes.size() == 1 ? "note." : "notes.";
|
||||||
|
@ -13,11 +13,6 @@ import dev.plex.punishment.Punishment;
|
|||||||
import dev.plex.punishment.extra.Note;
|
import dev.plex.punishment.extra.Note;
|
||||||
import dev.plex.rank.enums.Rank;
|
import dev.plex.rank.enums.Rank;
|
||||||
import dev.plex.storage.StorageType;
|
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 dev.plex.util.adapter.ZonedDateTimeSerializer;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -28,6 +23,11 @@ import org.bukkit.OfflinePlayer;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.permissions.PermissionAttachment;
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
|
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@Entity(value = "players", useDiscriminator = false)
|
@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;
|
this.uuid = playerUUID;
|
||||||
|
|
||||||
@ -91,13 +91,21 @@ public class PlexPlayer implements IPlexPlayer
|
|||||||
this.coins = 0;
|
this.coins = 0;
|
||||||
|
|
||||||
this.rank = "";
|
this.rank = "";
|
||||||
this.loadPunishments();
|
if (loadExtraData)
|
||||||
if (Plex.get().getStorageType() != StorageType.MONGODB)
|
|
||||||
{
|
{
|
||||||
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()
|
public String displayName()
|
||||||
{
|
{
|
||||||
return PlainTextComponentSerializer.plainText().serialize(player.displayName());
|
return PlainTextComponentSerializer.plainText().serialize(player.displayName());
|
||||||
@ -111,13 +119,11 @@ public class PlexPlayer implements IPlexPlayer
|
|||||||
if (player.isOp())
|
if (player.isOp())
|
||||||
{
|
{
|
||||||
return Rank.OP;
|
return Rank.OP;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return Rank.NONOP;
|
return Rank.NONOP;
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
return Rank.valueOf(rank.toUpperCase());
|
return Rank.valueOf(rank.toUpperCase());
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ public class SQLPlayerData
|
|||||||
* @return a PlexPlayer object
|
* @return a PlexPlayer object
|
||||||
* @see PlexPlayer
|
* @see PlexPlayer
|
||||||
*/
|
*/
|
||||||
public PlexPlayer getByUUID(UUID uuid)
|
public PlexPlayer getByUUID(UUID uuid, boolean loadExtraData)
|
||||||
{
|
{
|
||||||
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
|
||||||
{
|
{
|
||||||
@ -79,7 +79,7 @@ public class SQLPlayerData
|
|||||||
PreparedStatement statement = con.prepareStatement(SELECT);
|
PreparedStatement statement = con.prepareStatement(SELECT);
|
||||||
statement.setString(1, uuid.toString());
|
statement.setString(1, uuid.toString());
|
||||||
ResultSet set = statement.executeQuery();
|
ResultSet set = statement.executeQuery();
|
||||||
PlexPlayer plexPlayer = new PlexPlayer(uuid);
|
PlexPlayer plexPlayer = new PlexPlayer(uuid, loadExtraData);
|
||||||
while (set.next())
|
while (set.next())
|
||||||
{
|
{
|
||||||
String name = set.getString("name");
|
String name = set.getString("name");
|
||||||
@ -111,6 +111,11 @@ public class SQLPlayerData
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlexPlayer getByUUID(UUID uuid)
|
||||||
|
{
|
||||||
|
return this.getByUUID(uuid, true);
|
||||||
|
}
|
||||||
|
|
||||||
public PlexPlayer getByName(String username)
|
public PlexPlayer getByName(String username)
|
||||||
{
|
{
|
||||||
PlexPlayer player = PlayerCache.getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getName().equalsIgnoreCase(username)).findFirst().orElse(null);
|
PlexPlayer player = PlayerCache.getPlexPlayerMap().values().stream().filter(plexPlayer -> plexPlayer.getName().equalsIgnoreCase(username)).findFirst().orElse(null);
|
||||||
|
Loading…
Reference in New Issue
Block a user