Advertisement
Gamebuster

GameBuSK.class

Jan 12th, 2016
416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.36 KB | None | 0 0
  1. package com.gamebuster19901.GameBuSK;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7.  
  8. import org.apache.ant.compress.taskdefs.Unzip;
  9. import org.apache.commons.io.FileUtils;
  10. import org.bukkit.plugin.java.JavaPlugin;
  11. import org.openqa.selenium.WebElement;
  12.  
  13. import com.gamebuster19901.GameBuSK.conditions.CondIsBrowser;
  14. import com.gamebuster19901.GameBuSK.effects.EffClickElement;
  15. import com.gamebuster19901.GameBuSK.effects.EffCloseBrowser;
  16. import com.gamebuster19901.GameBuSK.effects.EffGoToURL;
  17. import com.gamebuster19901.GameBuSK.effects.EffNewTab;
  18. import com.gamebuster19901.GameBuSK.effects.EffOpenBrowser;
  19. import com.gamebuster19901.GameBuSK.effects.EffTypeToElement;
  20. import com.gamebuster19901.GameBuSK.effects.GWebDriver;
  21. import com.gamebuster19901.GameBuSK.expressions.ExprBrowserType;
  22. import com.gamebuster19901.GameBuSK.expressions.ExprGetAllWindows;
  23. import com.gamebuster19901.GameBuSK.expressions.ExprGetBrowser;
  24. import com.gamebuster19901.GameBuSK.expressions.ExprGetElement;
  25. import com.gamebuster19901.GameBuSK.expressions.ExprKey;
  26. import com.gamebuster19901.GameBuSK.expressions.ExprPitch;
  27. import com.gamebuster19901.GameBuSK.expressions.ExprYaw;
  28. import com.gamebuster19901.GameBuSK.misc.*;
  29. import com.gamebuster19901.GameBuSK.types.BrowserType;
  30. import com.gamebuster19901.GameBuSK.types.Element;
  31. import com.gamebuster19901.GameBuSK.types.KeyType;
  32. import com.gamebuster19901.GameBuSK.types.SearchType;
  33.  
  34. import ch.njol.skript.Skript;
  35. import ch.njol.skript.conditions.base.PropertyCondition;
  36. import ch.njol.skript.lang.ExpressionType;
  37.  
  38. public class GameBuSK extends JavaPlugin {
  39.     //the operating system
  40.     public static String os;
  41.     public static Boolean debug;
  42.     public static File firefoxFL;
  43.     public static void main(String args[]){
  44.         //need main method so maven dosn't fuck up
  45.     }
  46.    
  47.     public void onEnable() {
  48.         boolean googleDriverExists = false;
  49.         //boolean firefoxDriverExists = false;
  50.         String path = getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
  51.        
  52.         path = path.substring(0, path.lastIndexOf("/"));
  53.         path = path.replaceAll("%20", " ");
  54.        
  55.         File chromeD = new File(path + "/GameBuSK/dependencies/chrome.zip"); //directory of zip
  56.         File firefoxD = new File(path + "/GameBuSK/dependencies/firefox.zip"); //directory of zip
  57.         File chromeF = null; //final directory
  58.         File firefoxF = null; //final directory
  59.         String chromeFL = null; //final directory location (includes file suffix)
  60.         firefoxFL = null; //final directory location (includes file suffix)
  61.        
  62.         URL chromeLoc = null; //Where the chrome download is located on the internet
  63.         URL firefoxLoc = null; //Where the firefox download is located on the internet
  64.        
  65.         if (!getConfig().contains("Chrome")){
  66.             getConfig().set("Chrome", false);
  67.             getLogger().info("Chrome is false");
  68.         }
  69.         if (!getConfig().contains("Firefox")){
  70.             getConfig().set("Firefox", false);
  71.             getLogger().info("Firefox is false");
  72.         }
  73.         if (!getConfig().contains("Linux")){
  74.             getConfig().set("Linux", false);
  75.             getLogger().info("Linux is false");
  76.         }
  77.         if(!getConfig().contains("operating system")){
  78.             getConfig().set("operating system", System.getProperty("os.name"));
  79.             getLogger().info("OS is " + System.getProperty("os.name"));
  80.         }
  81.         if (!getConfig().contains("debug")){
  82.             getConfig().set("debug", false);
  83.         }
  84.         debug = getConfig().getBoolean("debug");
  85.         if (getConfig().getString("operating system").contains("Windows")){
  86.             os = "Windows";
  87.             Debug.Debug("Operating system is windows");
  88.             chromeF = new File(path + "/GameBuSK/dependencies/chromedriver");
  89.             chromeFL = chromeF + "/chromedriver.exe";
  90.             firefoxF = new File(path + "/GameBuSK/dependencies/firefoxdriver");
  91.             firefoxFL = new File(firefoxF + "/firefoxdriver.exe");
  92.             Debug.Debug("defined new file " + chromeF);
  93.             //Debug.Debug("defined new file " + firefoxF);
  94.             try {
  95.                 chromeLoc = new URL("http://chromedriver.storage.googleapis.com/2.20/chromedriver_win32.zip");
  96.                 Debug.Debug("Downloading chrome from " + chromeLoc);
  97.             } catch (MalformedURLException e) {
  98.                 // TODO Auto-generated catch block
  99.                 e.printStackTrace();
  100.             }
  101.             try {
  102.                 firefoxLoc = new URL("https://github.com/jgraham/wires/releases/download/v0.5.0/wires-v0.5.0-win.zip");
  103.                 Debug.Debug("Downloading firefox from " + chromeLoc);
  104.             } catch (MalformedURLException e) {
  105.                 // TODO Auto-generated catch block
  106.                 e.printStackTrace();
  107.             }
  108.  
  109.         }
  110.         else if (getConfig().getString("operating system").contains("Linux")){
  111.             os = "Linux";
  112.             chromeF = new File(path + "/GameBuSK/dependencies/chromedriver");
  113.             chromeFL = chromeF + "/chromedriver";
  114.             firefoxF = new File(path + "/GameBuSK/dependencies/firefoxdriver");
  115.             try {
  116.                 chromeLoc = new URL("http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux32.zip");
  117.             } catch (MalformedURLException e) {
  118.                 // TODO Auto-generated catch block
  119.                 e.printStackTrace();
  120.             }
  121.             try {
  122.                 firefoxLoc = new URL("https://github.com/jgraham/wires/releases/download/v0.5.0/wires-0.5.0-linux64.gz");
  123.             } catch (MalformedURLException e) {
  124.                 // TODO Auto-generated catch block
  125.                 e.printStackTrace();
  126.             }
  127.  
  128.         }
  129.         else if (getConfig().getString("operating system").contains("Mac")||getConfig().getString("operating system").contains("OS X")){
  130.             os = "Mac";
  131.             chromeF = new File(path + "/GameBuSK/dependencies/chromedriver");
  132.             chromeFL = chromeF + "/chromedriver";
  133.             firefoxF = new File(path + "/GameBuSK/dependencies/firefoxdriver");
  134.             try {
  135.                 chromeLoc = new URL("http://chromedriver.storage.googleapis.com/2.20/chromedriver_mac32.zip");
  136.             } catch (MalformedURLException e) {
  137.                 // TODO Auto-generated catch block
  138.                 e.printStackTrace();
  139.             }
  140.             try {
  141.                 chromeLoc = new URL ("https://github.com/jgraham/wires/releases/download/v0.5.0/wires-0.5.0-osx.gz");
  142.             } catch (MalformedURLException e) {
  143.                 // TODO Auto-generated catch block
  144.                 e.printStackTrace();
  145.             }
  146.         }
  147.         else{
  148.             getLogger().severe("Selenium does not support this operating system");
  149.         }
  150.  
  151.        
  152.         if (getConfig().getBoolean("Chrome")){
  153.             if (!chromeF.exists()) {
  154.                 getLogger().info("Chrome has been enabled but the driver has not been downloaded... downloading now. Please do not close the server.");
  155.                 try {
  156.                     FileUtils.copyURLToFile(chromeLoc, chromeD);
  157.                     getLogger().info("Unzipping file...");
  158.                     Unzip chromeUnzip = new Unzip();
  159.                     chromeUnzip.setSrc(chromeD);
  160.                     chromeUnzip.setDest(chromeF);
  161.                     chromeUnzip.execute();
  162.                 } catch (MalformedURLException e) {
  163.                     e.printStackTrace();
  164.                 } catch (IOException e) {
  165.                     e.printStackTrace();
  166.                 }
  167.                 catch (NullPointerException e){
  168.                     getLogger().severe("Operating system not supported, could not download chrome.");
  169.                 }
  170.             }
  171.         }
  172.         /*
  173.         if (getConfig().getBoolean("Firefox")){
  174.             if (!firefoxF.exists()){
  175.                 getLogger().info("Firefox has been enabled but the driver has not been downloaded... downloading now. Please do not close the server.");
  176.                 try{
  177.                     FileUtils.copyURLToFile(firefoxLoc, firefoxD);
  178.                     getLogger().info("Unzipping file...");
  179.                     Unzip firefoxUnzip = new Unzip();
  180.                     firefoxUnzip.setSrc(firefoxD);
  181.                     firefoxUnzip.setDest(firefoxF);
  182.                     firefoxUnzip.execute();
  183.                 } catch (MalformedURLException e) {
  184.                     // TODO Auto-generated catch block
  185.                     e.printStackTrace();
  186.                 } catch (IOException e) {
  187.                     // TODO Auto-generated catch block
  188.                     e.printStackTrace();
  189.                 }
  190.                 catch (NullPointerException e){
  191.                     getLogger().severe("Operating system not supported, could not download chrome.");
  192.                 }
  193.             }
  194.         }
  195.         */
  196.         if (chromeF.exists()){
  197.             googleDriverExists = true;
  198.             System.setProperty("webdriver.chrome.driver", chromeFL.toString()); //The chrome binary MUST be set in a system property
  199.             Debug.Debug("set chrome driver property to " + chromeFL.toString());
  200.             File theFile = new File(chromeFL);
  201.             Debug.Debug("setting file \"theFile\" to \"" + chromeFL + "\"");
  202.             Debug.Debug("can theFile execute?: " + theFile.canExecute()); //have to do the following because Ubuntu disables all executables by default.
  203.             theFile.setExecutable(true);
  204.             Debug.Debug("setting \"" + chromeFL + "\" as executable");
  205.             Debug.Debug("now can theFile execute?: " + theFile.canExecute());
  206.         }
  207.         saveConfig();
  208.         try{
  209.             GWebDriver.register();
  210.             BrowserType.register();
  211.             Element.register();
  212.             SearchType.register();
  213.             KeyType.register();
  214.            
  215.             Skript.registerAddon(this);
  216.             Skript.registerExpression(ExprYaw.class,Number.class,ExpressionType.PROPERTY,"[gamebuster's] [fixed] yaw of %location%","%location%'s [fixed] yaw");
  217.             Skript.registerExpression(ExprPitch.class,Number.class,ExpressionType.PROPERTY,"[gamebuster's] [fixed] pitch of %location%","%location%'s [fixed] pitch");
  218.             Skript.registerExpression(ExprGetBrowser.class, GWebDriver.class, ExpressionType.PROPERTY, "browser named %string%");
  219.             Skript.registerExpression(ExprGetAllWindows.class, String.class, ExpressionType.SIMPLE, "all browsers");
  220.             Skript.registerExpression(ExprBrowserType.class, BrowserType.class, ExpressionType.PROPERTY, "type of %browser%", "%browser%'s type");
  221.             Skript.registerExpression(ExprGetElement.class, WebElement.class, ExpressionType.PROPERTY, "element found (by|using) %searchtype% [with parameter] %string% in %browser%");
  222.             Skript.registerExpression(ExprKey.class, String.class, ExpressionType.PROPERTY, "%keytype% [key]");
  223.            
  224.             Skript.registerEffect(EffGoToURL.class, "(go to|open) [url] %string% in %browser%", "set %browser%'s url to %string%");
  225.             Skript.registerEffect(EffNewTab.class, "open new tab in %browser%");
  226.             Skript.registerEffect(EffCloseBrowser.class, "close browser %browser%");
  227.             Skript.registerEffect(EffOpenBrowser.class, "open %browsertype% [browser] named %string%");
  228.             Skript.registerEffect(EffClickElement.class, "click %element%");
  229.             Skript.registerEffect(EffTypeToElement.class, "send [key[s]] %string% to %element%");
  230.            
  231.             PropertyCondition.register(CondIsBrowser.class, "browsertype", "browsertype");
  232.             //types|Text|String
  233.             getLogger().info("Do not take life too seriously. You will never get out of it alive.");
  234.         }
  235.         catch (Exception e){
  236.             e.printStackTrace();
  237.         }
  238.     }
  239.    
  240.     public void onDisable() {
  241.         double n = Math.random() * 100;
  242.         if (n < 50){
  243.             getLogger().info("NO GOD! NO GOD PLEASE NO, NOO NOOO.... NOOOOOOOOOOOOOOOOOOOO!");
  244.         }
  245.         else{
  246.             getLogger().info("Y u do dis 3:");
  247.         }
  248.     }
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement