PageRenderTime 26ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 1ms

/Dependencies/Spigot/work/decompile-1ae486b6/net/minecraft/server/ChatMessage.java

https://gitlab.com/Meteor-MC/plugins
Java | 245 lines | 188 code | 57 blank | 0 comment | 34 complexity | ce80165caa217893a38460c0ab083caf MD5 | raw file
  1. package net.minecraft.server;
  2. import com.google.common.annotations.VisibleForTesting;
  3. import com.google.common.collect.Iterators;
  4. import com.google.common.collect.Lists;
  5. import java.util.Arrays;
  6. import java.util.IllegalFormatException;
  7. import java.util.Iterator;
  8. import java.util.List;
  9. import java.util.regex.Matcher;
  10. import java.util.regex.Pattern;
  11. public class ChatMessage extends ChatBaseComponent {
  12. private final String d;
  13. private final Object[] e;
  14. private final Object f = new Object();
  15. private long g = -1L;
  16. @VisibleForTesting
  17. List<IChatBaseComponent> b = Lists.newArrayList();
  18. public static final Pattern c = Pattern.compile("%(?:(\\d+)\\$)?([A-Za-z%]|$)");
  19. public ChatMessage(String s, Object... aobject) {
  20. this.d = s;
  21. this.e = aobject;
  22. Object[] aobject1 = aobject;
  23. int i = aobject.length;
  24. for (int j = 0; j < i; ++j) {
  25. Object object = aobject1[j];
  26. if (object instanceof IChatBaseComponent) {
  27. ((IChatBaseComponent) object).getChatModifier().setChatModifier(this.getChatModifier());
  28. }
  29. }
  30. }
  31. @VisibleForTesting
  32. synchronized void g() {
  33. Object object = this.f;
  34. synchronized (this.f) {
  35. long i = LocaleI18n.a();
  36. if (i == this.g) {
  37. return;
  38. }
  39. this.g = i;
  40. this.b.clear();
  41. }
  42. try {
  43. this.b(LocaleI18n.get(this.d));
  44. } catch (ChatMessageException chatmessageexception) {
  45. this.b.clear();
  46. try {
  47. this.b(LocaleI18n.b(this.d));
  48. } catch (ChatMessageException chatmessageexception1) {
  49. throw chatmessageexception;
  50. }
  51. }
  52. }
  53. protected void b(String s) {
  54. boolean flag = false;
  55. Matcher matcher = ChatMessage.c.matcher(s);
  56. int i = 0;
  57. int j = 0;
  58. try {
  59. int k;
  60. for (; matcher.find(j); j = k) {
  61. int l = matcher.start();
  62. k = matcher.end();
  63. if (l > j) {
  64. ChatComponentText chatcomponenttext = new ChatComponentText(String.format(s.substring(j, l), new Object[0]));
  65. chatcomponenttext.getChatModifier().setChatModifier(this.getChatModifier());
  66. this.b.add(chatcomponenttext);
  67. }
  68. String s1 = matcher.group(2);
  69. String s2 = s.substring(l, k);
  70. if ("%".equals(s1) && "%%".equals(s2)) {
  71. ChatComponentText chatcomponenttext1 = new ChatComponentText("%");
  72. chatcomponenttext1.getChatModifier().setChatModifier(this.getChatModifier());
  73. this.b.add(chatcomponenttext1);
  74. } else {
  75. if (!"s".equals(s1)) {
  76. throw new ChatMessageException(this, "Unsupported format: \'" + s2 + "\'");
  77. }
  78. String s3 = matcher.group(1);
  79. int i1 = s3 != null ? Integer.parseInt(s3) - 1 : i++;
  80. if (i1 < this.e.length) {
  81. this.b.add(this.a(i1));
  82. }
  83. }
  84. }
  85. if (j < s.length()) {
  86. ChatComponentText chatcomponenttext2 = new ChatComponentText(String.format(s.substring(j), new Object[0]));
  87. chatcomponenttext2.getChatModifier().setChatModifier(this.getChatModifier());
  88. this.b.add(chatcomponenttext2);
  89. }
  90. } catch (IllegalFormatException illegalformatexception) {
  91. throw new ChatMessageException(this, illegalformatexception);
  92. }
  93. }
  94. private IChatBaseComponent a(int i) {
  95. if (i >= this.e.length) {
  96. throw new ChatMessageException(this, i);
  97. } else {
  98. Object object = this.e[i];
  99. Object object1;
  100. if (object instanceof IChatBaseComponent) {
  101. object1 = (IChatBaseComponent) object;
  102. } else {
  103. object1 = new ChatComponentText(object == null ? "null" : object.toString());
  104. ((IChatBaseComponent) object1).getChatModifier().setChatModifier(this.getChatModifier());
  105. }
  106. return (IChatBaseComponent) object1;
  107. }
  108. }
  109. public IChatBaseComponent setChatModifier(ChatModifier chatmodifier) {
  110. super.setChatModifier(chatmodifier);
  111. Object[] aobject = this.e;
  112. int i = aobject.length;
  113. for (int j = 0; j < i; ++j) {
  114. Object object = aobject[j];
  115. if (object instanceof IChatBaseComponent) {
  116. ((IChatBaseComponent) object).getChatModifier().setChatModifier(this.getChatModifier());
  117. }
  118. }
  119. if (this.g > -1L) {
  120. Iterator iterator = this.b.iterator();
  121. while (iterator.hasNext()) {
  122. IChatBaseComponent ichatbasecomponent = (IChatBaseComponent) iterator.next();
  123. ichatbasecomponent.getChatModifier().setChatModifier(chatmodifier);
  124. }
  125. }
  126. return this;
  127. }
  128. public Iterator<IChatBaseComponent> iterator() {
  129. this.g();
  130. return Iterators.concat(a((Iterable) this.b), a((Iterable) this.a));
  131. }
  132. public String getText() {
  133. this.g();
  134. StringBuilder stringbuilder = new StringBuilder();
  135. Iterator iterator = this.b.iterator();
  136. while (iterator.hasNext()) {
  137. IChatBaseComponent ichatbasecomponent = (IChatBaseComponent) iterator.next();
  138. stringbuilder.append(ichatbasecomponent.getText());
  139. }
  140. return stringbuilder.toString();
  141. }
  142. public ChatMessage h() {
  143. Object[] aobject = new Object[this.e.length];
  144. for (int i = 0; i < this.e.length; ++i) {
  145. if (this.e[i] instanceof IChatBaseComponent) {
  146. aobject[i] = ((IChatBaseComponent) this.e[i]).f();
  147. } else {
  148. aobject[i] = this.e[i];
  149. }
  150. }
  151. ChatMessage chatmessage = new ChatMessage(this.d, aobject);
  152. chatmessage.setChatModifier(this.getChatModifier().clone());
  153. Iterator iterator = this.a().iterator();
  154. while (iterator.hasNext()) {
  155. IChatBaseComponent ichatbasecomponent = (IChatBaseComponent) iterator.next();
  156. chatmessage.addSibling(ichatbasecomponent.f());
  157. }
  158. return chatmessage;
  159. }
  160. public boolean equals(Object object) {
  161. if (this == object) {
  162. return true;
  163. } else if (!(object instanceof ChatMessage)) {
  164. return false;
  165. } else {
  166. ChatMessage chatmessage = (ChatMessage) object;
  167. return Arrays.equals(this.e, chatmessage.e) && this.d.equals(chatmessage.d) && super.equals(object);
  168. }
  169. }
  170. public int hashCode() {
  171. int i = super.hashCode();
  172. i = 31 * i + this.d.hashCode();
  173. i = 31 * i + Arrays.hashCode(this.e);
  174. return i;
  175. }
  176. public String toString() {
  177. return "TranslatableComponent{key=\'" + this.d + '\'' + ", args=" + Arrays.toString(this.e) + ", siblings=" + this.a + ", style=" + this.getChatModifier() + '}';
  178. }
  179. public String i() {
  180. return this.d;
  181. }
  182. public Object[] j() {
  183. return this.e;
  184. }
  185. public IChatBaseComponent f() {
  186. return this.h();
  187. }
  188. }