2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex.punishment;
|
2020-11-06 18:51:47 +00:00
|
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
2022-02-07 05:06:55 +00:00
|
|
|
import com.google.gson.GsonBuilder;
|
2022-02-26 06:24:11 +00:00
|
|
|
import dev.plex.Plex;
|
|
|
|
import dev.plex.util.MojangUtils;
|
|
|
|
import dev.plex.util.PlexUtils;
|
2022-02-07 05:06:55 +00:00
|
|
|
import dev.plex.util.adapter.LocalDateTimeDeserializer;
|
|
|
|
import dev.plex.util.adapter.LocalDateTimeSerializer;
|
2022-02-05 23:14:23 +00:00
|
|
|
import java.time.LocalDateTime;
|
2022-02-26 06:24:11 +00:00
|
|
|
import java.time.format.DateTimeFormatter;
|
2020-11-06 18:51:47 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
2022-02-07 05:53:57 +00:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2022-02-26 06:24:11 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
2022-02-07 03:43:37 +00:00
|
|
|
|
2020-11-06 18:51:47 +00:00
|
|
|
@Getter
|
|
|
|
@Setter
|
|
|
|
public class Punishment
|
|
|
|
{
|
2022-02-26 06:26:42 +00:00
|
|
|
private static final String banUrl = Plex.get().config.getString("banning.ban_url");
|
|
|
|
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("MM/dd/yyyy 'at' hh:mm:ss a");
|
2020-11-06 18:51:47 +00:00
|
|
|
private final UUID punished;
|
|
|
|
private final UUID punisher;
|
|
|
|
private final List<String> IPS;
|
|
|
|
private String punishedUsername;
|
|
|
|
private PunishmentType type;
|
|
|
|
private String reason;
|
|
|
|
private boolean customTime;
|
2022-02-26 06:24:11 +00:00
|
|
|
private boolean active; // Field is only for bans
|
2022-02-05 23:14:23 +00:00
|
|
|
private LocalDateTime endDate;
|
2020-11-06 18:51:47 +00:00
|
|
|
public Punishment(UUID punished, UUID punisher)
|
|
|
|
{
|
|
|
|
this.punished = punished;
|
|
|
|
this.punisher = punisher;
|
|
|
|
this.IPS = Lists.newArrayList();
|
|
|
|
|
|
|
|
this.punishedUsername = "";
|
|
|
|
this.type = null;
|
|
|
|
this.reason = "";
|
|
|
|
this.customTime = false;
|
2020-11-10 02:47:03 +00:00
|
|
|
this.endDate = null;
|
2020-11-06 18:51:47 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 06:24:11 +00:00
|
|
|
public static Component generateBanMessage(Punishment punishment)
|
|
|
|
{
|
|
|
|
return PlexUtils.messageComponent("banMessage", banUrl, punishment.getReason(),
|
|
|
|
DATE_FORMAT.format(punishment.getEndDate()), punishment.getPunisher() == null ? "CONSOLE" : MojangUtils.getInfo(punishment.getPunisher().toString()).getUsername());
|
|
|
|
}
|
|
|
|
|
2022-02-28 06:28:00 +00:00
|
|
|
public static Component generateIndefBanMessage(String type)
|
|
|
|
{
|
|
|
|
return PlexUtils.messageComponent("indefBanMessage", type, banUrl);
|
|
|
|
}
|
|
|
|
|
2022-02-26 06:26:42 +00:00
|
|
|
public static Punishment fromJson(String json)
|
2020-11-06 18:51:47 +00:00
|
|
|
{
|
2022-02-26 06:26:42 +00:00
|
|
|
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer()).create().fromJson(json, Punishment.class);
|
2020-11-06 18:51:47 +00:00
|
|
|
}
|
|
|
|
|
2022-02-26 06:26:42 +00:00
|
|
|
public String toJSON()
|
2020-11-06 18:51:47 +00:00
|
|
|
{
|
2022-02-26 06:26:42 +00:00
|
|
|
return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer()).create().toJson(this);
|
2020-11-06 18:51:47 +00:00
|
|
|
}
|
|
|
|
}
|