Plex/src/main/java/dev/plex/punishment/Punishment.java

68 lines
2.2 KiB
Java
Raw Normal View History

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;
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;
import lombok.Getter;
import lombok.Setter;
2022-02-26 06:24:11 +00:00
import net.kyori.adventure.text.Component;
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
private LocalDateTime endDate;
2022-03-17 22:16:17 +00:00
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;
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());
}
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
}
}