    001package net.minecraft.server.management;
    002
    003import java.text.ParseException;
    004import java.text.SimpleDateFormat;
    005import java.util.Date;
    006import java.util.logging.Level;
    007import java.util.logging.Logger;
    008import java.util.regex.Pattern;
    009
    010public class BanEntry
    011{
    012    public static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
    013
    014    /** Creates Ban Entry in the logger. */
    015    public static Logger loggerBanEntry = Logger.getLogger("Minecraft");
    016    private final String username;
    017    private Date banStartDate = new Date();
    018    private String bannedBy = "(Unknown)";
    019    private Date banEndDate = null;
    020    private String reason = "Banned by an operator.";
    021
    022    public BanEntry(String par1Str)
    023    {
    024        this.username = par1Str;
    025    }
    026
    027    public String getBannedUsername()
    028    {
    029        return this.username;
    030    }
    031
    032    public Date getBanStartDate()
    033    {
    034        return this.banStartDate;
    035    }
    036
    037    /**
    038     * null == start ban now
    039     */
    040    public void setBanStartDate(Date par1Date)
    041    {
    042        this.banStartDate = par1Date != null ? par1Date : new Date();
    043    }
    044
    045    public String getBannedBy()
    046    {
    047        return this.bannedBy;
    048    }
    049
    050    public void setBannedBy(String par1Str)
    051    {
    052        this.bannedBy = par1Str;
    053    }
    054
    055    public Date getBanEndDate()
    056    {
    057        return this.banEndDate;
    058    }
    059
    060    public void setBanEndDate(Date par1Date)
    061    {
    062        this.banEndDate = par1Date;
    063    }
    064
    065    public boolean hasBanExpired()
    066    {
    067        return this.banEndDate == null ? false : this.banEndDate.before(new Date());
    068    }
    069
    070    public String getBanReason()
    071    {
    072        return this.reason;
    073    }
    074
    075    public void setBanReason(String par1Str)
    076    {
    077        this.reason = par1Str;
    078    }
    079
    080    public String buildBanString()
    081    {
    082        StringBuilder var1 = new StringBuilder();
    083        var1.append(this.getBannedUsername());
    084        var1.append("|");
    085        var1.append(dateFormat.format(this.getBanStartDate()));
    086        var1.append("|");
    087        var1.append(this.getBannedBy());
    088        var1.append("|");
    089        var1.append(this.getBanEndDate() == null ? "Forever" : dateFormat.format(this.getBanEndDate()));
    090        var1.append("|");
    091        var1.append(this.getBanReason());
    092        return var1.toString();
    093    }
    094
    095    public static BanEntry parse(String par0Str)
    096    {
    097        if (par0Str.trim().length() < 2)
    098        {
    099            return null;
    100        }
    101        else
    102        {
    103            String[] var1 = par0Str.trim().split(Pattern.quote("|"), 5);
    104            BanEntry var2 = new BanEntry(var1[0].trim());
    105            byte var3 = 0;
    106            int var10000 = var1.length;
    107            int var7 = var3 + 1;
    108
    109            if (var10000 <= var7)
    110            {
    111                return var2;
    112            }
    113            else
    114            {
    115                try
    116                {
    117                    var2.setBanStartDate(dateFormat.parse(var1[var7].trim()));
    118                }
    119                catch (ParseException var6)
    120                {
    121                    loggerBanEntry.log(Level.WARNING, "Could not read creation date format for ban entry \'" + var2.getBannedUsername() + "\' (was: \'" + var1[var7] + "\')", var6);
    122                }
    123
    124                var10000 = var1.length;
    125                ++var7;
    126
    127                if (var10000 <= var7)
    128                {
    129                    return var2;
    130                }
    131                else
    132                {
    133                    var2.setBannedBy(var1[var7].trim());
    134                    var10000 = var1.length;
    135                    ++var7;
    136
    137                    if (var10000 <= var7)
    138                    {
    139                        return var2;
    140                    }
    141                    else
    142                    {
    143                        try
    144                        {
    145                            String var4 = var1[var7].trim();
    146
    147                            if (!var4.equalsIgnoreCase("Forever") && var4.length() > 0)
    148                            {
    149                                var2.setBanEndDate(dateFormat.parse(var4));
    150                            }
    151                        }
    152                        catch (ParseException var5)
    153                        {
    154                            loggerBanEntry.log(Level.WARNING, "Could not read expiry date format for ban entry \'" + var2.getBannedUsername() + "\' (was: \'" + var1[var7] + "\')", var5);
    155                        }
    156
    157                        var10000 = var1.length;
    158                        ++var7;
    159
    160                        if (var10000 <= var7)
    161                        {
    162                            return var2;
    163                        }
    164                        else
    165                        {
    166                            var2.setBanReason(var1[var7].trim());
    167                            return var2;
    168                        }
    169                    }
    170                }
    171            }
    172        }
    173    }
    174}