2016-02-12 02:40:06 +01:00
|
|
|
package net.frozenorb.apiv3.model;
|
|
|
|
|
2016-03-06 05:21:49 +01:00
|
|
|
import com.mongodb.async.SingleResultCallback;
|
2016-02-12 02:40:06 +01:00
|
|
|
import lombok.Getter;
|
2016-03-21 23:28:17 +01:00
|
|
|
import net.frozenorb.apiv3.APIv3;
|
|
|
|
import org.bson.types.ObjectId;
|
|
|
|
import org.mongodb.morphia.annotations.Entity;
|
|
|
|
import org.mongodb.morphia.annotations.Id;
|
2016-02-12 02:40:06 +01:00
|
|
|
|
2016-02-12 21:12:05 +01:00
|
|
|
import java.time.Instant;
|
2016-03-21 23:28:17 +01:00
|
|
|
import java.util.Date;
|
2016-02-12 21:12:05 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2016-03-21 23:28:17 +01:00
|
|
|
@Entity(value = "punishments", noClassnameStored = true)
|
|
|
|
public final class Punishment {
|
2016-02-12 02:40:06 +01:00
|
|
|
|
2016-03-21 23:28:17 +01:00
|
|
|
@Id private ObjectId id;
|
2016-02-12 21:12:05 +01:00
|
|
|
@Getter private UUID target;
|
|
|
|
@Getter private String reason;
|
|
|
|
@Getter private PunishmentType type;
|
2016-03-21 23:28:17 +01:00
|
|
|
@Getter private Date expiresAt;
|
2016-02-12 21:12:05 +01:00
|
|
|
|
|
|
|
@Getter private UUID addedBy;
|
2016-03-21 23:28:17 +01:00
|
|
|
@Getter private Date addedAt;
|
2016-02-12 21:12:05 +01:00
|
|
|
@Getter private String addedOn;
|
|
|
|
|
|
|
|
@Getter private UUID removedBy;
|
2016-03-21 23:28:17 +01:00
|
|
|
@Getter private Date removedAt;
|
2016-02-12 21:12:05 +01:00
|
|
|
@Getter private String removalReason;
|
2016-02-12 02:40:06 +01:00
|
|
|
|
2016-03-21 23:28:17 +01:00
|
|
|
public Punishment() {} // For Morphia
|
2016-02-12 06:31:57 +01:00
|
|
|
|
2016-03-21 23:28:17 +01:00
|
|
|
public Punishment(UUID target, String reason, PunishmentType type, Date expiresAt, UUID addedBy, String addedOn) {
|
|
|
|
this.target = target;
|
|
|
|
this.reason = reason;
|
|
|
|
this.type = type;
|
|
|
|
this.expiresAt = expiresAt;
|
|
|
|
this.addedBy = addedBy;
|
|
|
|
this.addedAt = new Date();
|
|
|
|
this.addedOn = addedOn;
|
2016-02-12 02:40:06 +01:00
|
|
|
}
|
|
|
|
|
2016-03-21 23:28:17 +01:00
|
|
|
public void delete(UUID removedBy, String reason) {
|
2016-02-12 21:12:05 +01:00
|
|
|
this.removedBy = removedBy;
|
2016-03-21 23:28:17 +01:00
|
|
|
this.removedAt = new Date();
|
2016-02-12 21:12:05 +01:00
|
|
|
this.removalReason = reason;
|
|
|
|
|
2016-03-21 23:28:17 +01:00
|
|
|
APIv3.getDatastore().save(this);
|
2016-02-12 21:12:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isActive() {
|
|
|
|
return !(isExpired() || isRemoved());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isExpired() {
|
|
|
|
if (expiresAt == null) {
|
|
|
|
return false; // Never expires
|
|
|
|
} else {
|
2016-03-21 23:28:17 +01:00
|
|
|
return expiresAt.after(new Date());
|
2016-02-12 21:12:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isRemoved() {
|
|
|
|
return removedBy != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum PunishmentType {
|
|
|
|
|
|
|
|
BAN, MUTE, WARN
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-02-12 02:40:06 +01:00
|
|
|
}
|