| 1 | package net.minecraft.server.management;
|
| 2 |
|
| 3 | import com.google.gson.JsonObject;
|
| 4 | import java.text.ParseException;
|
| 5 | import java.text.SimpleDateFormat;
|
| 6 | import java.util.Date;
|
| 7 |
|
| 8 | public abstract class BanEntry<T> extends UserListEntry<T>
|
| 9 | {
|
| 10 | public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
|
| 11 | protected final Date banStartDate;
|
| 12 | protected final String bannedBy;
|
| 13 | protected final Date banEndDate;
|
| 14 | protected final String reason;
|
| 15 |
|
| 16 | public BanEntry(T valueIn, Date startDate, String banner, Date endDate, String banReason)
|
| 17 | {
|
| 18 | super(valueIn);
|
| 19 | this.banStartDate = startDate == null ? new Date() : startDate;
|
| 20 | this.bannedBy = banner == null ? "(Unknown)" : banner;
|
| 21 | this.banEndDate = endDate;
|
| 22 | this.reason = banReason == null ? "Banned by an operator." : banReason;
|
| 23 | }
|
| 24 |
|
| 25 | protected BanEntry(T valueIn, JsonObject json)
|
| 26 | {
|
| 27 | super(valueIn, json);
|
| 28 | Date date;
|
| 29 |
|
| 30 | try
|
| 31 | {
|
| 32 | date = json.has("created") ? dateFormat.parse(json.get("created").getAsString()) : new Date();
|
| 33 | }
|
| 34 | catch (ParseException var7)
|
| 35 | {
|
| 36 | date = new Date();
|
| 37 | }
|
| 38 |
|
| 39 | this.banStartDate = date;
|
| 40 | this.bannedBy = json.has("source") ? json.get("source").getAsString() : "(Unknown)";
|
| 41 | Date date1;
|
| 42 |
|
| 43 | try
|
| 44 | {
|
| 45 | date1 = json.has("expires") ? dateFormat.parse(json.get("expires").getAsString()) : null;
|
| 46 | }
|
| 47 | catch (ParseException var6)
|
| 48 | {
|
| 49 | date1 = null;
|
| 50 | }
|
| 51 |
|
| 52 | this.banEndDate = date1;
|
| 53 | this.reason = json.has("reason") ? json.get("reason").getAsString() : "Banned by an operator.";
|
| 54 | }
|
| 55 |
|
| 56 | public Date getBanEndDate()
|
| 57 | {
|
| 58 | return this.banEndDate;
|
| 59 | }
|
| 60 |
|
| 61 | public String getBanReason()
|
| 62 | {
|
| 63 | return this.reason;
|
| 64 | }
|
| 65 |
|
| 66 | boolean hasBanExpired()
|
| 67 | {
|
| 68 | return this.banEndDate == null ? false : this.banEndDate.before(new Date());
|
| 69 | }
|
| 70 |
|
| 71 | protected void onSerialization(JsonObject data)
|
| 72 | {
|
| 73 | data.addProperty("created", dateFormat.format(this.banStartDate));
|
| 74 | data.addProperty("source", this.bannedBy);
|
| 75 | data.addProperty("expires", this.banEndDate == null ? "forever" : dateFormat.format(this.banEndDate));
|
| 76 | data.addProperty("reason", this.reason);
|
| 77 | }
|
| 78 | }
|
| 79 |
|