fixed changing settings mid-game not sending updates to the server

This commit is contained in:
Oth3r 2024-05-16 15:09:25 -05:00
commit 1d08ee6775
2 changed files with 10 additions and 6 deletions

View file

@ -5,7 +5,6 @@ import com.google.gson.GsonBuilder;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraft.network.packet.CustomPayload;
import one.oth3r.sit.packet.CustomPayloads; import one.oth3r.sit.packet.CustomPayloads;
public class SitClient implements ClientModInitializer { public class SitClient implements ClientModInitializer {
@ -16,14 +15,19 @@ public class SitClient implements ClientModInitializer {
ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> { ClientPlayConnectionEvents.JOIN.register((handler, sender, client) -> {
inGame = true; inGame = true;
// send a data packet whenever joining a server // send a data packet whenever joining a server
ClientPlayNetworking.send(sendPackets()); sendSettingsPackets();
}); });
// reset inGame // reset inGame
ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> inGame = false); ClientPlayConnectionEvents.DISCONNECT.register((handler, client) -> inGame = false);
} }
public static CustomPayload sendPackets() { /**
Gson gson = new GsonBuilder().disableHtmlEscaping().create(); * sends the settings packets to the server is the client is in game
return new CustomPayloads.SettingsPayload(gson.toJson(Utl.HandSettings.getHandSettings())); */
public static void sendSettingsPackets() {
if (inGame) {
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
ClientPlayNetworking.send(new CustomPayloads.SettingsPayload(gson.toJson(Utl.HandSettings.getHandSettings())));
}
} }
} }

View file

@ -213,7 +213,7 @@ public class Config {
file.write("\nhand.off.whitelist="+gson.toJson(offWhitelist)); file.write("\nhand.off.whitelist="+gson.toJson(offWhitelist));
file.write("\nhand.off.blacklist="+gson.toJson(offBlacklist)); file.write("\nhand.off.blacklist="+gson.toJson(offBlacklist));
// send packets to update the settings on the server // send packets to update the settings on the server
if (SitClient.inGame) SitClient.sendPackets(); SitClient.sendSettingsPackets();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }