/net/minecraft/server/BanEntry.java

https://bitbucket.org/agaricusb/mc-dev · Java · 132 lines · 111 code · 21 blank · 0 comment · 15 complexity · 40c01b6574fb794a340d69ed120f531b MD5 · raw file

  1. package net.minecraft.server;
  2. import java.text.ParseException;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7. import java.util.regex.Pattern;
  8. public class BanEntry {
  9. public static final SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
  10. public static Logger b = Logger.getLogger("Minecraft");
  11. private final String c;
  12. private Date d = new Date();
  13. private String e = "(Unknown)";
  14. private Date f = null;
  15. private String g = "Banned by an operator.";
  16. public BanEntry(String s) {
  17. this.c = s;
  18. }
  19. public String getName() {
  20. return this.c;
  21. }
  22. public Date getCreated() {
  23. return this.d;
  24. }
  25. public void setCreated(Date date) {
  26. this.d = date != null ? date : new Date();
  27. }
  28. public String getSource() {
  29. return this.e;
  30. }
  31. public void setSource(String s) {
  32. this.e = s;
  33. }
  34. public Date getExpires() {
  35. return this.f;
  36. }
  37. public void setExpires(Date date) {
  38. this.f = date;
  39. }
  40. public boolean hasExpired() {
  41. return this.f == null ? false : this.f.before(new Date());
  42. }
  43. public String getReason() {
  44. return this.g;
  45. }
  46. public void setReason(String s) {
  47. this.g = s;
  48. }
  49. public String g() {
  50. StringBuilder stringbuilder = new StringBuilder();
  51. stringbuilder.append(this.getName());
  52. stringbuilder.append("|");
  53. stringbuilder.append(a.format(this.getCreated()));
  54. stringbuilder.append("|");
  55. stringbuilder.append(this.getSource());
  56. stringbuilder.append("|");
  57. stringbuilder.append(this.getExpires() == null ? "Forever" : a.format(this.getExpires()));
  58. stringbuilder.append("|");
  59. stringbuilder.append(this.getReason());
  60. return stringbuilder.toString();
  61. }
  62. public static BanEntry c(String s) {
  63. if (s.trim().length() < 2) {
  64. return null;
  65. } else {
  66. String[] astring = s.trim().split(Pattern.quote("|"), 5);
  67. BanEntry banentry = new BanEntry(astring[0].trim());
  68. byte b0 = 0;
  69. int i = astring.length;
  70. int j = b0 + 1;
  71. if (i <= j) {
  72. return banentry;
  73. } else {
  74. try {
  75. banentry.setCreated(a.parse(astring[j].trim()));
  76. } catch (ParseException parseexception) {
  77. b.log(Level.WARNING, "Could not read creation date format for ban entry \'" + banentry.getName() + "\' (was: \'" + astring[j] + "\')", parseexception);
  78. }
  79. i = astring.length;
  80. ++j;
  81. if (i <= j) {
  82. return banentry;
  83. } else {
  84. banentry.setSource(astring[j].trim());
  85. i = astring.length;
  86. ++j;
  87. if (i <= j) {
  88. return banentry;
  89. } else {
  90. try {
  91. String s1 = astring[j].trim();
  92. if (!s1.equalsIgnoreCase("Forever") && s1.length() > 0) {
  93. banentry.setExpires(a.parse(s1));
  94. }
  95. } catch (ParseException parseexception1) {
  96. b.log(Level.WARNING, "Could not read expiry date format for ban entry \'" + banentry.getName() + "\' (was: \'" + astring[j] + "\')", parseexception1);
  97. }
  98. i = astring.length;
  99. ++j;
  100. if (i <= j) {
  101. return banentry;
  102. } else {
  103. banentry.setReason(astring[j].trim());
  104. return banentry;
  105. }
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }