|
13 | 13 | import java.util.stream.Collectors; |
14 | 14 |
|
15 | 15 | public interface HexDebugCoreAPI { |
| 16 | + // required methods |
| 17 | + |
16 | 18 | @Nullable |
17 | | - DebugEnvironment getDebugEnv(@NotNull CastingEnvironment env); |
| 19 | + default DebugEnvironment getDebugEnv(@NotNull CastingEnvironment env) { |
| 20 | + return null; |
| 21 | + } |
18 | 22 |
|
19 | | - void printDebugMessage( |
| 23 | + default void printDebugMessage( |
20 | 24 | @NotNull ServerPlayer caster, |
21 | 25 | @NotNull UUID sessionId, |
22 | 26 | @NotNull Component message, |
23 | 27 | @NotNull DebugOutputCategory category, |
24 | 28 | boolean withSource |
25 | | - ); |
| 29 | + ) {} |
| 30 | + |
| 31 | + // singleton service loading |
26 | 32 |
|
27 | 33 | HexDebugCoreAPI INSTANCE = findInstance(); |
28 | 34 |
|
29 | 35 | private static HexDebugCoreAPI findInstance() { |
30 | 36 | var providers = ServiceLoader.load(HexDebugCoreAPI.class).stream().toList(); |
31 | 37 | if (providers.size() > 1) { |
| 38 | + // this should be impossible, barring shenanigans by other addons |
32 | 39 | var names = providers.stream() |
33 | 40 | .map(p -> p.type().getName()) |
34 | 41 | .collect(Collectors.joining(",", "[", "]")); |
35 | 42 | throw new IllegalStateException( |
36 | 43 | "Expected at most one HexDebugCoreAPI implementation on the classpath. Found: " + names |
37 | 44 | ); |
38 | 45 | } else if (providers.size() == 1) { |
| 46 | + // use HexDebug's full API implementation |
39 | 47 | return providers.get(0).get(); |
40 | 48 | } else { |
41 | | - return new HexDebugCoreAPIStubImpl(); |
| 49 | + // fall back to stub implementation if HexDebug isn't present |
| 50 | + return new HexDebugCoreAPI() {}; |
42 | 51 | } |
43 | 52 | } |
44 | 53 | } |
0 commit comments