mirror of
https://github.com/CompeyDev/touch-grass-reminder.git
synced 2025-01-05 18:39:10 +00:00
fix: load & apply config explicitly
This commit is contained in:
parent
2d9aefccb0
commit
cdc6cf7299
2 changed files with 24 additions and 4 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import xyz.devcomp.touch_grass_reminder.config.ConfigHandler;
|
||||||
import xyz.devcomp.touch_grass_reminder.config.ConfigModel;
|
import xyz.devcomp.touch_grass_reminder.config.ConfigModel;
|
||||||
import xyz.devcomp.touch_grass_reminder.utils.PlayDurationHandler;
|
import xyz.devcomp.touch_grass_reminder.utils.PlayDurationHandler;
|
||||||
|
|
||||||
|
@ -16,7 +17,7 @@
|
||||||
|
|
||||||
public class TouchGrassReminderClient implements ClientModInitializer {
|
public class TouchGrassReminderClient implements ClientModInitializer {
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger("Touch Grass Reminder");
|
public static final Logger LOGGER = LoggerFactory.getLogger("Touch Grass Reminder");
|
||||||
private ConfigModel config = new ConfigModel();
|
private ConfigModel config = new ConfigHandler().getInstance();
|
||||||
private Thread thread;
|
private Thread thread;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,12 +29,16 @@ public void onInitializeClient(ModContainer mod) {
|
||||||
if (config.isEnabled) {
|
if (config.isEnabled) {
|
||||||
ClientPlayConnectionEvents.JOIN.register((net, packet, client) -> {
|
ClientPlayConnectionEvents.JOIN.register((net, packet, client) -> {
|
||||||
UUID sessionId = net.getId();
|
UUID sessionId = net.getId();
|
||||||
ServerData serverInfo = net.getServerData() == null ? new ServerData("Unknown", "Unknown", false)
|
ServerData serverInfo = net.getServerData();
|
||||||
: net.getServerData();
|
|
||||||
|
|
||||||
LOGGER.info(
|
if (serverInfo != null) {
|
||||||
|
LOGGER.info(
|
||||||
"Player initiated connection; sessionId={}, name={}, version={}, protocolVersion={}, isLocal={}",
|
"Player initiated connection; sessionId={}, name={}, version={}, protocolVersion={}, isLocal={}",
|
||||||
sessionId, serverInfo.name, serverInfo.version, serverInfo.protocol, serverInfo.isLan());
|
sessionId, serverInfo.name, serverInfo.version, serverInfo.protocol, serverInfo.isLan());
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("Could not get details about joined server.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
PlayDurationHandler worker = new PlayDurationHandler(client, System.currentTimeMillis(),
|
PlayDurationHandler worker = new PlayDurationHandler(client, System.currentTimeMillis(),
|
||||||
config.reminderFrequency * 60 * 60 * 1000);
|
config.reminderFrequency * 60 * 60 * 1000);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import xyz.devcomp.touch_grass_reminder.client.TouchGrassReminderClient;
|
||||||
|
|
||||||
import org.quiltmc.loader.api.QuiltLoader;
|
import org.quiltmc.loader.api.QuiltLoader;
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@
|
||||||
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
|
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
|
||||||
|
|
||||||
public class ConfigHandler {
|
public class ConfigHandler {
|
||||||
|
private boolean isLoaded = false;
|
||||||
public static final ConfigClassHandler<ConfigModel> HANDLER = ConfigClassHandler.createBuilder(ConfigModel.class)
|
public static final ConfigClassHandler<ConfigModel> HANDLER = ConfigClassHandler.createBuilder(ConfigModel.class)
|
||||||
.id(new ResourceLocation("touchgrassreminder", "config"))
|
.id(new ResourceLocation("touchgrassreminder", "config"))
|
||||||
.serializer(config -> GsonConfigSerializerBuilder.create(config)
|
.serializer(config -> GsonConfigSerializerBuilder.create(config)
|
||||||
|
@ -17,7 +19,20 @@ public class ConfigHandler {
|
||||||
.build())
|
.build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
private void loadConfig() {
|
||||||
|
if (!this.isLoaded) {
|
||||||
|
this.isLoaded = HANDLER.load();
|
||||||
|
TouchGrassReminderClient.LOGGER.info("Config not loaded. Attempting to load.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Screen showGui(Screen parent) {
|
public Screen showGui(Screen parent) {
|
||||||
|
this.loadConfig();
|
||||||
return HANDLER.generateGui().generateScreen(parent);
|
return HANDLER.generateGui().generateScreen(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConfigModel getInstance() {
|
||||||
|
this.loadConfig();
|
||||||
|
return HANDLER.instance();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue