Skip to content

Commit

Permalink
fix config event crash
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Dec 6, 2024
1 parent 627125b commit ca6e6ad
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
* <p>
* This is a client-only event, and is never triggered serverside!
*/
@SideOnly(Side.CLIENT)
@StableAPI(since = "0.10.0")
public class AllConfigSyncEvent extends Event {

Expand All @@ -54,7 +53,7 @@ public static void postEnd() {
EventUtil.postOnCommonBus(new End());
}

@SideOnly(Side.CLIENT)
// Only posted on client
@StableAPI(since = "0.10.0")
public static final class Start extends AllConfigSyncEvent {
@StableAPI.Internal
Expand All @@ -67,7 +66,7 @@ public boolean isCancelable() {
}
}

@SideOnly(Side.CLIENT)
// Only posted on client
@StableAPI(since = "0.10.0")
public static final class End extends AllConfigSyncEvent {
@StableAPI.Internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@
import lombok.val;

import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

/**
* This event is pushed on the FMLCommonHandler event bus once each time a single config synchronization has finished.
* <p>
* This is a client-only event, and is never triggered serverside!
*/
@SideOnly(Side.CLIENT)
@StableAPI(since = "0.10.0")
public class ConfigSyncEvent extends Event {
@StableAPI.Expose
Expand All @@ -62,7 +59,6 @@ public static void postEndFailure(Class<?> configClass, Throwable error) {
EventUtil.postOnCommonBus(new End(configClass, false, error));
}

@SideOnly(Side.CLIENT)
@StableAPI(since = "0.10.0")
public static final class Start extends ConfigSyncEvent {

Expand All @@ -77,7 +73,6 @@ public boolean isCancelable() {
}
}

@SideOnly(Side.CLIENT)
@StableAPI(since = "0.10.0")
public static final class End extends ConfigSyncEvent {
@StableAPI.Expose
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ public static void postServer(List<EntityPlayerMP> players) {
EventUtil.postOnCommonBus(new Server(new ArrayList<>(players)));
}

// Only posted on client
@StableAPI(since = "0.10.0")
public static final class Client extends ConfigSyncRequestEvent {
@StableAPI.Internal
public Client() {
}
}

// Only posted on server
@StableAPI(since = "0.10.0")
public static final class Server extends ConfigSyncRequestEvent {
private final List<EntityPlayerMP> players;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
import com.falsepattern.lib.internal.FPLog;
import com.falsepattern.lib.internal.config.ConfigEngineConfig;
import com.falsepattern.lib.internal.config.MiscConfig;
import com.falsepattern.lib.text.FormattedText;
import com.falsepattern.lib.toasts.GuiToast;
import com.falsepattern.lib.toasts.SimpleToast;
Expand Down Expand Up @@ -75,6 +74,9 @@ public void onConfigSyncFinished(ConfigSyncEvent.End e) {
false,
5000));
}
if (ConfigEngineConfig.CONFIG_SYNC_SUCCESS_LOGGING != ConfigEngineConfig.LoggingLevel.None) {
FPLog.LOG.info("Synced config: {}:{}", cfg.modid(), cfg.category());
}
} else {
if (ConfigEngineConfig.CONFIG_SYNC_FAILURE_LOGGING == ConfigEngineConfig.LoggingLevel.LogAndToast) {
GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK,
Expand All @@ -86,6 +88,13 @@ public void onConfigSyncFinished(ConfigSyncEvent.End e) {
false,
5000));
}
if (ConfigEngineConfig.CONFIG_SYNC_FAILURE_LOGGING != ConfigEngineConfig.LoggingLevel.None) {
FPLog.LOG.error("Failed to sync config: {}:{}", cfg.modid(), cfg.category());
val t = e.error;
if (t != null) {
FPLog.LOG.error(t.getMessage(), t);
}
}

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,4 @@ public void onValidationErrorLog(ConfigValidationFailureEvent e) {
e.logWarn();
}
}

@SubscribeEvent
public void onConfigSyncFinished(ConfigSyncEvent.End e) {
if (e.successful) {
if (ConfigEngineConfig.CONFIG_SYNC_SUCCESS_LOGGING != ConfigEngineConfig.LoggingLevel.None) {
val cfg = e.configClass.getAnnotation(Config.class);
FPLog.LOG.info("Synced config: {}:{}", cfg.modid(), cfg.category());
}
} else {
if (ConfigEngineConfig.CONFIG_SYNC_FAILURE_LOGGING != ConfigEngineConfig.LoggingLevel.None) {
val cfg = e.configClass.getAnnotation(Config.class);
FPLog.LOG.error("Failed to sync config: {}:{}", cfg.modid(), cfg.category());
val t = e.error;
if (t != null) {
FPLog.LOG.error(t.getMessage(), t);
}
}
}
}
}

0 comments on commit ca6e6ad

Please # to comment.