From c3b42035543ed1e3028ee1c8925c8587c0f55378 Mon Sep 17 00:00:00 2001 From: Emma Stone Date: Wed, 11 Jan 2017 22:57:53 +0000 Subject: [PATCH 01/21] [FEATURE] Added Library To The Client #requiresJar() should be changed. --- pom.xml | 2 +- .../core/lib/jpushbullet/JPushBullet.java | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java diff --git a/pom.xml b/pom.xml index 0f5810a..4944707 100755 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.parabot client - 2.6.2 + 2.6.3 jar diff --git a/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java b/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java new file mode 100644 index 0000000..6f0242b --- /dev/null +++ b/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java @@ -0,0 +1,71 @@ +package org.parabot.core.lib.jpushbullet; + +import org.parabot.core.Core; +import org.parabot.core.Directories; +import org.parabot.core.build.BuildPath; +import org.parabot.core.lib.Library; + +import java.io.File; +import java.net.URL; + +/** + * @author EmmaStone + */ +public class JPushBullet extends Library { + private static boolean valid; + + @Override + public void init() { + if (!hasJar()) { + System.err.println("Failed to load jpushbullet... [jar missing]"); + return; + } + Core.verbose("Adding jpushbullet jar file to build path: " + + getJarFileURL().getPath()); + BuildPath.add(getJarFileURL()); + + try { + Class.forName("com.shakethat.jpushbullet.net.PushbulletClient"); + valid = true; + } catch (ClassNotFoundException e) { + System.err + .println("Failed to add jpushbullet to build path, or incorrupt download"); + } + + Core.verbose("JPushBullet initialized."); + } + + @Override + public boolean isAdded() { + return valid; + } + + @Override + public File getJarFile() { + return new File(Directories.getCachePath(), "jpushbullet.jar"); + } + + @Override + public URL getDownloadLink() { + try { + return new URL("https://github.com/silk8192/jpushbullet/releases/download/1.0/jpushbullet-1.0.jar"); + } catch (Throwable t) { + t.printStackTrace(); + } + return null; + } + + @Override + public boolean requiresJar() { + return false; + } + + @Override + public String getLibraryName() { + return "JPushBullet"; + } + + public static boolean isValid() { + return valid; + } +} From 1817800135d619d24ba86cfc7487fa7da376afd5 Mon Sep 17 00:00:00 2001 From: Emma Stone Date: Wed, 11 Jan 2017 22:58:30 +0000 Subject: [PATCH 02/21] [BUGFIX] Made requiresJar true instead of false --- src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java b/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java index 6f0242b..0bd5078 100644 --- a/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java +++ b/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java @@ -57,7 +57,7 @@ public class JPushBullet extends Library { @Override public boolean requiresJar() { - return false; + return true; } @Override From d6f45ed9cbed88ff5585b08c5ad8205692b8c7c5 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 00:11:21 +0100 Subject: [PATCH 03/21] [BUGFIX] Added redirect for issue #161 For `exec(Ljava/lang/Runtime;[Ljava/lang/String;)Ljava/lang/Process;` --- .../core/asm/redirect/RuntimeRedirect.java | 61 ++++++++++--------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/src/main/java/org/parabot/core/asm/redirect/RuntimeRedirect.java b/src/main/java/org/parabot/core/asm/redirect/RuntimeRedirect.java index 41f48ef..f5074c2 100644 --- a/src/main/java/org/parabot/core/asm/redirect/RuntimeRedirect.java +++ b/src/main/java/org/parabot/core/asm/redirect/RuntimeRedirect.java @@ -5,35 +5,40 @@ import org.parabot.core.asm.RedirectClassAdapter; import java.io.IOException; public class RuntimeRedirect { - - public static Runtime getRuntime(){ - return Runtime.getRuntime(); - } - - public static int availableProcessors(Runtime r){ - return 2; - } - public static long totalMemory(Runtime runtime){ - return (long) 1024; - } + public static Runtime getRuntime() { + return Runtime.getRuntime(); + } - public static long freeMemory(Runtime runtime){ - return (long) 1024; - } - - public static Process exec(Runtime r,String s){ - if (s.contains("ping")){ - System.out.println("Faked attempted command: " + s); - try { - return r.exec("ping 127.0.0.1"); - } catch (IOException e) { - throw RedirectClassAdapter.createSecurityException(); - } - }else{ - System.out.println("Blocked attempted command: " + s); - throw RedirectClassAdapter.createSecurityException(); - } - } + public static int availableProcessors(Runtime r) { + return 2; + } + + public static long totalMemory(Runtime runtime) { + return (long) 1024; + } + + public static long freeMemory(Runtime runtime) { + return (long) 1024; + } + + public static Process exec(Runtime r, String[] s) { + System.out.println("Blocked attempted command: " + s); + throw RedirectClassAdapter.createSecurityException(); + } + + public static Process exec(Runtime r, String s) { + if (s.contains("ping")) { + System.out.println("Faked attempted command: " + s); + try { + return r.exec("ping 127.0.0.1"); + } catch (IOException e) { + throw RedirectClassAdapter.createSecurityException(); + } + } else { + System.out.println("Blocked attempted command: " + s); + throw RedirectClassAdapter.createSecurityException(); + } + } } From 7d591f015e77e51b9e37b02a050e8df7911035b9 Mon Sep 17 00:00:00 2001 From: Emma Stone Date: Fri, 3 Feb 2017 15:56:57 +0000 Subject: [PATCH 04/21] [BUGFIX] Fixed a bug in RandomType MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The id’s for the types were all the same --- .../java/org/parabot/environment/randoms/RandomType.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/parabot/environment/randoms/RandomType.java b/src/main/java/org/parabot/environment/randoms/RandomType.java index 250bd9a..3743812 100644 --- a/src/main/java/org/parabot/environment/randoms/RandomType.java +++ b/src/main/java/org/parabot/environment/randoms/RandomType.java @@ -6,9 +6,9 @@ package org.parabot.environment.randoms; public enum RandomType { SCRIPT(0, "Script"), - ON_SCRIPT_START(0, "On script start"), - ON_SERVER_START(0, "On server start"), - ON_SCRIPT_FINISH(0, "On script finish"); + ON_SCRIPT_START(1, "On script start"), + ON_SERVER_START(2, "On server start"), + ON_SCRIPT_FINISH(3, "On script finish"); private int id; private String name; From 5a2e12eb5496e203c1cbe999e63044b46944e5e7 Mon Sep 17 00:00:00 2001 From: Emma Stone Date: Fri, 3 Feb 2017 17:34:28 +0000 Subject: [PATCH 05/21] [BUGFIX] Remade validateCache Closes issue #167. --- src/main/java/org/parabot/core/Core.java | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/parabot/core/Core.java b/src/main/java/org/parabot/core/Core.java index 16f0204..ff70069 100644 --- a/src/main/java/org/parabot/core/Core.java +++ b/src/main/java/org/parabot/core/Core.java @@ -20,6 +20,7 @@ import java.net.URISyntaxException; import java.net.URLEncoder; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Date; /** * The core of parabot @@ -206,31 +207,20 @@ public class Core { } /** - * Validates the cache and removes the cache contents if required + * Method that removes the cache contents after 3 days */ private static void validateCache() { File[] cache = Directories.getCachePath().listFiles(); - Integer lowest = null; + if (cache != null) { for (File f : cache) { - int date = (int) (f.lastModified() / 1000); - if (lowest == null || date < lowest) { - lowest = date; + long age = new Date().getTime() - f.lastModified(); + + if (age > 3 * 24 * 60 * 60 * 1000) { + f.delete(); } } } - - try { - JSONObject object = (JSONObject) WebUtil.getJsonParser().parse(WebUtil.getContents("http://bdn.parabot.org/api/v2/bot/cache", "date=" + lowest)); - if ((boolean) object.get("result")) { - Core.verbose("Making space for the latest cache files"); - Directories.clearCache(); - } else { - Core.verbose("Cache is up to date"); - } - } catch (MalformedURLException | ParseException e) { - e.printStackTrace(); - } } public static void downloadNewVersion() { From 6be4aaf8999a2f39fb0fad377c143d87ac03a4b2 Mon Sep 17 00:00:00 2001 From: Emma Stone Date: Fri, 3 Feb 2017 19:02:22 +0000 Subject: [PATCH 06/21] [FEATURE] Added redirectErrorStream --- .../org/parabot/core/asm/redirect/ProcessBuilderRedirect.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/parabot/core/asm/redirect/ProcessBuilderRedirect.java b/src/main/java/org/parabot/core/asm/redirect/ProcessBuilderRedirect.java index 9df397d..ddee308 100644 --- a/src/main/java/org/parabot/core/asm/redirect/ProcessBuilderRedirect.java +++ b/src/main/java/org/parabot/core/asm/redirect/ProcessBuilderRedirect.java @@ -2,4 +2,7 @@ package org.parabot.core.asm.redirect; public class ProcessBuilderRedirect { + public static ProcessBuilder redirectErrorStream(ProcessBuilder pb, boolean redirectErrorStream) { + return pb; + } } From e18e59f502750a4943559f29a7728cc2626bfca2 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:02:13 +0100 Subject: [PATCH 07/21] [TASK] Updated internal API to 1.4.5 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c356eb2..a97cdad 100755 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ org.parabot internal-api - 1.4.46 + 1.4.5 From 801cd9f6d112aa8153176ccb68d3342871654978 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:02:31 +0100 Subject: [PATCH 08/21] [TASK] Removed invalid cache clearing --- src/main/java/org/parabot/core/Core.java | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/parabot/core/Core.java b/src/main/java/org/parabot/core/Core.java index ff70069..240b8be 100644 --- a/src/main/java/org/parabot/core/Core.java +++ b/src/main/java/org/parabot/core/Core.java @@ -210,17 +210,8 @@ public class Core { * Method that removes the cache contents after 3 days */ private static void validateCache() { - File[] cache = Directories.getCachePath().listFiles(); - - if (cache != null) { - for (File f : cache) { - long age = new Date().getTime() - f.lastModified(); - - if (age > 3 * 24 * 60 * 60 * 1000) { - f.delete(); - } - } - } + // Already handled by Directories initiating + // Method will be used once BDN V3 has a functionality for this } public static void downloadNewVersion() { From c451bb6d29226c49fc2cd33393c012462ed26ca3 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:02:45 +0100 Subject: [PATCH 09/21] [TASK] Moved StringUtils to Internal API StringUtil --- .../environment/api/utils/StringUtils.java | 48 ++----------------- 1 file changed, 3 insertions(+), 45 deletions(-) diff --git a/src/main/java/org/parabot/environment/api/utils/StringUtils.java b/src/main/java/org/parabot/environment/api/utils/StringUtils.java index 892c75b..8911317 100644 --- a/src/main/java/org/parabot/environment/api/utils/StringUtils.java +++ b/src/main/java/org/parabot/environment/api/utils/StringUtils.java @@ -1,52 +1,10 @@ package org.parabot.environment.api.utils; +import org.parabot.api.misc.StringUtil; + /** * @author mkyong, JKetelaar */ -public class StringUtils { +public class StringUtils extends StringUtil { - private static java.util.Random random = new java.util.Random(); - private static char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray(); - - public static String convertHexToString(String hex) { - - StringBuilder sb = new StringBuilder(); - StringBuilder temp = new StringBuilder(); - - for (int i = 0; i < hex.length() - 1; i += 2) { - - // grab the hex in pairs - String output = hex.substring(i, (i + 2)); - // convert hex to decimal - int decimal = Integer.parseInt(output, 16); - // convert the decimal to character - sb.append((char) decimal); - - temp.append(decimal); - } - - return sb.toString(); - } - - public static String implode(String separator, String... data) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < data.length - 1; i++) { - //data.length - 1 => to not add separator at the end - if (!data[i].matches(" *")) {//empty string are ""; " "; " "; and so on - sb.append(data[i]); - sb.append(separator); - } - } - sb.append(data[data.length - 1].trim()); - return sb.toString(); - } - - public static String randomString(final int length) { - StringBuilder sb = new StringBuilder(); - for (int i = 0; i < 20; i++) { - char c = chars[random.nextInt(chars.length)]; - sb.append(c); - } - return sb.toString(); - } } From f77aa730eed27e26e580a60f8bf0d069259ac478 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:03:01 +0100 Subject: [PATCH 10/21] [FEATURE] Added CacheValidation unit test --- .../java/org/parabot/CacheValidation.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/java/org/parabot/CacheValidation.java diff --git a/src/test/java/org/parabot/CacheValidation.java b/src/test/java/org/parabot/CacheValidation.java new file mode 100644 index 0000000..c9b8e8d --- /dev/null +++ b/src/test/java/org/parabot/CacheValidation.java @@ -0,0 +1,34 @@ +package org.parabot; + +import org.junit.Assert; +import org.junit.Test; +import org.parabot.core.Directories; + +import java.io.File; +import java.io.IOException; + +/** + * @author JKetelaar + */ +public class CacheValidation { + + @Test + public void test(){ + try { + File fileOne = new File(Directories.getCachePath(), "should-exist.tmp"); + File fileTwo = new File(Directories.getCachePath(), "should-not-exist.tmp"); + + fileOne.createNewFile(); + fileTwo.createNewFile(); + + fileTwo.setLastModified(System.currentTimeMillis() / 1000 - 350000); + + Directories.clearCache(259200, false); + + Assert.assertTrue(fileOne.exists()); + Assert.assertTrue(!fileTwo.exists()); + } catch (IOException e) { + e.printStackTrace(); + } + } +} From 296025cbb2ce7b001672d6e8d7de63c29b75edfd Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:10:05 +0100 Subject: [PATCH 11/21] [BUGFIX] Renamed CacheValidation to CacheValidationTest Allowing JUnit to understand it has to run this test too --- .../parabot/{CacheValidation.java => CacheValidationTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/test/java/org/parabot/{CacheValidation.java => CacheValidationTest.java} (95%) diff --git a/src/test/java/org/parabot/CacheValidation.java b/src/test/java/org/parabot/CacheValidationTest.java similarity index 95% rename from src/test/java/org/parabot/CacheValidation.java rename to src/test/java/org/parabot/CacheValidationTest.java index c9b8e8d..e966b78 100644 --- a/src/test/java/org/parabot/CacheValidation.java +++ b/src/test/java/org/parabot/CacheValidationTest.java @@ -10,7 +10,7 @@ import java.io.IOException; /** * @author JKetelaar */ -public class CacheValidation { +public class CacheValidationTest { @Test public void test(){ From 0badb2f0947cffb22d8aff895371cd78866d8f4e Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:19:39 +0100 Subject: [PATCH 12/21] [BUGFIX] Added maven test requirement --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 780a3d9..e3121ac 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,9 @@ before_install: install: - sudo apt-get update && sudo apt-get --assume-yes install zip unzip -script: "./.travis/maven-build.sh" +script: + - mvn test + - "./.travis/maven-build.sh" after_deploy: "./.travis/call-creation.sh" From 3198b3aff9dec835d8f0b6be69eded80c6e2eff7 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:22:19 +0100 Subject: [PATCH 13/21] [BUGFIX] Added throwable to method, instead of catching --- .../java/org/parabot/CacheValidationTest.java | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/test/java/org/parabot/CacheValidationTest.java b/src/test/java/org/parabot/CacheValidationTest.java index e966b78..cecaed6 100644 --- a/src/test/java/org/parabot/CacheValidationTest.java +++ b/src/test/java/org/parabot/CacheValidationTest.java @@ -13,22 +13,18 @@ import java.io.IOException; public class CacheValidationTest { @Test - public void test(){ - try { - File fileOne = new File(Directories.getCachePath(), "should-exist.tmp"); - File fileTwo = new File(Directories.getCachePath(), "should-not-exist.tmp"); + public void test() throws IOException { + File fileOne = new File(Directories.getCachePath(), "should-exist.tmp"); + File fileTwo = new File(Directories.getCachePath(), "should-not-exist.tmp"); - fileOne.createNewFile(); - fileTwo.createNewFile(); + fileOne.createNewFile(); + fileTwo.createNewFile(); - fileTwo.setLastModified(System.currentTimeMillis() / 1000 - 350000); + fileTwo.setLastModified(System.currentTimeMillis() / 1000 - 350000); - Directories.clearCache(259200, false); + Directories.clearCache(259200, false); - Assert.assertTrue(fileOne.exists()); - Assert.assertTrue(!fileTwo.exists()); - } catch (IOException e) { - e.printStackTrace(); - } + Assert.assertTrue(fileOne.exists()); + Assert.assertTrue(!fileTwo.exists()); } } From 1b2375145ca5cfc802dfa00fe20e49cc81d21ca4 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:22:46 +0100 Subject: [PATCH 14/21] [TASK] Removed mvn test --- .travis.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e3121ac..780a3d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,9 +12,7 @@ before_install: install: - sudo apt-get update && sudo apt-get --assume-yes install zip unzip -script: - - mvn test - - "./.travis/maven-build.sh" +script: "./.travis/maven-build.sh" after_deploy: "./.travis/call-creation.sh" From f58eef3c62662913e0450f973e13e8cc498769fe Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 21:25:34 +0100 Subject: [PATCH 15/21] [BUGFIX] Added validate to create required directories --- src/test/java/org/parabot/CacheValidationTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/parabot/CacheValidationTest.java b/src/test/java/org/parabot/CacheValidationTest.java index cecaed6..24aa1de 100644 --- a/src/test/java/org/parabot/CacheValidationTest.java +++ b/src/test/java/org/parabot/CacheValidationTest.java @@ -14,6 +14,8 @@ public class CacheValidationTest { @Test public void test() throws IOException { + Directories.validate(); + File fileOne = new File(Directories.getCachePath(), "should-exist.tmp"); File fileTwo = new File(Directories.getCachePath(), "should-not-exist.tmp"); From 3f5aaf42b64d4474ea800bf9056f95382e98d145 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Fri, 3 Feb 2017 22:49:34 +0100 Subject: [PATCH 16/21] [TASK] Seperated library loading Allowing to load libraries into the environment, seperated from loading the entire environment --- .../org/parabot/environment/Environment.java | 73 +++++++++++-------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/parabot/environment/Environment.java b/src/main/java/org/parabot/environment/Environment.java index e17d0fd..b3ba652 100644 --- a/src/main/java/org/parabot/environment/Environment.java +++ b/src/main/java/org/parabot/environment/Environment.java @@ -12,40 +12,49 @@ import java.util.LinkedList; /** - * - * Initiliazes the bot environment - * - * @author Everel - * + * Initializes the bot environment + * + * @author Everel, JKetelaar */ public class Environment { - /** - * Loads a new environment - * - * @param desc - */ - public static void load(final ServerDescription desc) { - - LinkedList libs = new LinkedList<>(); - libs.add(new JavaFX()); - - for(Library lib : libs) { - if (lib.requiresJar()) { - if (!lib.hasJar()) { - Core.verbose("Downloading " + lib.getLibraryName() + "..."); - VerboseLoader.setState("Downloading " + lib.getLibraryName() + "..."); - WebUtil.downloadFile(lib.getDownloadLink(), lib.getJarFile(), VerboseLoader.get()); - Core.verbose("Downloaded " + lib.getLibraryName() + "."); - } - Core.verbose("Initializing " + lib.getLibraryName()); - lib.init(); - } - } - - Core.verbose("Loading server: " + desc.toString() + "..."); + /** + * Loads a new environment + * + * @param desc + */ + public static void load(final ServerDescription desc) { - ServerParser.SERVER_CACHE.get(desc).run(); - - } + LinkedList libs = new LinkedList<>(); + libs.add(new JavaFX()); + + for (Library lib : libs) { + loadLibrary(lib, true); + } + + Core.verbose("Loading server: " + desc.toString() + "..."); + + ServerParser.SERVER_CACHE.get(desc).run(); + } + + /** + * Loads library into environment + * + * @param library + * @param verboseLoader defines if verboseLoader should be enabled + */ + public static void loadLibrary(Library library, boolean verboseLoader) { + if (library.requiresJar()) { + if (!library.hasJar()) { + Core.verbose("Downloading " + library.getLibraryName() + "..."); + if (verboseLoader) { + VerboseLoader.setState("Downloading " + library.getLibraryName() + "..."); + } + WebUtil.downloadFile(library.getDownloadLink(), library.getJarFile(), VerboseLoader.get()); + Core.verbose("Downloaded " + library.getLibraryName() + "."); + } + Core.verbose("Initializing " + library.getLibraryName()); + library.init(); + } + } } From e7f4c6a15ce34979974c9336ce93f77c492986c8 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Sun, 5 Feb 2017 18:47:07 +0100 Subject: [PATCH 17/21] [BUGFIX] Removed user.home property --- .../org/parabot/core/asm/redirect/SystemRedirect.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/parabot/core/asm/redirect/SystemRedirect.java b/src/main/java/org/parabot/core/asm/redirect/SystemRedirect.java index f18fe1f..5ddfe88 100644 --- a/src/main/java/org/parabot/core/asm/redirect/SystemRedirect.java +++ b/src/main/java/org/parabot/core/asm/redirect/SystemRedirect.java @@ -26,14 +26,12 @@ public class SystemRedirect { public static String getProperty(String s) { String value; switch (s) { - case "user.home": - value = Directories.getCachePath().getAbsolutePath(); - break; case "java.class.path": value = "."; break; default: value = System.getProperty(s); + break; } System.out.printf("GetSystemProp %s = %s\n", s, value); return value; @@ -42,9 +40,6 @@ public class SystemRedirect { public static String getProperty(String s, String s2) { String value = null; switch (s2) { - case "user.home": - value = Directories.getCachePath().getAbsolutePath(); - break; case "java.class.path": value = "."; break; @@ -52,14 +47,12 @@ public class SystemRedirect { if (value == null) { switch (s) { - case "user.home": - value = Directories.getCachePath().getAbsolutePath(); - break; case "java.class.path": value = "."; break; default: value = System.getProperty(s); + break; } } System.out.printf("GetSystemProp %s = %s\n", s, value); From d9230448dd1b86289e93348708a47484a0551afd Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Sun, 5 Feb 2017 21:00:47 +0100 Subject: [PATCH 18/21] [CLEANUP] Added brackets and set output to err --- .../core/asm/redirect/ClassRedirect.java | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/parabot/core/asm/redirect/ClassRedirect.java b/src/main/java/org/parabot/core/asm/redirect/ClassRedirect.java index 40fc7a4..8de3935 100644 --- a/src/main/java/org/parabot/core/asm/redirect/ClassRedirect.java +++ b/src/main/java/org/parabot/core/asm/redirect/ClassRedirect.java @@ -1,5 +1,6 @@ package org.parabot.core.asm.redirect; +import org.parabot.core.Core; import org.parabot.core.asm.RedirectClassAdapter; import org.parabot.environment.scripts.Script; @@ -11,9 +12,11 @@ import java.lang.reflect.Method; public class ClassRedirect { public static Object newInstance(Class c) throws IllegalAccessException, InstantiationException { - if (validStack()){ + if (validStack()) { return c.newInstance(); } + + System.err.println(c.getName() + ".newInstance() Blocked."); throw RedirectClassAdapter.createSecurityException(); } @@ -22,7 +25,7 @@ public class ClassRedirect { return c.getDeclaredField(s); } - System.out.println(c.getName() + "." + c.getDeclaredField(s) + " Blocked."); + System.err.println(c.getName() + "." + c.getDeclaredField(s) + " Blocked."); throw RedirectClassAdapter.createSecurityException(); } @@ -31,17 +34,20 @@ public class ClassRedirect { return c.getDeclaredMethod(name, params); } - System.out.println(c.getName() + "#" + c.getDeclaredMethod(name, params) + " Blocked."); + System.err.println(c.getName() + "#" + c.getDeclaredMethod(name, params) + " Blocked."); throw RedirectClassAdapter.createSecurityException(); } public static Class forName(String name) throws ClassNotFoundException { - if (name.contains("parabot")) + if (name.contains("parabot")) { throw new ClassNotFoundException(); + } + Core.verbose("Received #forName(" + name + ") call"); return Class.forName(name); } public static ClassLoader getClassLoader(Class c) { + System.err.println(c.getName() + "#getClassLoader()" + " Blocked."); throw RedirectClassAdapter.createSecurityException(); } @@ -49,7 +55,7 @@ public class ClassRedirect { if (validStack()) { return c.getDeclaredFields(); } - System.out.println(c.getName() + "#getDeclaredFields()" + " Blocked."); + System.err.println(c.getName() + "#getDeclaredFields()" + " Blocked."); throw RedirectClassAdapter.createSecurityException(); } @@ -57,31 +63,31 @@ public class ClassRedirect { if (validStack()) { return c.getDeclaredMethods(); } - System.out.println(c.getName() + "#getDeclaredMethods()" + " Blocked."); + System.err.println(c.getName() + "#getDeclaredMethods()" + " Blocked."); throw RedirectClassAdapter.createSecurityException(); } - public static Field[] getFields(Class c){ + public static Field[] getFields(Class c) { if (validStack()) { return c.getFields(); } - System.out.println(c.getName() + "#getFields()" + " Blocked."); + System.err.println(c.getName() + "#getFields()" + " Blocked."); throw RedirectClassAdapter.createSecurityException(); } - public static Annotation[] getAnnotations(Class c){ - if (validStack()){ + public static Annotation[] getAnnotations(Class c) { + if (validStack()) { return c.getAnnotations(); } - System.out.println(c.getName() + "#getFields()" + " Blocked."); + System.err.println(c.getName() + "#getFields()" + " Blocked."); throw RedirectClassAdapter.createSecurityException(); } - public static Method[] getMethods(Class c){ + public static Method[] getMethods(Class c) { if (validStack()) { return c.getMethods(); } - System.out.println(c.getName() + "#getMethods()" + " Blocked."); + System.err.println(c.getName() + "#getMethods()" + " Blocked."); throw RedirectClassAdapter.createSecurityException(); } @@ -89,7 +95,7 @@ public class ClassRedirect { if (validStack()) { return c.getMethod(name, params); } - System.out.println(c.getName() + "#getMethod()" + " Blocked."); + System.err.println(c.getName() + "#getMethod()" + " Blocked."); throw RedirectClassAdapter.createSecurityException(); } @@ -98,13 +104,14 @@ public class ClassRedirect { if (validStack()) { return c.getField(name); } - System.out.println(c.getName() + "#getField()" + " Blocked."); + System.err.println(c.getName() + "#getField()" + " Blocked."); throw RedirectClassAdapter.createSecurityException(); } public static String getName(Class c) { - if (c.getName().contains("parabot")) + if (c.getName().contains("parabot")) { return "java.lang.String"; + } return c.getName(); } From 6559261154ec89af30512c4fd7b23f384a0e2669 Mon Sep 17 00:00:00 2001 From: Emma Stone Date: Mon, 6 Feb 2017 17:22:53 +0000 Subject: [PATCH 19/21] [TASK] Updated download link --- .../java/org/parabot/core/lib/jpushbullet/JPushBullet.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java b/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java index 0bd5078..0f7fdfc 100644 --- a/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java +++ b/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java @@ -1,5 +1,6 @@ package org.parabot.core.lib.jpushbullet; +import org.parabot.core.Configuration; import org.parabot.core.Core; import org.parabot.core.Directories; import org.parabot.core.build.BuildPath; @@ -48,7 +49,7 @@ public class JPushBullet extends Library { @Override public URL getDownloadLink() { try { - return new URL("https://github.com/silk8192/jpushbullet/releases/download/1.0/jpushbullet-1.0.jar"); + return new URL(Configuration.LIBRARIES_DOWNLOAD + "/JPushBullet"); } catch (Throwable t) { t.printStackTrace(); } From f7c1c47fe844293d016bce9d2f88bfa72d0ce079 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Mon, 6 Feb 2017 19:50:04 +0100 Subject: [PATCH 20/21] [BUGFIX] Updated internal API version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b3f6630..4c9fcaf 100755 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ org.parabot internal-api - 1.4.5 + 1.4.5.1 From bff0bfbe6a4dc498f2c17908ff3e5650e7de0fb1 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Tue, 7 Feb 2017 00:32:50 +0100 Subject: [PATCH 21/21] [FEATURE] Finished notifications system --- pom.xml | 2 +- .../org/parabot/core/build/BuildPath.java | 16 +--- .../java/org/parabot/core/lib/Library.java | 59 +------------- .../core/lib/jpushbullet/JPushBullet.java | 72 ------------------ src/main/java/org/parabot/core/ui/BotUI.java | 10 +++ .../notifications/NotificationUI.java | 20 +++++ .../NotificationUIController.java | 72 ++++++++++++++++++ .../org/parabot/environment/Environment.java | 12 +-- src/main/resources/storage/images/bell.png | Bin 0 -> 1171 bytes .../resources/storage/ui/notifications.fxml | 35 +++++++++ 10 files changed, 147 insertions(+), 151 deletions(-) delete mode 100644 src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java create mode 100644 src/main/java/org/parabot/core/ui/components/notifications/NotificationUI.java create mode 100644 src/main/java/org/parabot/core/ui/components/notifications/NotificationUIController.java create mode 100644 src/main/resources/storage/images/bell.png create mode 100644 src/main/resources/storage/ui/notifications.fxml diff --git a/pom.xml b/pom.xml index 4c9fcaf..3a412fd 100755 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ org.parabot internal-api - 1.4.5.1 + 1.51.1 diff --git a/src/main/java/org/parabot/core/build/BuildPath.java b/src/main/java/org/parabot/core/build/BuildPath.java index b80e78e..5ca4971 100644 --- a/src/main/java/org/parabot/core/build/BuildPath.java +++ b/src/main/java/org/parabot/core/build/BuildPath.java @@ -1,9 +1,5 @@ package org.parabot.core.build; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; - /** * * Class used for adding urls to the buildpath @@ -11,16 +7,6 @@ import java.net.URLClassLoader; * @author Everel * */ -public class BuildPath { - - public static void add(final URL url) { - try { - Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); - method.setAccessible(true); - method.invoke((URLClassLoader) ClassLoader.getSystemClassLoader(), url); - } catch (Exception e) { - e.printStackTrace(); - } - } +public class BuildPath extends org.parabot.api.io.build.BuildPath { } diff --git a/src/main/java/org/parabot/core/lib/Library.java b/src/main/java/org/parabot/core/lib/Library.java index 9ac49e5..c8a7645 100644 --- a/src/main/java/org/parabot/core/lib/Library.java +++ b/src/main/java/org/parabot/core/lib/Library.java @@ -1,67 +1,10 @@ package org.parabot.core.lib; -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; - /** * * @author Everel * */ -public abstract class Library { - - /** - * Determines if this library jar has already been downloaded. - * @return false if library jar has not been downloaded, otherwise true - */ - public boolean hasJar() { - return getJarFile().exists(); - } - - /** - * Adds the library to the buildpath and validates if it has been added - */ - public abstract void init(); - - /** - * Determines if library has been added to the buildpath - * @return true if library has been added to the buildpath, otherwise false. - */ - public abstract boolean isAdded(); - - /** - * Gets the local file target/location of the jar file - * @return local file (target) to library - */ - public abstract File getJarFile(); - - /** - * Gets download url to the library - * @return url - */ - public abstract URL getDownloadLink(); - - /** - * Defines if the system requires a jar - * @return boolean - */ - public abstract boolean requiresJar(); - - - /** - * Fetches URL from {@link Library#getJarFile()} - * @return URL to local library jar file - */ - public URL getJarFileURL() { - try { - return getJarFile().toURI().toURL(); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - return null; - } - - public abstract String getLibraryName(); +public abstract class Library extends org.parabot.api.io.libraries.Library { } diff --git a/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java b/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java deleted file mode 100644 index 0f7fdfc..0000000 --- a/src/main/java/org/parabot/core/lib/jpushbullet/JPushBullet.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.parabot.core.lib.jpushbullet; - -import org.parabot.core.Configuration; -import org.parabot.core.Core; -import org.parabot.core.Directories; -import org.parabot.core.build.BuildPath; -import org.parabot.core.lib.Library; - -import java.io.File; -import java.net.URL; - -/** - * @author EmmaStone - */ -public class JPushBullet extends Library { - private static boolean valid; - - @Override - public void init() { - if (!hasJar()) { - System.err.println("Failed to load jpushbullet... [jar missing]"); - return; - } - Core.verbose("Adding jpushbullet jar file to build path: " - + getJarFileURL().getPath()); - BuildPath.add(getJarFileURL()); - - try { - Class.forName("com.shakethat.jpushbullet.net.PushbulletClient"); - valid = true; - } catch (ClassNotFoundException e) { - System.err - .println("Failed to add jpushbullet to build path, or incorrupt download"); - } - - Core.verbose("JPushBullet initialized."); - } - - @Override - public boolean isAdded() { - return valid; - } - - @Override - public File getJarFile() { - return new File(Directories.getCachePath(), "jpushbullet.jar"); - } - - @Override - public URL getDownloadLink() { - try { - return new URL(Configuration.LIBRARIES_DOWNLOAD + "/JPushBullet"); - } catch (Throwable t) { - t.printStackTrace(); - } - return null; - } - - @Override - public boolean requiresJar() { - return true; - } - - @Override - public String getLibraryName() { - return "JPushBullet"; - } - - public static boolean isValid() { - return valid; - } -} diff --git a/src/main/java/org/parabot/core/ui/BotUI.java b/src/main/java/org/parabot/core/ui/BotUI.java index e2f8b1c..8ec5532 100644 --- a/src/main/java/org/parabot/core/ui/BotUI.java +++ b/src/main/java/org/parabot/core/ui/BotUI.java @@ -1,10 +1,12 @@ package org.parabot.core.ui; +import javafx.application.Application; import org.parabot.core.Configuration; import org.parabot.core.Context; import org.parabot.core.Directories; import org.parabot.core.ui.components.GamePanel; import org.parabot.core.ui.components.VerboseLoader; +import org.parabot.core.ui.components.notifications.NotificationUI; import org.parabot.core.ui.images.Images; import org.parabot.core.ui.utils.SwingUtil; import org.parabot.environment.OperatingSystem; @@ -105,6 +107,9 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener, JMenuItem cacheClear = new JMenuItem("Clear cache"); cacheClear.setIcon(new ImageIcon(Images.getResource("/storage/images/trash.png"))); + JMenuItem notifications = new JMenuItem("Notifications"); + notifications.setIcon(new ImageIcon(Images.getResource("/storage/images/bell.png"))); + screenshot.addActionListener(this); proxy.addActionListener(this); randoms.addActionListener(this); @@ -113,6 +118,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener, explorer.addActionListener(this); exit.addActionListener(this); cacheClear.addActionListener(this); + notifications.addActionListener(this); run.addActionListener(this); pause.addActionListener(this); @@ -131,6 +137,7 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener, scripts.add(stop); features.add(cacheClear); + features.add(notifications); menuBar.add(file); menuBar.add(scripts); @@ -237,6 +244,9 @@ public class BotUI extends JFrame implements ActionListener, ComponentListener, case "Clear cache": Directories.clearCache(); break; + case "Notifications": + Application.launch(NotificationUI.class); + break; default: System.out.println("Invalid command: " + command); } diff --git a/src/main/java/org/parabot/core/ui/components/notifications/NotificationUI.java b/src/main/java/org/parabot/core/ui/components/notifications/NotificationUI.java new file mode 100644 index 0000000..bc55311 --- /dev/null +++ b/src/main/java/org/parabot/core/ui/components/notifications/NotificationUI.java @@ -0,0 +1,20 @@ +package org.parabot.core.ui.components.notifications; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.layout.BorderPane; +import javafx.stage.Stage; +import org.parabot.core.Configuration; + +public class NotificationUI extends Application { + + @Override + public void start(Stage stage) throws Exception { + //noinspection RedundantCast + BorderPane root = (BorderPane) FXMLLoader.load(this.getClass().getResource("/storage/ui/notifications.fxml")); + stage.setTitle(Configuration.BOT_TITLE); + stage.setScene(new Scene(root)); + stage.show(); + } +} \ No newline at end of file diff --git a/src/main/java/org/parabot/core/ui/components/notifications/NotificationUIController.java b/src/main/java/org/parabot/core/ui/components/notifications/NotificationUIController.java new file mode 100644 index 0000000..bc7a42d --- /dev/null +++ b/src/main/java/org/parabot/core/ui/components/notifications/NotificationUIController.java @@ -0,0 +1,72 @@ +package org.parabot.core.ui.components.notifications; + +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.ListView; +import javafx.stage.Stage; +import org.parabot.api.notifications.NotificationManager; +import org.parabot.api.notifications.types.NotificationType; + +import java.net.URL; +import java.util.ResourceBundle; + +/** + * @author JKetelaar + */ +public class NotificationUIController implements Initializable { + + @FXML // fx:id="availableTypes" + private ListView availableTypes; + + @FXML // fx:id="enabledTypes" + private ListView enabledTypes; + + @Override + public void initialize(URL location, ResourceBundle resources) { + this.refreshTypes(); + } + + private void refreshTypes() { + availableTypes.getItems().clear(); + for (NotificationType notificationType : NotificationManager.getContext().getAvailableNotificationTypes()) { + availableTypes.getItems().add(notificationType.getName()); + } + + enabledTypes.getItems().clear(); + for (NotificationType notificationType : NotificationManager.getContext().getEnabledTypes()) { + enabledTypes.getItems().add(notificationType.getName()); + } + } + + @FXML + private void enableType() { + Object object = availableTypes.getSelectionModel().getSelectedItem(); + if (object != null) { + String name = (String) object; + + NotificationType type = NotificationManager.getContext().getNotificationType(name); + NotificationManager.getContext().enableNotificationType(type); + + this.refreshTypes(); + } + } + + @FXML + private void disableType() { + Object object = enabledTypes.getSelectionModel().getSelectedItem(); + if (object != null) { + String name = (String) object; + + NotificationType type = NotificationManager.getContext().getNotificationType(name); + NotificationManager.getContext().disableNotificationType(type); + + this.refreshTypes(); + } + } + + @FXML + private void save() { + Stage stage = (Stage) this.enabledTypes.getScene().getWindow(); + stage.close(); + } +} diff --git a/src/main/java/org/parabot/environment/Environment.java b/src/main/java/org/parabot/environment/Environment.java index b3ba652..75b7bf8 100644 --- a/src/main/java/org/parabot/environment/Environment.java +++ b/src/main/java/org/parabot/environment/Environment.java @@ -16,7 +16,13 @@ import java.util.LinkedList; * * @author Everel, JKetelaar */ -public class Environment { +public class Environment extends org.parabot.api.io.libraries.Environment { + + private static LinkedList libs = new LinkedList<>(); + + static { + libs.add(new JavaFX()); + } /** * Loads a new environment @@ -24,10 +30,6 @@ public class Environment { * @param desc */ public static void load(final ServerDescription desc) { - - LinkedList libs = new LinkedList<>(); - libs.add(new JavaFX()); - for (Library lib : libs) { loadLibrary(lib, true); } diff --git a/src/main/resources/storage/images/bell.png b/src/main/resources/storage/images/bell.png new file mode 100644 index 0000000000000000000000000000000000000000..5aab10f65c708c3230bc3cb5d1fd1192a6ccf5dd GIT binary patch literal 1171 zcmeAS@N?(olHy`uVBq!ia0vp^oIuRO!3HEZ#7tidq$EpRBT9nv(@M${i&7aJQ}UBi z6+Ckj(^G>|6H_V+Po~;1FfglRhD4M^`1)8S=jZArg4F0$^BXQ!4Z zB&DWj=GiK}-@RW+Av48RDcsc8z_-9TH6zobswg$M$}c3jDm&RSMakYy!KT6rXh3di zNuokUZcbjYRfVk**jy_h8zii+qySb@l5ML5aa4qFfP!;=QL2Kep0RGSfuW&-nVFuU ziK&^Hp^k!)fuWJU0T7w#8k$&{npqi{D?ot~(6*wKG^-#NH>h1eo~=?wNlAf~zJ7Um zxn8-kUVc%!zM-Y1CCCgTBVC{h-Qvo;lEez#ykcdT2`;I{$wiq3C7Jno3Lp~`lk!VT zY?Xj6g?J&i0B&qvF*KNf0j6J(SfFpHX8`gNOrftYexnUy@&(kzb(T9Bihb;hUJ8nFkWk z1ncniwerj>E=kNwPW5!LRRWr!mzkMjWn^OD>SSqd>1yI?Vrb}UW?|y&;$Qa(k zcQrSF>2=9ZF3nBND}m`vLFjeFsTY(OatnYqyQCInmZhe+73JqDfIV%MiQ6saIL(9V zO~LIJ3!HlOfsWA!MJ-ZP!-Rn82gHOYTp$OY^i%VI>AeV;uzwj}UB|${$m;3h7*cVo zCBQnXH9){Nu6}`{!o@>s+#T8lqGj(CvJ3em9WR*miY3ht5;jS7s8Ha{=;(0COFN?- z_pw4!;@sSw#_8vJCImgQzdmbOW1>XFG}c53yEC6_*1!Ih9U9vBdRN4C(HFb;E}JNx z|E$e$Y110!#R5%&xwn~I13yTwTBUd7$Gz{iBCbE5Ii1=&C6!axH+bE|+uIudn0X3a zOO!7zxAEjT+z>2%ywE-Acfy+2Qc8Wv6E4g%(V5e;C_`UqoAfaSj(@v+FWXr3eJ(lW z;XD7yYq^Sf#}}!blg|I`ws@+%orHeHx-PSSLXp!lRl<_j?t5?lsXh1hd6~_Z4cAXq eKJEHjG=af9rg + + + + + + + + + + + + + + +
+ + +
+ + + +