sync event refactoring. Delombok some stuff and fix rogue classloading.

This commit is contained in:
FalsePattern committed 2022-08-18 17:45:42 +02:00
1 parent a479935017
commit aaa0fca75f
7 files changed
+97 -60

No files matched your search

@@ -21,8 +21,6 @@
package com.falsepattern.lib.config.event;
import com.falsepattern.lib.StableAPI;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.val;
import cpw.mods.fml.common.FMLCommonHandler;
@@ -37,10 +35,12 @@ import cpw.mods.fml.relauncher.SideOnly;
*/
@SideOnly(Side.CLIENT)
@StableAPI(since = "0.10.0")
@NoArgsConstructor(access = AccessLevel.PROTECTED,
onConstructor_ = @StableAPI.Internal)
public class AllConfigSyncEvent extends Event {
@StableAPI.Internal
public AllConfigSyncEvent() {
}
@StableAPI.Internal
public static boolean postStart() {
val event = new Start();
@@ -55,9 +55,11 @@ public class AllConfigSyncEvent extends Event {
@SideOnly(Side.CLIENT)
@StableAPI(since = "0.10.0")
@NoArgsConstructor(access = AccessLevel.PUBLIC,
onConstructor_ = @StableAPI.Internal)
public static final class Start extends AllConfigSyncEvent {
@StableAPI.Internal
public Start() {
}
@Override
public boolean isCancelable() {
return true;
@@ -66,8 +68,9 @@ public class AllConfigSyncEvent extends Event {
@SideOnly(Side.CLIENT)
@StableAPI(since = "0.10.0")
@NoArgsConstructor(access = AccessLevel.PUBLIC,
onConstructor_ = @StableAPI.Internal)
public static final class End extends AllConfigSyncEvent {
@StableAPI.Internal
public End() {
}
}
}
@@ -21,8 +21,6 @@
package com.falsepattern.lib.config.event;
import com.falsepattern.lib.StableAPI;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.val;
import cpw.mods.fml.common.FMLCommonHandler;
@@ -37,12 +35,15 @@ import cpw.mods.fml.relauncher.SideOnly;
*/
@SideOnly(Side.CLIENT)
@StableAPI(since = "0.10.0")
@RequiredArgsConstructor(access = AccessLevel.PROTECTED,
onConstructor_ = @StableAPI.Internal)
public class ConfigSyncEvent extends Event {
@StableAPI.Expose
public final Class<?> configClass;
@StableAPI.Internal
public ConfigSyncEvent(Class<?> configClass) {
this.configClass = configClass;
}
@StableAPI.Internal
public static boolean postStart(Class<?> configClass) {
val event = new Start(configClass);
@@ -21,8 +21,6 @@
package com.falsepattern.lib.config.event;
import com.falsepattern.lib.StableAPI;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import net.minecraft.entity.player.EntityPlayerMP;
import cpw.mods.fml.common.FMLCommonHandler;
@@ -38,9 +36,11 @@ import java.util.List;
* {@link #postClient}
*/
@StableAPI(since = "0.10.0")
@RequiredArgsConstructor(access = AccessLevel.PROTECTED,
onConstructor_ = @StableAPI.Internal)
public class ConfigSyncRequestEvent extends Event {
@StableAPI.Internal
public ConfigSyncRequestEvent() {
}
@StableAPI.Expose
public static void postClient() {
FMLCommonHandler.instance().bus().post(new Client());
@@ -52,18 +52,21 @@ public class ConfigSyncRequestEvent extends Event {
}
@StableAPI(since = "0.10.0")
@RequiredArgsConstructor(access = AccessLevel.PROTECTED,
onConstructor_ = @StableAPI.Internal)
public static final class Client extends ConfigSyncRequestEvent {
@StableAPI.Internal
public Client() {
}
}
@StableAPI(since = "0.10.0")
@RequiredArgsConstructor(access = AccessLevel.PUBLIC,
onConstructor_ = @StableAPI.Internal)
public static final class Server extends ConfigSyncRequestEvent {
private final List<EntityPlayerMP> players;
@StableAPI.Internal
public Server(List<EntityPlayerMP> players) {
this.players = players;
}
@StableAPI.Expose
public List<EntityPlayerMP> getPlayers() {
return Collections.unmodifiableList(players);
@@ -27,8 +27,6 @@ import com.falsepattern.lib.text.FormattedText;
import com.falsepattern.lib.toasts.GuiToast;
import com.falsepattern.lib.toasts.SimpleToast;
import com.falsepattern.lib.toasts.icon.ToastBG;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.val;
import net.minecraft.util.EnumChatFormatting;
@@ -40,8 +38,6 @@ import cpw.mods.fml.relauncher.SideOnly;
import java.lang.reflect.Field;
@StableAPI(since = "0.10.0")
@RequiredArgsConstructor(access = AccessLevel.PROTECTED,
onConstructor_ = @StableAPI.Internal)
public abstract class ConfigValidationFailureEvent extends Event {
@StableAPI.Expose
public final String reason;
@@ -54,6 +50,15 @@ public abstract class ConfigValidationFailureEvent extends Event {
@StableAPI.Expose
public final int listIndex;
@StableAPI.Internal
public ConfigValidationFailureEvent(String reason, Class<?> configClass, String fieldName, boolean listElement, int listIndex) {
this.reason = reason;
this.configClass = configClass;
this.fieldName = fieldName;
this.listElement = listElement;
this.listIndex = listIndex;
}
@StableAPI.Internal
public static void postNumericRangeOutOfBounds(Field field, int listIndex, String value, String min, String max) {
FMLCommonHandler.instance()
@@ -0,0 +1,57 @@
package com.falsepattern.lib.internal.impl.config;
import com.falsepattern.lib.config.event.ConfigSyncRequestEvent;
import com.falsepattern.lib.internal.FalsePatternLib;
import com.falsepattern.lib.internal.impl.config.net.SyncPrompt;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import lombok.val;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ConfigSyncEventHandler {
private static ConfigSyncEventHandler instance;
public static void registerBus() {
if (instance == null) {
instance = new ConfigSyncEventHandler();
MinecraftForge.EVENT_BUS.register(instance);
FMLCommonHandler.instance().bus().register(instance);
}
}
@SneakyThrows
@SubscribeEvent
public void onJoinWorld(EntityJoinWorldEvent e) {
if (e.world.isRemote && e.entity instanceof EntityClientPlayerMP) {
ConfigurationManagerImpl.sendSyncRequest();
}
}
@SideOnly(Side.CLIENT)
@SneakyThrows
@SubscribeEvent
public void onSyncRequestClient(ConfigSyncRequestEvent.Client e) {
ConfigurationManagerImpl.sendSyncRequest();
}
@SubscribeEvent
public void onSyncRequestServer(ConfigSyncRequestEvent.Server e) {
val players = e.getPlayers();
if (players.size() == 0) {
FalsePatternLib.NETWORK.sendToAll(new SyncPrompt());
} else {
for (EntityPlayerMP player : e.getPlayers()) {
FalsePatternLib.NETWORK.sendTo(new SyncPrompt(), player);
}
}
}
}
@@ -24,11 +24,9 @@ import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.config.ConfigException;
import com.falsepattern.lib.config.event.AllConfigSyncEvent;
import com.falsepattern.lib.config.event.ConfigSyncEvent;
import com.falsepattern.lib.config.event.ConfigSyncRequestEvent;
import com.falsepattern.lib.config.event.ConfigValidationFailureEvent;
import com.falsepattern.lib.internal.FalsePatternLib;
import com.falsepattern.lib.internal.config.LibraryConfig;
import com.falsepattern.lib.internal.impl.config.net.SyncPrompt;
import com.falsepattern.lib.internal.impl.config.net.SyncRequest;
import com.falsepattern.lib.text.FormattedText;
import com.falsepattern.lib.toasts.GuiToast;
@@ -39,15 +37,11 @@ import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
import lombok.val;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import cpw.mods.fml.client.config.IConfigElement;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
@@ -265,39 +259,12 @@ public class ConfigurationManagerImpl {
MinecraftForge.EVENT_BUS.register(instance);
}
private static void sendSyncRequest() throws IOException {
static void sendSyncRequest() throws IOException {
val event = new SyncRequest();
event.transmit();
FalsePatternLib.NETWORK.sendToServer(event);
}
@SneakyThrows
@SubscribeEvent
public void onJoinWorld(EntityJoinWorldEvent e) {
if (e.world.isRemote && e.entity instanceof EntityClientPlayerMP) {
sendSyncRequest();
}
}
@SideOnly(Side.CLIENT)
@SneakyThrows
@SubscribeEvent
public void onSyncRequestClient(ConfigSyncRequestEvent.Client e) {
sendSyncRequest();
}
@SubscribeEvent
public void onSyncRequestServer(ConfigSyncRequestEvent.Server e) {
val players = e.getPlayers();
if (players.size() == 0) {
FalsePatternLib.NETWORK.sendToAll(new SyncPrompt());
} else {
for (EntityPlayerMP player : e.getPlayers()) {
FalsePatternLib.NETWORK.sendTo(new SyncPrompt(), player);
}
}
}
@SubscribeEvent
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent event) {
init();
@@ -24,6 +24,7 @@ import com.falsepattern.lib.config.ConfigException;
import com.falsepattern.lib.config.ConfigurationManager;
import com.falsepattern.lib.internal.FalsePatternLib;
import com.falsepattern.lib.internal.config.LibraryConfig;
import com.falsepattern.lib.internal.impl.config.ConfigSyncEventHandler;
import com.falsepattern.lib.internal.impl.config.ConfigurationManagerImpl;
import com.falsepattern.lib.internal.impl.config.net.SyncPrompt;
import com.falsepattern.lib.internal.impl.config.net.SyncPromptHandler;
@@ -86,7 +87,7 @@ public class CommonProxy {
}
public void postInit(FMLPostInitializationEvent e) {
ConfigSyncEventHandler.registerBus();
}