From bff0bfbe6a4dc498f2c17908ff3e5650e7de0fb1 Mon Sep 17 00:00:00 2001 From: JKetelaar Date: Tue, 7 Feb 2017 00:32:50 +0100 Subject: [PATCH] [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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