-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: api not being accessible through TritonAPI
Due to #285, the TritonAPI class in the core module was no longer overshadowing the same class in the api module, effectively breaking the TritonAPI#getInstance method. This commit works around that by saving a reference to the Triton instance in the TritonAPI class ifself.
- Loading branch information
1 parent
aee7002
commit 9d5a140
Showing
7 changed files
with
59 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
core/src/main/java/com/rexcantor64/triton/utils/TritonAPIUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.rexcantor64.triton.utils; | ||
|
||
import com.rexcantor64.triton.api.Triton; | ||
import com.rexcantor64.triton.api.TritonAPI; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* Utility functions to easily register the {@link Triton} instance in | ||
* {@link TritonAPI} for consumption by other plugins. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
public class TritonAPIUtils { | ||
private static final Method REGISTER; | ||
|
||
static { | ||
try { | ||
REGISTER = TritonAPI.class.getDeclaredMethod("register", Triton.class); | ||
REGISTER.setAccessible(true); | ||
|
||
} catch (NoSuchMethodException e) { | ||
throw new RuntimeException("Failed to initialize Triton API", e); | ||
} | ||
} | ||
|
||
public static void register(@NotNull Triton instance) { | ||
try { | ||
REGISTER.invoke(null, instance); | ||
} catch (Exception e) { | ||
com.rexcantor64.triton.Triton.get().getLogger().logError(e, "Failed to initialize Triton API"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters