Skip to content

Commit 21a1c4e

Browse files
committed
Future-proof Voyager support
1 parent 01ed966 commit 21a1c4e

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/main/java/meteordevelopment/meteorclient/pathing/PathManagers.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import meteordevelopment.meteorclient.MeteorClient;
99
import meteordevelopment.meteorclient.utils.PreInit;
1010

11+
import java.lang.reflect.InvocationTargetException;
12+
1113
public class PathManagers {
1214
private static IPathManager INSTANCE = new NopPathManager();
1315

@@ -17,13 +19,31 @@ public static IPathManager get() {
1719

1820
@PreInit
1921
public static void init() {
20-
try {
21-
Class.forName("baritone.api.BaritoneAPI");
22+
if (exists("meteordevelopment.voyager.PathManager")) {
23+
try {
24+
INSTANCE = (IPathManager) Class.forName("meteordevelopment.voyager.PathManager").getConstructor().newInstance();
25+
} catch (InstantiationException | IllegalAccessException | InvocationTargetException |
26+
NoSuchMethodException | ClassNotFoundException e) {
27+
throw new RuntimeException(e);
28+
}
29+
}
2230

31+
if (exists("baritone.api.BaritoneAPI")) {
2332
BaritoneUtils.IS_AVAILABLE = true;
24-
INSTANCE = new BaritonePathManager();
2533

26-
MeteorClient.LOG.info("Found Baritone, using a Baritone path manager");
27-
} catch (ClassNotFoundException ignored) {}
34+
if (INSTANCE instanceof NopPathManager)
35+
INSTANCE = new BaritonePathManager();
36+
}
37+
38+
MeteorClient.LOG.info("Path Manager: {}", INSTANCE.getName());
39+
}
40+
41+
private static boolean exists(String name) {
42+
try {
43+
Class.forName(name);
44+
return true;
45+
} catch (ClassNotFoundException e) {
46+
return false;
47+
}
2848
}
2949
}

0 commit comments

Comments
 (0)