-
Notifications
You must be signed in to change notification settings - Fork 0
/
CraftProfileBanEntry.java
88 lines (73 loc) · 2.43 KB
/
CraftProfileBanEntry.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package org.bukkit.craftbukkit;
import com.mojang.authlib.GameProfile;
import net.minecraft.server.management.UserListBansEntry;
import net.minecraft.server.management.UserListBans;
import java.io.IOException;
import java.util.Date;
import java.util.logging.Level;
import org.bukkit.Bukkit;
public final class CraftProfileBanEntry implements org.bukkit.BanEntry {
private final UserListBans list;
private final GameProfile profile;
private Date created;
private String source;
private Date expiration;
private String reason;
public CraftProfileBanEntry(GameProfile profile, UserListBansEntry entry, UserListBans list) {
this.list = list;
this.profile = profile;
this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null;
this.source = entry.getSource();
this.expiration = entry.getBanEndDate() != null ? new Date(entry.getBanEndDate().getTime()) : null;
this.reason = entry.getBanReason();
}
@Override
public String getTarget() {
return this.profile.getName();
}
@Override
public Date getCreated() {
return this.created == null ? null : (Date) this.created.clone();
}
@Override
public void setCreated(Date created) {
this.created = created;
}
@Override
public String getSource() {
return this.source;
}
@Override
public void setSource(String source) {
this.source = source;
}
@Override
public Date getExpiration() {
return this.expiration == null ? null : (Date) this.expiration.clone();
}
@Override
public void setExpiration(Date expiration) {
if (expiration != null && expiration.getTime() == new Date(0, 0, 0, 0, 0, 0).getTime()) {
expiration = null; // Forces "forever"
}
this.expiration = expiration;
}
@Override
public String getReason() {
return this.reason;
}
@Override
public void setReason(String reason) {
this.reason = reason;
}
@Override
public void save() {
UserListBansEntry entry = new UserListBansEntry(profile, this.created, this.source, this.expiration, this.reason);
this.list.addEntry(entry);
try {
this.list.writeChanges();
} catch (IOException ex) {
Bukkit.getLogger().log(Level.SEVERE, "Failed to save banned-players.json, {0}", ex.getMessage());
}
}
}