geforkt von Mirrors/Paper
6ad36f09e5
The getEntries methods on these return player names instead of UUIDs. As we need the UUIDs for our API we add a getValues method to get at the data we need. To further ensure we get the most data possible we also add a way to get at the stored GameProfile to ensure we always have both the UUID and the name from the list.
87 Zeilen
2.3 KiB
Java
87 Zeilen
2.3 KiB
Java
package org.bukkit.craftbukkit;
|
|
|
|
import net.minecraft.server.IpBanEntry;
|
|
import net.minecraft.server.IpBanList;
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
import java.io.IOException;
|
|
import java.util.Date;
|
|
|
|
public final class CraftIpBanEntry implements org.bukkit.BanEntry {
|
|
private final IpBanList list;
|
|
private final String target;
|
|
private Date created;
|
|
private String source;
|
|
private Date expiration;
|
|
private String reason;
|
|
|
|
public CraftIpBanEntry(String target, IpBanEntry entry, IpBanList list) {
|
|
this.list = list;
|
|
this.target = target;
|
|
this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null;
|
|
this.source = entry.getSource();
|
|
this.expiration = entry.getExpires() != null ? new Date(entry.getExpires().getTime()) : null;
|
|
this.reason = entry.getReason();
|
|
}
|
|
|
|
@Override
|
|
public String getTarget() {
|
|
return this.target;
|
|
}
|
|
|
|
@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() {
|
|
IpBanEntry entry = new IpBanEntry(target, this.created, this.source, this.expiration, this.reason);
|
|
this.list.add(entry);
|
|
try {
|
|
this.list.save();
|
|
} catch (IOException ex) {
|
|
MinecraftServer.getLogger().error("Failed to save banned-ips.json, " + ex.getMessage());
|
|
}
|
|
}
|
|
}
|