2019-03-03 22:33:44 +01:00
|
|
|
package com.songoda.ultimatemoderation.punish.player;
|
|
|
|
|
2020-08-05 00:20:25 +02:00
|
|
|
import com.songoda.ultimatemoderation.UltimateModeration;
|
2019-03-03 22:33:44 +01:00
|
|
|
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
|
2020-09-08 22:29:25 +02:00
|
|
|
import com.songoda.ultimatemoderation.punish.PunishmentNote;
|
2019-03-03 22:33:44 +01:00
|
|
|
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
public class PlayerPunishData {
|
|
|
|
private final UUID player;
|
|
|
|
|
|
|
|
private final List<AppliedPunishment> activePunishments = new ArrayList<>();
|
|
|
|
private final List<AppliedPunishment> expiredPunishments = new ArrayList<>();
|
|
|
|
|
2019-03-05 06:06:02 +01:00
|
|
|
private final List<PunishmentNote> punishmentNotes = new ArrayList<>();
|
|
|
|
|
2019-03-03 22:33:44 +01:00
|
|
|
public PlayerPunishData(UUID player) {
|
|
|
|
this.player = player;
|
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerPunishData(UUID player, List<AppliedPunishment> punishments) {
|
|
|
|
this.player = player;
|
|
|
|
this.activePunishments.addAll(punishments);
|
|
|
|
}
|
|
|
|
|
|
|
|
public UUID getPlayer() {
|
2023-07-20 17:32:46 +02:00
|
|
|
return this.player;
|
2019-03-03 22:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<AppliedPunishment> getActivePunishments() {
|
|
|
|
audit();
|
2023-07-20 17:32:46 +02:00
|
|
|
return new ArrayList<>(this.activePunishments);
|
2019-03-03 22:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<AppliedPunishment> getActivePunishments(PunishmentType type) {
|
|
|
|
audit();
|
2023-07-20 17:32:46 +02:00
|
|
|
return this.activePunishments.stream().filter(punishment -> punishment.getPunishmentType() == type).collect(Collectors.toList());
|
2019-03-03 22:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<AppliedPunishment> getExpiredPunishments() {
|
|
|
|
audit();
|
2023-07-20 17:32:46 +02:00
|
|
|
return new ArrayList<>(this.expiredPunishments);
|
2019-03-03 22:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public List<AppliedPunishment> getExpiredPunishments(PunishmentType type) {
|
|
|
|
audit();
|
2023-07-20 17:32:46 +02:00
|
|
|
return this.expiredPunishments.stream().filter(punishment -> punishment.getPunishmentType() == type).collect(Collectors.toList());
|
2019-03-03 22:33:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public AppliedPunishment[] addPunishment(AppliedPunishment... appliedPunishments) {
|
|
|
|
this.activePunishments.addAll(Arrays.asList(appliedPunishments));
|
|
|
|
return appliedPunishments;
|
|
|
|
}
|
|
|
|
|
2020-08-05 00:20:25 +02:00
|
|
|
public AppliedPunishment[] addExpiredPunishment(AppliedPunishment... appliedPunishments) {
|
|
|
|
this.expiredPunishments.addAll(Arrays.asList(appliedPunishments));
|
|
|
|
return appliedPunishments;
|
|
|
|
}
|
|
|
|
|
2019-03-03 22:33:44 +01:00
|
|
|
public AppliedPunishment[] removePunishment(AppliedPunishment... appliedPunishments) {
|
|
|
|
this.activePunishments.removeAll(Arrays.asList(appliedPunishments));
|
|
|
|
return appliedPunishments;
|
|
|
|
}
|
|
|
|
|
|
|
|
public AppliedPunishment[] removeExpiredPunishment(AppliedPunishment... appliedPunishments) {
|
|
|
|
this.activePunishments.removeAll(Arrays.asList(appliedPunishments));
|
|
|
|
return appliedPunishments;
|
|
|
|
}
|
|
|
|
|
2019-03-05 06:06:02 +01:00
|
|
|
public List<PunishmentNote> getNotes() {
|
2023-07-20 17:32:46 +02:00
|
|
|
return new ArrayList<>(this.punishmentNotes);
|
2019-03-05 06:06:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public PunishmentNote[] addNotes(PunishmentNote... notes) {
|
|
|
|
this.punishmentNotes.addAll(Arrays.asList(notes));
|
|
|
|
return notes;
|
|
|
|
}
|
|
|
|
|
2020-08-05 00:20:25 +02:00
|
|
|
public PunishmentNote[] removeNotes(PunishmentNote... notes) {
|
2019-03-05 06:06:02 +01:00
|
|
|
this.punishmentNotes.removeAll(Arrays.asList(notes));
|
|
|
|
return notes;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void audit() {
|
2019-03-03 22:33:44 +01:00
|
|
|
audit(false, PunishmentType.ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void audit(boolean forced, PunishmentType punishmentType) {
|
2023-07-20 17:32:46 +02:00
|
|
|
List<AppliedPunishment> expired = this.activePunishments.stream().filter(appliedPunishment ->
|
2019-03-09 06:30:00 +01:00
|
|
|
(appliedPunishment.getDuration() != -1 || forced || appliedPunishment.getExpiration() == -1)
|
2019-03-03 22:33:44 +01:00
|
|
|
&& (appliedPunishment.getPunishmentType() == punishmentType || punishmentType == PunishmentType.ALL)
|
|
|
|
&& appliedPunishment.getExpiration() <= System.currentTimeMillis()).collect(Collectors.toList());
|
|
|
|
|
|
|
|
this.expiredPunishments.addAll(expired);
|
|
|
|
this.activePunishments.removeAll(expired);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void expirePunishments(PunishmentType type) {
|
|
|
|
List<AppliedPunishment> toAudit = new ArrayList<>();
|
2023-07-20 17:32:46 +02:00
|
|
|
this.activePunishments.stream().filter(appliedPunishment ->
|
2019-03-03 22:33:44 +01:00
|
|
|
type == appliedPunishment.getPunishmentType()).forEach(appliedPunishment -> {
|
|
|
|
appliedPunishment.expire();
|
2020-08-05 00:20:25 +02:00
|
|
|
UltimateModeration.getInstance().getDataManager().updateAppliedPunishment(appliedPunishment);
|
2019-03-03 22:33:44 +01:00
|
|
|
toAudit.add(appliedPunishment);
|
|
|
|
});
|
2019-03-09 06:30:00 +01:00
|
|
|
toAudit.forEach(appliedPunishment -> this.audit(true, type));
|
2019-03-03 22:33:44 +01:00
|
|
|
}
|
|
|
|
}
|