Skip to content

Commit

Permalink
Fixed Bug with Customization Overwriting Server Config
Browse files Browse the repository at this point in the history
  • Loading branch information
hammy275 committed Jun 24, 2022
1 parent f61f732 commit 489851c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
39 changes: 24 additions & 15 deletions src/main/java/net/blf02/immersivemc/common/config/ActiveConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.blf02.immersivemc.ImmersiveMC;
import net.blf02.immersivemc.common.network.Network;
import net.blf02.immersivemc.common.network.packet.ConfigSyncPacket;
import net.minecraft.client.Minecraft;
import net.minecraft.network.PacketBuffer;

public class ActiveConfig {
Expand Down Expand Up @@ -43,7 +44,7 @@ public static void loadConfigFromPacket(PacketBuffer buffer) {
}
// We combine client config with server, so if a user doesn't want to use an immersion, they don't
// even if a server is OK with it.
loadConfigFromFile();
loadConfigFromFile(true);
useAnvilImmersion = buffer.readBoolean() && useAnvilImmersion;
useBrewingImmersion = buffer.readBoolean() && useBrewingImmersion;
useChestImmersion = buffer.readBoolean() && useChestImmersion;
Expand All @@ -62,20 +63,28 @@ public static void loadConfigFromPacket(PacketBuffer buffer) {
}

public static void loadConfigFromFile() {
// Synced values
useAnvilImmersion = ImmersiveMCConfig.useAnvilImmersion.get();
useBrewingImmersion = ImmersiveMCConfig.useBrewingImmersion.get();
useChestImmersion = ImmersiveMCConfig.useChestImmersion.get();
useCraftingImmersion = ImmersiveMCConfig.useCraftingImmersion.get();
useFurnaceImmersion = ImmersiveMCConfig.useFurnaceImmersion.get();
useJukeboxImmersion = ImmersiveMCConfig.useJukeboxImmersion.get();
useRangedGrab = ImmersiveMCConfig.useRangedGrab.get();
useButton = ImmersiveMCConfig.useButton.get();
useETableImmersion = ImmersiveMCConfig.useETableImmersion.get();
useCampfireImmersion = ImmersiveMCConfig.useCampfireImmersion.get();
useLever = ImmersiveMCConfig.useLever.get();
useBackpack = ImmersiveMCConfig.useBackpack.get();
useRepeaterImmersion = ImmersiveMCConfig.useRepeaterImmersion.get();
loadConfigFromFile(false);
}

public static void loadConfigFromFile(boolean forceLoadServerSettings) {
// Synced values (only loaded if we're not in a server)
if (Minecraft.getInstance().level == null || forceLoadServerSettings) {
useAnvilImmersion = ImmersiveMCConfig.useAnvilImmersion.get();
useBrewingImmersion = ImmersiveMCConfig.useBrewingImmersion.get();
useChestImmersion = ImmersiveMCConfig.useChestImmersion.get();
useCraftingImmersion = ImmersiveMCConfig.useCraftingImmersion.get();
useFurnaceImmersion = ImmersiveMCConfig.useFurnaceImmersion.get();
useJukeboxImmersion = ImmersiveMCConfig.useJukeboxImmersion.get();
useRangedGrab = ImmersiveMCConfig.useRangedGrab.get();
useButton = ImmersiveMCConfig.useButton.get();
useETableImmersion = ImmersiveMCConfig.useETableImmersion.get();
useCampfireImmersion = ImmersiveMCConfig.useCampfireImmersion.get();
useLever = ImmersiveMCConfig.useLever.get();
useBackpack = ImmersiveMCConfig.useBackpack.get();
useRepeaterImmersion = ImmersiveMCConfig.useRepeaterImmersion.get();
} else {
ImmersiveMC.LOGGER.debug("Not re-loading immersive options since we're in a world!");
}

// Non-synced values
backpackColor = ImmersiveMCConfig.backpackColor.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void onPlayerTick(TickEvent.PlayerTickEvent event) {
@SubscribeEvent
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
if (!event.getPlayer().level.isClientSide && event.getPlayer() instanceof ServerPlayerEntity) {
ActiveConfig.loadConfigFromFile();
ActiveConfig.loadConfigFromFile(true);
Network.INSTANCE.send(PacketDistributor.PLAYER.with(() -> (ServerPlayerEntity) event.getPlayer()),
new ConfigSyncPacket());
}
Expand Down

0 comments on commit 489851c

Please sign in to comment.