Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. package com.pablo67340.main;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileOutputStream;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.io.InputStreamReader;
  9. import java.net.HttpURLConnection;
  10. import java.net.InetAddress;
  11. import java.net.ServerSocket;
  12. import java.net.URL;
  13. import java.net.UnknownHostException;
  14. import java.util.HashMap;
  15.  
  16. import org.bukkit.Bukkit;
  17. import org.bukkit.command.Command;
  18. import org.bukkit.command.CommandSender;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.plugin.PluginManager;
  21. import org.bukkit.plugin.java.JavaPlugin;
  22.  
  23. import com.pablo67340.listeners.AmmoListener;
  24. import com.pablo67340.listeners.EventListener;
  25. import com.pablo67340.textures.FTListener;
  26. import com.pablo67340.textures.Webserver;
  27.  
  28. public class Main extends JavaPlugin {
  29.  
  30. public EventListener eventlistener = new EventListener(this);
  31. public AmmoListener ammolistener = new AmmoListener(this);
  32. public ServerSocket Server = null;
  33. Webserver ws = null;
  34. public String ip = "";
  35. public int port = 5000;
  36. public String filename = "halo.zip";
  37. @SuppressWarnings({ "unchecked", "rawtypes" })
  38. public HashMap<String, Boolean> checks = new HashMap();
  39. public boolean checklocked = false;
  40. public boolean opoverride = false;
  41. public boolean permoverride = false;
  42.  
  43. public boolean checkServer(String ip) {
  44. try { URL u = new URL("http://" + ip + ":" + this.port + "/ping");
  45. HttpURLConnection huc = (HttpURLConnection)u.openConnection();
  46. huc.setRequestMethod("GET");
  47. huc.connect();
  48. if (huc.getResponseCode() == 222) {
  49. return true;
  50. }
  51. }
  52. catch (IOException localIOException)
  53. {
  54. }
  55. return false;
  56. }
  57. public String getExternalIP() {
  58. String i = "";
  59. try {
  60. URL whatismyip = new URL("http://automation.whatismyip.com/n09230945.asp");
  61. BufferedReader in = new BufferedReader(
  62. new InputStreamReader(whatismyip.openStream()));
  63.  
  64. i = in.readLine();
  65. } catch (Exception e) {
  66. return "";
  67. }
  68. return i;
  69. }
  70.  
  71. public void onDisable(){
  72. System.out.print("Halo Disabled.");
  73. try {
  74. this.ws.interrupt();
  75. this.ws.running = false;
  76. this.ws = null;
  77. this.Server.close();
  78. }
  79. catch (IOException localIOException) {
  80. }
  81. getLogger().info("Disabled");
  82. }
  83.  
  84. public void onEnable(){
  85. new File("plugins/Halo/").mkdir();
  86. createDefaultConfiguration("config.yml");
  87. System.out.print("Halo Xeon Enabled. Developed by pablo67340 Distrubed for open source.");
  88. this.getServer().getPluginManager().registerEvents(eventlistener, this);
  89.  
  90. // Not Implemented yet. Merged into EventListener
  91. this.getServer().getPluginManager().registerEvents(ammolistener, this);
  92. // Checks for snowballs AND Counts ammo. DO NOT DISABLE!
  93. EventListener.startTicker();
  94.  
  95. (this.ws = new Webserver(this)).start();
  96. PluginManager pm = Bukkit.getPluginManager();
  97. pm.registerEvents(new FTListener(this), this);
  98. if (this.ip == "")
  99. try {
  100. String i = getExternalIP();
  101. if ((i != "") &&
  102. (checkServer(i))) {
  103. System.out.println("Got IP: " + InetAddress.getLocalHost().getHostAddress());
  104. System.out.println("Warning: It is recommended that you port forward 5000 as only users on your Local Network can access your texture pack!");
  105. this.ip = InetAddress.getLocalHost().getHostAddress();
  106. return;
  107. }
  108. }
  109. catch (UnknownHostException localUnknownHostException1)
  110. {
  111. try {
  112. if (checkServer(InetAddress.getLocalHost().getHostAddress())) {
  113. System.out.println("Got IP: " + InetAddress.getLocalHost().getHostAddress());
  114. System.out.println("Warning: It is recommended that you port forward 5000 as only users on your Local Network can access your texture pack!");
  115. this.ip = InetAddress.getLocalHost().getHostAddress();
  116. return;
  117. }
  118. }
  119. catch (UnknownHostException localUnknownHostException11) {
  120. if (checkServer("localhost")) {
  121. System.out.println("Got IP: localhost");
  122. System.out.println("Warning: It is recommended that you port forward 5000 as other users cannot access your texture pack!");
  123. this.ip = "localhost";
  124. return;
  125. }
  126. }
  127. }
  128. }
  129.  
  130. @Override
  131. public boolean onCommand(final CommandSender sender, Command command, String label, final String[] args) {
  132. if(sender instanceof Player){
  133. @SuppressWarnings("unused")
  134. final Player player = (Player) sender;
  135. if(command.getName().equalsIgnoreCase("halo")){
  136. //Work on it when i have time. Prints CLEAN & THEMED help menu
  137. sender.sendMessage("§cPrint menu here");
  138. }
  139. }
  140. return false;
  141. }
  142. //Config shit
  143. public void createDefaultConfiguration(String name) {
  144. File actual = new File(getDataFolder(), name);
  145. if (!actual.exists()) {
  146.  
  147. InputStream input =
  148. this.getClass().getResourceAsStream("/" + name);
  149. if (input != null) {
  150. FileOutputStream output = null;
  151.  
  152. try {
  153. output = new FileOutputStream(actual);
  154. byte[] buf = new byte[8192];
  155. int length = 0;
  156. while ((length = input.read(buf)) > 0) {
  157. output.write(buf, 0, length);
  158. }
  159.  
  160. System.out.println(getDescription().getName()
  161. + ": Default configuration file written: " + name);
  162. } catch (IOException e) {
  163. e.printStackTrace();
  164. } finally {
  165. try {
  166. if (input != null)
  167. input.close();
  168. } catch (IOException e) {}
  169.  
  170. try {
  171. if (output != null)
  172. output.close();
  173. } catch (IOException e) {}
  174. }
  175. }
  176. }
  177. }
  178.  
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement