@@ -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