Formatting

This commit is contained in:
aUniqueUser 2020-02-22 20:12:43 -05:00
parent 2d2571cff5
commit 0dcb9d4b69
No known key found for this signature in database
GPG Key ID: 84D7C232A1AFDD16
2 changed files with 20 additions and 13 deletions

View File

@ -217,8 +217,9 @@ public abstract class AbstractNodeCostSearch implements IPathFinder, Helper {
if (logInfo) { if (logInfo) {
logDebug("Even with a cost coefficient of " + COEFFICIENTS[COEFFICIENTS.length - 1] + ", I couldn't get more than " + Math.sqrt(bestDist) + " blocks"); 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 =("); logDebug("No path found =(");
if (Baritone.settings().desktopNotifications.value) if (Baritone.settings().desktopNotifications.value) {
NotificationHelper.notify("No path found =(", true); NotificationHelper.notify("No path found =(", true);
}
} }
return Optional.empty(); return Optional.empty();
} }

View File

@ -20,12 +20,20 @@ package baritone.utils;
import java.awt.*; import java.awt.*;
import java.io.IOException; 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 class NotificationHelper {
public static void notify(String text, boolean error) { public static void notify(String text, boolean error) {
if (System.getProperty("os.name").contains("Linux")) if (System.getProperty("os.name").contains("Linux")) {
linux(text); linux(text);
else } else {
notification(text, error); notification(text, error);
}
} }
public static void notification(String text, boolean error) { public static void notification(String text, boolean error) {
@ -33,30 +41,29 @@ public class NotificationHelper {
try { try {
SystemTray tray = SystemTray.getSystemTray(); SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().createImage(""); Image image = Toolkit.getDefaultToolkit().createImage("");
// Replace with some logo
TrayIcon trayIcon = new TrayIcon(image, "Baritone"); TrayIcon trayIcon = new TrayIcon(image, "Baritone");
trayIcon.setImageAutoSize(true); trayIcon.setImageAutoSize(true);
trayIcon.setToolTip("Baritone"); trayIcon.setToolTip("Baritone");
tray.add(trayIcon); tray.add(trayIcon);
if(error) if (error) {
trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.ERROR); trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.ERROR);
else } else {
trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.INFO); trayIcon.displayMessage("Baritone", text, TrayIcon.MessageType.INFO);
} }
catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} } else {
else {
System.out.println("SystemTray is not supported"); 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 * The only way to display notifications on linux is to use the java-gnome library,
* Unfortunately the java-gnome library is licenced under the GPL, see: (https://en.wikipedia.org/wiki/Java-gnome) * 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) { public static void linux(String text) {
@ -67,6 +74,5 @@ public class NotificationHelper {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }