Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.pablo67340.main;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.InetAddress;
- import java.net.ServerSocket;
- import java.net.URL;
- import java.net.UnknownHostException;
- import java.util.HashMap;
- import org.bukkit.Bukkit;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandSender;
- import org.bukkit.entity.Player;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.plugin.java.JavaPlugin;
- import com.pablo67340.listeners.AmmoListener;
- import com.pablo67340.listeners.EventListener;
- import com.pablo67340.textures.FTListener;
- import com.pablo67340.textures.Webserver;
- public class Main extends JavaPlugin {
- public EventListener eventlistener = new EventListener(this);
- public AmmoListener ammolistener = new AmmoListener(this);
- public ServerSocket Server = null;
- Webserver ws = null;
- public String ip = "";
- public int port = 5000;
- public String filename = "halo.zip";
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public HashMap<String, Boolean> checks = new HashMap();
- public boolean checklocked = false;
- public boolean opoverride = false;
- public boolean permoverride = false;
- public boolean checkServer(String ip) {
- try { URL u = new URL("http://" + ip + ":" + this.port + "/ping");
- HttpURLConnection huc = (HttpURLConnection)u.openConnection();
- huc.setRequestMethod("GET");
- huc.connect();
- if (huc.getResponseCode() == 222) {
- return true;
- }
- }
- catch (IOException localIOException)
- {
- }
- return false;
- }
- public String getExternalIP() {
- String i = "";
- try {
- URL whatismyip = new URL("http://automation.whatismyip.com/n09230945.asp");
- BufferedReader in = new BufferedReader(
- new InputStreamReader(whatismyip.openStream()));
- i = in.readLine();
- } catch (Exception e) {
- return "";
- }
- return i;
- }
- public void onDisable(){
- System.out.print("Halo Disabled.");
- try {
- this.ws.interrupt();
- this.ws.running = false;
- this.ws = null;
- this.Server.close();
- }
- catch (IOException localIOException) {
- }
- getLogger().info("Disabled");
- }
- public void onEnable(){
- new File("plugins/Halo/").mkdir();
- createDefaultConfiguration("config.yml");
- System.out.print("Halo Xeon Enabled. Developed by pablo67340 Distrubed for open source.");
- this.getServer().getPluginManager().registerEvents(eventlistener, this);
- // Not Implemented yet. Merged into EventListener
- this.getServer().getPluginManager().registerEvents(ammolistener, this);
- // Checks for snowballs AND Counts ammo. DO NOT DISABLE!
- EventListener.startTicker();
- (this.ws = new Webserver(this)).start();
- PluginManager pm = Bukkit.getPluginManager();
- pm.registerEvents(new FTListener(this), this);
- if (this.ip == "")
- try {
- String i = getExternalIP();
- if ((i != "") &&
- (checkServer(i))) {
- System.out.println("Got IP: " + InetAddress.getLocalHost().getHostAddress());
- System.out.println("Warning: It is recommended that you port forward 5000 as only users on your Local Network can access your texture pack!");
- this.ip = InetAddress.getLocalHost().getHostAddress();
- return;
- }
- }
- catch (UnknownHostException localUnknownHostException1)
- {
- try {
- if (checkServer(InetAddress.getLocalHost().getHostAddress())) {
- System.out.println("Got IP: " + InetAddress.getLocalHost().getHostAddress());
- System.out.println("Warning: It is recommended that you port forward 5000 as only users on your Local Network can access your texture pack!");
- this.ip = InetAddress.getLocalHost().getHostAddress();
- return;
- }
- }
- catch (UnknownHostException localUnknownHostException11) {
- if (checkServer("localhost")) {
- System.out.println("Got IP: localhost");
- System.out.println("Warning: It is recommended that you port forward 5000 as other users cannot access your texture pack!");
- this.ip = "localhost";
- return;
- }
- }
- }
- }
- @Override
- public boolean onCommand(final CommandSender sender, Command command, String label, final String[] args) {
- if(sender instanceof Player){
- @SuppressWarnings("unused")
- final Player player = (Player) sender;
- if(command.getName().equalsIgnoreCase("halo")){
- //Work on it when i have time. Prints CLEAN & THEMED help menu
- sender.sendMessage("§cPrint menu here");
- }
- }
- return false;
- }
- //Config shit
- public void createDefaultConfiguration(String name) {
- File actual = new File(getDataFolder(), name);
- if (!actual.exists()) {
- InputStream input =
- this.getClass().getResourceAsStream("/" + name);
- if (input != null) {
- FileOutputStream output = null;
- try {
- output = new FileOutputStream(actual);
- byte[] buf = new byte[8192];
- int length = 0;
- while ((length = input.read(buf)) > 0) {
- output.write(buf, 0, length);
- }
- System.out.println(getDescription().getName()
- + ": Default configuration file written: " + name);
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- if (input != null)
- input.close();
- } catch (IOException e) {}
- try {
- if (output != null)
- output.close();
- } catch (IOException e) {}
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement