yanniclord

Untitled

Mar 4th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. /*
  2. * Decompiled with CFR 0_110.
  3. *
  4. * Could not load the following classes:
  5. * net.montoyo.mcef.MCEF
  6. * net.montoyo.mcef.utilities.Log
  7. */
  8. package net.montoyo.mcef.remote;
  9.  
  10. import java.io.IOException;
  11. import java.net.HttpURLConnection;
  12. import java.net.MalformedURLException;
  13. import java.net.URL;
  14. import java.net.URLConnection;
  15. import java.util.Random;
  16. import net.montoyo.mcef.MCEF;
  17. import net.montoyo.mcef.utilities.Log;
  18.  
  19. public enum Mirror {
  20. MONTOYO("http://montoyo.net/jcef", "montoyo.net");
  21.  
  22. private static Mirror current;
  23. private final String url;
  24. private final String name;
  25. private boolean broken;
  26.  
  27. private Mirror(String url, String name) {
  28. this.url = url;
  29. this.name = name;
  30. this.broken = false;
  31. }
  32.  
  33. public boolean isBroken() {
  34. return this.broken;
  35. }
  36.  
  37. public String getMirrorString() {
  38. if (MCEF.FORCE_MIRROR == null) {
  39. return "Mirror kindly provided by " + this.name;
  40. }
  41. return "Mirror location was set to " + MCEF.FORCE_MIRROR;
  42. }
  43.  
  44. public HttpURLConnection getResource(String name) throws MalformedURLException, IOException {
  45. HttpURLConnection ret = (HttpURLConnection)new URL((MCEF.FORCE_MIRROR == null ? this.url : MCEF.FORCE_MIRROR) + '/' + name).openConnection();
  46. ret.setConnectTimeout(30000);
  47. ret.setReadTimeout(15000);
  48. ret.setRequestProperty("User-Agent", "MCEF");
  49. return ret;
  50. }
  51.  
  52. private static Mirror pickRandom() {
  53. Mirror[] lst = Mirror.values();
  54. int idx = new Random().nextInt(lst.length);
  55. return lst[idx];
  56. }
  57.  
  58. private static Mirror pickWorking() {
  59. for (Mirror m : Mirror.values()) {
  60. if (m.broken) continue;
  61. return m;
  62. }
  63. return null;
  64. }
  65.  
  66. public static Mirror markAsBroken() {
  67. Mirror.current.broken = true;
  68. Mirror old = current;
  69. current = Mirror.pickWorking();
  70. Object[] arrobject = new Object[2];
  71. arrobject[0] = old.url;
  72. arrobject[1] = current == null ? "NULL" : Mirror.current.url;
  73. Log.info((String)"Mirror %s marked as broken; using %s", (Object[])arrobject);
  74. return current;
  75. }
  76.  
  77. public static Mirror getCurrent() {
  78. return current;
  79. }
  80.  
  81. public static Mirror reset() {
  82. for (Mirror m : Mirror.values()) {
  83. m.broken = false;
  84. }
  85. if (current == null) {
  86. current = Mirror.pickRandom();
  87. }
  88. return current;
  89. }
  90.  
  91. static {
  92. current = Mirror.pickRandom();
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment