From 21a1c4e311111e90cd4b86a224278500a3f5e16c Mon Sep 17 00:00:00 2001 From: MineGame159 Date: Sun, 22 Oct 2023 11:02:56 +0200 Subject: [PATCH] Future-proof Voyager support --- .../meteorclient/pathing/PathManagers.java | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/main/java/meteordevelopment/meteorclient/pathing/PathManagers.java b/src/main/java/meteordevelopment/meteorclient/pathing/PathManagers.java index 0598ce704f..d7f9ebf45d 100644 --- a/src/main/java/meteordevelopment/meteorclient/pathing/PathManagers.java +++ b/src/main/java/meteordevelopment/meteorclient/pathing/PathManagers.java @@ -8,6 +8,8 @@ import meteordevelopment.meteorclient.MeteorClient; import meteordevelopment.meteorclient.utils.PreInit; +import java.lang.reflect.InvocationTargetException; + public class PathManagers { private static IPathManager INSTANCE = new NopPathManager(); @@ -17,13 +19,31 @@ public static IPathManager get() { @PreInit public static void init() { - try { - Class.forName("baritone.api.BaritoneAPI"); + if (exists("meteordevelopment.voyager.PathManager")) { + try { + INSTANCE = (IPathManager) Class.forName("meteordevelopment.voyager.PathManager").getConstructor().newInstance(); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException | + NoSuchMethodException | ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + if (exists("baritone.api.BaritoneAPI")) { BaritoneUtils.IS_AVAILABLE = true; - INSTANCE = new BaritonePathManager(); - MeteorClient.LOG.info("Found Baritone, using a Baritone path manager"); - } catch (ClassNotFoundException ignored) {} + if (INSTANCE instanceof NopPathManager) + INSTANCE = new BaritonePathManager(); + } + + MeteorClient.LOG.info("Path Manager: {}", INSTANCE.getName()); + } + + private static boolean exists(String name) { + try { + Class.forName(name); + return true; + } catch (ClassNotFoundException e) { + return false; + } } }