From 0dcb9d4b6968584f9cf3c15f1089bfcff055034e Mon Sep 17 00:00:00 2001 From: aUniqueUser Date: Sat, 22 Feb 2020 20:12:43 -0500 Subject: [PATCH] Formatting --- .../pathing/calc/AbstractNodeCostSearch.java | 3 +- .../baritone/utils/NotificationHelper.java | 30 +++++++++++-------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java index baaeed8b..eea23905 100644 --- a/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java +++ b/src/main/java/baritone/pathing/calc/AbstractNodeCostSearch.java @@ -217,8 +217,9 @@ public abstract class AbstractNodeCostSearch implements IPathFinder, Helper { if (logInfo) { logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks"); logDebug("No path found =("); - if (Baritone.settings().desktopNotifications.value) + if (Baritone.settings().desktopNotifications.value) { NotificationHelper.notify("No path found =(", true); + } } return Optional.empty(); } diff --git a/src/main/java/baritone/utils/NotificationHelper.java b/src/main/java/baritone/utils/NotificationHelper.java index 927befb0..9ab0b545 100644 --- a/src/main/java/baritone/utils/NotificationHelper.java +++ b/src/main/java/baritone/utils/NotificationHelper.java @@ -20,12 +20,20 @@ package baritone.utils; import java.awt.*; import java.io.IOException; +/** + * This class is not called from the main game thread. + * Do not refer to any Minecraft classes, it wouldn't be thread safe. + * + * @author aUniqueUser + */ public class NotificationHelper { + public static void notify(String text, boolean error) { - if (System.getProperty("os.name").contains("Linux")) + if (System.getProperty("os.name").contains("Linux")) { linux(text); - else + } else { notification(text, error); + } } public static void notification(String text, boolean error) { @@ -33,30 +41,29 @@ public class NotificationHelper { try { SystemTray tray = SystemTray.getSystemTray(); Image image = Toolkit.getDefaultToolkit().createImage(""); - // Replace with some logo TrayIcon trayIcon = new TrayIcon(image, "Baritone"); trayIcon.setImageAutoSize(true); trayIcon.setToolTip("Baritone"); tray.add(trayIcon); - if(error) + if (error) { trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.ERROR); - else + } else { trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.INFO); - } - catch (Exception e) { + } + } catch (Exception e) { e.printStackTrace(); } - } - else { + } else { System.out.println("SystemTray is not supported"); } } /* - * The only way to display notifications on linux is to use the java-gnome library, or send notify-send to shell with a ProcessBuilder - * Unfortunately the java-gnome library is licenced under the GPL, see: (https://en.wikipedia.org/wiki/Java-gnome) + * The only way to display notifications on linux is to use the java-gnome library, + * or send notify-send to shell with a ProcessBuilder. Unfortunately the java-gnome + * library is licenced under the GPL, see (https://en.wikipedia.org/wiki/Java-gnome) */ public static void linux(String text) { @@ -67,6 +74,5 @@ public class NotificationHelper { } catch (IOException e) { e.printStackTrace(); } - } }