h31ix

Untitled

Apr 1st, 2013
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. package de.st_ddt.crazyplugin;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.InputStreamReader;
  7. import java.io.PrintStream;
  8. import java.net.URL;
  9.  
  10. public final class Main
  11. implements Runnable
  12. {
  13. private String name = null;
  14. private String author = null;
  15. private String version = null;
  16. private String website = null;
  17. private String depend = null;
  18. private String softdepend = null;
  19. private String description = null;
  20.  
  21. public static void main(String[] args)
  22. {
  23. new Main().run();
  24. }
  25.  
  26. public void run()
  27. {
  28. try
  29. {
  30. InputStream stream = null;
  31. BufferedReader in = null;
  32. try
  33. {
  34. stream = getClass().getResourceAsStream("/plugin.yml");
  35. if (stream == null)
  36. return;
  37. in = new BufferedReader(new InputStreamReader(stream));
  38.  
  39. boolean descr = false;
  40. String zeile;
  41. while ((zeile = in.readLine()) != null)
  42. {
  43. String zeile;
  44. if (zeile.matches("[a-z]+\\:.*"))
  45. {
  46. descr = false;
  47. if (zeile.startsWith("name:")) {
  48. this.name = zeile.substring(6);
  49. } else if (zeile.startsWith("author:")) {
  50. this.author = zeile.substring(8);
  51. } else if (zeile.startsWith("version:")) {
  52. this.version = zeile.substring(9);
  53. } else if (zeile.startsWith("website:")) {
  54. this.website = zeile.substring(9);
  55. } else if (zeile.startsWith("depend:")) {
  56. this.depend = zeile.substring(8);
  57. } else if (zeile.startsWith("softdepend:")) {
  58. this.softdepend = zeile.substring(12);
  59. } else if (zeile.startsWith("description:"))
  60. {
  61. descr = true;
  62. this.description = zeile.substring(13).trim();
  63. if (this.description.equals(">"))
  64. this.description = "";
  65. else
  66. this.description += "\n ";
  67. }
  68. }
  69. else if (descr) {
  70. this.description = (this.description + zeile.trim() + "\n "); }
  71. }if (this.description != null)
  72. this.description = this.description.trim();
  73. }
  74. finally
  75. {
  76. if (stream != null)
  77. stream.close();
  78. if (in != null)
  79. in.close();
  80. }
  81. if (stream != null)
  82. stream.close();
  83. if (in != null) {
  84. in.close();
  85. }
  86. }
  87. catch (IOException e)
  88. {
  89. e.printStackTrace();
  90. }
  91. PrintStream out = System.out;
  92. out.println();
  93. out.println();
  94. out.println();
  95. out.println(" Sorry, this is a plugin and won't run without a compatible Bukkit server software.");
  96. out.println(" You can download it here:");
  97. out.println(" http://dl.bukkit.org/");
  98. out.println();
  99. out.println();
  100. out.println(" Pluginname: " + this.name);
  101. out.println(" Current Version: " + this.version);
  102. try
  103. {
  104. BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
  105. out.println(" Check for Updates ?");
  106. out.println(" - Type \"Yes\" or \"No\" ?");
  107. out.print(" > ");
  108. String zeile = console.readLine();
  109. if ((zeile != null) && (
  110. (zeile.equalsIgnoreCase("yes")) || (zeile.equalsIgnoreCase("y"))))
  111. {
  112. String latest = getLastestVersion();
  113. if (latest == null)
  114. out.println(" Latest official Version: none");
  115. else
  116. out.println(" Latest official Version: " + latest);
  117. }
  118. }
  119. catch (Exception localException) {
  120. }
  121. if (this.website != null)
  122. out.println(" Website: " + this.website);
  123. out.println(" Author: " + this.author);
  124. if (this.depend != null)
  125. out.println(" Required plugins: " + this.depend.replace(" ", "").replace("[", "").replace("]", "").replace(",", ", "));
  126. if (this.softdepend != null)
  127. out.println(" Optional plugins: " + this.softdepend.replace(" ", "").replace("[", "").replace("]", "").replace(",", ", "));
  128. if ((this.description != null) &&
  129. (this.description.length() > 1))
  130. {
  131. out.println();
  132. out.println();
  133. out.println(" Description:");
  134. out.println(" " + this.description);
  135. }
  136. out.println();
  137. try
  138. {
  139. Thread.sleep(5000L);
  140. }
  141. catch (InterruptedException localInterruptedException)
  142. {
  143. }
  144. }
  145.  
  146. private String getLastestVersion()
  147. {
  148. try {
  149. BufferedReader bufreader = null;
  150. try
  151. {
  152. InputStream stream = new URL("http://dev.bukkit.org/server-mods/" + this.name.toLowerCase() + "/files.rss").openStream();
  153. if (stream == null)
  154. return null;
  155. bufreader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
  156. String zeile = null;
  157. boolean active = false;
  158. while ((zeile = bufreader.readLine()) != null)
  159. {
  160. zeile = zeile.trim();
  161. if ((active) && (zeile.startsWith("<title>")))
  162. return zeile.substring(7 + this.name.length() + 2).split("<")[0];
  163. if (zeile.equals("<item>")) {
  164. active = true;
  165. }
  166. }
  167.  
  168. }
  169. finally
  170. {
  171. if (bufreader != null)
  172. bufreader.close();
  173. }
  174. if (bufreader != null) {
  175. bufreader.close();
  176. }
  177. }
  178. catch (Exception e)
  179. {
  180. return null;
  181. }
  182. return null;
  183. }
  184. }
Advertisement
Add Comment
Please, Sign In to add comment