Gamebuster icon

GameBuSK.class

Gamebuster | PRO | 01/12/16 09:05:12 PM UTC | 0 ⭐ | 892 👁️ | Never ⏰ | []
Java |

10.36 KB

|

None

|

0 👍

/

0 👎

package com.gamebuster19901.GameBuSK;
 
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
 
import org.apache.ant.compress.taskdefs.Unzip;
import org.apache.commons.io.FileUtils;
import org.bukkit.plugin.java.JavaPlugin;
import org.openqa.selenium.WebElement;
 
import com.gamebuster19901.GameBuSK.conditions.CondIsBrowser;
import com.gamebuster19901.GameBuSK.effects.EffClickElement;
import com.gamebuster19901.GameBuSK.effects.EffCloseBrowser;
import com.gamebuster19901.GameBuSK.effects.EffGoToURL;
import com.gamebuster19901.GameBuSK.effects.EffNewTab;
import com.gamebuster19901.GameBuSK.effects.EffOpenBrowser;
import com.gamebuster19901.GameBuSK.effects.EffTypeToElement;
import com.gamebuster19901.GameBuSK.effects.GWebDriver;
import com.gamebuster19901.GameBuSK.expressions.ExprBrowserType;
import com.gamebuster19901.GameBuSK.expressions.ExprGetAllWindows;
import com.gamebuster19901.GameBuSK.expressions.ExprGetBrowser;
import com.gamebuster19901.GameBuSK.expressions.ExprGetElement;
import com.gamebuster19901.GameBuSK.expressions.ExprKey;
import com.gamebuster19901.GameBuSK.expressions.ExprPitch;
import com.gamebuster19901.GameBuSK.expressions.ExprYaw;
import com.gamebuster19901.GameBuSK.misc.*;
import com.gamebuster19901.GameBuSK.types.BrowserType;
import com.gamebuster19901.GameBuSK.types.Element;
import com.gamebuster19901.GameBuSK.types.KeyType;
import com.gamebuster19901.GameBuSK.types.SearchType;
 
import ch.njol.skript.Skript;
import ch.njol.skript.conditions.base.PropertyCondition;
import ch.njol.skript.lang.ExpressionType;
 
public class GameBuSK extends JavaPlugin {
    //the operating system
    public static String os;
    public static Boolean debug;
    public static File firefoxFL;
    public static void main(String args[]){
        //need main method so maven dosn't fuck up
    }
    
    public void onEnable() {
        boolean googleDriverExists = false;
        //boolean firefoxDriverExists = false;
        String path = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
        
        path = path.substring(0, path.lastIndexOf("/"));
        path = path.replaceAll("%20", " ");
        
        File chromeD = new File(path + "/GameBuSK/dependencies/chrome.zip"); //directory of zip
        File firefoxD = new File(path + "/GameBuSK/dependencies/firefox.zip"); //directory of zip
        File chromeF = null; //final directory
        File firefoxF = null; //final directory
        String chromeFL = null; //final directory location (includes file suffix)
        firefoxFL = null; //final directory location (includes file suffix)
        
        URL chromeLoc = null; //Where the chrome download is located on the internet
        URL firefoxLoc = null; //Where the firefox download is located on the internet
        
        if (!getConfig().contains("Chrome")){
            getConfig().set("Chrome", false);
            getLogger().info("Chrome is false");
        }
        if (!getConfig().contains("Firefox")){
            getConfig().set("Firefox", false);
            getLogger().info("Firefox is false");
        }
        if (!getConfig().contains("Linux")){
            getConfig().set("Linux", false);
            getLogger().info("Linux is false");
        }
        if(!getConfig().contains("operating system")){
            getConfig().set("operating system", System.getProperty("os.name"));
            getLogger().info("OS is " + System.getProperty("os.name"));
        }
        if (!getConfig().contains("debug")){
            getConfig().set("debug", false);
        }
        debug = getConfig().getBoolean("debug");
        if (getConfig().getString("operating system").contains("Windows")){
            os = "Windows";
            Debug.Debug("Operating system is windows");
            chromeF = new File(path + "/GameBuSK/dependencies/chromedriver");
            chromeFL = chromeF + "/chromedriver.exe";
            firefoxF = new File(path + "/GameBuSK/dependencies/firefoxdriver");
            firefoxFL = new File(firefoxF + "/firefoxdriver.exe");
            Debug.Debug("defined new file " + chromeF);
            //Debug.Debug("defined new file " + firefoxF);
            try {
                chromeLoc = new URL("http://chromedriver.storage.googleapis.com/2.20/chromedriver_win32.zip");
                Debug.Debug("Downloading chrome from " + chromeLoc);
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                firefoxLoc = new URL("https://github.com/jgraham/wires/releases/download/v0.5.0/wires-v0.5.0-win.zip");
                Debug.Debug("Downloading firefox from " + chromeLoc);
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
 
        }
        else if (getConfig().getString("operating system").contains("Linux")){
            os = "Linux";
            chromeF = new File(path + "/GameBuSK/dependencies/chromedriver");
            chromeFL = chromeF + "/chromedriver";
            firefoxF = new File(path + "/GameBuSK/dependencies/firefoxdriver");
            try {
                chromeLoc = new URL("http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux32.zip");
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                firefoxLoc = new URL("https://github.com/jgraham/wires/releases/download/v0.5.0/wires-0.5.0-linux64.gz");
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
 
        }
        else if (getConfig().getString("operating system").contains("Mac")||getConfig().getString("operating system").contains("OS X")){
            os = "Mac";
            chromeF = new File(path + "/GameBuSK/dependencies/chromedriver");
            chromeFL = chromeF + "/chromedriver";
            firefoxF = new File(path + "/GameBuSK/dependencies/firefoxdriver");
            try {
                chromeLoc = new URL("http://chromedriver.storage.googleapis.com/2.20/chromedriver_mac32.zip");
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            try {
                chromeLoc = new URL ("https://github.com/jgraham/wires/releases/download/v0.5.0/wires-0.5.0-osx.gz");
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        else{
            getLogger().severe("Selenium does not support this operating system");
        }
 
        
        if (getConfig().getBoolean("Chrome")){
            if (!chromeF.exists()) {
                getLogger().info("Chrome has been enabled but the driver has not been downloaded... downloading now. Please do not close the server.");
                try {
                    FileUtils.copyURLToFile(chromeLoc, chromeD);
                    getLogger().info("Unzipping file...");
                    Unzip chromeUnzip = new Unzip();
                    chromeUnzip.setSrc(chromeD);
                    chromeUnzip.setDest(chromeF);
                    chromeUnzip.execute();
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                catch (NullPointerException e){
                    getLogger().severe("Operating system not supported, could not download chrome.");
                }
            }
        }
        /*
        if (getConfig().getBoolean("Firefox")){
            if (!firefoxF.exists()){
                getLogger().info("Firefox has been enabled but the driver has not been downloaded... downloading now. Please do not close the server.");
                try{
                    FileUtils.copyURLToFile(firefoxLoc, firefoxD);
                    getLogger().info("Unzipping file...");
                    Unzip firefoxUnzip = new Unzip();
                    firefoxUnzip.setSrc(firefoxD);
                    firefoxUnzip.setDest(firefoxF);
                    firefoxUnzip.execute(); 
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                catch (NullPointerException e){
                    getLogger().severe("Operating system not supported, could not download chrome.");
                }
            }
        }
        */
        if (chromeF.exists()){
            googleDriverExists = true;
            System.setProperty("webdriver.chrome.driver", chromeFL.toString()); //The chrome binary MUST be set in a system property
            Debug.Debug("set chrome driver property to " + chromeFL.toString());
            File theFile = new File(chromeFL);
            Debug.Debug("setting file \"theFile\" to \"" + chromeFL + "\"");
            Debug.Debug("can theFile execute?: " + theFile.canExecute()); //have to do the following because Ubuntu disables all executables by default.
            theFile.setExecutable(true);
            Debug.Debug("setting \"" + chromeFL + "\" as executable");
            Debug.Debug("now can theFile execute?: " + theFile.canExecute());
        }
        saveConfig();
        try{
            GWebDriver.register();
            BrowserType.register();
            Element.register();
            SearchType.register();
            KeyType.register();
            
            Skript.registerAddon(this);
            Skript.registerExpression(ExprYaw.class,Number.class,ExpressionType.PROPERTY,"[gamebuster's] [fixed] yaw of %location%","%location%'s [fixed] yaw");
            Skript.registerExpression(ExprPitch.class,Number.class,ExpressionType.PROPERTY,"[gamebuster's] [fixed] pitch of %location%","%location%'s [fixed] pitch");
            Skript.registerExpression(ExprGetBrowser.class, GWebDriver.class, ExpressionType.PROPERTY, "browser named %string%");
            Skript.registerExpression(ExprGetAllWindows.class, String.class, ExpressionType.SIMPLE, "all browsers");
            Skript.registerExpression(ExprBrowserType.class, BrowserType.class, ExpressionType.PROPERTY, "type of %browser%", "%browser%'s type");
            Skript.registerExpression(ExprGetElement.class, WebElement.class, ExpressionType.PROPERTY, "element found (by|using) %searchtype% [with parameter] %string% in %browser%");
            Skript.registerExpression(ExprKey.class, String.class, ExpressionType.PROPERTY, "%keytype% [key]");
            
            Skript.registerEffect(EffGoToURL.class, "(go to|open) [url] %string% in %browser%", "set %browser%'s url to %string%");
            Skript.registerEffect(EffNewTab.class, "open new tab in %browser%");
            Skript.registerEffect(EffCloseBrowser.class, "close browser %browser%");
            Skript.registerEffect(EffOpenBrowser.class, "open %browsertype% [browser] named %string%");
            Skript.registerEffect(EffClickElement.class, "click %element%");
            Skript.registerEffect(EffTypeToElement.class, "send [key[s]] %string% to %element%");
            
            PropertyCondition.register(CondIsBrowser.class, "browsertype", "browsertype");
            //types|Text|String 
            getLogger().info("Do not take life too seriously. You will never get out of it alive.");
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }
    
    public void onDisable() {
        double n = Math.random() * 100;
        if (n < 50){
            getLogger().info("NO GOD! NO GOD PLEASE NO, NOO NOOO.... NOOOOOOOOOOOOOOOOOOOO!");
        }
        else{
            getLogger().info("Y u do dis 3:");
        }
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎