fix mute & freeze not staying after relog

add configurable timers for mute and freeze
This commit is contained in:
Taah
2024-03-23 08:14:36 -07:00
parent 54015f668a
commit 85605774cf
11 changed files with 117 additions and 41 deletions
@@ -4,6 +4,7 @@ import com.google.common.collect.Lists;
import com.google.gson.GsonBuilder;
import dev.plex.Plex;
import dev.plex.punishment.Punishment;
import dev.plex.punishment.PunishmentType;
import dev.plex.punishment.extra.Note;
import dev.plex.storage.annotation.MapObjectList;
import dev.plex.storage.annotation.PrimaryKey;
@@ -79,6 +80,7 @@ public class PlexPlayer
if (loadPunishments)
{
this.loadPunishments();
this.checkMutesAndFreeze();
// this.permissions.addAll(Plex.get().getSqlPermissions().getPermissions(this.uuid));
}
}
@@ -93,6 +95,12 @@ public class PlexPlayer
return PlainTextComponentSerializer.plainText().serialize(getPlayer().displayName());
}
public void checkMutesAndFreeze() {
final ZonedDateTime now = ZonedDateTime.now();
this.muted = this.punishments.stream().filter(punishment -> punishment.getType() == PunishmentType.MUTE).anyMatch(punishment -> punishment.isActive() && now.isBefore(punishment.getEndDate()));
this.frozen = this.punishments.stream().filter(punishment -> punishment.getType() == PunishmentType.FREEZE).anyMatch(punishment -> punishment.isActive() && now.isBefore(punishment.getEndDate()));
}
public void loadPunishments()
{
this.setPunishments(Plex.get().getSqlPunishment().getPunishments(this.getUuid()));