Skip to content

Commit 09cb7f4

Browse files
committed
Dear Essential, stop changing the way you handle configs this often 🙏
Remote Control: = Fixed disabling Essential's Screenshot Manager for the new version
1 parent 4bf76c1 commit 09cb7f4

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ baseGroup=com.jelly.farmhelperv2
44
mcVersion=1.8.9
55
modid=farmhelperv2
66
modName=FarmHelper
7-
version=2.8.8-pre2
7+
version=2.8.8-pre3
88
shouldRelease=true

src/main/java/com/jelly/farmhelperv2/remote/command/commands/ClientCommand.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,46 @@ private static void disablePatcherScrenshotManager() {
8181
}
8282
}
8383

84+
// Why did they switch back to static methods again right after I finally fixed it?...
8485
private static void disableEssentialScreenshotManager() {
8586
if (ReflectionUtils.hasPackageInstalled("gg.essential")) {
8687
try {
87-
// Get the EssentialConfig class
8888
Class<?> essentialConfigClass = Class.forName("gg.essential.config.EssentialConfig");
8989

90-
// Get the INSTANCE field
90+
Field screenshotsStateField = essentialConfigClass.getDeclaredField("essentialScreenshotsState");
91+
screenshotsStateField.setAccessible(true);
92+
Object essentialScreenshotsState = screenshotsStateField.get(null);
93+
94+
Method getMethod = essentialScreenshotsState.getClass().getMethod("get");
95+
getMethod.setAccessible(true);
96+
97+
Boolean currentValue = (Boolean) getMethod.invoke(essentialScreenshotsState);
98+
if (currentValue != null && !currentValue) {
99+
return;
100+
}
101+
102+
Method setMethod = essentialScreenshotsState.getClass().getMethod("set", Object.class);
103+
setMethod.setAccessible(true);
104+
setMethod.invoke(essentialScreenshotsState, false);
105+
106+
LogUtils.sendWarning("Disabling Essential Mod's Screenshot Manager");
107+
} catch (Exception e) {
108+
LogUtils.sendError("Failed to disable Essential Mod's Screenshot Manager. Trying the other method...");
109+
disableOldEssentialScreenshotManager();
110+
e.printStackTrace();
111+
}
112+
}
113+
}
114+
115+
private static void disableOldEssentialScreenshotManager() {
116+
if (ReflectionUtils.hasPackageInstalled("gg.essential")) {
117+
try {
118+
Class<?> essentialConfigClass = Class.forName("gg.essential.config.EssentialConfig");
119+
91120
Field instanceField = essentialConfigClass.getDeclaredField("INSTANCE");
92121
instanceField.setAccessible(true);
93122
Object configInstance = instanceField.get(null);
94123

95-
// Get the essentialScreenshots field
96124
Field screenshotsField = essentialConfigClass.getDeclaredField("essentialScreenshots");
97125
screenshotsField.setAccessible(true);
98126

@@ -101,17 +129,14 @@ private static void disableEssentialScreenshotManager() {
101129
modifiersField.setAccessible(true);
102130
modifiersField.setInt(screenshotsField, screenshotsField.getModifiers() & ~Modifier.FINAL);
103131

104-
// Set essentialScreenshots to false
105132
screenshotsField.set(null, false);
106133

107134
// Call markDirty() method from Vigilant superclass to save the changes
108135
Method markDirtyMethod = essentialConfigClass.getSuperclass().getDeclaredMethod("markDirty");
109136
markDirtyMethod.setAccessible(true);
110137
markDirtyMethod.invoke(configInstance);
111-
112-
LogUtils.sendWarning("Disabling Essential Mod's Screenshot Manager");
113138
} catch (Exception e) {
114-
LogUtils.sendError("Failed to disable Essential Mod's Screenshot Manager. Please disable it manually.");
139+
LogUtils.sendError("Failed to disable Essential Mod's Screenshot Manager again. Please disable it manually.");
115140
e.printStackTrace();
116141
}
117142
}

0 commit comments

Comments
 (0)