Move NotificationHelper to api and give Helper some methods for notifications

This commit is contained in:
ZacSharp 2021-05-09 23:15:34 +02:00
parent 2cb6402189
commit dc9ae67657
No known key found for this signature in database
GPG Key ID: 9453647B005083A3
8 changed files with 61 additions and 26 deletions

View File

@ -19,6 +19,7 @@ package baritone.api.utils;
import baritone.api.BaritoneAPI; import baritone.api.BaritoneAPI;
import baritone.api.utils.gui.BaritoneToast; import baritone.api.utils.gui.BaritoneToast;
import baritone.api.utils.NotificationHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentString;
@ -93,6 +94,48 @@ public interface Helper {
logToast(Helper.getPrefix(), new TextComponentString(message)); logToast(Helper.getPrefix(), new TextComponentString(message));
} }
/**
* Send a message as a desktop notification
*
* @param message The message to display in the notification
*/
default void logNotification(String message) {
logNotification(message, false);
}
/**
* Send a message as a desktop notification
*
* @param message The message to display in the notification
* @param error Whether to log as an error
*/
default void logNotification(String message, boolean error) {
if (BaritoneAPI.getSettings().desktopNotifications.value) {
logNotificationDirect(message, error);
}
}
/**
* Send a message as a desktop notification regardless of desktopNotifications
* (should only be used for critically important messages)
*
* @param message The message to display in the notification
*/
default void logNotificationDirect(String message) {
logNotificationDirect(message, false);
}
/**
* Send a message as a desktop notification regardless of desktopNotifications
* (should only be used for critically important messages)
*
* @param message The message to display in the notification
* @param error Whether to log as an error
*/
default void logNotificationDirect(String message, boolean error) {
NotificationHelper.notify(message, error);
}
/** /**
* Send a message to chat only if chatDebug is on * Send a message to chat only if chatDebug is on
* *

View File

@ -15,7 +15,7 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>. * along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/ */
package baritone.utils; package baritone.api.utils;
import org.apache.commons.lang3.SystemUtils; import org.apache.commons.lang3.SystemUtils;

View File

@ -25,7 +25,6 @@ import baritone.api.utils.BetterBlockPos;
import baritone.api.utils.Helper; import baritone.api.utils.Helper;
import baritone.api.utils.PathCalculationResult; import baritone.api.utils.PathCalculationResult;
import baritone.pathing.movement.CalculationContext; import baritone.pathing.movement.CalculationContext;
import baritone.utils.NotificationHelper;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.Optional; import java.util.Optional;
@ -217,9 +216,7 @@ 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) { logNotification("No path found =(", true);
NotificationHelper.notify("No path found =(", true);
}
} }
return Optional.empty(); return Optional.empty();
} }

View File

@ -40,7 +40,6 @@ import baritone.pathing.movement.Movement;
import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper; import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.NotificationHelper;
import baritone.utils.PathingCommandContext; import baritone.utils.PathingCommandContext;
import baritone.utils.schematic.MapArtSchematic; import baritone.utils.schematic.MapArtSchematic;
import baritone.utils.schematic.SchematicSystem; import baritone.utils.schematic.SchematicSystem;
@ -424,8 +423,8 @@ public final class BuilderProcess extends BaritoneProcessHelper implements IBuil
numRepeats++; numRepeats++;
if (repeat.equals(new Vec3i(0, 0, 0)) || (max != -1 && numRepeats >= max)) { if (repeat.equals(new Vec3i(0, 0, 0)) || (max != -1 && numRepeats >= max)) {
logDirect("Done building"); logDirect("Done building");
if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnBuildFinished.value) { if (Baritone.settings().notificationOnBuildFinished.value) {
NotificationHelper.notify("Done building", false); logNotification("Done building", false);
} }
onLostControl(); onLostControl();
return null; return null;

View File

@ -23,7 +23,6 @@ import baritone.api.process.ICustomGoalProcess;
import baritone.api.process.PathingCommand; import baritone.api.process.PathingCommand;
import baritone.api.process.PathingCommandType; import baritone.api.process.PathingCommandType;
import baritone.utils.BaritoneProcessHelper; import baritone.utils.BaritoneProcessHelper;
import baritone.utils.NotificationHelper;
/** /**
* As set by ExampleBaritoneControl or something idk * As set by ExampleBaritoneControl or something idk
@ -94,8 +93,8 @@ public final class CustomGoalProcess extends BaritoneProcessHelper implements IC
if (Baritone.settings().disconnectOnArrival.value) { if (Baritone.settings().disconnectOnArrival.value) {
ctx.world().sendQuittingDisconnectingPacket(); ctx.world().sendQuittingDisconnectingPacket();
} }
if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnPathComplete.value) { if (Baritone.settings().notificationOnPathComplete.value) {
NotificationHelper.notify("Pathing complete", false); logNotification("Pathing complete", false);
} }
return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL); return new PathingCommand(this.goal, PathingCommandType.CANCEL_AND_SET_GOAL);
} }

View File

@ -29,7 +29,6 @@ import baritone.api.process.PathingCommandType;
import baritone.api.utils.MyChunkPos; import baritone.api.utils.MyChunkPos;
import baritone.cache.CachedWorld; import baritone.cache.CachedWorld;
import baritone.utils.BaritoneProcessHelper; import baritone.utils.BaritoneProcessHelper;
import baritone.utils.NotificationHelper;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet; import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
@ -84,8 +83,8 @@ public final class ExploreProcess extends BaritoneProcessHelper implements IExpl
public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) { public PathingCommand onTick(boolean calcFailed, boolean isSafeToCancel) {
if (calcFailed) { if (calcFailed) {
logDirect("Failed"); logDirect("Failed");
if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnExploreFinished.value) { if (Baritone.settings().notificationOnExploreFinished.value) {
NotificationHelper.notify("Exploration failed", true); logNotification("Exploration failed", true);
} }
onLostControl(); onLostControl();
return null; return null;
@ -93,8 +92,8 @@ public final class ExploreProcess extends BaritoneProcessHelper implements IExpl
IChunkFilter filter = calcFilter(); IChunkFilter filter = calcFilter();
if (!Baritone.settings().disableCompletionCheck.value && filter.countRemain() == 0) { if (!Baritone.settings().disableCompletionCheck.value && filter.countRemain() == 0) {
logDirect("Explored all chunks"); logDirect("Explored all chunks");
if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnExploreFinished.value) { if (Baritone.settings().notificationOnExploreFinished.value) {
NotificationHelper.notify("Explored all chunks", false); logNotification("Explored all chunks", false);
} }
onLostControl(); onLostControl();
return null; return null;

View File

@ -31,7 +31,6 @@ import baritone.api.utils.input.Input;
import baritone.cache.WorldScanner; import baritone.cache.WorldScanner;
import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper; import baritone.utils.BaritoneProcessHelper;
import baritone.utils.NotificationHelper;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -272,8 +271,8 @@ public final class FarmProcess extends BaritoneProcessHelper implements IFarmPro
if (calcFailed) { if (calcFailed) {
logDirect("Farm failed"); logDirect("Farm failed");
if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnFarmFail.value) { if (Baritone.settings().notificationOnFarmFail.value) {
NotificationHelper.notify("Farm failed", true); logNotification("Farm failed", true);
} }
onLostControl(); onLostControl();
return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE); return new PathingCommand(null, PathingCommandType.REQUEST_PAUSE);

View File

@ -30,7 +30,6 @@ import baritone.pathing.movement.CalculationContext;
import baritone.pathing.movement.MovementHelper; import baritone.pathing.movement.MovementHelper;
import baritone.utils.BaritoneProcessHelper; import baritone.utils.BaritoneProcessHelper;
import baritone.utils.BlockStateInterface; import baritone.utils.BlockStateInterface;
import baritone.utils.NotificationHelper;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockAir; import net.minecraft.block.BlockAir;
import net.minecraft.block.BlockFalling; import net.minecraft.block.BlockFalling;
@ -89,15 +88,15 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
if (calcFailed) { if (calcFailed) {
if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) { if (!knownOreLocations.isEmpty() && Baritone.settings().blacklistClosestOnFailure.value) {
logDirect("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance..."); logDirect("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance...");
if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnMineFail.value) { if (Baritone.settings().notificationOnMineFail.value) {
NotificationHelper.notify("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance...", true); logNotification("Unable to find any path to " + filter + ", blacklisting presumably unreachable closest instance...", true);
} }
knownOreLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(blacklist::add); knownOreLocations.stream().min(Comparator.comparingDouble(ctx.player()::getDistanceSq)).ifPresent(blacklist::add);
knownOreLocations.removeIf(blacklist::contains); knownOreLocations.removeIf(blacklist::contains);
} else { } else {
logDirect("Unable to find any path to " + filter + ", canceling mine"); logDirect("Unable to find any path to " + filter + ", canceling mine");
if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnMineFail.value) { if (Baritone.settings().notificationOnMineFail.value) {
NotificationHelper.notify("Unable to find any path to " + filter + ", canceling mine", true); logNotification("Unable to find any path to " + filter + ", canceling mine", true);
} }
cancel(); cancel();
return null; return null;
@ -232,8 +231,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro
locs.addAll(dropped); locs.addAll(dropped);
if (locs.isEmpty()) { if (locs.isEmpty()) {
logDirect("No locations for " + filter + " known, cancelling"); logDirect("No locations for " + filter + " known, cancelling");
if (Baritone.settings().desktopNotifications.value && Baritone.settings().notificationOnMineFail.value) { if (Baritone.settings().notificationOnMineFail.value) {
NotificationHelper.notify("No locations for " + filter + " known, cancelling", true); logNotification("No locations for " + filter + " known, cancelling", true);
} }
cancel(); cancel();
return; return;