Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.91 KB | None | 0 0
  1. package net.minecraft.client.gui;
  2.  
  3. import com.google.common.base.Splitter;
  4. import com.google.common.collect.Lists;
  5. import java.util.List;
  6. import net.minecraft.client.multiplayer.GuiConnecting;
  7. import net.minecraft.client.multiplayer.ServerData;
  8. import net.minecraft.client.multiplayer.ServerList;
  9. import net.minecraft.client.network.LanServerDetector;
  10. import net.minecraft.client.network.OldServerPinger;
  11. import net.minecraft.client.resources.I18n;
  12. import org.apache.logging.log4j.LogManager;
  13. import org.apache.logging.log4j.Logger;
  14. import org.lwjgl.input.Keyboard;
  15.  
  16. public class GuiMultiplayer extends GuiScreen implements GuiYesNoCallback
  17. {
  18. private static final Logger logger = LogManager.getLogger();
  19. private final OldServerPinger field_146797_f = new OldServerPinger();
  20. private GuiScreen field_146798_g;
  21. private ServerSelectionList field_146803_h;
  22. private ServerList field_146804_i;
  23. // private GuiButton field_146810_r;
  24. private GuiButton field_146809_s;
  25. // private GuiButton field_146808_t;
  26. private boolean field_146807_u;
  27. private boolean field_146806_v;
  28. private boolean field_146805_w;
  29. private boolean field_146813_x;
  30. private String field_146812_y;
  31. private ServerData field_146811_z;
  32. private LanServerDetector.LanServerList field_146799_A;
  33. private LanServerDetector.ThreadLanServerFind field_146800_B;
  34. private boolean field_146801_C;
  35. private static final String __OBFID = "CL_00000814";
  36.  
  37. public GuiMultiplayer(GuiScreen p_i1040_1_)
  38. {
  39. this.field_146798_g = p_i1040_1_;
  40. }
  41.  
  42. /**
  43. * Adds the buttons (and other controls) to the screen in question.
  44. */
  45. public void initGui()
  46. {
  47. Keyboard.enableRepeatEvents(true);
  48. this.buttonList.clear();
  49.  
  50. if (!this.field_146801_C)
  51. {
  52. this.field_146801_C = true;
  53. this.field_146804_i = new ServerList(this.mc);
  54. this.field_146804_i.loadServerList();
  55. this.field_146799_A = new LanServerDetector.LanServerList();
  56.  
  57. try
  58. {
  59. this.field_146800_B = new LanServerDetector.ThreadLanServerFind(this.field_146799_A);
  60. this.field_146800_B.start();
  61. }
  62. catch (Exception var2)
  63. {
  64. logger.warn("Unable to start LAN server detection: " + var2.getMessage());
  65. }
  66.  
  67. this.field_146803_h = new ServerSelectionList(this, this.mc, this.width, this.height, 32, this.height - 64, 36);
  68. this.field_146803_h.func_148195_a(this.field_146804_i);
  69. }
  70. else
  71. {
  72. this.field_146803_h.func_148122_a(this.width, this.height, 32, this.height - 64);
  73. }
  74.  
  75. this.func_146794_g();
  76. }
  77.  
  78. public void func_146794_g()
  79. {
  80. // this.buttonList.add(this.field_146810_r = new GuiButton(7, this.width / 2 - 154, this.height - 28, 70, 20, I18n.format("selectServer.edit", new Object[0])));
  81. // this.buttonList.add(this.field_146808_t = new GuiButton(2, this.width / 2 - 74, this.height - 28, 70, 20, I18n.format("selectServer.delete", new Object[0])));
  82. this.buttonList.add(this.field_146809_s = new GuiButton(1, this.width / 2 - 154, this.height - 52, 100, 20, I18n.format("selectServer.select", new Object[0])));
  83. this.buttonList.add(new GuiButton(4, this.width / 2 - 50, this.height - 52, 100, 20, I18n.format("selectServer.direct", new Object[0])));
  84. // this.buttonList.add(new GuiButton(3, this.width / 2 + 4 + 50, this.height - 52, 100, 20, I18n.format("selectServer.add", new Object[0])));
  85. this.buttonList.add(new GuiButton(8, this.width / 2 + 4, this.height - 28, 70, 20, I18n.format("selectServer.refresh", new Object[0])));
  86. this.buttonList.add(new GuiButton(0, this.width / 2 + 4 + 76, this.height - 28, 75, 20, I18n.format("gui.cancel", new Object[0])));
  87. this.func_146790_a(this.field_146803_h.func_148193_k());
  88. }
  89.  
  90. /**
  91. * Called from the main game loop to update the screen.
  92. */
  93. public void updateScreen()
  94. {
  95. super.updateScreen();
  96.  
  97. if (this.field_146799_A.getWasUpdated())
  98. {
  99. List var1 = this.field_146799_A.getLanServers();
  100. this.field_146799_A.setWasNotUpdated();
  101. this.field_146803_h.func_148194_a(var1);
  102. }
  103.  
  104. this.field_146797_f.func_147223_a();
  105. }
  106.  
  107. /**
  108. * "Called when the screen is unloaded. Used to disable keyboard repeat events."
  109. */
  110. public void onGuiClosed()
  111. {
  112. Keyboard.enableRepeatEvents(false);
  113.  
  114. if (this.field_146800_B != null)
  115. {
  116. this.field_146800_B.interrupt();
  117. this.field_146800_B = null;
  118. }
  119.  
  120. this.field_146797_f.func_147226_b();
  121. }
  122.  
  123. protected void actionPerformed(GuiButton p_146284_1_)
  124. {
  125. if (p_146284_1_.enabled)
  126. {
  127. GuiListExtended.IGuiListEntry var2 = this.field_146803_h.func_148193_k() < 0 ? null : this.field_146803_h.func_148180_b(this.field_146803_h.func_148193_k());
  128.  
  129. if (p_146284_1_.id == 2 && var2 instanceof ServerListEntryNormal)
  130. {
  131. String var9 = ((ServerListEntryNormal)var2).func_148296_a().serverName;
  132.  
  133. if (var9 != null)
  134. {
  135. this.field_146807_u = true;
  136. String var4 = I18n.format("selectServer.deleteQuestion", new Object[0]);
  137. String var5 = "\'" + var9 + "\' " + I18n.format("selectServer.deleteWarning", new Object[0]);
  138. String var6 = I18n.format("selectServer.deleteButton", new Object[0]);
  139. String var7 = I18n.format("gui.cancel", new Object[0]);
  140. GuiYesNo var8 = new GuiYesNo(this, var4, var5, var6, var7, this.field_146803_h.func_148193_k());
  141. this.mc.displayGuiScreen(var8);
  142. }
  143. }
  144. else if (p_146284_1_.id == 1)
  145. {
  146. this.func_146796_h();
  147. }
  148. else if (p_146284_1_.id == 4)
  149. {
  150. this.field_146813_x = true;
  151. this.mc.displayGuiScreen(new GuiScreenServerList(this, this.field_146811_z = new ServerData(I18n.format("selectServer.defaultName", new Object[0]), "")));
  152. }
  153. else if (p_146284_1_.id == 3)
  154. {
  155. this.field_146806_v = true;
  156. this.mc.displayGuiScreen(new GuiScreenAddServer(this, this.field_146811_z = new ServerData(I18n.format("selectServer.defaultName", new Object[0]), "")));
  157. }
  158. else if (p_146284_1_.id == 7 && var2 instanceof ServerListEntryNormal)
  159. {
  160. this.field_146805_w = true;
  161. ServerData var3 = ((ServerListEntryNormal)var2).func_148296_a();
  162. this.field_146811_z = new ServerData(var3.serverName, var3.serverIP);
  163. this.field_146811_z.func_152583_a(var3);
  164. this.mc.displayGuiScreen(new GuiScreenAddServer(this, this.field_146811_z));
  165. }
  166. else if (p_146284_1_.id == 0)
  167. {
  168. this.mc.displayGuiScreen(this.field_146798_g);
  169. }
  170. else if (p_146284_1_.id == 8)
  171. {
  172. this.func_146792_q();
  173. }
  174. }
  175. }
  176.  
  177. private void func_146792_q()
  178. {
  179. this.mc.displayGuiScreen(new GuiMultiplayer(this.field_146798_g));
  180. }
  181.  
  182. public void confirmClicked(boolean p_73878_1_, int p_73878_2_)
  183. {
  184. GuiListExtended.IGuiListEntry var3 = this.field_146803_h.func_148193_k() < 0 ? null : this.field_146803_h.func_148180_b(this.field_146803_h.func_148193_k());
  185.  
  186. if (this.field_146807_u)
  187. {
  188. this.field_146807_u = false;
  189.  
  190. if (p_73878_1_ && var3 instanceof ServerListEntryNormal)
  191. {
  192. this.field_146804_i.removeServerData(this.field_146803_h.func_148193_k());
  193. this.field_146804_i.saveServerList();
  194. this.field_146803_h.func_148192_c(-1);
  195. this.field_146803_h.func_148195_a(this.field_146804_i);
  196. }
  197.  
  198. this.mc.displayGuiScreen(this);
  199. }
  200. else if (this.field_146813_x)
  201. {
  202. this.field_146813_x = false;
  203.  
  204. if (p_73878_1_)
  205. {
  206. this.func_146791_a(this.field_146811_z);
  207. }
  208. else
  209. {
  210. this.mc.displayGuiScreen(this);
  211. }
  212. }
  213. else if (this.field_146806_v)
  214. {
  215. this.field_146806_v = false;
  216.  
  217. if (p_73878_1_)
  218. {
  219. this.field_146804_i.addServerData(this.field_146811_z);
  220. this.field_146804_i.saveServerList();
  221. this.field_146803_h.func_148192_c(-1);
  222. this.field_146803_h.func_148195_a(this.field_146804_i);
  223. }
  224.  
  225. this.mc.displayGuiScreen(this);
  226. }
  227. else if (this.field_146805_w)
  228. {
  229. this.field_146805_w = false;
  230.  
  231. if (p_73878_1_ && var3 instanceof ServerListEntryNormal)
  232. {
  233. ServerData var4 = ((ServerListEntryNormal)var3).func_148296_a();
  234. var4.serverName = this.field_146811_z.serverName;
  235. var4.serverIP = this.field_146811_z.serverIP;
  236. var4.func_152583_a(this.field_146811_z);
  237. this.field_146804_i.saveServerList();
  238. this.field_146803_h.func_148195_a(this.field_146804_i);
  239. }
  240.  
  241. this.mc.displayGuiScreen(this);
  242. }
  243. }
  244.  
  245. /**
  246. * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
  247. */
  248. protected void keyTyped(char p_73869_1_, int p_73869_2_)
  249. {
  250. int var3 = this.field_146803_h.func_148193_k();
  251. GuiListExtended.IGuiListEntry var4 = var3 < 0 ? null : this.field_146803_h.func_148180_b(var3);
  252.  
  253. if (p_73869_2_ == 63)
  254. {
  255. this.func_146792_q();
  256. }
  257. else
  258. {
  259. if (var3 >= 0)
  260. {
  261. if (p_73869_2_ == 200)
  262. {
  263. if (isShiftKeyDown())
  264. {
  265. if (var3 > 0 && var4 instanceof ServerListEntryNormal)
  266. {
  267. this.field_146804_i.swapServers(var3, var3 - 1);
  268. this.func_146790_a(this.field_146803_h.func_148193_k() - 1);
  269. this.field_146803_h.func_148145_f(-this.field_146803_h.func_148146_j());
  270. this.field_146803_h.func_148195_a(this.field_146804_i);
  271. }
  272. }
  273. else if (var3 > 0)
  274. {
  275. this.func_146790_a(this.field_146803_h.func_148193_k() - 1);
  276. this.field_146803_h.func_148145_f(-this.field_146803_h.func_148146_j());
  277.  
  278. if (this.field_146803_h.func_148180_b(this.field_146803_h.func_148193_k()) instanceof ServerListEntryLanScan)
  279. {
  280. if (this.field_146803_h.func_148193_k() > 0)
  281. {
  282. this.func_146790_a(this.field_146803_h.getSize() - 1);
  283. this.field_146803_h.func_148145_f(-this.field_146803_h.func_148146_j());
  284. }
  285. else
  286. {
  287. this.func_146790_a(-1);
  288. }
  289. }
  290. }
  291. else
  292. {
  293. this.func_146790_a(-1);
  294. }
  295. }
  296. else if (p_73869_2_ == 208)
  297. {
  298. if (isShiftKeyDown())
  299. {
  300. if (var3 < this.field_146804_i.countServers() - 1)
  301. {
  302. this.field_146804_i.swapServers(var3, var3 + 1);
  303. this.func_146790_a(var3 + 1);
  304. this.field_146803_h.func_148145_f(this.field_146803_h.func_148146_j());
  305. this.field_146803_h.func_148195_a(this.field_146804_i);
  306. }
  307. }
  308. else if (var3 < this.field_146803_h.getSize())
  309. {
  310. this.func_146790_a(this.field_146803_h.func_148193_k() + 1);
  311. this.field_146803_h.func_148145_f(this.field_146803_h.func_148146_j());
  312.  
  313. if (this.field_146803_h.func_148180_b(this.field_146803_h.func_148193_k()) instanceof ServerListEntryLanScan)
  314. {
  315. if (this.field_146803_h.func_148193_k() < this.field_146803_h.getSize() - 1)
  316. {
  317. this.func_146790_a(this.field_146803_h.getSize() + 1);
  318. this.field_146803_h.func_148145_f(this.field_146803_h.func_148146_j());
  319. }
  320. else
  321. {
  322. this.func_146790_a(-1);
  323. }
  324. }
  325. }
  326. else
  327. {
  328. this.func_146790_a(-1);
  329. }
  330. }
  331. else if (p_73869_2_ != 28 && p_73869_2_ != 156)
  332. {
  333. super.keyTyped(p_73869_1_, p_73869_2_);
  334. }
  335. else
  336. {
  337. this.actionPerformed((GuiButton)this.buttonList.get(2));
  338. }
  339. }
  340. else
  341. {
  342. super.keyTyped(p_73869_1_, p_73869_2_);
  343. }
  344. }
  345. }
  346.  
  347. /**
  348. * Draws the screen and all the components in it.
  349. */
  350. public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_)
  351. {
  352. this.field_146812_y = null;
  353. this.drawDefaultBackground();
  354. this.field_146803_h.func_148128_a(p_73863_1_, p_73863_2_, p_73863_3_);
  355. this.drawCenteredString(this.fontRendererObj, I18n.format("multiplayer.title", new Object[0]), this.width / 2, 20, 16777215);
  356. super.drawScreen(p_73863_1_, p_73863_2_, p_73863_3_);
  357.  
  358. if (this.field_146812_y != null)
  359. {
  360. this.func_146283_a(Lists.newArrayList(Splitter.on("\n").split(this.field_146812_y)), p_73863_1_, p_73863_2_);
  361. }
  362. }
  363.  
  364. public void func_146796_h()
  365. {
  366. GuiListExtended.IGuiListEntry var1 = this.field_146803_h.func_148193_k() < 0 ? null : this.field_146803_h.func_148180_b(this.field_146803_h.func_148193_k());
  367.  
  368. if (var1 instanceof ServerListEntryNormal)
  369. {
  370. this.func_146791_a(((ServerListEntryNormal)var1).func_148296_a());
  371. }
  372. else if (var1 instanceof ServerListEntryLanDetected)
  373. {
  374. LanServerDetector.LanServer var2 = ((ServerListEntryLanDetected)var1).func_148289_a();
  375. this.func_146791_a(new ServerData(var2.getServerMotd(), var2.getServerIpPort(), true));
  376. }
  377. }
  378.  
  379. private void func_146791_a(ServerData p_146791_1_)
  380. {
  381. this.mc.displayGuiScreen(new GuiConnecting(this, this.mc, p_146791_1_));
  382. }
  383.  
  384. public void func_146790_a(int p_146790_1_)
  385. {
  386. this.field_146803_h.func_148192_c(p_146790_1_);
  387. GuiListExtended.IGuiListEntry var2 = p_146790_1_ < 0 ? null : this.field_146803_h.func_148180_b(p_146790_1_);
  388. this.field_146809_s.enabled = false;
  389. // this.field_146810_r.enabled = false;
  390. // this.field_146808_t.enabled = false;
  391.  
  392. if (var2 != null && !(var2 instanceof ServerListEntryLanScan))
  393. {
  394. this.field_146809_s.enabled = true;
  395.  
  396. if (var2 instanceof ServerListEntryNormal)
  397. {
  398. this.field_146810_r.enabled = true;
  399. this.field_146808_t.enabled = true;
  400. }
  401. }
  402. }
  403.  
  404. public OldServerPinger func_146789_i()
  405. {
  406. return this.field_146797_f;
  407. }
  408.  
  409. public void func_146793_a(String p_146793_1_)
  410. {
  411. this.field_146812_y = p_146793_1_;
  412. }
  413.  
  414. /**
  415. * Called when the mouse is clicked.
  416. */
  417. protected void mouseClicked(int p_73864_1_, int p_73864_2_, int p_73864_3_)
  418. {
  419. super.mouseClicked(p_73864_1_, p_73864_2_, p_73864_3_);
  420. this.field_146803_h.func_148179_a(p_73864_1_, p_73864_2_, p_73864_3_);
  421. }
  422.  
  423. protected void mouseMovedOrUp(int p_146286_1_, int p_146286_2_, int p_146286_3_)
  424. {
  425. super.mouseMovedOrUp(p_146286_1_, p_146286_2_, p_146286_3_);
  426. this.field_146803_h.func_148181_b(p_146286_1_, p_146286_2_, p_146286_3_);
  427. }
  428.  
  429. public ServerList func_146795_p()
  430. {
  431. return this.field_146804_i;
  432. }
  433. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement