mirror of
https://github.com/GTNewHorizons/EnderCore.git
synced 2026-11-21 12:32:15 +00:00
Add support for scala objects when using @Handler
This commit is contained in:
1 parent
58ddb5b251
commit
5060a9ce5e
2 files changed
+20
-2
No files matched your search
@@ -144,7 +144,10 @@ public class GuiEnhancedModList extends GuiModList {
|
||||
@Override
|
||||
public void initGui() {
|
||||
// Super code reinitializes the mod list every time, need to preserve scroll state
|
||||
float scroll = getGuiModListScroll();
|
||||
float scroll = 0;
|
||||
if (getGuiModList() != null) {
|
||||
scroll = getGuiModListScroll();
|
||||
}
|
||||
|
||||
super.initGui();
|
||||
|
||||
|
||||
@@ -123,7 +123,13 @@ public class Handlers {
|
||||
* The handler should be grabbed from the static {@code instance()} method
|
||||
* of the class
|
||||
*/
|
||||
METHOD;
|
||||
METHOD,
|
||||
|
||||
/**
|
||||
* Added for scala compat, not necessary to set explicitly ({@link #AUTO}
|
||||
* will find this).
|
||||
*/
|
||||
SCALA_OBJECT;
|
||||
|
||||
boolean matches(Inst other) {
|
||||
return this == AUTO || other == AUTO || other == this;
|
||||
@@ -279,6 +285,15 @@ public class Handlers {
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (pref.matches(SCALA_OBJECT)) {
|
||||
try {
|
||||
Field inst = Class.forName(c.getName()+ "$").getDeclaredField("MODULE$");
|
||||
inst.setAccessible(true);
|
||||
return inst.get(null);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Could not instantiate @Handler class " + c.getName() + " or access INSTANCE field or instance() method.");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user