Skip to content

Commit

Permalink
Future-proof Voyager support
Browse files Browse the repository at this point in the history
  • Loading branch information
MineGame159 committed Oct 22, 2023
1 parent 01ed966 commit 21a1c4e
Showing 1 changed file with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}
}
}

0 comments on commit 21a1c4e

Please sign in to comment.